BUGFIX: stabs lookup ( particularly line # lookup )
authorRoyce Mitchell III <royce3@ev1.net>
Fri, 17 Dec 2004 17:51:57 +0000 (17:51 +0000)
committerRoyce Mitchell III <royce3@ev1.net>
Fri, 17 Dec 2004 17:51:57 +0000 (17:51 +0000)
svn path=/trunk/; revision=12169

reactos/ntoskrnl/dbg/kdb_stabs.c
reactos/ntoskrnl/dbg/kdb_symbols.c

index 968e9e5..cbe0b72 100644 (file)
@@ -79,32 +79,35 @@ KdbpStabFindEntry(IN PIMAGE_SYMBOL_INFO SymbolInfo,
       StabEntry = StartEntry;
     }
 
       StabEntry = StartEntry;
     }
 
-  for (; (ULONG_PTR)StabEntry < (ULONG_PTR)StabsEnd; StabEntry++)
+  if ( RelativeAddress != NULL )
+  {
+    for (; (ULONG_PTR)StabEntry < (ULONG_PTR)StabsEnd; StabEntry++)
     {
       ULONG_PTR SymbolRelativeAddress;
     {
       ULONG_PTR SymbolRelativeAddress;
-      
+    
       if (StabEntry->n_type != Type)
         continue;
 
       if (RelativeAddress != NULL)
       if (StabEntry->n_type != Type)
         continue;
 
       if (RelativeAddress != NULL)
-        {
-          if (StabEntry->n_value >= SymbolInfo->ImageSize)
-            continue;
+      {
+        if (StabEntry->n_value >= SymbolInfo->ImageSize)
+          continue;
 
 
-          SymbolRelativeAddress = StabEntry->n_value;
-          if ((SymbolRelativeAddress <= (ULONG_PTR)RelativeAddress) &&
-              (SymbolRelativeAddress > AddrFound))
-            {
-             AddrFound = SymbolRelativeAddress;
-             BestStabEntry = StabEntry;
-            }
-        }
-      else
+        if (StabEntry->n_value > (ULONG_PTR)RelativeAddress )
+          break;
+
+        SymbolRelativeAddress = StabEntry->n_value;
+        if ((SymbolRelativeAddress <= (ULONG_PTR)RelativeAddress) &&
+            (SymbolRelativeAddress > AddrFound))
         {
         {
+          AddrFound = SymbolRelativeAddress;
           BestStabEntry = StabEntry;
           BestStabEntry = StabEntry;
-          break;
         }
         }
+      }
     }
     }
+  }
+  else
+    BestStabEntry = StabEntry;
 
   if (BestStabEntry == NULL)
   {
 
   if (BestStabEntry == NULL)
   {
@@ -117,4 +120,3 @@ KdbpStabFindEntry(IN PIMAGE_SYMBOL_INFO SymbolInfo,
 
   return BestStabEntry;
 }
 
   return BestStabEntry;
 }
-
index 02e00b9..e74c14e 100644 (file)
@@ -136,7 +136,7 @@ KdbpSymFindUserModule(IN PVOID Address  OPTIONAL,
         }
       current_entry = current_entry->Flink;
     }
         }
       current_entry = current_entry->Flink;
     }
-    
+
   return FALSE;
 }
 
   return FALSE;
 }
 
@@ -158,7 +158,7 @@ KdbpSymFindModule(IN PVOID Address  OPTIONAL,
   INT Count = 0;
 
   current_entry = ModuleTextListHead.Flink;
   INT Count = 0;
 
   current_entry = ModuleTextListHead.Flink;
-   
+
   while (current_entry != &ModuleTextListHead &&
          current_entry != NULL)
     {
   while (current_entry != &ModuleTextListHead &&
          current_entry != NULL)
     {
@@ -178,7 +178,7 @@ KdbpSymFindModule(IN PVOID Address  OPTIONAL,
         }
       current_entry = current_entry->Flink;
     }
         }
       current_entry = current_entry->Flink;
     }
-    
+
   return KdbpSymFindUserModule(Address, Name, Index-Count, pInfo);
 }
 
   return KdbpSymFindUserModule(Address, Name, Index-Count, pInfo);
 }
 
@@ -241,16 +241,16 @@ KdbpSymFindModuleByIndex(IN INT Index,
 
 /*! \brief Print address...
  *
 
 /*! \brief Print address...
  *
- * Tries to lookup line number, file name and function name for the given 
+ * Tries to lookup line number, file name and function name for the given
  * address and prints it.
  * If no such information is found the address is printed in the format
  * address and prints it.
  * If no such information is found the address is printed in the format
- * <module: offset>, otherwise the format will be 
+ * <module: offset>, otherwise the format will be
  * <module: offset (filename:linenumber (functionname))>
  *
  * \retval TRUE  Module containing \a Address was found, \a Address was printed.
  * \retval FALSE  No module containing \a Address was found, nothing was printed.
  */
  * <module: offset (filename:linenumber (functionname))>
  *
  * \retval TRUE  Module containing \a Address was found, \a Address was printed.
  * \retval FALSE  No module containing \a Address was found, nothing was printed.
  */
-BOOLEAN 
+BOOLEAN
 KdbSymPrintAddress(IN PVOID Address)
 {
   KDB_MODULE_INFO Info;
 KdbSymPrintAddress(IN PVOID Address)
 {
   KDB_MODULE_INFO Info;
@@ -335,14 +335,14 @@ KdbSymGetAddressInformation(IN PIMAGE_SYMBOL_INFO SymbolInfo,
         {
           DPRINT("No function stab entry found. RelativeAddress %p\n", RelativeAddress);
         }
         {
           DPRINT("No function stab entry found. RelativeAddress %p\n", RelativeAddress);
         }
-        
+
       if (LineNumber != NULL && FunctionEntry != NULL)
         {
           /* find stab entry for line number */
       if (LineNumber != NULL && FunctionEntry != NULL)
         {
           /* find stab entry for line number */
-          ULONG_PTR FunctionRelativeAddress = FunctionEntry->n_value - (ULONG_PTR)SymbolInfo->ImageBase;
+          ULONG_PTR FunctionRelativeAddress = RelativeAddress - FunctionEntry->n_value;
           ULONG_PTR AddrFound = 0;
           PSTAB_ENTRY NextLineEntry;
           ULONG_PTR AddrFound = 0;
           PSTAB_ENTRY NextLineEntry;
-          
+
           LineEntry = NextLineEntry = FunctionEntry;
           while (NextLineEntry != NULL)
             {
           LineEntry = NextLineEntry = FunctionEntry;
           while (NextLineEntry != NULL)
             {
@@ -353,9 +353,9 @@ KdbSymGetAddressInformation(IN PIMAGE_SYMBOL_INFO SymbolInfo,
                 break;
               if (NextLineEntry->n_type != N_SLINE)
                 continue;
                 break;
               if (NextLineEntry->n_type != N_SLINE)
                 continue;
-              
-              if (((NextLineEntry->n_value+FunctionRelativeAddress) <= RelativeAddress) &&
-                  (NextLineEntry->n_value > AddrFound))
+
+              if ( NextLineEntry->n_value <= FunctionRelativeAddress
+                && NextLineEntry->n_value >= AddrFound )
                 {
                   AddrFound = NextLineEntry->n_value;
                   LineEntry = NextLineEntry;
                 {
                   AddrFound = NextLineEntry->n_value;
                   LineEntry = NextLineEntry;
@@ -363,13 +363,13 @@ KdbSymGetAddressInformation(IN PIMAGE_SYMBOL_INFO SymbolInfo,
             }
         }
     }
             }
         }
     }
-  
+
   if (FileName != NULL)
     {
       /* find stab entry for file name */
       PCHAR p;
       INT Length;
   if (FileName != NULL)
     {
       /* find stab entry for file name */
       PCHAR p;
       INT Length;
-      
+
       FileEntry = KdbpStabFindEntry(SymbolInfo, N_SO, (PVOID)RelativeAddress, NULL);
       if (FileEntry != NULL)
         {
       FileEntry = KdbpStabFindEntry(SymbolInfo, N_SO, (PVOID)RelativeAddress, NULL);
       if (FileEntry != NULL)
         {
@@ -383,7 +383,7 @@ KdbSymGetAddressInformation(IN PIMAGE_SYMBOL_INFO SymbolInfo,
           DPRINT("No filename stab entry found. RelativeAddress %p\n", RelativeAddress);
         }
     }
           DPRINT("No filename stab entry found. RelativeAddress %p\n", RelativeAddress);
         }
     }
-  
+
   if (((LineNumber   != NULL && LineEntry     == NULL) || LineNumber   == NULL) &&
       ((FileName     != NULL && FileEntry     == NULL) || FileName     == NULL) &&
       ((FunctionName != NULL && FunctionEntry == NULL) || FunctionName == NULL))
   if (((LineNumber   != NULL && LineEntry     == NULL) || LineNumber   == NULL) &&
       ((FileName     != NULL && FileEntry     == NULL) || FileName     == NULL) &&
       ((FunctionName != NULL && FunctionEntry == NULL) || FunctionName == NULL))
@@ -443,10 +443,10 @@ KdbpSymGetSourceAddress(IN PIMAGE_SYMBOL_INFO SymbolInfo,
   PCHAR SymbolName, p;
   CHAR Buffer[512] = "";
   INT Length, FileNameLength, FuncNameLength = 0;
   PCHAR SymbolName, p;
   CHAR Buffer[512] = "";
   INT Length, FileNameLength, FuncNameLength = 0;
-  
+
   if (FuncName == NULL && LineNumber < 1)
     return FALSE;
   if (FuncName == NULL && LineNumber < 1)
     return FALSE;
-  
+
   FileNameLength = strlen(FileName);
   FuncNameLength = strlen(FuncName);
   for (Entry = SymbolInfo->SymbolsBase;
   FileNameLength = strlen(FileName);
   FuncNameLength = strlen(FuncName);
   for (Entry = SymbolInfo->SymbolsBase;
@@ -467,7 +467,7 @@ KdbpSymGetSourceAddress(IN PIMAGE_SYMBOL_INFO SymbolInfo,
         }
       strncat(Buffer, SymbolName, sizeof (Buffer) - 1);
       Buffer[sizeof (Buffer) - 1] = '\0';
         }
       strncat(Buffer, SymbolName, sizeof (Buffer) - 1);
       Buffer[sizeof (Buffer) - 1] = '\0';
-      
+
       Length = strlen(Buffer);
       if (strcmp(Buffer + Length - FileNameLength, FileName) != 0)
         continue;
       Length = strlen(Buffer);
       if (strcmp(Buffer + Length - FileNameLength, FileName) != 0)
         continue;
@@ -513,7 +513,7 @@ KdbpSymGetSourceAddress(IN PIMAGE_SYMBOL_INFO SymbolInfo,
         }
       break;
     }
         }
       break;
     }
-    
+
     return FALSE;
 }
 
     return FALSE;
 }
 
@@ -574,7 +574,7 @@ KdbpSymAddCachedFile(IN PUNICODE_STRING FileName,
                     IN PIMAGE_SYMBOL_INFO SymbolInfo)
 {
   PIMAGE_SYMBOL_INFO_CACHE CacheEntry;
                     IN PIMAGE_SYMBOL_INFO SymbolInfo)
 {
   PIMAGE_SYMBOL_INFO_CACHE CacheEntry;
-  
+
   DPRINT("Adding symbol file: FileBuffer = %p, ImageBase = %p\n",
          SymbolInfo->FileBuffer, SymbolInfo->ImageBase);
 
   DPRINT("Adding symbol file: FileBuffer = %p, ImageBase = %p\n",
          SymbolInfo->FileBuffer, SymbolInfo->ImageBase);
 
@@ -664,7 +664,7 @@ KdbpSymLoadModuleSymbols(IN PUNICODE_STRING FileName,
   IO_STATUS_BLOCK IoStatusBlock;
   PSYMBOLFILE_HEADER SymbolFileHeader;
   PIMAGE_SYMBOL_INFO_CACHE CachedSymbolFile;
   IO_STATUS_BLOCK IoStatusBlock;
   PSYMBOLFILE_HEADER SymbolFileHeader;
   PIMAGE_SYMBOL_INFO_CACHE CachedSymbolFile;
-  
+
   /*  Get the path to the symbol store  */
   wcscpy(TmpFileName, L"\\SystemRoot\\symbols\\");
 
   /*  Get the path to the symbol store  */
   wcscpy(TmpFileName, L"\\SystemRoot\\symbols\\");
 
@@ -747,7 +747,7 @@ KdbpSymLoadModuleSymbols(IN PUNICODE_STRING FileName,
       ZwClose(FileHandle);
       return;
     }
       ZwClose(FileHandle);
       return;
     }
-   
+
   /*  Load file into memory chunk  */
   Status = ZwReadFile(FileHandle,
                       0, 0, 0,
   /*  Load file into memory chunk  */
   Status = ZwReadFile(FileHandle,
                       0, 0, 0,
@@ -779,7 +779,7 @@ KdbpSymLoadModuleSymbols(IN PUNICODE_STRING FileName,
 
   DPRINT("Installed stabs: %wZ (%08x-%08x,%08x)\n",
         FileName,
 
   DPRINT("Installed stabs: %wZ (%08x-%08x,%08x)\n",
         FileName,
-        SymbolInfo->SymbolsBase, 
+        SymbolInfo->SymbolsBase,
         SymbolInfo->SymbolsLength + SymbolInfo->SymbolsBase,
         SymbolInfo->SymbolStringsBase);
 }
         SymbolInfo->SymbolsLength + SymbolInfo->SymbolsBase,
         SymbolInfo->SymbolStringsBase);
 }
@@ -844,7 +844,7 @@ KdbSymFreeProcessSymbols(IN PEPROCESS Process)
   ASSERT(Peb->Ldr);
 
   CurrentEntry = Peb->Ldr->InLoadOrderModuleList.Flink;
   ASSERT(Peb->Ldr);
 
   CurrentEntry = Peb->Ldr->InLoadOrderModuleList.Flink;
-  while (CurrentEntry != &Peb->Ldr->InLoadOrderModuleList && 
+  while (CurrentEntry != &Peb->Ldr->InLoadOrderModuleList &&
         CurrentEntry != NULL)
     {
       Current = CONTAINING_RECORD(CurrentEntry, LDR_MODULE, InLoadOrderModuleList);
         CurrentEntry != NULL)
     {
       Current = CONTAINING_RECORD(CurrentEntry, LDR_MODULE, InLoadOrderModuleList);
@@ -871,11 +871,11 @@ KdbSymLoadDriverSymbols(IN PUNICODE_STRING Filename,
 {
   /* Load symbols for the image if available */
   DPRINT("Loading driver %wZ symbols (driver @ %08x)\n", Filename, Module->Base);
 {
   /* Load symbols for the image if available */
   DPRINT("Loading driver %wZ symbols (driver @ %08x)\n", Filename, Module->Base);
-  
+
   RtlZeroMemory(&Module->TextSection->SymbolInfo, sizeof (Module->TextSection->SymbolInfo));
   Module->TextSection->SymbolInfo.ImageBase = Module->TextSection->Base;
   Module->TextSection->SymbolInfo.ImageSize = Module->TextSection->Length;
   RtlZeroMemory(&Module->TextSection->SymbolInfo, sizeof (Module->TextSection->SymbolInfo));
   Module->TextSection->SymbolInfo.ImageBase = Module->TextSection->Base;
   Module->TextSection->SymbolInfo.ImageSize = Module->TextSection->Length;
-  
+
   KdbpSymLoadModuleSymbols(Filename, &Module->TextSection->SymbolInfo);
 }
 
   KdbpSymLoadModuleSymbols(Filename, &Module->TextSection->SymbolInfo);
 }
 
@@ -893,7 +893,7 @@ KdbSymUnloadDriverSymbols(IN PMODULE_OBJECT ModuleObject)
 /*! \brief Called when a symbol file is loaded by the loader?
  *
  * Tries to find a driver (.sys) or executable (.exe) with the same base name
 /*! \brief Called when a symbol file is loaded by the loader?
  *
  * Tries to find a driver (.sys) or executable (.exe) with the same base name
- * as the symbol file and sets the drivers/exes symbol info to the loaded 
+ * as the symbol file and sets the drivers/exes symbol info to the loaded
  * module.
  * Used to load ntoskrnl and hal symbols before the SystemRoot is available to us.
  *
  * module.
  * Used to load ntoskrnl and hal symbols before the SystemRoot is available to us.
  *
@@ -925,13 +925,13 @@ KdbSymProcessSymbolFile(IN PVOID ModuleLoadBase,
     {
       *Extension = 0;
     }
     {
       *Extension = 0;
     }
-  
+
   DPRINT("base: %s (Length %d)\n", TmpBaseName, Length);
   DPRINT("base: %s (Length %d)\n", TmpBaseName, Length);
-  
+
   strcpy(TmpFileName, TmpBaseName);
   strcat(TmpFileName, ".sys");
   RtlInitAnsiString(&AnsiString, TmpFileName);
   strcpy(TmpFileName, TmpBaseName);
   strcat(TmpFileName, ".sys");
   RtlInitAnsiString(&AnsiString, TmpFileName);
-  
+
   RtlAnsiStringToUnicodeString(&ModuleName, &AnsiString, TRUE);
   ModuleObject = LdrGetModuleObject(&ModuleName);
   RtlFreeUnicodeString(&ModuleName);
   RtlAnsiStringToUnicodeString(&ModuleName, &AnsiString, TRUE);
   ModuleObject = LdrGetModuleObject(&ModuleName);
   RtlFreeUnicodeString(&ModuleName);
@@ -951,7 +951,7 @@ KdbSymProcessSymbolFile(IN PVOID ModuleLoadBase,
         {
           KdbpSymRemoveCachedFile(SymbolInfo);
         }
         {
           KdbpSymRemoveCachedFile(SymbolInfo);
         }
-      
+
       SymbolFileHeader = (PSYMBOLFILE_HEADER) ModuleLoadBase;
       SymbolInfo->FileBuffer = ModuleLoadBase;
       SymbolInfo->SymbolsBase = ModuleLoadBase + SymbolFileHeader->StabsOffset;
       SymbolFileHeader = (PSYMBOLFILE_HEADER) ModuleLoadBase;
       SymbolInfo->FileBuffer = ModuleLoadBase;
       SymbolInfo->SymbolsBase = ModuleLoadBase + SymbolFileHeader->StabsOffset;
@@ -960,11 +960,12 @@ KdbSymProcessSymbolFile(IN PVOID ModuleLoadBase,
       SymbolInfo->SymbolStringsLength = SymbolFileHeader->StabstrLength;
       DPRINT("Installed stabs: %s@%08x-%08x (%08x-%08x,%08x)\n",
               FileName,
       SymbolInfo->SymbolStringsLength = SymbolFileHeader->StabstrLength;
       DPRINT("Installed stabs: %s@%08x-%08x (%08x-%08x,%08x)\n",
               FileName,
-              ModuleObject->Base, ModuleObject->Length + ModuleObject->Base,
-              SymbolInfo->SymbolsBase, 
+              ModuleObject->Base,
+              ModuleObject->Length + ModuleObject->Base,
+              SymbolInfo->SymbolsBase,
               SymbolInfo->SymbolsLength + SymbolInfo->SymbolsBase,
               SymbolInfo->SymbolStringsBase);
               SymbolInfo->SymbolsLength + SymbolInfo->SymbolsBase,
               SymbolInfo->SymbolStringsBase);
-    } 
+    }
 }
 
 /*! \brief Initializes the KDB symbols implementation.
 }
 
 /*! \brief Initializes the KDB symbols implementation.