fixed uninitialized variable warning
[reactos.git] / reactos / ntoskrnl / kdbg / kdb_symbols.c
index 4a465fd..bc37191 100644 (file)
@@ -55,6 +55,7 @@ KdbpSymFindUserModule(IN PVOID Address  OPTIONAL,
   PEPROCESS CurrentProcess;
   PPEB Peb = NULL;
   INT Count = 0;
+  INT Length;
 
   CurrentProcess = PsGetCurrentProcess();
   if (CurrentProcess != NULL)
@@ -73,20 +74,17 @@ KdbpSymFindUserModule(IN PVOID Address  OPTIONAL,
          current_entry != NULL)
     {
       current = CONTAINING_RECORD(current_entry, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
-
+      Length = min(current->BaseDllName.Length / sizeof(WCHAR), 255);
       if ((Address != NULL && (Address >= (PVOID)current->DllBase &&
                                Address < (PVOID)((char *)current->DllBase + current->SizeOfImage))) ||
-          (Name != NULL && _wcsicmp(current->BaseDllName.Buffer, Name) == 0) ||
+          (Name != NULL && _wcsnicmp(current->BaseDllName.Buffer, Name, Length) == 0) ||
           (Index >= 0 && Count++ == Index))
         {
-         INT Length = current->BaseDllName.Length;
-         if (Length > 255)
-           Length = 255;
          wcsncpy(pInfo->Name, current->BaseDllName.Buffer, Length);
          pInfo->Name[Length] = L'\0';
           pInfo->Base = (ULONG_PTR)current->DllBase;
           pInfo->Size = current->SizeOfImage;
-          pInfo->RosSymInfo = current->RosSymInfo;
+          pInfo->RosSymInfo = current->PatchInformation;
           return TRUE;
         }
       current_entry = current_entry->Flink;
@@ -108,27 +106,28 @@ KdbpSymFindModule(IN PVOID Address  OPTIONAL,
                   OUT PKDB_MODULE_INFO pInfo)
 {
   PLIST_ENTRY current_entry;
-  MODULE_TEXT_SECTION* current;
-  extern LIST_ENTRY ModuleTextListHead;
+  PLDR_DATA_TABLE_ENTRY current;
+  extern LIST_ENTRY ModuleListHead;
   INT Count = 0;
+  INT Length;
 
-  current_entry = ModuleTextListHead.Flink;
+  current_entry = ModuleListHead.Flink;
 
-  while (current_entry != &ModuleTextListHead &&
-         current_entry != NULL)
+  while (current_entry != &ModuleListHead)
     {
-      current = CONTAINING_RECORD(current_entry, MODULE_TEXT_SECTION, ListEntry);
+      current = CONTAINING_RECORD(current_entry, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
 
-      if ((Address != NULL && (Address >= (PVOID)current->Base &&
-                               Address < (PVOID)(current->Base + current->Length))) ||
-          (Name != NULL && _wcsicmp(current->Name, Name) == 0) ||
+      Length = min(current->BaseDllName.Length / sizeof(WCHAR), 255);
+      if ((Address != NULL && (Address >= (PVOID)current->DllBase &&
+                               Address < (PVOID)((ULONG_PTR)current->DllBase + current->SizeOfImage))) ||
+          (Name != NULL && _wcsnicmp(current->BaseDllName.Buffer, Name, Length) == 0) ||
           (Index >= 0 && Count++ == Index))
         {
-         wcsncpy(pInfo->Name, current->Name, 255);
-         pInfo->Name[255] = L'\0';
-          pInfo->Base = (ULONG_PTR)current->Base;
-          pInfo->Size = current->Length;
-          pInfo->RosSymInfo = current->RosSymInfo;
+         wcsncpy(pInfo->Name, current->BaseDllName.Buffer, Length);
+         pInfo->Name[Length] = L'\0';
+          pInfo->Base = (ULONG_PTR)current->DllBase;
+          pInfo->Size = current->SizeOfImage;
+          pInfo->RosSymInfo = current->PatchInformation;
           return TRUE;
         }
       current_entry = current_entry->Flink;
@@ -342,7 +341,7 @@ KdbpSymAddCachedFile(IN PUNICODE_STRING FileName,
   RtlZeroMemory(CacheEntry, sizeof (IMAGE_SYMBOL_INFO_CACHE));
 
   /* fill entry */
-  RtlpCreateUnicodeString(&CacheEntry->FileName, FileName->Buffer, PagedPool);
+  RtlCreateUnicodeString(&CacheEntry->FileName, FileName->Buffer);
   ASSERT(CacheEntry->FileName.Buffer);
   CacheEntry->RefCount = 1;
   CacheEntry->RosSymInfo = RosSymInfo;
@@ -494,7 +493,7 @@ KdbSymLoadUserModuleSymbols(IN PLDR_DATA_TABLE_ENTRY LdrModule)
   UNICODE_STRING KernelName;
   DPRINT("LdrModule %p\n", LdrModule);
 
-  LdrModule->RosSymInfo = NULL;
+  LdrModule->PatchInformation = NULL;
 
   KernelName.MaximumLength = sizeof(Prefix) + LdrModule->FullDllName.Length;
   KernelName.Length = KernelName.MaximumLength - sizeof(WCHAR);
@@ -508,7 +507,7 @@ KdbSymLoadUserModuleSymbols(IN PLDR_DATA_TABLE_ENTRY LdrModule)
          LdrModule->FullDllName.Length);
   KernelName.Buffer[KernelName.Length / sizeof(WCHAR)] = L'\0';
 
-  KdbpSymLoadModuleSymbols(&KernelName, (PROSSYM_INFO*)&LdrModule->RosSymInfo);
+  KdbpSymLoadModuleSymbols(&KernelName, (PROSSYM_INFO*)&LdrModule->PatchInformation);
 
   ExFreePool(KernelName.Buffer);
 }
@@ -528,7 +527,7 @@ KdbSymFreeProcessSymbols(IN PEPROCESS Process)
   CurrentProcess = PsGetCurrentProcess();
   if (CurrentProcess != Process)
   {
-    KeAttachProcess(EPROCESS_TO_KPROCESS(Process));
+    KeAttachProcess(&Process->Pcb);
   }
   Peb = Process->Peb;
   ASSERT(Peb);
@@ -540,7 +539,7 @@ KdbSymFreeProcessSymbols(IN PEPROCESS Process)
     {
       Current = CONTAINING_RECORD(CurrentEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
 
-      KdbpSymUnloadModuleSymbols(Current->RosSymInfo);
+      KdbpSymUnloadModuleSymbols(Current->PatchInformation);
 
       CurrentEntry = CurrentEntry->Flink;
     }
@@ -553,30 +552,30 @@ KdbSymFreeProcessSymbols(IN PEPROCESS Process)
 /*! \brief Load symbol info for a driver.
  *
  * \param Filename  Filename of the driver.
- * \param Module    Pointer to the driver MODULE_OBJECT.
+ * \param Module    Pointer to the driver LDR_DATA_TABLE_ENTRY.
  */
 VOID
 KdbSymLoadDriverSymbols(IN PUNICODE_STRING Filename,
-                        IN PMODULE_OBJECT Module)
+                        IN PLDR_DATA_TABLE_ENTRY Module)
 {
   /* Load symbols for the image if available */
-  DPRINT("Loading driver %wZ symbols (driver @ %08x)\n", Filename, Module->Base);
+  DPRINT("Loading driver %wZ symbols (driver @ %08x)\n", Filename, Module->DllBase);
 
-  Module->TextSection->RosSymInfo = NULL;
+  Module->PatchInformation = NULL;
 
-  KdbpSymLoadModuleSymbols(Filename, &Module->TextSection->RosSymInfo);
+  KdbpSymLoadModuleSymbols(Filename, (PROSSYM_INFO*)&Module->PatchInformation);
 }
 
 /*! \brief Unloads symbol info for a driver.
  *
- * \param ModuleObject  Pointer to the driver MODULE_OBJECT.
+ * \param ModuleObject  Pointer to the driver LDR_DATA_TABLE_ENTRY.
  */
 VOID
-KdbSymUnloadDriverSymbols(IN PMODULE_OBJECT ModuleObject)
+KdbSymUnloadDriverSymbols(IN PLDR_DATA_TABLE_ENTRY ModuleObject)
 {
   /* Unload symbols for module if available */
-  KdbpSymUnloadModuleSymbols(ModuleObject->TextSection->RosSymInfo);
-  ModuleObject->TextSection->RosSymInfo = NULL;
+  KdbpSymUnloadModuleSymbols(ModuleObject->PatchInformation);
+  ModuleObject->PatchInformation = NULL;
 }
 
 /*! \brief Called when a symbol file is loaded by the loader?
@@ -591,7 +590,7 @@ KdbSymUnloadDriverSymbols(IN PMODULE_OBJECT ModuleObject)
 VOID
 KdbSymProcessBootSymbols(IN PCHAR FileName)
 {
-  PMODULE_OBJECT ModuleObject;
+  PLDR_DATA_TABLE_ENTRY ModuleObject;
   UNICODE_STRING UnicodeString;
   PLOADER_MODULE KeLoaderModules = (PLOADER_MODULE)KeLoaderBlock.ModsAddr;
   ANSI_STRING AnsiString;
@@ -618,7 +617,7 @@ KdbSymProcessBootSymbols(IN PCHAR FileName)
   {
      if (! LoadSymbols)
      {
-        ModuleObject->TextSection->RosSymInfo = NULL;
+        ModuleObject->PatchInformation = NULL;
         return;
      }
 
@@ -632,16 +631,16 @@ KdbSymProcessBootSymbols(IN PCHAR FileName)
      if (i < KeLoaderBlock.ModsCount)
      {
         KeLoaderModules[i].Reserved = 1;
-        if (ModuleObject->TextSection->RosSymInfo != NULL)
+        if (ModuleObject->PatchInformation != NULL)
         {
-           KdbpSymRemoveCachedFile(ModuleObject->TextSection->RosSymInfo);
+           KdbpSymRemoveCachedFile(ModuleObject->PatchInformation);
         }
 
         if (IsRaw)
         {
            if (! RosSymCreateFromRaw((PVOID) KeLoaderModules[i].ModStart,
                                      KeLoaderModules[i].ModEnd - KeLoaderModules[i].ModStart,
-                                     &ModuleObject->TextSection->RosSymInfo))
+                                     (PROSSYM_INFO*)&ModuleObject->PatchInformation))
            {
               return;
            }
@@ -650,7 +649,7 @@ KdbSymProcessBootSymbols(IN PCHAR FileName)
         {
            if (! RosSymCreateFromMem((PVOID) KeLoaderModules[i].ModStart,
                                      KeLoaderModules[i].ModEnd - KeLoaderModules[i].ModStart,
-                                     &ModuleObject->TextSection->RosSymInfo))
+                                     (PROSSYM_INFO*)&ModuleObject->PatchInformation))
            {
               return;
            }
@@ -659,33 +658,33 @@ KdbSymProcessBootSymbols(IN PCHAR FileName)
         /* add file to cache */
         RtlInitAnsiString(&AnsiString, FileName);
        RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, TRUE);
-        KdbpSymAddCachedFile(&UnicodeString, ModuleObject->TextSection->RosSymInfo);
+        KdbpSymAddCachedFile(&UnicodeString, ModuleObject->PatchInformation);
         RtlFreeUnicodeString(&UnicodeString);
 
         DPRINT("Installed symbols: %s@%08x-%08x %p\n",
               FileName,
-              ModuleObject->Base,
-              ModuleObject->Length + ModuleObject->Base,
-              ModuleObject->TextSection->RosSymInfo);
+              ModuleObject->DllBase,
+              ModuleObject->SizeOfImage + (ULONG)ModuleObject->DllBase,
+              ModuleObject->PatchInformation);
      }
   }
 }
 
 /*! \brief Initializes the KDB symbols implementation.
  *
- * \param NtoskrnlTextSection  MODULE_TEXT_SECTION of ntoskrnl.exe
- * \param LdrHalTextSection    MODULE_TEXT_SECTION of hal.sys
+ * \param NtoskrnlModuleObject  LDR_DATA_TABLE_ENTRY of ntoskrnl.exe
+ * \param LdrHalModuleObject    LDR_DATA_TABLE_ENTRY of hal.sys
  */
 VOID
-KdbSymInit(IN PMODULE_TEXT_SECTION NtoskrnlTextSection,
-          IN PMODULE_TEXT_SECTION LdrHalTextSection)
+KdbSymInit(IN PLDR_DATA_TABLE_ENTRY NtoskrnlModuleObject,
+          IN PLDR_DATA_TABLE_ENTRY LdrHalModuleObject)
 {
   PCHAR p1, p2;
   int Found;
   char YesNo;
 
-  NtoskrnlTextSection->RosSymInfo = NULL;
-  LdrHalTextSection->RosSymInfo = NULL;
+  NtoskrnlModuleObject->PatchInformation = NULL;
+  LdrHalModuleObject->PatchInformation = NULL;
 
   InitializeListHead(&SymbolFileListHead);
   KeInitializeSpinLock(&SymbolFileListLock);