Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenkdb_symbols.cmake.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS kernel 00004 * FILE: ntoskrnl/dbg/kdb_symbols.c 00005 * PURPOSE: Getting symbol information... 00006 * 00007 * PROGRAMMERS: David Welch (welch@cwcom.net) 00008 * Colin Finck (colin@reactos.org) 00009 */ 00010 00011 /* INCLUDES *****************************************************************/ 00012 00013 #include <ntoskrnl.h> 00014 00015 #define NDEBUG 00016 #include "../cache/section/newmm.h" 00017 #include <debug.h> 00018 00019 /* GLOBALS ******************************************************************/ 00020 00021 typedef struct _IMAGE_SYMBOL_INFO_CACHE 00022 { 00023 LIST_ENTRY ListEntry; 00024 ULONG RefCount; 00025 UNICODE_STRING FileName; 00026 PROSSYM_INFO RosSymInfo; 00027 } 00028 IMAGE_SYMBOL_INFO_CACHE, *PIMAGE_SYMBOL_INFO_CACHE; 00029 00030 typedef struct _ROSSYM_KM_OWN_CONTEXT { 00031 LARGE_INTEGER FileOffset; 00032 PFILE_OBJECT FileObject; 00033 } ROSSYM_KM_OWN_CONTEXT, *PROSSYM_KM_OWN_CONTEXT; 00034 00035 static BOOLEAN LoadSymbols; 00036 static LIST_ENTRY SymbolFileListHead; 00037 static KSPIN_LOCK SymbolFileListLock; 00038 //static PROSSYM_INFO KdbpRosSymInfo; 00039 //static ULONG_PTR KdbpImageBase; 00040 BOOLEAN KdbpSymbolsInitialized = FALSE; 00041 00042 /* FUNCTIONS ****************************************************************/ 00043 00044 static BOOLEAN 00045 KdbpSeekSymFile(PVOID FileContext, ULONG_PTR Target) 00046 { 00047 PROSSYM_KM_OWN_CONTEXT Context = (PROSSYM_KM_OWN_CONTEXT)FileContext; 00048 Context->FileOffset.QuadPart = Target; 00049 return TRUE; 00050 } 00051 00052 static BOOLEAN 00053 KdbpReadSymFile(PVOID FileContext, PVOID Buffer, ULONG Length) 00054 { 00055 PROSSYM_KM_OWN_CONTEXT Context = (PROSSYM_KM_OWN_CONTEXT)FileContext; 00056 IO_STATUS_BLOCK Iosb; 00057 NTSTATUS Status = MiSimpleRead 00058 (Context->FileObject, 00059 &Context->FileOffset, 00060 Buffer, 00061 Length, 00062 FALSE, 00063 &Iosb); 00064 return NT_SUCCESS(Status); 00065 } 00066 00067 static PROSSYM_KM_OWN_CONTEXT 00068 KdbpCaptureFileForSymbols(PFILE_OBJECT FileObject) 00069 { 00070 PROSSYM_KM_OWN_CONTEXT Context = ExAllocatePool(NonPagedPool, sizeof(*Context)); 00071 if (!Context) return NULL; 00072 ObReferenceObject(FileObject); 00073 Context->FileOffset.QuadPart = 0; 00074 Context->FileObject = FileObject; 00075 return Context; 00076 } 00077 00078 static VOID 00079 KdbpReleaseFileForSymbols(PROSSYM_KM_OWN_CONTEXT Context) 00080 { 00081 ObDereferenceObject(Context->FileObject); 00082 ExFreePool(Context); 00083 } 00084 00085 static BOOLEAN 00086 KdbpSymSearchModuleList( 00087 IN PLIST_ENTRY current_entry, 00088 IN PLIST_ENTRY end_entry, 00089 IN PLONG Count, 00090 IN PVOID Address, 00091 IN LPCWSTR Name, 00092 IN INT Index, 00093 OUT PLDR_DATA_TABLE_ENTRY* pLdrEntry) 00094 { 00095 while (current_entry && current_entry != end_entry) 00096 { 00097 *pLdrEntry = CONTAINING_RECORD(current_entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); 00098 00099 if ((Address && Address >= (PVOID)(*pLdrEntry)->DllBase && Address < (PVOID)((ULONG_PTR)(*pLdrEntry)->DllBase + (*pLdrEntry)->SizeOfImage)) || 00100 (Name && !_wcsnicmp((*pLdrEntry)->BaseDllName.Buffer, Name, (*pLdrEntry)->BaseDllName.Length / sizeof(WCHAR))) || 00101 (Index >= 0 && (*Count)++ == Index)) 00102 { 00103 return TRUE; 00104 } 00105 00106 current_entry = current_entry->Flink; 00107 } 00108 00109 return FALSE; 00110 } 00111 00124 BOOLEAN 00125 KdbpSymFindModule( 00126 IN PVOID Address OPTIONAL, 00127 IN LPCWSTR Name OPTIONAL, 00128 IN INT Index OPTIONAL, 00129 OUT PLDR_DATA_TABLE_ENTRY* pLdrEntry) 00130 { 00131 LONG Count = 0; 00132 PEPROCESS CurrentProcess; 00133 00134 /* First try to look up the module in the kernel module list. */ 00135 if(KdbpSymSearchModuleList(PsLoadedModuleList.Flink, 00136 &PsLoadedModuleList, 00137 &Count, 00138 Address, 00139 Name, 00140 Index, 00141 pLdrEntry)) 00142 { 00143 return TRUE; 00144 } 00145 00146 /* That didn't succeed. Try the module list of the current process now. */ 00147 CurrentProcess = PsGetCurrentProcess(); 00148 00149 if(!CurrentProcess || !CurrentProcess->Peb || !CurrentProcess->Peb->Ldr) 00150 return FALSE; 00151 00152 return KdbpSymSearchModuleList(CurrentProcess->Peb->Ldr->InLoadOrderModuleList.Flink, 00153 &CurrentProcess->Peb->Ldr->InLoadOrderModuleList, 00154 &Count, 00155 Address, 00156 Name, 00157 Index, 00158 pLdrEntry); 00159 } 00160 00172 BOOLEAN 00173 KdbSymPrintAddress( 00174 IN PVOID Address, 00175 IN PKTRAP_FRAME Context) 00176 { 00177 int i; 00178 PMEMORY_AREA MemoryArea = NULL; 00179 PROS_SECTION_OBJECT SectionObject; 00180 PLDR_DATA_TABLE_ENTRY LdrEntry; 00181 #if 0 00182 PROSSYM_KM_OWN_CONTEXT FileContext; 00183 #endif 00184 ULONG_PTR RelativeAddress; 00185 NTSTATUS Status; 00186 ROSSYM_LINEINFO LineInfo = {0}; 00187 00188 struct { 00189 enum _ROSSYM_REGNAME regname; 00190 size_t ctx_offset; 00191 } regmap[] = { 00192 { ROSSYM_X86_EDX, FIELD_OFFSET(KTRAP_FRAME, Edx) }, 00193 { ROSSYM_X86_EAX, FIELD_OFFSET(KTRAP_FRAME, Eax) }, 00194 { ROSSYM_X86_ECX, FIELD_OFFSET(KTRAP_FRAME, Ecx) }, 00195 { ROSSYM_X86_EBX, FIELD_OFFSET(KTRAP_FRAME, Ebx) }, 00196 { ROSSYM_X86_ESI, FIELD_OFFSET(KTRAP_FRAME, Esi) }, 00197 { ROSSYM_X86_EDI, FIELD_OFFSET(KTRAP_FRAME, Edi) }, 00198 { ROSSYM_X86_EBP, FIELD_OFFSET(KTRAP_FRAME, Ebp) }, 00199 { ROSSYM_X86_ESP, FIELD_OFFSET(KTRAP_FRAME, HardwareEsp) } 00200 }; 00201 00202 if (Context) 00203 { 00204 #if 0 00205 // Disable arguments for now 00206 DPRINT("Has Context %x (EBP %x)\n", Context, Context->Ebp); 00207 LineInfo.Flags = ROSSYM_LINEINFO_HAS_REGISTERS; 00208 #endif 00209 00210 for (i = 0; i < sizeof(regmap) / sizeof(regmap[0]); i++) { 00211 memcpy 00212 (&LineInfo.Registers.Registers[regmap[i].regname], 00213 ((PCHAR)Context)+regmap[i].ctx_offset, 00214 sizeof(ULONG_PTR)); 00215 DPRINT("DWARF REG[%d] -> %x\n", regmap[i].regname, LineInfo.Registers.Registers[regmap[i].regname]); 00216 } 00217 } 00218 00219 if (!KdbpSymbolsInitialized || !KdbpSymFindModule(Address, NULL, -1, &LdrEntry)) 00220 return FALSE; 00221 00222 RelativeAddress = (ULONG_PTR)Address - (ULONG_PTR)LdrEntry->DllBase; 00223 Status = KdbSymGetAddressInformation 00224 (LdrEntry->PatchInformation, 00225 RelativeAddress, 00226 &LineInfo); 00227 00228 if (NT_SUCCESS(Status)) 00229 { 00230 DbgPrint("<%wZ:%x (%s:%d (%s))>", 00231 &LdrEntry->BaseDllName, RelativeAddress, LineInfo.FileName, LineInfo.LineNumber, LineInfo.FunctionName); 00232 if (Context && LineInfo.NumParams) 00233 { 00234 int i; 00235 char *comma = ""; 00236 DbgPrint("("); 00237 for (i = 0; i < LineInfo.NumParams; i++) { 00238 DbgPrint 00239 ("%s%s=%llx", 00240 comma, 00241 LineInfo.Parameters[i].ValueName, 00242 LineInfo.Parameters[i].Value); 00243 comma = ","; 00244 } 00245 DbgPrint(")"); 00246 } 00247 00248 return TRUE; 00249 } 00250 else if (Address < MmSystemRangeStart) 00251 { 00252 MemoryArea = MmLocateMemoryAreaByAddress(&PsGetCurrentProcess()->Vm, Address); 00253 if (!MemoryArea || MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) 00254 { 00255 goto end; 00256 } 00257 00258 SectionObject = MemoryArea->Data.SectionData.Section; 00259 if (!(SectionObject->AllocationAttributes & SEC_IMAGE)) goto end; 00260 #if 0 00261 if (MemoryArea->StartingAddress != (PVOID)KdbpImageBase) 00262 { 00263 if (KdbpRosSymInfo) 00264 { 00265 RosSymDelete(KdbpRosSymInfo); 00266 KdbpRosSymInfo = NULL; 00267 KdbpImageBase = 0; 00268 } 00269 00270 if ((FileContext = KdbpCaptureFileForSymbols(SectionObject->FileObject))) 00271 { 00272 if (RosSymCreateFromFile(FileContext, &KdbpRosSymInfo)) 00273 KdbpImageBase = (ULONG_PTR)MemoryArea->StartingAddress; 00274 00275 KdbpReleaseFileForSymbols(FileContext); 00276 } 00277 } 00278 00279 if (KdbpRosSymInfo) 00280 { 00281 RelativeAddress = (ULONG_PTR)Address - KdbpImageBase; 00282 RosSymFreeInfo(&LineInfo); 00283 Status = KdbSymGetAddressInformation 00284 (KdbpRosSymInfo, 00285 RelativeAddress, 00286 &LineInfo); 00287 if (NT_SUCCESS(Status)) 00288 { 00289 DbgPrint 00290 ("<%wZ:%x (%s:%d (%s))>", 00291 &SectionObject->FileObject->FileName, 00292 RelativeAddress, 00293 LineInfo.FileName, 00294 LineInfo.LineNumber, 00295 LineInfo.FunctionName); 00296 00297 if (Context && LineInfo.NumParams) 00298 { 00299 int i; 00300 char *comma = ""; 00301 DbgPrint("("); 00302 for (i = 0; i < LineInfo.NumParams; i++) { 00303 DbgPrint 00304 ("%s%s=%llx", 00305 comma, 00306 LineInfo.Parameters[i].ValueName, 00307 LineInfo.Parameters[i].Value); 00308 comma = ","; 00309 } 00310 DbgPrint(")"); 00311 } 00312 00313 return TRUE; 00314 } 00315 } 00316 #endif 00317 } 00318 00319 end: 00320 DbgPrint("<%wZ:%x>", &LdrEntry->BaseDllName, RelativeAddress); 00321 00322 return TRUE; 00323 } 00324 00325 00342 NTSTATUS 00343 KdbSymGetAddressInformation( 00344 IN PROSSYM_INFO RosSymInfo, 00345 IN ULONG_PTR RelativeAddress, 00346 IN PROSSYM_LINEINFO LineInfo) 00347 { 00348 if (!KdbpSymbolsInitialized || 00349 !RosSymInfo || 00350 !RosSymGetAddressInformation(RosSymInfo, RelativeAddress, LineInfo)) 00351 { 00352 return STATUS_UNSUCCESSFUL; 00353 } 00354 00355 return STATUS_SUCCESS; 00356 } 00357 00370 PROSSYM_INFO 00371 KdbpSymFindCachedFile( 00372 IN PUNICODE_STRING FileName) 00373 { 00374 PIMAGE_SYMBOL_INFO_CACHE Current; 00375 PLIST_ENTRY CurrentEntry; 00376 KIRQL Irql; 00377 00378 KeAcquireSpinLock(&SymbolFileListLock, &Irql); 00379 00380 CurrentEntry = SymbolFileListHead.Flink; 00381 while (CurrentEntry != (&SymbolFileListHead)) 00382 { 00383 Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry); 00384 00385 if (RtlEqualUnicodeString(&Current->FileName, FileName, TRUE)) 00386 { 00387 Current->RefCount++; 00388 KeReleaseSpinLock(&SymbolFileListLock, Irql); 00389 DPRINT("Found cached file!\n"); 00390 return Current->RosSymInfo; 00391 } 00392 00393 CurrentEntry = CurrentEntry->Flink; 00394 } 00395 00396 KeReleaseSpinLock(&SymbolFileListLock, Irql); 00397 00398 DPRINT("Cached file not found!\n"); 00399 return NULL; 00400 } 00401 00409 static VOID 00410 KdbpSymAddCachedFile( 00411 IN PUNICODE_STRING FileName, 00412 IN PROSSYM_INFO RosSymInfo) 00413 { 00414 PIMAGE_SYMBOL_INFO_CACHE CacheEntry; 00415 00416 DPRINT("Adding symbol file: %wZ RosSymInfo = %p\n", FileName, RosSymInfo); 00417 00418 /* allocate entry */ 00419 CacheEntry = ExAllocatePoolWithTag(NonPagedPool, sizeof (IMAGE_SYMBOL_INFO_CACHE), TAG_KDBS); 00420 ASSERT(CacheEntry); 00421 RtlZeroMemory(CacheEntry, sizeof (IMAGE_SYMBOL_INFO_CACHE)); 00422 00423 /* fill entry */ 00424 CacheEntry->FileName.Buffer = ExAllocatePoolWithTag(NonPagedPool, 00425 FileName->Length, 00426 TAG_KDBS); 00427 CacheEntry->FileName.MaximumLength = FileName->Length; 00428 RtlCopyUnicodeString(&CacheEntry->FileName, FileName); 00429 ASSERT(CacheEntry->FileName.Buffer); 00430 CacheEntry->RefCount = 1; 00431 CacheEntry->RosSymInfo = RosSymInfo; 00432 InsertTailList(&SymbolFileListHead, &CacheEntry->ListEntry); /* FIXME: Lock list? */ 00433 } 00434 00445 static VOID 00446 KdbpSymRemoveCachedFile( 00447 IN PROSSYM_INFO RosSymInfo) 00448 { 00449 PIMAGE_SYMBOL_INFO_CACHE Current; 00450 PLIST_ENTRY CurrentEntry; 00451 KIRQL Irql; 00452 00453 KeAcquireSpinLock(&SymbolFileListLock, &Irql); 00454 00455 CurrentEntry = SymbolFileListHead.Flink; 00456 while (CurrentEntry != (&SymbolFileListHead)) 00457 { 00458 Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry); 00459 00460 if (Current->RosSymInfo == RosSymInfo) /* found */ 00461 { 00462 ASSERT(Current->RefCount > 0); 00463 Current->RefCount--; 00464 if (Current->RefCount < 1) 00465 { 00466 RemoveEntryList(&Current->ListEntry); 00467 RosSymDelete(Current->RosSymInfo); 00468 ExFreePool(Current); 00469 } 00470 00471 KeReleaseSpinLock(&SymbolFileListLock, Irql); 00472 return; 00473 } 00474 00475 CurrentEntry = CurrentEntry->Flink; 00476 } 00477 00478 KeReleaseSpinLock(&SymbolFileListLock, Irql); 00479 } 00480 00488 VOID 00489 KdbpSymLoadModuleSymbols( 00490 IN PUNICODE_STRING FileName, 00491 OUT PROSSYM_INFO *RosSymInfo) 00492 { 00493 OBJECT_ATTRIBUTES ObjectAttributes; 00494 HANDLE FileHandle; 00495 NTSTATUS Status; 00496 IO_STATUS_BLOCK IoStatusBlock; 00497 PFILE_OBJECT FileObject; 00498 PROSSYM_KM_OWN_CONTEXT FileContext; 00499 00500 /* Allow KDB to break on module load */ 00501 KdbModuleLoaded(FileName); 00502 00503 if (!LoadSymbols) 00504 { 00505 *RosSymInfo = NULL; 00506 return; 00507 } 00508 00509 /* Try to find cached (already loaded) symbol file */ 00510 *RosSymInfo = KdbpSymFindCachedFile(FileName); 00511 if (*RosSymInfo) 00512 { 00513 DPRINT("Found cached symbol file %wZ\n", FileName); 00514 return; 00515 } 00516 00517 /* Open the file */ 00518 InitializeObjectAttributes(&ObjectAttributes, 00519 FileName, 00520 OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE, 00521 NULL, 00522 NULL); 00523 00524 DPRINT("Attempting to open image: %wZ\n", FileName); 00525 00526 Status = ZwOpenFile(&FileHandle, 00527 FILE_READ_ACCESS, 00528 &ObjectAttributes, 00529 &IoStatusBlock, 00530 FILE_SHARE_READ|FILE_SHARE_WRITE, 00531 FILE_NON_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT); 00532 if (!NT_SUCCESS(Status)) 00533 { 00534 DPRINT("Could not open image file(%x): %wZ\n", Status, FileName); 00535 return; 00536 } 00537 00538 DPRINT("Loading symbols from %wZ...\n", FileName); 00539 00540 Status = ObReferenceObjectByHandle 00541 (FileHandle, 00542 FILE_READ_DATA|SYNCHRONIZE, 00543 NULL, 00544 KernelMode, 00545 (PVOID*)&FileObject, 00546 NULL); 00547 00548 if (!NT_SUCCESS(Status)) 00549 { 00550 DPRINT("Could not get the file object\n"); 00551 ZwClose(FileHandle); 00552 return; 00553 } 00554 00555 if ((FileContext = KdbpCaptureFileForSymbols(FileObject))) 00556 { 00557 if (RosSymCreateFromFile(FileContext, RosSymInfo)) 00558 { 00559 /* add file to cache */ 00560 int i; 00561 UNICODE_STRING TruncatedName = *FileName; 00562 for (i = (TruncatedName.Length / sizeof(WCHAR)) - 1; i >= 0; i--) 00563 if (TruncatedName.Buffer[i] == '\\') { 00564 TruncatedName.Buffer += i+1; 00565 TruncatedName.Length -= (i+1)*sizeof(WCHAR); 00566 TruncatedName.MaximumLength -= (i+1)*sizeof(WCHAR); 00567 break; 00568 } 00569 KdbpSymAddCachedFile(&TruncatedName, *RosSymInfo); 00570 DPRINT("Installed symbols: %wZ %p\n", &TruncatedName, *RosSymInfo); 00571 } 00572 KdbpReleaseFileForSymbols(FileContext); 00573 } 00574 00575 ObDereferenceObject(FileObject); 00576 ZwClose(FileHandle); 00577 } 00578 00579 VOID 00580 KdbSymProcessSymbols( 00581 IN PLDR_DATA_TABLE_ENTRY LdrEntry) 00582 { 00583 if (!LoadSymbols) 00584 { 00585 LdrEntry->PatchInformation = NULL; 00586 return; 00587 } 00588 00589 /* Remove symbol info if it already exists */ 00590 if (LdrEntry->PatchInformation) { 00591 KdbpSymRemoveCachedFile(LdrEntry->PatchInformation); 00592 } 00593 00594 /* Error loading symbol info, try to load it from file */ 00595 KdbpSymLoadModuleSymbols(&LdrEntry->FullDllName, 00596 (PROSSYM_INFO*)&LdrEntry->PatchInformation); 00597 00598 if (!LdrEntry->PatchInformation) { 00599 // HACK: module dll names don't identify the real files 00600 UNICODE_STRING SystemRoot; 00601 UNICODE_STRING ModuleNameCopy; 00602 RtlInitUnicodeString(&SystemRoot, L"\\SystemRoot\\system32\\Drivers\\"); 00603 ModuleNameCopy.Length = 0; 00604 ModuleNameCopy.MaximumLength = 00605 LdrEntry->BaseDllName.MaximumLength + SystemRoot.MaximumLength; 00606 ModuleNameCopy.Buffer = ExAllocatePool(NonPagedPool, SystemRoot.MaximumLength + LdrEntry->BaseDllName.MaximumLength); 00607 RtlCopyUnicodeString(&ModuleNameCopy, &SystemRoot); 00608 RtlCopyMemory 00609 (ModuleNameCopy.Buffer + ModuleNameCopy.Length / sizeof(WCHAR), 00610 LdrEntry->BaseDllName.Buffer, 00611 LdrEntry->BaseDllName.Length); 00612 ModuleNameCopy.Length += LdrEntry->BaseDllName.Length; 00613 KdbpSymLoadModuleSymbols(&ModuleNameCopy, 00614 (PROSSYM_INFO*)&LdrEntry->PatchInformation); 00615 if (!LdrEntry->PatchInformation) { 00616 SystemRoot.Length -= strlen("Drivers\\") * sizeof(WCHAR); 00617 RtlCopyUnicodeString(&ModuleNameCopy, &SystemRoot); 00618 RtlCopyMemory 00619 (ModuleNameCopy.Buffer + ModuleNameCopy.Length / sizeof(WCHAR), 00620 LdrEntry->BaseDllName.Buffer, 00621 LdrEntry->BaseDllName.Length); 00622 ModuleNameCopy.Length += LdrEntry->BaseDllName.Length; 00623 KdbpSymLoadModuleSymbols(&ModuleNameCopy, 00624 (PROSSYM_INFO*)&LdrEntry->PatchInformation); 00625 } 00626 RtlFreeUnicodeString(&ModuleNameCopy); 00627 } 00628 00629 /* It already added symbols to cache */ 00630 DPRINT("Installed symbols: %wZ@%p-%p %p\n", 00631 &LdrEntry->BaseDllName, 00632 LdrEntry->DllBase, 00633 (PVOID)(LdrEntry->SizeOfImage + (ULONG_PTR)LdrEntry->DllBase), 00634 LdrEntry->PatchInformation); 00635 } 00636 00637 VOID 00638 NTAPI 00639 KdbDebugPrint( 00640 PCH Message, 00641 ULONG Length) 00642 { 00643 /* Nothing here */ 00644 } 00645 00646 static PVOID KdbpSymAllocMem(ULONG_PTR size) 00647 { 00648 return ExAllocatePoolWithTag(NonPagedPool, size, 'RSYM'); 00649 } 00650 00651 static VOID KdbpSymFreeMem(PVOID Area) 00652 { 00653 return ExFreePool(Area); 00654 } 00655 00656 static BOOLEAN KdbpSymReadMem(PVOID FileContext, ULONG_PTR* TargetDebug, PVOID SourceMem, ULONG Size) 00657 { 00658 return NT_SUCCESS(KdbpSafeReadMemory(TargetDebug, SourceMem, Size)); 00659 } 00660 00661 static ROSSYM_CALLBACKS KdbpRosSymCallbacks = { 00662 KdbpSymAllocMem, KdbpSymFreeMem, 00663 KdbpReadSymFile, KdbpSeekSymFile, 00664 KdbpSymReadMem 00665 }; 00666 00672 VOID 00673 NTAPI 00674 KdbInitialize( 00675 PKD_DISPATCH_TABLE DispatchTable, 00676 ULONG BootPhase) 00677 { 00678 PCHAR p1, p2; 00679 SHORT Found = FALSE; 00680 CHAR YesNo; 00681 PLDR_DATA_TABLE_ENTRY LdrEntry; 00682 00683 DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase); 00684 00685 LoadSymbols = FALSE; 00686 00687 #if DBG 00688 /* Load symbols only if we have 96Mb of RAM or more */ 00689 if (MmNumberOfPhysicalPages >= 0x6000) 00690 LoadSymbols = TRUE; 00691 #endif 00692 00693 if (BootPhase == 0) 00694 { 00695 /* Write out the functions that we support for now */ 00696 DispatchTable->KdpInitRoutine = KdpKdbgInit; 00697 DispatchTable->KdpPrintRoutine = KdbDebugPrint; 00698 00699 /* Register as a Provider */ 00700 InsertTailList(&KdProviders, &DispatchTable->KdProvidersList); 00701 00702 /* Perform actual initialization of symbol module */ 00703 //NtoskrnlModuleObject->PatchInformation = NULL; 00704 //LdrHalModuleObject->PatchInformation = NULL; 00705 00706 InitializeListHead(&SymbolFileListHead); 00707 KeInitializeSpinLock(&SymbolFileListLock); 00708 00709 /* Check the command line for /LOADSYMBOLS, /NOLOADSYMBOLS, 00710 * /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */ 00711 ASSERT(KeLoaderBlock); 00712 p1 = KeLoaderBlock->LoadOptions; 00713 while('\0' != *p1 && NULL != (p2 = strchr(p1, '/'))) 00714 { 00715 p2++; 00716 Found = 0; 00717 if (0 == _strnicmp(p2, "LOADSYMBOLS", 11)) 00718 { 00719 Found = +1; 00720 p2 += 11; 00721 } 00722 else if (0 == _strnicmp(p2, "NOLOADSYMBOLS", 13)) 00723 { 00724 Found = -1; 00725 p2 += 13; 00726 } 00727 if (0 != Found) 00728 { 00729 while (isspace(*p2)) 00730 { 00731 p2++; 00732 } 00733 if ('=' == *p2) 00734 { 00735 p2++; 00736 while (isspace(*p2)) 00737 { 00738 p2++; 00739 } 00740 YesNo = toupper(*p2); 00741 if ('N' == YesNo || 'F' == YesNo || '0' == YesNo) 00742 { 00743 Found = -1 * Found; 00744 } 00745 } 00746 LoadSymbols = (0 < Found); 00747 } 00748 p1 = p2; 00749 } 00750 00751 RosSymInit(&KdbpRosSymCallbacks); 00752 } 00753 else if (BootPhase == 3) 00754 { 00755 /* Load symbols for NTOSKRNL.EXE. 00756 It is always the first module in PsLoadedModuleList. KeLoaderBlock can't be used here as its content is just temporary. */ 00757 LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); 00758 KdbSymProcessSymbols(LdrEntry); 00759 00760 /* Also load them for HAL.DLL. */ 00761 LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); 00762 KdbSymProcessSymbols(LdrEntry); 00763 00764 KdbpSymbolsInitialized = TRUE; 00765 } 00766 } 00767 00768 /* EOF */ Generated on Sun May 27 2012 04:37:29 for ReactOS by
1.7.6.1
|