[Gd-chatter] r10805 - trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32

andreas at gwydiondylan.org andreas at gwydiondylan.org
Sun Jun 18 00:29:38 CEST 2006


Author: andreas
Date: Sun Jun 18 00:29:36 2006
New Revision: 10805

Modified:
   trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32/misc_utils.c
   trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32/symbol_lookup.c
Log:
job: fd

Use SymFromAddr instead of SymEnumSymbolsForAddr results in dgbhelp.dll actually finding symbols. This slightly improves the debug situation with the VC7 family of linkers (such as Visual Studio .NET 2003).

Modified: trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32/misc_utils.c
==============================================================================
--- trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32/misc_utils.c	(original)
+++ trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32/misc_utils.c	Sun Jun 18 00:29:36 2006
@@ -466,6 +466,9 @@
   LPDBGLIBRARY  last_library;
   LPDBGLIBRARY  new_library;
 
+  debugger_message("Adding DLL: %= %=", info.lpBaseOfDll, info.hFile);
+
+
   // Create the new library first.
 
   new_library = (LPDBGLIBRARY) malloc (sizeof (DBGLIBRARY));
@@ -545,7 +548,10 @@
 void ensure_debug_information_for_library
     (LPDBGPROCESS process, LPDBGLIBRARY module)
 {
+  BOOL success;
+
   if ((module == NULL) || (module->DebugType == NOT_YET_LOADED)) {
+    debugger_message("Loading debug information\n", 0, 0);
 
     module->DebugType = NONE;
     create_library_debug_map(process, module);
@@ -562,15 +568,21 @@
 			NULL,
 			(DWORD64) module->ImageInformation.ImageBase,
 			0);
-      if (base != 0)
+      if (base != 0) {
 	module->SymbolHandlerWorking = 1;
+        debugger_message("Succeeded!\n", 0, 0);
+      }
 
       memset(&(module->ImagehlpModuleStruct), 0, sizeof(IMAGEHLP_MODULE64));
       module->ImagehlpModuleStruct.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
       if (module->SymbolHandlerWorking) {
-	SymGetModuleInfo64(process->ProcessHandle,
-			   (DWORD64) module->ImageInformation.ImageBase,
-			   &(module->ImagehlpModuleStruct));
+	success = 
+          SymGetModuleInfo64(process->ProcessHandle,
+		            (DWORD64) module->ImageInformation.ImageBase,
+		            &(module->ImagehlpModuleStruct));
+	if(!success) {
+          debugger_message("SymGetModuleInfo64 failed with %=\n", GetLastError(), 0);
+        }
       }
     }
   }

Modified: trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32/symbol_lookup.c
==============================================================================
--- trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32/symbol_lookup.c	(original)
+++ trunk/fundev/sources/runtime-manager/debugger-nub/x86-win32/symbol_lookup.c	Sun Jun 18 00:29:36 2006
@@ -37,6 +37,12 @@
 // Adds a pair of function boundaries enclosing "addr" to the specified
 // cache.
 
+char out[1024];
+
+#define debug_me(x, y) \
+  sprintf(out, x, y); \
+  debugger_message(out, 0, 0);
+
 BOOL CALLBACK nub_enumerate_symbol_callback
   (PSYMBOL_INFO pSymInfo,
    ULONG        SymbolSize,
@@ -45,11 +51,13 @@
   LPDBGPROCESS      process = (LPDBGPROCESS) UserContext;
 
   process->SymbolBuffer.Info = *pSymInfo;
-  strcpy(process->SymbolBuffer.Info.Name, pSymInfo->Name);
+//  strcpy(process->SymbolBuffer.Info.Name, pSymInfo->Name);
   
   process->SymbolBufferValid = TRUE;
 
-  return FALSE;			// Don't continue enumerating
+  debug_me("Found symbol: %s", pSymInfo->Name);
+
+  return TRUE;
 }
 
 
@@ -71,11 +79,14 @@
 {
   LPDBGPROCESS      process = (LPDBGPROCESS) nub;
   BOOL              status;
+  DWORD64           dw_disp;
   LPDBGLIBRARY      module 
                       = library_descriptor_from_address (process,
                                                          (DWORD) location);
 
 
+  debug_me("nub_closest_symbol for address 0x%x", location);
+
   ensure_debug_information_for_library(process, module);
 
   switch (module->DebugType) {
@@ -115,28 +126,28 @@
     // If the symbol handler is working, try to use DbgHelp to lookup the
     // symbol.
 
-    process->SymbolBufferValid = FALSE;
+    process->SymbolBuffer.Info.MaxNameLen = 256;
+
+    debug_me("Searching symbol", 0);
 
     status =
-      SymEnumSymbolsForAddr(process->ProcessHandle,
-			    (DWORD64) location,
-			    nub_enumerate_symbol_callback,
-			    process);
-    if (status && process->SymbolBufferValid) {
+      SymFromAddr(process->ProcessHandle,
+	         (DWORD64) location,
+                 &dw_disp,
+                 (SYMBOL_INFO*) &(process->SymbolBuffer.Info));
+    if (status) {
       BYTE    i = 0;
+      debug_me("Located a symbol: %s", process->SymbolBuffer.Info.Name);
       //printf("Located the symbol: ");
-      while(process->SymbolBuffer.Info.Name[i] != '\0') {
-        //printf("%c", process->SymbolBuffer.Name[i]);
-        i++;
-      }
-      //printf("\n");
       (*actual_address) = (TARGET_ADDRESS) process->SymbolBuffer.Info.Address;
       (*offset)
-	= (NUBINT) ((DWORD64) location - process->SymbolBuffer.Info.Address);
+	= (NUBINT) dw_disp;
       // TODO: Something better here.
       // When using DbgHelp's symbol handler, we have no real way to
       // identify the programming language that defined the symbol.
       // This is a slight hack.
+      // In fact, there's a corresponding function in the high-level code...
+      i = strlen(process->SymbolBuffer.Info.Name);
       if ((i > 0) &&
           (process->SymbolBuffer.Info.Name[0] == 'K') &&
           (process->SymbolBuffer.Info.Name[i - 1] == 'I'))
@@ -156,6 +167,11 @@
       return ((NUBINT) 1);
     }
     else {
+      if (status) {
+        debug_me("no symbol found for addr\n",0 );
+      } else {
+	debug_me("Error %x\n", GetLastError());
+      }
       return((NUBINT) 0);
     }
   }
@@ -168,6 +184,9 @@
   int              limit = (int) buf_size;
   char             *name = process->NameCache;
   int              i = 0;
+
+  debug_me("nub_closest_symbol_name",0);
+
   while (i < limit) {
     buf[i] = name[i];
     i++;
@@ -194,6 +213,8 @@
   int               i = 0;
   int               j = 0;
 
+  debug_me("nub_find_symbol_in_library",0);
+
   ensure_debug_information_for_library(process, module);
 
   switch (module->DebugType) {
@@ -248,6 +269,8 @@
 
     process->SymbolBufferValid = FALSE;
 
+    debug_me("Enumerating symbols for %s", extended_name);
+
     status =
       SymEnumSymbols(process->ProcessHandle,
 		     module->ImageInformation.ImageBase,
@@ -260,7 +283,7 @@
       // When using DbgHelp's symbol handler, we have no real way to
       // identify the programming language that defined the symbol.
       // This is a slight hack.
-      if ((name[0] == 'K') && (name[name_length - 1] == 'I'))
+      if ((name[0] == 'K')  && (name[name_length - 1] == 'I'))
         (*language) = DYLAN_LANGUAGE;
       else
         (*language) = C_LANGUAGE;
@@ -292,6 +315,8 @@
   LOOKUP_TABLE      *table;
   DWORD             dwFirst, dwLast;
 
+  debug_me("nub_do_static_symbols",0);
+
   switch (module->DebugType) {
 
   case CODEVIEW_IMAGE:
@@ -331,6 +356,8 @@
   LOOKUP_TABLE      *table;
   DWORD             dwFirst, dwLast;
 
+  debug_me("nub_do_global_symbols",0);
+
   switch (module->DebugType) {
 
   case CODEVIEW_IMAGE:
@@ -370,6 +397,8 @@
   LOOKUP_TABLE      *table;
   DWORD             dwFirst, dwLast;
 
+  debug_me("nub_do_exported_symbols",0);
+
   switch (module->DebugType) {
 
   case CODEVIEW_IMAGE:
@@ -409,6 +438,8 @@
                                                          (DWORD) addr);
   LOOKUP_TABLE      *table;
 
+  debug_me("nub_nearest_symbols",0);
+
   if (module == NULL) {
     (*lookups) = NULL;
     return ((NUBINT) 0);
@@ -448,6 +479,8 @@
                                                          (DWORD) addr);
   BOOL                   status = FALSE;
 
+  debug_me("nub_function_bounding_addresses",0);
+
   ensure_debug_information_for_library(process, module);
 
   // The first place to look is the cache.
@@ -482,6 +515,8 @@
     // DbgHelp did not come through for us, so defer to bruteforce
     // methods.
 
+    debugger_message("Tried to lookup symbols for %= and failed!\n", addr, 0);
+
     module = library_descriptor_from_address (process, (DWORD) addr);
 
     if (module == NULL) {
@@ -518,6 +553,9 @@
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
 
+  debug_me("nub_lexical_variable_name_length",0);
+
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:
@@ -544,6 +582,8 @@
 
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
+  debug_me("nub_lookup_symbol_name_length",0);
+
 
   switch (sym->LookupType) {
 
@@ -570,6 +610,8 @@
 {
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
+  debug_me("nub_lookup_symbol_language_code",0);
+
   return ((NUBINT) (sym->LanguageCode));
 }
 
@@ -581,9 +623,10 @@
    NUBINT buf_size, 
    char *buf)
 {
-
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
+  debug_me("nub_get_lexical_variable_name",0);
+
 
   switch (sym->LookupType) {
 
@@ -608,6 +651,8 @@
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
 
+  debug_me("nub_get_lexical_variable_name_fast",0);
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:
@@ -633,6 +678,8 @@
 {
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
+  debug_me("nub_lookup_symbol_name",0);
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:
@@ -655,6 +702,8 @@
 
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
+  debug_me("nub_lookup_symbol_name_fast",0);
+
 
   switch (sym->LookupType) {
 
@@ -688,6 +737,8 @@
   DWORD               offset;
   DWORD               addr;
 
+  debug_me("nub_lexical_variable_address",0);
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:
@@ -713,10 +764,12 @@
    NUBHANDLE table, 
    NUB_INDEX index)
 {
-
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
 
+  debug_me("nub_lookup_symbol_address",0);
+
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:
@@ -734,10 +787,12 @@
    NUBHANDLE table, 
    NUB_INDEX index)
 {
-
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
 
+  debug_me("nub_lookup_function_debug_start",0);
+
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:
@@ -755,10 +810,12 @@
    NUBHANDLE table, 
    NUB_INDEX index)
 {
-
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
 
+  debug_me("nub_lookup_function_debug_end",0);
+
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:
@@ -780,10 +837,12 @@
    NUBHANDLE table, 
    NUB_INDEX index)
 {
-
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
 
+  debug_me("nub_lookup_function_end",0);
+
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:
@@ -805,6 +864,9 @@
   SYMBOL_LOOKUP_ENTRY *sym = find_entry ((LOOKUP_TABLE*) table,
                                          (DWORD) index);
 
+  debug_me("nub_symbol_is_function",0);
+
+
   switch (sym->LookupType) {
 
   case MAPPED_CODEVIEW_SYMBOL:



More information about the chatter mailing list