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>
|
2004-08-26 16:04:50 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +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
|
|
|
|
2005-06-05 20:56:14 +00:00
|
|
|
static BOOLEAN LoadSymbols;
|
2004-08-26 16:04:50 +00:00
|
|
|
static LIST_ENTRY SymbolFileListHead;
|
|
|
|
static KSPIN_LOCK SymbolFileListLock;
|
2008-08-02 22:01:46 +00:00
|
|
|
BOOLEAN KdbpSymbolsInitialized = FALSE;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2009-06-13 15:28:33 +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 LPCWSTR Name,
|
|
|
|
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)) ||
|
|
|
|
(Name && !_wcsnicmp((*pLdrEntry)->BaseDllName.Buffer, Name, (*pLdrEntry)->BaseDllName.Length / sizeof(WCHAR))) ||
|
|
|
|
(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 LPCWSTR Name 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. */
|
|
|
|
if(KdbpSymSearchModuleList(PsLoadedModuleList.Flink,
|
|
|
|
&PsLoadedModuleList,
|
|
|
|
&Count,
|
|
|
|
Address,
|
|
|
|
Name,
|
|
|
|
Index,
|
|
|
|
pLdrEntry))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-22 21:31:55 +00:00
|
|
|
return TRUE;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
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,
|
|
|
|
Name,
|
|
|
|
Index,
|
|
|
|
pLdrEntry);
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
IN PKTRAP_FRAME 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;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG LineNumber;
|
|
|
|
CHAR FileName[256];
|
|
|
|
CHAR FunctionName[256];
|
2012-03-26 13:51:15 +00:00
|
|
|
CHAR ModuleNameAnsi[64];
|
2009-09-09 13:49:04 +00:00
|
|
|
|
2009-09-22 21:31:55 +00:00
|
|
|
if (!KdbpSymbolsInitialized || !KdbpSymFindModule(Address, NULL, -1, &LdrEntry))
|
2009-09-09 13:49:04 +00:00
|
|
|
return FALSE;
|
2012-03-26 13:51:15 +00:00
|
|
|
|
|
|
|
KdbpSymUnicodeToAnsi(&LdrEntry->BaseDllName,
|
|
|
|
ModuleNameAnsi,
|
|
|
|
sizeof(ModuleNameAnsi));
|
2009-09-09 13:49:04 +00:00
|
|
|
|
2009-09-22 21:31:55 +00:00
|
|
|
RelativeAddress = (ULONG_PTR)Address - (ULONG_PTR)LdrEntry->DllBase;
|
|
|
|
Status = KdbSymGetAddressInformation(LdrEntry->PatchInformation,
|
2009-09-09 13:49:04 +00:00
|
|
|
RelativeAddress,
|
|
|
|
&LineNumber,
|
|
|
|
FileName,
|
|
|
|
FunctionName);
|
|
|
|
if (NT_SUCCESS(Status))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2012-03-26 13:51:15 +00:00
|
|
|
DbgPrint("<%s:%x (%s:%d (%s))>",
|
|
|
|
ModuleNameAnsi, RelativeAddress, FileName, LineNumber, FunctionName);
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
2009-09-09 13:49:04 +00:00
|
|
|
else
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2012-03-26 13:51:15 +00:00
|
|
|
DbgPrint("<%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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief Get information for an address (source file, line number,
|
|
|
|
* function name)
|
|
|
|
*
|
2005-02-02 23:07:33 +00:00
|
|
|
* \param SymbolInfo Pointer to ROSSYM_INFO.
|
2004-08-26 16:04:50 +00:00
|
|
|
* \param RelativeAddress Relative address to look up.
|
|
|
|
* \param LineNumber Pointer to an ULONG which is filled with the line
|
|
|
|
* number (can be NULL)
|
|
|
|
* \param FileName Pointer to an array of CHARs which gets filled with
|
|
|
|
* the filename (can be NULL)
|
|
|
|
* \param FunctionName Pointer to an array of CHARs which gets filled with
|
|
|
|
* the function name (can be NULL)
|
|
|
|
*
|
|
|
|
* \returns NTSTATUS error code.
|
|
|
|
* \retval STATUS_SUCCESS At least one of the requested informations was found.
|
|
|
|
* \retval STATUS_UNSUCCESSFUL None of the requested information was found.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbSymGetAddressInformation(
|
|
|
|
IN PROSSYM_INFO RosSymInfo,
|
|
|
|
IN ULONG_PTR RelativeAddress,
|
|
|
|
OUT PULONG LineNumber OPTIONAL,
|
|
|
|
OUT PCH FileName OPTIONAL,
|
|
|
|
OUT PCH FunctionName OPTIONAL)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
if (!KdbpSymbolsInitialized ||
|
|
|
|
!RosSymInfo ||
|
|
|
|
!RosSymGetAddressInformation(RosSymInfo, RelativeAddress, LineNumber, FileName, FunctionName))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Find cached symbol file.
|
|
|
|
*
|
|
|
|
* Looks through the list of cached symbol files and tries to find an already
|
|
|
|
* loaded one.
|
|
|
|
*
|
|
|
|
* \param FileName FileName of the symbol file to look for.
|
|
|
|
*
|
|
|
|
* \returns A pointer to the cached symbol info.
|
|
|
|
* \retval NULL No cached info found.
|
|
|
|
*
|
|
|
|
* \sa KdbpSymAddCachedFile
|
|
|
|
*/
|
2009-06-13 15:28:33 +00:00
|
|
|
static PROSSYM_INFO
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbpSymFindCachedFile(
|
|
|
|
IN PUNICODE_STRING FileName)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
PIMAGE_SYMBOL_INFO_CACHE Current;
|
|
|
|
PLIST_ENTRY CurrentEntry;
|
|
|
|
KIRQL Irql;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Looking for cached symbol file %wZ\n", FileName);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
KeAcquireSpinLock(&SymbolFileListLock, &Irql);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
CurrentEntry = SymbolFileListHead.Flink;
|
|
|
|
while (CurrentEntry != (&SymbolFileListHead))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Current->FileName %wZ FileName %wZ\n", &Current->FileName, FileName);
|
|
|
|
if (RtlEqualUnicodeString(&Current->FileName, FileName, TRUE))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
Current->RefCount++;
|
|
|
|
KeReleaseSpinLock(&SymbolFileListLock, Irql);
|
|
|
|
DPRINT("Found cached file!\n");
|
|
|
|
return Current->RosSymInfo;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
KeReleaseSpinLock(&SymbolFileListLock, Irql);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Cached file not found!\n");
|
|
|
|
return NULL;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Add a symbol file to the cache.
|
|
|
|
*
|
|
|
|
* \param FileName Filename of the symbol file.
|
2005-02-02 23:07:33 +00:00
|
|
|
* \param RosSymInfo Pointer to the symbol info.
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
|
|
|
* \sa KdbpSymRemoveCachedFile
|
|
|
|
*/
|
2009-06-13 15:28:33 +00:00
|
|
|
static VOID
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbpSymAddCachedFile(
|
|
|
|
IN PUNICODE_STRING FileName,
|
|
|
|
IN PROSSYM_INFO RosSymInfo)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
PIMAGE_SYMBOL_INFO_CACHE CacheEntry;
|
2011-06-01 13:16:49 +00:00
|
|
|
KIRQL Irql;
|
2009-09-09 13:49:04 +00:00
|
|
|
|
|
|
|
DPRINT("Adding symbol file: RosSymInfo = %p\n", RosSymInfo);
|
|
|
|
|
|
|
|
/* allocate entry */
|
|
|
|
CacheEntry = ExAllocatePoolWithTag(NonPagedPool, sizeof (IMAGE_SYMBOL_INFO_CACHE), TAG_KDBS);
|
|
|
|
ASSERT(CacheEntry);
|
|
|
|
RtlZeroMemory(CacheEntry, sizeof (IMAGE_SYMBOL_INFO_CACHE));
|
|
|
|
|
|
|
|
/* fill entry */
|
|
|
|
CacheEntry->FileName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
FileName->Length,
|
|
|
|
TAG_KDBS);
|
|
|
|
RtlCopyUnicodeString(&CacheEntry->FileName, FileName);
|
|
|
|
ASSERT(CacheEntry->FileName.Buffer);
|
|
|
|
CacheEntry->RefCount = 1;
|
|
|
|
CacheEntry->RosSymInfo = RosSymInfo;
|
2011-06-01 13:16:49 +00:00
|
|
|
KeAcquireSpinLock(&SymbolFileListLock, &Irql);
|
|
|
|
InsertTailList(&SymbolFileListHead, &CacheEntry->ListEntry);
|
|
|
|
KeReleaseSpinLock(&SymbolFileListLock, Irql);
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Remove a symbol file (reference) from the cache.
|
|
|
|
*
|
|
|
|
* Tries to find a cache entry matching the given symbol info and decreases
|
|
|
|
* it's reference count. If the refcount is 0 after decreasing it the cache
|
|
|
|
* entry will be removed from the list and freed.
|
|
|
|
*
|
2005-02-02 23:07:33 +00:00
|
|
|
* \param RosSymInfo Pointer to the symbol info.
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
|
|
|
* \sa KdbpSymAddCachedFile
|
|
|
|
*/
|
2009-06-13 15:28:33 +00:00
|
|
|
static VOID
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbpSymRemoveCachedFile(
|
|
|
|
IN PROSSYM_INFO RosSymInfo)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
PIMAGE_SYMBOL_INFO_CACHE Current;
|
|
|
|
PLIST_ENTRY CurrentEntry;
|
|
|
|
KIRQL Irql;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
KeAcquireSpinLock(&SymbolFileListLock, &Irql);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
CurrentEntry = SymbolFileListHead.Flink;
|
|
|
|
while (CurrentEntry != (&SymbolFileListHead))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
if (Current->RosSymInfo == RosSymInfo) /* found */
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
ASSERT(Current->RefCount > 0);
|
|
|
|
Current->RefCount--;
|
|
|
|
if (Current->RefCount < 1)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
RemoveEntryList(&Current->ListEntry);
|
|
|
|
RosSymDelete(Current->RosSymInfo);
|
|
|
|
ExFreePool(Current);
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
2009-09-09 13:49:04 +00:00
|
|
|
|
|
|
|
KeReleaseSpinLock(&SymbolFileListLock, Irql);
|
|
|
|
return;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
KeReleaseSpinLock(&SymbolFileListLock, Irql);
|
|
|
|
DPRINT1("Warning: Removing unknown symbol file: RosSymInfo = %p\n", RosSymInfo);
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Loads a symbol file.
|
|
|
|
*
|
|
|
|
* \param FileName Filename of the symbol file to load.
|
2005-02-02 23:07:33 +00:00
|
|
|
* \param RosSymInfo Pointer to a ROSSYM_INFO which gets filled.
|
2004-08-26 16:04:50 +00:00
|
|
|
*
|
|
|
|
* \sa KdbpSymUnloadModuleSymbols
|
|
|
|
*/
|
2009-06-13 15:28:33 +00:00
|
|
|
static VOID
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbpSymLoadModuleSymbols(
|
|
|
|
IN PUNICODE_STRING FileName,
|
|
|
|
OUT PROSSYM_INFO *RosSymInfo)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
HANDLE FileHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
2004-12-17 17:51:57 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
/* Allow KDB to break on module load */
|
|
|
|
KdbModuleLoaded(FileName);
|
2005-01-12 19:04:06 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
if (!LoadSymbols)
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
*RosSymInfo = NULL;
|
|
|
|
return;
|
2005-06-05 20:56:14 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
/* Try to find cached (already loaded) symbol file */
|
|
|
|
*RosSymInfo = KdbpSymFindCachedFile(FileName);
|
|
|
|
if (*RosSymInfo)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Found cached symbol file %wZ\n", FileName);
|
|
|
|
return;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
/* Open the file */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
FileName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
DPRINT("Attempting to open image: %wZ\n", FileName);
|
|
|
|
|
|
|
|
Status = ZwOpenFile(&FileHandle,
|
2013-07-19 15:05:28 +00:00
|
|
|
FILE_READ_ACCESS | SYNCHRONIZE,
|
2009-09-09 13:49:04 +00:00
|
|
|
&ObjectAttributes,
|
|
|
|
&IoStatusBlock,
|
2013-07-19 15:05:28 +00:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
2009-09-09 13:49:04 +00:00
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Could not open image file: %wZ\n", FileName);
|
|
|
|
return;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Loading symbols from %wZ...\n", FileName);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
if (!RosSymCreateFromFile(&FileHandle, RosSymInfo))
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Failed to load symbols from %wZ\n", FileName);
|
|
|
|
return;
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
ZwClose(FileHandle);
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Symbols loaded.\n");
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
/* add file to cache */
|
|
|
|
KdbpSymAddCachedFile(FileName, *RosSymInfo);
|
2005-02-02 23:07:33 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
DPRINT("Installed symbols: %wZ %p\n", FileName, *RosSymInfo);
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
2007-10-31 14:41:27 +00:00
|
|
|
VOID
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbSymProcessSymbols(
|
2009-09-22 21:31:55 +00:00
|
|
|
IN PLDR_DATA_TABLE_ENTRY LdrEntry)
|
2007-10-31 14:41:27 +00:00
|
|
|
{
|
2007-11-19 11:26:52 +00:00
|
|
|
if (!LoadSymbols)
|
2007-10-31 14:41:27 +00:00
|
|
|
{
|
2007-11-19 11:26:52 +00:00
|
|
|
LdrEntry->PatchInformation = NULL;
|
|
|
|
return;
|
2007-10-31 14:41:27 +00:00
|
|
|
}
|
2007-11-19 11:26:52 +00:00
|
|
|
|
|
|
|
/* Remove symbol info if it already exists */
|
2009-09-09 13:49:04 +00:00
|
|
|
if (LdrEntry->PatchInformation)
|
2007-11-19 11:26:52 +00:00
|
|
|
KdbpSymRemoveCachedFile(LdrEntry->PatchInformation);
|
|
|
|
|
|
|
|
/* Load new symbol information */
|
|
|
|
if (! RosSymCreateFromMem(LdrEntry->DllBase,
|
|
|
|
LdrEntry->SizeOfImage,
|
|
|
|
(PROSSYM_INFO*)&LdrEntry->PatchInformation))
|
|
|
|
{
|
|
|
|
/* Error loading symbol info, try to load it from file */
|
|
|
|
KdbpSymLoadModuleSymbols(&LdrEntry->FullDllName,
|
|
|
|
(PROSSYM_INFO*)&LdrEntry->PatchInformation);
|
|
|
|
|
|
|
|
/* It already added symbols to cache */
|
2007-10-31 14:41:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-19 11:26:52 +00:00
|
|
|
/* Add file to cache */
|
|
|
|
KdbpSymAddCachedFile(&LdrEntry->FullDllName, LdrEntry->PatchInformation);
|
2007-10-31 14:41:27 +00:00
|
|
|
}
|
2007-11-19 11:26:52 +00:00
|
|
|
|
2010-01-13 22:35:43 +00:00
|
|
|
DPRINT("Installed symbols: %wZ@%p-%p %p\n",
|
2007-11-19 11:26:52 +00:00
|
|
|
&LdrEntry->BaseDllName,
|
|
|
|
LdrEntry->DllBase,
|
2010-01-13 22:35:43 +00:00
|
|
|
(PVOID)(LdrEntry->SizeOfImage + (ULONG_PTR)LdrEntry->DllBase),
|
2007-11-19 11:26:52 +00:00
|
|
|
LdrEntry->PatchInformation);
|
|
|
|
|
2007-10-31 14:41:27 +00:00
|
|
|
}
|
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
VOID
|
2007-08-09 07:50:31 +00:00
|
|
|
NTAPI
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbDebugPrint(
|
|
|
|
PCH Message,
|
|
|
|
ULONG Length)
|
2007-06-28 17:49:02 +00:00
|
|
|
{
|
2007-08-09 07:50:31 +00:00
|
|
|
/* Nothing here */
|
2007-06-28 17:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-26 16:04:50 +00:00
|
|
|
/*! \brief Initializes the KDB symbols implementation.
|
|
|
|
*
|
2007-08-09 07:50:31 +00:00
|
|
|
* \param DispatchTable Pointer to the KD dispatch table
|
|
|
|
* \param BootPhase Phase of initialization
|
2004-08-26 16:04:50 +00:00
|
|
|
*/
|
|
|
|
VOID
|
2007-08-09 07:50:31 +00:00
|
|
|
NTAPI
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbInitialize(
|
|
|
|
PKD_DISPATCH_TABLE DispatchTable,
|
|
|
|
ULONG BootPhase)
|
2004-08-26 16:04:50 +00:00
|
|
|
{
|
2007-06-28 17:49:02 +00:00
|
|
|
PCHAR p1, p2;
|
2009-02-18 16:56:42 +00:00
|
|
|
SHORT Found = FALSE;
|
2007-11-20 10:17:34 +00:00
|
|
|
CHAR YesNo;
|
2009-09-22 21:31:55 +00:00
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
2007-06-28 17:49:02 +00:00
|
|
|
|
|
|
|
DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase);
|
|
|
|
|
2009-03-12 10:42:45 +00:00
|
|
|
LoadSymbols = FALSE;
|
|
|
|
|
2009-06-17 12:44:05 +00:00
|
|
|
#if DBG
|
2009-03-12 10:42:45 +00:00
|
|
|
/* Load symbols only if we have 96Mb of RAM or more */
|
|
|
|
if (MmNumberOfPhysicalPages >= 0x6000)
|
|
|
|
LoadSymbols = TRUE;
|
|
|
|
#endif
|
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
if (BootPhase == 0)
|
|
|
|
{
|
|
|
|
/* Write out the functions that we support for now */
|
2007-07-06 09:02:16 +00:00
|
|
|
DispatchTable->KdpInitRoutine = KdpKdbgInit;
|
2007-06-28 17:49:02 +00:00
|
|
|
DispatchTable->KdpPrintRoutine = KdbDebugPrint;
|
|
|
|
|
|
|
|
/* Register as a Provider */
|
|
|
|
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
|
2005-06-05 20:56:14 +00:00
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
/* Perform actual initialization of symbol module */
|
|
|
|
//NtoskrnlModuleObject->PatchInformation = NULL;
|
|
|
|
//LdrHalModuleObject->PatchInformation = NULL;
|
2004-08-26 16:04:50 +00:00
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
InitializeListHead(&SymbolFileListHead);
|
|
|
|
KeInitializeSpinLock(&SymbolFileListLock);
|
2005-02-02 23:07:33 +00:00
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
/* Check the command line for /LOADSYMBOLS, /NOLOADSYMBOLS,
|
|
|
|
* /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */
|
|
|
|
ASSERT(KeLoaderBlock);
|
|
|
|
p1 = KeLoaderBlock->LoadOptions;
|
|
|
|
while('\0' != *p1 && NULL != (p2 = strchr(p1, '/')))
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2007-06-28 17:49:02 +00:00
|
|
|
p2++;
|
|
|
|
Found = 0;
|
|
|
|
if (0 == _strnicmp(p2, "LOADSYMBOLS", 11))
|
|
|
|
{
|
|
|
|
Found = +1;
|
|
|
|
p2 += 11;
|
|
|
|
}
|
|
|
|
else if (0 == _strnicmp(p2, "NOLOADSYMBOLS", 13))
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2007-06-28 17:49:02 +00:00
|
|
|
Found = -1;
|
|
|
|
p2 += 13;
|
2005-06-05 20:56:14 +00:00
|
|
|
}
|
2007-06-28 17:49:02 +00:00
|
|
|
if (0 != Found)
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2007-06-28 17:49:02 +00:00
|
|
|
while (isspace(*p2))
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2007-06-28 17:49:02 +00:00
|
|
|
p2++;
|
2005-06-05 20:56:14 +00:00
|
|
|
}
|
2007-06-28 17:49:02 +00:00
|
|
|
if ('=' == *p2)
|
2005-06-05 20:56:14 +00:00
|
|
|
{
|
2007-06-28 17:49:02 +00:00
|
|
|
p2++;
|
|
|
|
while (isspace(*p2))
|
|
|
|
{
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
YesNo = toupper(*p2);
|
|
|
|
if ('N' == YesNo || 'F' == YesNo || '0' == YesNo)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2007-06-28 17:49:02 +00:00
|
|
|
p1 = p2;
|
2005-06-05 20:56:14 +00:00
|
|
|
}
|
|
|
|
|
2007-06-28 17:49:02 +00:00
|
|
|
RosSymInitKernelMode();
|
|
|
|
}
|
2007-06-28 20:19:16 +00:00
|
|
|
else if (BootPhase == 1)
|
|
|
|
{
|
2009-09-22 21:31:55 +00:00
|
|
|
/* Load symbols for NTOSKRNL.EXE.
|
|
|
|
It is always the first module in PsLoadedModuleList. KeLoaderBlock can't be used here as its content is just temporary. */
|
|
|
|
LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
|
|
|
|
KdbSymProcessSymbols(LdrEntry);
|
2007-11-20 10:17:34 +00:00
|
|
|
|
2009-11-08 01:13:49 +00:00
|
|
|
/* Also load them for HAL.DLL. */
|
|
|
|
LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
|
|
|
|
KdbSymProcessSymbols(LdrEntry);
|
2007-11-20 10:17:34 +00:00
|
|
|
|
2009-09-09 13:49:04 +00:00
|
|
|
KdbpSymbolsInitialized = TRUE;
|
2007-06-28 20:19:16 +00:00
|
|
|
}
|
2004-08-26 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|