2005-05-09 01:38:29 +00:00
|
|
|
/*
|
2005-01-26 13:58:37 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
2015-10-04 11:54:25 +00:00
|
|
|
* FILE: ntoskrnl/kdbg/kdb_symbols.c
|
2005-01-26 13:58:37 +00:00
|
|
|
* PURPOSE: Getting symbol information...
|
2005-05-09 01:38:29 +00:00
|
|
|
*
|
2005-01-26 13:58:37 +00:00
|
|
|
* PROGRAMMERS: David Welch (welch@cwcom.net)
|
2009-09-22 21:31:55 +00:00
|
|
|
* Colin Finck (colin@reactos.org)
|
2004-08-26 16:04:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2005-04-25 18:29:16 +00:00
|
|
|
#include <ntoskrnl.h>
|
2023-04-04 21:38:32 +00:00
|
|
|
#include "kdb.h"
|
2004-08-26 16:04:50 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
2023-04-12 16:38:47 +00:00
|
|
|
#include "debug.h"
|
2004-08-26 16:04:50 +00:00
|
|
|
|
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
typedef struct _IMAGE_SYMBOL_INFO_CACHE
|
|
|
|
{
|
|
|
|
LIST_ENTRY ListEntry;
|
|
|
|
ULONG RefCount;
|
|
|
|
UNICODE_STRING FileName;
|
|
|
|
PROSSYM_INFO RosSymInfo;
|
|
|
|
}
|
|
|
|
IMAGE_SYMBOL_INFO_CACHE, *PIMAGE_SYMBOL_INFO_CACHE;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2023-03-13 23:51:03 +00:00
|
|
|
static BOOLEAN LoadSymbols = FALSE;
|
2021-06-22 17:46:27 +00:00
|
|
|
static LIST_ENTRY SymbolsToLoad;
|
|
|
|
static KSPIN_LOCK SymbolsToLoadLock;
|
|
|
|
static KEVENT SymbolsToLoadEvent;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
static
|
|
|
|
BOOLEAN
|
2009-09-22 21:31:55 +00:00
|
|
|
KdbpSymSearchModuleList(
|
|
|
|
IN PLIST_ENTRY current_entry,
|
|
|
|
IN PLIST_ENTRY end_entry,
|
|
|
|
IN PLONG Count,
|
|
|
|
IN PVOID Address,
|
|
|
|
IN INT Index,
|
|
|
|
OUT PLDR_DATA_TABLE_ENTRY* pLdrEntry)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-22 21:31:55 +00:00
|
|
|
while (current_entry && current_entry != end_entry)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-22 21:31:55 +00:00
|
|
|
*pLdrEntry = CONTAINING_RECORD(current_entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
|
|
|
|
|
|
|
|
if ((Address && Address >= (PVOID)(*pLdrEntry)->DllBase && Address < (PVOID)((ULONG_PTR)(*pLdrEntry)->DllBase + (*pLdrEntry)->SizeOfImage)) ||
|
|
|
|
(Index >= 0 && (*Count)++ == Index))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
return TRUE;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
2009-09-09 13:49:04 +00:00
|
|
|
|
|
|
|
current_entry = current_entry->Flink;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
2004-12-17 17:51:57 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
return FALSE;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-22 21:31:55 +00:00
|
|
|
/*! \brief Find a module...
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
2009-09-22 21:31:55 +00:00
|
|
|
* \param Address If \a Address is not NULL the module containing \a Address
|
|
|
|
* is searched.
|
|
|
|
* \param Name If \a Name is not NULL the module named \a Name will be
|
|
|
|
* searched.
|
|
|
|
* \param Index If \a Index is >= 0 the Index'th module will be returned.
|
|
|
|
* \param pLdrEntry Pointer to a PLDR_DATA_TABLE_ENTRY which is filled.
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
2009-09-22 21:31:55 +00:00
|
|
|
* \retval TRUE Module was found, \a pLdrEntry was filled.
|
|
|
|
* \retval FALSE No module was found.
|
2004-08-26 16:04:50 +00:00
|
|
|
*/
|
2009-09-22 21:31:55 +00:00
|
|
|
BOOLEAN
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbpSymFindModule(
|
|
|
|
IN PVOID Address OPTIONAL,
|
|
|
|
IN INT Index OPTIONAL,
|
2009-09-22 21:31:55 +00:00
|
|
|
OUT PLDR_DATA_TABLE_ENTRY* pLdrEntry)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-22 21:31:55 +00:00
|
|
|
LONG Count = 0;
|
|
|
|
PEPROCESS CurrentProcess;
|
2004-12-17 17:51:57 +00:00
|
|
|
|
2009-09-22 21:31:55 +00:00
|
|
|
/* First try to look up the module in the kernel module list. */
|
2021-06-22 17:46:27 +00:00
|
|
|
KeAcquireSpinLockAtDpcLevel(&PsLoadedModuleSpinLock);
|
2009-09-22 21:31:55 +00:00
|
|
|
if(KdbpSymSearchModuleList(PsLoadedModuleList.Flink,
|
|
|
|
&PsLoadedModuleList,
|
|
|
|
&Count,
|
|
|
|
Address,
|
|
|
|
Index,
|
|
|
|
pLdrEntry))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&PsLoadedModuleSpinLock);
|
2009-09-22 21:31:55 +00:00
|
|
|
return TRUE;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
2021-06-22 17:46:27 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&PsLoadedModuleSpinLock);
|
2004-12-17 17:51:57 +00:00
|
|
|
|
2009-09-22 21:31:55 +00:00
|
|
|
/* That didn't succeed. Try the module list of the current process now. */
|
|
|
|
CurrentProcess = PsGetCurrentProcess();
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-22 21:31:55 +00:00
|
|
|
if(!CurrentProcess || !CurrentProcess->Peb || !CurrentProcess->Peb->Ldr)
|
|
|
|
return FALSE;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-22 21:31:55 +00:00
|
|
|
return KdbpSymSearchModuleList(CurrentProcess->Peb->Ldr->InLoadOrderModuleList.Flink,
|
|
|
|
&CurrentProcess->Peb->Ldr->InLoadOrderModuleList,
|
|
|
|
&Count,
|
|
|
|
Address,
|
|
|
|
Index,
|
|
|
|
pLdrEntry);
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
static
|
2012-03-26 13:51:15 +00:00
|
|
|
PCHAR
|
|
|
|
NTAPI
|
|
|
|
KdbpSymUnicodeToAnsi(IN PUNICODE_STRING Unicode,
|
|
|
|
OUT PCHAR Ansi,
|
|
|
|
IN ULONG Length)
|
|
|
|
{
|
|
|
|
PCHAR p;
|
|
|
|
PWCHAR pw;
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
/* Set length and normalize it */
|
|
|
|
i = Unicode->Length / sizeof(WCHAR);
|
|
|
|
i = min(i, Length - 1);
|
|
|
|
|
|
|
|
/* Set source and destination, and copy */
|
|
|
|
pw = Unicode->Buffer;
|
|
|
|
p = Ansi;
|
|
|
|
while (i--) *p++ = (CHAR)*pw++;
|
|
|
|
|
|
|
|
/* Null terminate and return */
|
|
|
|
*p = ANSI_NULL;
|
|
|
|
return Ansi;
|
|
|
|
}
|
|
|
|
|
2004-08-26 16:04:50 +00:00
|
|
|
/*! \brief Print address...
|
|
|
|
*
|
2004-12-17 17:51:57 +00:00
|
|
|
* Tries to lookup line number, file name and function name for the given
|
2004-08-26 16:04:50 +00:00
|
|
|
* address and prints it.
|
|
|
|
* If no such information is found the address is printed in the format
|
2004-12-17 17:51:57 +00:00
|
|
|
* <module: offset>, otherwise the format will be
|
2004-08-26 16:04:50 +00:00
|
|
|
* <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.
|
|
|
|
*/
|
2004-12-17 17:51:57 +00:00
|
|
|
BOOLEAN
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbSymPrintAddress(
|
2011-06-01 20:36:40 +00:00
|
|
|
IN PVOID Address,
|
2020-04-08 21:08:57 +00:00
|
|
|
IN PCONTEXT Context)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-22 21:31:55 +00:00
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
2009-09-09 13:49:04 +00:00
|
|
|
ULONG_PTR RelativeAddress;
|
2021-06-22 17:46:27 +00:00
|
|
|
BOOLEAN Printed = FALSE;
|
2012-03-26 13:51:15 +00:00
|
|
|
CHAR ModuleNameAnsi[64];
|
2009-09-09 13:49:04 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
if (!KdbpSymFindModule(Address, -1, &LdrEntry))
|
2009-09-09 13:49:04 +00:00
|
|
|
return FALSE;
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
RelativeAddress = (ULONG_PTR)Address - (ULONG_PTR)LdrEntry->DllBase;
|
|
|
|
|
2012-03-26 13:51:15 +00:00
|
|
|
KdbpSymUnicodeToAnsi(&LdrEntry->BaseDllName,
|
2021-06-22 17:46:27 +00:00
|
|
|
ModuleNameAnsi,
|
|
|
|
sizeof(ModuleNameAnsi));
|
2009-09-09 13:49:04 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
if (LdrEntry->PatchInformation)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
ULONG LineNumber;
|
|
|
|
CHAR FileName[256];
|
|
|
|
CHAR FunctionName[256];
|
|
|
|
|
2023-04-12 16:38:47 +00:00
|
|
|
if (RosSymGetAddressInformation(LdrEntry->PatchInformation,
|
|
|
|
RelativeAddress,
|
|
|
|
&LineNumber,
|
|
|
|
FileName,
|
|
|
|
FunctionName))
|
2021-06-22 17:46:27 +00:00
|
|
|
{
|
2023-04-12 16:38:47 +00:00
|
|
|
KdbPrintf("<%s:%x (%s:%d (%s))>",
|
|
|
|
ModuleNameAnsi, RelativeAddress,
|
|
|
|
FileName, LineNumber, FunctionName);
|
2021-06-22 17:46:27 +00:00
|
|
|
Printed = TRUE;
|
|
|
|
}
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
2021-06-22 17:46:27 +00:00
|
|
|
|
|
|
|
if (!Printed)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
/* Just print module & address */
|
2023-04-12 16:38:47 +00:00
|
|
|
KdbPrintf("<%s:%x>", ModuleNameAnsi, RelativeAddress);
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
return TRUE;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
static KSTART_ROUTINE LoadSymbolsRoutine;
|
|
|
|
/*! \brief The symbol loader thread routine.
|
|
|
|
* This opens the image file for reading and loads the symbols
|
|
|
|
* section from there.
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
2021-06-22 17:46:27 +00:00
|
|
|
* \note We must do this because KdbSymProcessSymbols is
|
|
|
|
* called at high IRQL and we can't set the event from here
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
2021-06-22 17:46:27 +00:00
|
|
|
* \param Context Unused
|
2004-08-26 16:04:50 +00:00
|
|
|
*/
|
2021-06-22 17:46:27 +00:00
|
|
|
_Use_decl_annotations_
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
LoadSymbolsRoutine(
|
|
|
|
_In_ PVOID Context)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
UNREFERENCED_PARAMETER(Context);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
while (TRUE)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
PLIST_ENTRY ListEntry;
|
|
|
|
NTSTATUS Status = KeWaitForSingleObject(&SymbolsToLoadEvent, WrKernel, KernelMode, FALSE, NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
DPRINT1("KeWaitForSingleObject failed?! 0x%08x\n", Status);
|
|
|
|
LoadSymbols = FALSE;
|
|
|
|
return;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
while ((ListEntry = ExInterlockedRemoveHeadList(&SymbolsToLoad, &SymbolsToLoadLock)))
|
|
|
|
{
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
|
|
|
|
HANDLE FileHandle;
|
|
|
|
OBJECT_ATTRIBUTES Attrib;
|
|
|
|
IO_STATUS_BLOCK Iosb;
|
|
|
|
InitializeObjectAttributes(&Attrib, &LdrEntry->FullDllName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
|
|
|
DPRINT1("Trying %wZ\n", &LdrEntry->FullDllName);
|
|
|
|
Status = ZwOpenFile(&FileHandle,
|
|
|
|
FILE_READ_ACCESS | SYNCHRONIZE,
|
|
|
|
&Attrib,
|
|
|
|
&Iosb,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Try system paths */
|
|
|
|
static const UNICODE_STRING System32Dir = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\");
|
|
|
|
UNICODE_STRING ImagePath;
|
|
|
|
WCHAR ImagePathBuffer[256];
|
|
|
|
RtlInitEmptyUnicodeString(&ImagePath, ImagePathBuffer, sizeof(ImagePathBuffer));
|
|
|
|
RtlCopyUnicodeString(&ImagePath, &System32Dir);
|
|
|
|
RtlAppendUnicodeStringToString(&ImagePath, &LdrEntry->BaseDllName);
|
|
|
|
InitializeObjectAttributes(&Attrib, &ImagePath, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
|
|
|
DPRINT1("Trying %wZ\n", &ImagePath);
|
|
|
|
Status = ZwOpenFile(&FileHandle,
|
|
|
|
FILE_READ_ACCESS | SYNCHRONIZE,
|
|
|
|
&Attrib,
|
|
|
|
&Iosb,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
static const UNICODE_STRING DriversDir= RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\drivers\\");
|
|
|
|
|
|
|
|
RtlInitEmptyUnicodeString(&ImagePath, ImagePathBuffer, sizeof(ImagePathBuffer));
|
|
|
|
RtlCopyUnicodeString(&ImagePath, &DriversDir);
|
|
|
|
RtlAppendUnicodeStringToString(&ImagePath, &LdrEntry->BaseDllName);
|
|
|
|
InitializeObjectAttributes(&Attrib, &ImagePath, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
|
|
|
DPRINT1("Trying %wZ\n", &ImagePath);
|
|
|
|
Status = ZwOpenFile(&FileHandle,
|
|
|
|
FILE_READ_ACCESS | SYNCHRONIZE,
|
|
|
|
&Attrib,
|
|
|
|
&Iosb,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
|
|
|
}
|
|
|
|
}
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed opening file %wZ (%wZ) for reading symbols (0x%08x)\n", &LdrEntry->FullDllName, &LdrEntry->BaseDllName, Status);
|
|
|
|
/* We took a ref previously */
|
|
|
|
MmUnloadSystemImage(LdrEntry);
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
/* Hand it to Rossym */
|
|
|
|
if (!RosSymCreateFromFile(&FileHandle, (PROSSYM_INFO*)&LdrEntry->PatchInformation))
|
|
|
|
LdrEntry->PatchInformation = NULL;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
/* We're done for this one. */
|
|
|
|
NtClose(FileHandle);
|
|
|
|
MmUnloadSystemImage(LdrEntry);
|
|
|
|
}
|
|
|
|
}
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
/*! \brief Load symbols from image mapping. If this fails,
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
2021-06-22 17:46:27 +00:00
|
|
|
* \param LdrEntry The entry to load symbols from
|
2004-08-26 16:04:50 +00:00
|
|
|
*/
|
2021-06-22 17:46:27 +00:00
|
|
|
VOID
|
|
|
|
KdbSymProcessSymbols(
|
|
|
|
_Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry,
|
|
|
|
_In_ BOOLEAN Load)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
if (!LoadSymbols)
|
|
|
|
return;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
/* Check if this is unload */
|
|
|
|
if (!Load)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
/* Did we process it */
|
|
|
|
if (LdrEntry->PatchInformation)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
RosSymDelete(LdrEntry->PatchInformation);
|
|
|
|
LdrEntry->PatchInformation = NULL;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
2021-06-22 17:46:27 +00:00
|
|
|
return;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
if (RosSymCreateFromMem(LdrEntry->DllBase, LdrEntry->SizeOfImage, (PROSSYM_INFO*)&LdrEntry->PatchInformation))
|
2007-10-31 14:41:27 +00:00
|
|
|
{
|
2007-11-19 11:26:52 +00:00
|
|
|
return;
|
2007-10-31 14:41:27 +00:00
|
|
|
}
|
2007-11-19 11:26:52 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
/* Add a ref until we really process it */
|
|
|
|
LdrEntry->LoadCount++;
|
2007-11-19 11:26:52 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
/* Tell our worker thread to read from it */
|
|
|
|
KeAcquireSpinLockAtDpcLevel(&SymbolsToLoadLock);
|
|
|
|
InsertTailList(&SymbolsToLoad, &LdrEntry->InInitializationOrderLinks);
|
|
|
|
KeReleaseSpinLockFromDpcLevel(&SymbolsToLoadLock);
|
2007-11-19 11:26:52 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
KeSetEvent(&SymbolsToLoadEvent, IO_NO_INCREMENT, FALSE);
|
2007-10-31 14:41:27 +00:00
|
|
|
}
|
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
|
2023-03-10 17:12:32 +00:00
|
|
|
/**
|
|
|
|
* @brief Initializes the KDB symbols implementation.
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
2023-03-10 17:12:32 +00:00
|
|
|
* @param[in] BootPhase
|
|
|
|
* Phase of initialization.
|
|
|
|
*
|
2023-03-20 01:28:16 +00:00
|
|
|
* @return
|
|
|
|
* TRUE if symbols are to be loaded at this given BootPhase; FALSE if not.
|
2023-03-10 17:12:32 +00:00
|
|
|
**/
|
2023-03-20 01:28:16 +00:00
|
|
|
BOOLEAN
|
2023-03-10 17:12:32 +00:00
|
|
|
KdbSymInit(
|
2023-01-09 11:31:03 +00:00
|
|
|
_In_ ULONG BootPhase)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2023-03-20 02:10:14 +00:00
|
|
|
#if 1 // FIXME: This is a workaround HACK!!
|
|
|
|
static BOOLEAN OrigLoadSymbols = FALSE;
|
|
|
|
#endif
|
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase);
|
|
|
|
|
|
|
|
if (BootPhase == 0)
|
|
|
|
{
|
2023-03-20 01:28:16 +00:00
|
|
|
PSTR CommandLine;
|
2023-03-10 17:12:32 +00:00
|
|
|
SHORT Found = FALSE;
|
|
|
|
CHAR YesNo;
|
2005-06-05 20:56:14 +00:00
|
|
|
|
2023-04-14 10:07:11 +00:00
|
|
|
/* By default, load symbols in DBG builds, but not in REL builds
|
|
|
|
or anything other than x86, because they only work on x86
|
|
|
|
and can cause the system to hang on x64. */
|
|
|
|
#if DBG && defined(_M_IX86)
|
2023-03-20 01:28:16 +00:00
|
|
|
LoadSymbols = TRUE;
|
2023-03-13 23:51:03 +00:00
|
|
|
#else
|
|
|
|
LoadSymbols = FALSE;
|
|
|
|
#endif
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2023-03-20 01:28:16 +00:00
|
|
|
/* Check the command line for LOADSYMBOLS, NOLOADSYMBOLS,
|
|
|
|
* LOADSYMBOLS={YES|NO}, NOLOADSYMBOLS={YES|NO} */
|
2007-06-28 17:49:02 +00:00
|
|
|
ASSERT(KeLoaderBlock);
|
2023-03-20 01:28:16 +00:00
|
|
|
CommandLine = KeLoaderBlock->LoadOptions;
|
|
|
|
while (*CommandLine)
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2023-03-20 01:28:16 +00:00
|
|
|
/* Skip any whitespace */
|
|
|
|
while (isspace(*CommandLine))
|
|
|
|
++CommandLine;
|
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
Found = 0;
|
2023-03-20 01:28:16 +00:00
|
|
|
if (_strnicmp(CommandLine, "LOADSYMBOLS", 11) == 0)
|
2007-06-28 17:49:02 +00:00
|
|
|
{
|
|
|
|
Found = +1;
|
2023-03-20 01:28:16 +00:00
|
|
|
CommandLine += 11;
|
2007-06-28 17:49:02 +00:00
|
|
|
}
|
2023-03-20 01:28:16 +00:00
|
|
|
else if (_strnicmp(CommandLine, "NOLOADSYMBOLS", 13) == 0)
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2007-06-28 17:49:02 +00:00
|
|
|
Found = -1;
|
2023-03-20 01:28:16 +00:00
|
|
|
CommandLine += 13;
|
2005-06-05 20:56:14 +00:00
|
|
|
}
|
2023-03-20 01:28:16 +00:00
|
|
|
if (Found != 0)
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2023-03-20 01:28:16 +00:00
|
|
|
if (*CommandLine == '=')
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2023-03-20 01:28:16 +00:00
|
|
|
++CommandLine;
|
|
|
|
YesNo = toupper(*CommandLine);
|
|
|
|
if (YesNo == 'N' || YesNo == '0')
|
2007-06-28 17:49:02 +00:00
|
|
|
{
|
|
|
|
Found = -1 * Found;
|
|
|
|
}
|
2005-06-05 20:56:14 +00:00
|
|
|
}
|
2007-06-28 17:49:02 +00:00
|
|
|
LoadSymbols = (0 < Found);
|
2005-06-05 20:56:14 +00:00
|
|
|
}
|
2023-03-20 01:28:16 +00:00
|
|
|
|
|
|
|
/* Move on to the next option */
|
|
|
|
while (*CommandLine && !isspace(*CommandLine))
|
|
|
|
++CommandLine;
|
2005-06-05 20:56:14 +00:00
|
|
|
}
|
2023-03-20 02:10:14 +00:00
|
|
|
|
|
|
|
#if 1 // FIXME: This is a workaround HACK!!
|
|
|
|
// Save the actual value of LoadSymbols but disable it for BootPhase 0.
|
|
|
|
OrigLoadSymbols = LoadSymbols;
|
|
|
|
LoadSymbols = FALSE;
|
|
|
|
return OrigLoadSymbols;
|
|
|
|
#endif
|
2007-06-28 17:49:02 +00:00
|
|
|
}
|
2023-03-13 23:51:03 +00:00
|
|
|
else if (BootPhase == 1)
|
2007-06-28 20:19:16 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
HANDLE Thread;
|
|
|
|
NTSTATUS Status;
|
2021-06-22 09:41:25 +00:00
|
|
|
KIRQL OldIrql;
|
2023-03-10 17:12:32 +00:00
|
|
|
PLIST_ENTRY ListEntry;
|
2021-06-22 17:46:27 +00:00
|
|
|
|
2023-03-20 02:10:14 +00:00
|
|
|
#if 1 // FIXME: This is a workaround HACK!!
|
|
|
|
// Now, restore the actual value of LoadSymbols.
|
|
|
|
LoadSymbols = OrigLoadSymbols;
|
|
|
|
#endif
|
|
|
|
|
2023-03-20 01:28:16 +00:00
|
|
|
/* Do not continue loading symbols if we have less than 96MB of RAM */
|
|
|
|
if (MmNumberOfPhysicalPages < (96 * 1024 * 1024 / PAGE_SIZE))
|
2023-03-13 23:51:03 +00:00
|
|
|
LoadSymbols = FALSE;
|
|
|
|
|
|
|
|
/* Continue this phase only if we need to load symbols */
|
|
|
|
if (!LoadSymbols)
|
2023-03-20 01:28:16 +00:00
|
|
|
return LoadSymbols;
|
2023-03-13 23:51:03 +00:00
|
|
|
|
2021-06-22 17:46:27 +00:00
|
|
|
/* Launch our worker thread */
|
|
|
|
InitializeListHead(&SymbolsToLoad);
|
|
|
|
KeInitializeSpinLock(&SymbolsToLoadLock);
|
|
|
|
KeInitializeEvent(&SymbolsToLoadEvent, SynchronizationEvent, FALSE);
|
|
|
|
|
2023-03-10 17:12:32 +00:00
|
|
|
Status = PsCreateSystemThread(&Thread,
|
|
|
|
THREAD_ALL_ACCESS,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
LoadSymbolsRoutine,
|
|
|
|
NULL);
|
2021-06-22 17:46:27 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed starting symbols loader thread: 0x%08x\n", Status);
|
|
|
|
LoadSymbols = FALSE;
|
2023-03-20 01:28:16 +00:00
|
|
|
return LoadSymbols;
|
2021-06-22 17:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RosSymInitKernelMode();
|
|
|
|
|
|
|
|
KeAcquireSpinLock(&PsLoadedModuleSpinLock, &OldIrql);
|
|
|
|
|
2023-03-10 17:12:32 +00:00
|
|
|
for (ListEntry = PsLoadedModuleList.Flink;
|
|
|
|
ListEntry != &PsLoadedModuleList;
|
|
|
|
ListEntry = ListEntry->Flink)
|
2021-06-22 17:46:27 +00:00
|
|
|
{
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
|
|
|
|
KdbSymProcessSymbols(LdrEntry, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
KeReleaseSpinLock(&PsLoadedModuleSpinLock, OldIrql);
|
2007-06-28 20:19:16 +00:00
|
|
|
}
|
2023-03-20 01:28:16 +00:00
|
|
|
|
|
|
|
return LoadSymbols;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|