ReactOS  0.4.15-dev-1638-gc0caa5c
kdb_symbols.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kdb_symbols.c:

Go to the source code of this file.

Classes

struct  _IMAGE_SYMBOL_INFO_CACHE
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _IMAGE_SYMBOL_INFO_CACHE IMAGE_SYMBOL_INFO_CACHE
 
typedef struct _IMAGE_SYMBOL_INFO_CACHEPIMAGE_SYMBOL_INFO_CACHE
 

Functions

static NTSTATUS KdbSymGetAddressInformation (IN PROSSYM_INFO RosSymInfo, IN ULONG_PTR RelativeAddress, OUT PULONG LineNumber OPTIONAL, OUT PCH FileName OPTIONAL, OUT PCH FunctionName OPTIONAL)
 Get information for an address (source file, line number, function name) More...
 
static BOOLEAN 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)
 
BOOLEAN KdbpSymFindModule (IN PVOID Address OPTIONAL, IN LPCWSTR Name OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
 Find a module... More...
 
PCHAR NTAPI KdbpSymUnicodeToAnsi (IN PUNICODE_STRING Unicode, OUT PCHAR Ansi, IN ULONG Length)
 
BOOLEAN KdbSymPrintAddress (IN PVOID Address, IN PCONTEXT Context)
 Print address... More...
 
static PROSSYM_INFO KdbpSymFindCachedFile (IN PUNICODE_STRING FileName)
 Find cached symbol file. More...
 
static VOID KdbpSymAddCachedFile (IN PUNICODE_STRING FileName, IN PROSSYM_INFO RosSymInfo)
 Add a symbol file to the cache. More...
 
static VOID KdbpSymRemoveCachedFile (IN PROSSYM_INFO RosSymInfo)
 Remove a symbol file (reference) from the cache. More...
 
static VOID KdbpSymLoadModuleSymbols (IN PUNICODE_STRING FileName, OUT PROSSYM_INFO *RosSymInfo)
 Loads a symbol file. More...
 
VOID KdbSymProcessSymbols (IN PLDR_DATA_TABLE_ENTRY LdrEntry)
 
VOID NTAPI KdbDebugPrint (PCH Message, ULONG Length)
 
VOID NTAPI KdbInitialize (PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
 Initializes the KDB symbols implementation. More...
 

Variables

static BOOLEAN LoadSymbols
 
static LIST_ENTRY SymbolFileListHead
 
static KSPIN_LOCK SymbolFileListLock
 
BOOLEAN KdbpSymbolsInitialized = FALSE
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file kdb_symbols.c.

Typedef Documentation

◆ IMAGE_SYMBOL_INFO_CACHE

◆ PIMAGE_SYMBOL_INFO_CACHE

Function Documentation

◆ KdbDebugPrint()

VOID NTAPI KdbDebugPrint ( PCH  Message,
ULONG  Length 
)

Definition at line 474 of file kdb_symbols.c.

477 {
478  /* Nothing here */
479 }

Referenced by KdbInitialize().

◆ KdbInitialize()

VOID NTAPI KdbInitialize ( PKD_DISPATCH_TABLE  DispatchTable,
ULONG  BootPhase 
)

Initializes the KDB symbols implementation.

Parameters
DispatchTablePointer to the KD dispatch table
BootPhasePhase of initialization

Definition at line 489 of file kdb_symbols.c.

492 {
493  PCHAR p1, p2;
494  SHORT Found = FALSE;
495  CHAR YesNo;
496  PLDR_DATA_TABLE_ENTRY LdrEntry;
497 
498  DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase);
499 
500  LoadSymbols = FALSE;
501 
502 #if DBG
503  /* Load symbols only if we have 96Mb of RAM or more */
504  if (MmNumberOfPhysicalPages >= 0x6000)
505  LoadSymbols = TRUE;
506 #endif
507 
508  if (BootPhase == 0)
509  {
510  /* Write out the functions that we support for now */
511  DispatchTable->KdpInitRoutine = KdpKdbgInit;
512  DispatchTable->KdpPrintRoutine = KdbDebugPrint;
513 
514  /* Register as a Provider */
515  InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
516 
517  /* Perform actual initialization of symbol module */
518  //NtoskrnlModuleObject->PatchInformation = NULL;
519  //LdrHalModuleObject->PatchInformation = NULL;
520 
523 
524  /* Check the command line for /LOADSYMBOLS, /NOLOADSYMBOLS,
525  * /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */
528  while('\0' != *p1 && NULL != (p2 = strchr(p1, '/')))
529  {
530  p2++;
531  Found = 0;
532  if (0 == _strnicmp(p2, "LOADSYMBOLS", 11))
533  {
534  Found = +1;
535  p2 += 11;
536  }
537  else if (0 == _strnicmp(p2, "NOLOADSYMBOLS", 13))
538  {
539  Found = -1;
540  p2 += 13;
541  }
542  if (0 != Found)
543  {
544  while (isspace(*p2))
545  {
546  p2++;
547  }
548  if ('=' == *p2)
549  {
550  p2++;
551  while (isspace(*p2))
552  {
553  p2++;
554  }
555  YesNo = toupper(*p2);
556  if ('N' == YesNo || 'F' == YesNo || '0' == YesNo)
557  {
558  Found = -1 * Found;
559  }
560  }
561  LoadSymbols = (0 < Found);
562  }
563  p1 = p2;
564  }
565 
567  }
568  else if (BootPhase == 1)
569  {
570  /* Load symbols for NTOSKRNL.EXE.
571  It is always the first module in PsLoadedModuleList. KeLoaderBlock can't be used here as its content is just temporary. */
572  LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
573  KdbSymProcessSymbols(LdrEntry);
574 
575  /* Also load them for HAL.DLL. */
576  LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
577  KdbSymProcessSymbols(LdrEntry);
578 
580  }
581 }
signed char * PCHAR
Definition: retypes.h:7
BOOLEAN KdbpSymbolsInitialized
Definition: kdb_symbols.c:32
#define isspace(c)
Definition: acclib.h:69
VOID RosSymInitKernelMode(VOID)
Definition: initkm.c:32
VOID NTAPI KdpKdbgInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdbg.c:21
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
#define InsertTailList(ListHead, Entry)
#define FALSE
Definition: types.h:117
static KSPIN_LOCK SymbolFileListLock
Definition: kdb_symbols.c:31
short SHORT
Definition: pedump.c:59
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
void DPRINT(...)
Definition: polytest.cpp:61
return Found
Definition: dirsup.c:1270
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID NTAPI KdbDebugPrint(PCH Message, ULONG Length)
Definition: kdb_symbols.c:474
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
int toupper(int c)
Definition: utclib.c:881
#define ASSERT(a)
Definition: mode.c:45
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
VOID KdbSymProcessSymbols(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: kdb_symbols.c:434
Definition: btrfs_drv.h:1922
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static BOOLEAN LoadSymbols
Definition: kdb_symbols.c:29
_In_ PWDFDEVICE_INIT _In_ PWDF_PDO_EVENT_CALLBACKS DispatchTable
Definition: wdfpdo.h:245
LIST_ENTRY KdProviders
Definition: kdio.c:47
static LIST_ENTRY SymbolFileListHead
Definition: kdb_symbols.c:30

Referenced by KdpKdbgInit().

◆ KdbpSymAddCachedFile()

static VOID KdbpSymAddCachedFile ( IN PUNICODE_STRING  FileName,
IN PROSSYM_INFO  RosSymInfo 
)
static

Add a symbol file to the cache.

Parameters
FileNameFilename of the symbol file.
RosSymInfoPointer to the symbol info.
See also
KdbpSymRemoveCachedFile

Definition at line 284 of file kdb_symbols.c.

287 {
288  PIMAGE_SYMBOL_INFO_CACHE CacheEntry;
289  KIRQL Irql;
290 
291  DPRINT("Adding symbol file: RosSymInfo = %p\n", RosSymInfo);
292 
293  /* allocate entry */
295  ASSERT(CacheEntry);
296  RtlZeroMemory(CacheEntry, sizeof (IMAGE_SYMBOL_INFO_CACHE));
297 
298  /* fill entry */
300  FileName->Length,
301  TAG_KDBS);
302  RtlCopyUnicodeString(&CacheEntry->FileName, FileName);
303  ASSERT(CacheEntry->FileName.Buffer);
304  CacheEntry->RefCount = 1;
305  CacheEntry->RosSymInfo = RosSymInfo;
309 }
#define InsertTailList(ListHead, Entry)
_Out_ PKIRQL Irql
Definition: csq.h:179
UNICODE_STRING FileName
Definition: kdb_symbols.c:24
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
UCHAR KIRQL
Definition: env_spec_w32.h:591
static KSPIN_LOCK SymbolFileListLock
Definition: kdb_symbols.c:31
void DPRINT(...)
Definition: polytest.cpp:61
#define ASSERT(a)
Definition: mode.c:45
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
PROSSYM_INFO RosSymInfo
Definition: kdb_symbols.c:25
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define TAG_KDBS
Definition: kdb.h:7
static LIST_ENTRY SymbolFileListHead
Definition: kdb_symbols.c:30

Referenced by KdbpSymLoadModuleSymbols(), and KdbSymProcessSymbols().

◆ KdbpSymFindCachedFile()

static PROSSYM_INFO KdbpSymFindCachedFile ( IN PUNICODE_STRING  FileName)
static

Find cached symbol file.

Looks through the list of cached symbol files and tries to find an already loaded one.

Parameters
FileNameFileName of the symbol file to look for.
Returns
A pointer to the cached symbol info.
Return values
NULLNo cached info found.
See also
KdbpSymAddCachedFile

Definition at line 242 of file kdb_symbols.c.

244 {
245  PIMAGE_SYMBOL_INFO_CACHE Current;
246  PLIST_ENTRY CurrentEntry;
247  KIRQL Irql;
248 
249  DPRINT("Looking for cached symbol file %wZ\n", FileName);
250 
252 
253  CurrentEntry = SymbolFileListHead.Flink;
254  while (CurrentEntry != (&SymbolFileListHead))
255  {
256  Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry);
257 
258  DPRINT("Current->FileName %wZ FileName %wZ\n", &Current->FileName, FileName);
259  if (RtlEqualUnicodeString(&Current->FileName, FileName, TRUE))
260  {
261  Current->RefCount++;
263  DPRINT("Found cached file!\n");
264  return Current->RosSymInfo;
265  }
266 
267  CurrentEntry = CurrentEntry->Flink;
268  }
269 
271 
272  DPRINT("Cached file not found!\n");
273  return NULL;
274 }
#define TRUE
Definition: types.h:120
_Out_ PKIRQL Irql
Definition: csq.h:179
UNICODE_STRING FileName
Definition: kdb_symbols.c:24
UCHAR KIRQL
Definition: env_spec_w32.h:591
static KSPIN_LOCK SymbolFileListLock
Definition: kdb_symbols.c:31
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
Definition: typedefs.h:119
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
PROSSYM_INFO RosSymInfo
Definition: kdb_symbols.c:25
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
static LIST_ENTRY SymbolFileListHead
Definition: kdb_symbols.c:30

Referenced by KdbpSymLoadModuleSymbols().

◆ KdbpSymFindModule()

BOOLEAN KdbpSymFindModule ( IN PVOID Address  OPTIONAL,
IN LPCWSTR Name  OPTIONAL,
IN INT Index  OPTIONAL,
OUT PLDR_DATA_TABLE_ENTRY pLdrEntry 
)

Find a module...

Parameters
AddressIf Address is not NULL the module containing Address is searched.
NameIf Name is not NULL the module named Name will be searched.
IndexIf Index is >= 0 the Index'th module will be returned.
pLdrEntryPointer to a PLDR_DATA_TABLE_ENTRY which is filled.
Return values
TRUEModule was found, pLdrEntry was filled.
FALSENo module was found.

Definition at line 84 of file kdb_symbols.c.

89 {
90  LONG Count = 0;
92 
93  /* First try to look up the module in the kernel module list. */
96  &Count,
97  Address,
98  Name,
99  Index,
100  pLdrEntry))
101  {
102  return TRUE;
103  }
104 
105  /* That didn't succeed. Try the module list of the current process now. */
107 
108  if(!CurrentProcess || !CurrentProcess->Peb || !CurrentProcess->Peb->Ldr)
109  return FALSE;
110 
111  return KdbpSymSearchModuleList(CurrentProcess->Peb->Ldr->InLoadOrderModuleList.Flink,
112  &CurrentProcess->Peb->Ldr->InLoadOrderModuleList,
113  &Count,
114  Address,
115  Name,
116  Index,
117  pLdrEntry);
118 }
static BOOLEAN 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)
Definition: kdb_symbols.c:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
int Count
Definition: noreturn.cpp:7
ULONG CurrentProcess
Definition: shell.c:125
_In_ WDFCOLLECTION _In_ ULONG Index
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34

Referenced by KdbpCmdMod(), KdbSymPrintAddress(), and KdSendPacket().

◆ KdbpSymLoadModuleSymbols()

static VOID KdbpSymLoadModuleSymbols ( IN PUNICODE_STRING  FileName,
OUT PROSSYM_INFO RosSymInfo 
)
static

Loads a symbol file.

Parameters
FileNameFilename of the symbol file to load.
RosSymInfoPointer to a ROSSYM_INFO which gets filled.
See also
KdbpSymUnloadModuleSymbols

Definition at line 366 of file kdb_symbols.c.

369 {
374  BOOLEAN Result;
375 
376  /* Allow KDB to break on module load */
377  KdbModuleLoaded(FileName);
378 
379  if (!LoadSymbols)
380  {
381  *RosSymInfo = NULL;
382  return;
383  }
384 
385  /* Try to find cached (already loaded) symbol file */
386  *RosSymInfo = KdbpSymFindCachedFile(FileName);
387  if (*RosSymInfo)
388  {
389  DPRINT("Found cached symbol file %wZ\n", FileName);
390  return;
391  }
392 
393  /* Open the file */
395  FileName,
397  NULL,
398  NULL);
399 
400  DPRINT("Attempting to open image: %wZ\n", FileName);
401 
405  &IoStatusBlock,
408  if (!NT_SUCCESS(Status))
409  {
410  DPRINT("Could not open image file: %wZ\n", FileName);
411  return;
412  }
413 
414  DPRINT("Loading symbols from %wZ...\n", FileName);
415 
416  Result = RosSymCreateFromFile(&FileHandle, RosSymInfo);
418 
419  if (!Result)
420  {
421  DPRINT("Failed to load symbols from %wZ\n", FileName);
422  return;
423  }
424 
425  DPRINT("Symbols loaded.\n");
426 
427  /* add file to cache */
428  KdbpSymAddCachedFile(FileName, *RosSymInfo);
429 
430  DPRINT("Installed symbols: %wZ %p\n", FileName, *RosSymInfo);
431 }
static VOID KdbpSymAddCachedFile(IN PUNICODE_STRING FileName, IN PROSSYM_INFO RosSymInfo)
Add a symbol file to the cache.
Definition: kdb_symbols.c:284
#define FILE_READ_ACCESS
Definition: nt_native.h:610
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN RosSymCreateFromFile(PVOID FileContext, PROSSYM_INFO *RosSymInfo)
Definition: fromfile.c:20
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define FILE_SHARE_READ
Definition: compat.h:136
HANDLE FileHandle
Definition: stats.c:38
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static PROSSYM_INFO KdbpSymFindCachedFile(IN PUNICODE_STRING FileName)
Find cached symbol file.
Definition: kdb_symbols.c:242
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
#define SYNCHRONIZE
Definition: nt_native.h:61
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static BOOLEAN LoadSymbols
Definition: kdb_symbols.c:29

Referenced by KdbSymProcessSymbols().

◆ KdbpSymRemoveCachedFile()

static VOID KdbpSymRemoveCachedFile ( IN PROSSYM_INFO  RosSymInfo)
static

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.

Parameters
RosSymInfoPointer to the symbol info.
See also
KdbpSymAddCachedFile

Definition at line 322 of file kdb_symbols.c.

324 {
325  PIMAGE_SYMBOL_INFO_CACHE Current;
326  PLIST_ENTRY CurrentEntry;
327  KIRQL Irql;
328 
330 
331  CurrentEntry = SymbolFileListHead.Flink;
332  while (CurrentEntry != (&SymbolFileListHead))
333  {
334  Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry);
335 
336  if (Current->RosSymInfo == RosSymInfo) /* found */
337  {
338  ASSERT(Current->RefCount > 0);
339  Current->RefCount--;
340  if (Current->RefCount < 1)
341  {
342  RemoveEntryList(&Current->ListEntry);
343  RosSymDelete(Current->RosSymInfo);
344  ExFreePool(Current);
345  }
346 
348  return;
349  }
350 
351  CurrentEntry = CurrentEntry->Flink;
352  }
353 
355  DPRINT1("Warning: Removing unknown symbol file: RosSymInfo = %p\n", RosSymInfo);
356 }
VOID RosSymDelete(PROSSYM_INFO RosSymInfo)
Definition: delete.c:16
_Out_ PKIRQL Irql
Definition: csq.h:179
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
static KSPIN_LOCK SymbolFileListLock
Definition: kdb_symbols.c:31
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:45
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
Definition: typedefs.h:119
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
PROSSYM_INFO RosSymInfo
Definition: kdb_symbols.c:25
#define DPRINT1
Definition: precomp.h:8
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
static LIST_ENTRY SymbolFileListHead
Definition: kdb_symbols.c:30

Referenced by KdbSymProcessSymbols().

◆ KdbpSymSearchModuleList()

static BOOLEAN 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 
)
static

Definition at line 45 of file kdb_symbols.c.

53 {
54  while (current_entry && current_entry != end_entry)
55  {
56  *pLdrEntry = CONTAINING_RECORD(current_entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
57 
58  if ((Address && Address >= (PVOID)(*pLdrEntry)->DllBase && Address < (PVOID)((ULONG_PTR)(*pLdrEntry)->DllBase + (*pLdrEntry)->SizeOfImage)) ||
59  (Name && !_wcsnicmp((*pLdrEntry)->BaseDllName.Buffer, Name, (*pLdrEntry)->BaseDllName.Length / sizeof(WCHAR))) ||
60  (Index >= 0 && (*Count)++ == Index))
61  {
62  return TRUE;
63  }
64 
65  current_entry = current_entry->Flink;
66  }
67 
68  return FALSE;
69 }
#define TRUE
Definition: types.h:120
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
static WCHAR Address[46]
Definition: ping.c:68
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
int Count
Definition: noreturn.cpp:7
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ WDFCOLLECTION _In_ ULONG Index
Definition: btrfs_drv.h:1922

Referenced by KdbpSymFindModule().

◆ KdbpSymUnicodeToAnsi()

PCHAR NTAPI KdbpSymUnicodeToAnsi ( IN PUNICODE_STRING  Unicode,
OUT PCHAR  Ansi,
IN ULONG  Length 
)

Definition at line 122 of file kdb_symbols.c.

125 {
126  PCHAR p;
127  PWCHAR pw;
128  ULONG i;
129 
130  /* Set length and normalize it */
131  i = Unicode->Length / sizeof(WCHAR);
132  i = min(i, Length - 1);
133 
134  /* Set source and destination, and copy */
135  pw = Unicode->Buffer;
136  p = Ansi;
137  while (i--) *p++ = (CHAR)*pw++;
138 
139  /* Null terminate and return */
140  *p = ANSI_NULL;
141  return Ansi;
142 }
signed char * PCHAR
Definition: retypes.h:7
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
uint16_t * PWCHAR
Definition: typedefs.h:56
#define ANSI_NULL
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
#define CHAR(Char)

Referenced by KdbSymPrintAddress().

◆ KdbSymGetAddressInformation()

static NTSTATUS KdbSymGetAddressInformation ( IN PROSSYM_INFO  RosSymInfo,
IN ULONG_PTR  RelativeAddress,
OUT PULONG LineNumber  OPTIONAL,
OUT PCH FileName  OPTIONAL,
OUT PCH FunctionName  OPTIONAL 
)
static

Get information for an address (source file, line number, function name)

Parameters
SymbolInfoPointer to ROSSYM_INFO.
RelativeAddressRelative address to look up.
LineNumberPointer to an ULONG which is filled with the line number (can be NULL)
FileNamePointer to an array of CHARs which gets filled with the filename (can be NULL)
FunctionNamePointer to an array of CHARs which gets filled with the function name (can be NULL)
Returns
NTSTATUS error code.
Return values
STATUS_SUCCESSAt least one of the requested informations was found.
STATUS_UNSUCCESSFULNone of the requested information was found.

Definition at line 212 of file kdb_symbols.c.

218 {
219  if (!KdbpSymbolsInitialized ||
220  !RosSymInfo ||
221  !RosSymGetAddressInformation(RosSymInfo, RelativeAddress, LineNumber, FileName, FunctionName))
222  {
223  return STATUS_UNSUCCESSFUL;
224  }
225 
226  return STATUS_SUCCESS;
227 }
BOOLEAN KdbpSymbolsInitialized
Definition: kdb_symbols.c:32
BOOLEAN RosSymGetAddressInformation(PROSSYM_INFO RosSymInfo, ULONG_PTR RelativeAddress, ULONG *LineNumber, char *FileName, char *FunctionName)
Definition: find.c:94
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 LineNumber
Definition: acpixf.h:1216
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1274
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by KdbSymPrintAddress().

◆ KdbSymPrintAddress()

BOOLEAN KdbSymPrintAddress ( IN PVOID  Address,
IN PCONTEXT  Context 
)

Print address...

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 <module: offset>, otherwise the format will be <module: offset (filename:linenumber (functionname))>

Return values
TRUEModule containing Address was found, Address was printed.
FALSENo module containing Address was found, nothing was printed.

Definition at line 156 of file kdb_symbols.c.

159 {
160  PLDR_DATA_TABLE_ENTRY LdrEntry;
161  ULONG_PTR RelativeAddress;
164  CHAR FileName[256];
165  CHAR FunctionName[256];
166  CHAR ModuleNameAnsi[64];
167 
168  if (!KdbpSymbolsInitialized || !KdbpSymFindModule(Address, NULL, -1, &LdrEntry))
169  return FALSE;
170 
172  ModuleNameAnsi,
173  sizeof(ModuleNameAnsi));
174 
175  RelativeAddress = (ULONG_PTR)Address - (ULONG_PTR)LdrEntry->DllBase;
177  RelativeAddress,
178  &LineNumber,
179  FileName,
180  FunctionName);
181  if (NT_SUCCESS(Status))
182  {
183  DbgPrint("<%s:%x (%s:%d (%s))>",
184  ModuleNameAnsi, RelativeAddress, FileName, LineNumber, FunctionName);
185  }
186  else
187  {
188  DbgPrint("<%s:%x>", ModuleNameAnsi, RelativeAddress);
189  }
190 
191  return TRUE;
192 }
BOOLEAN KdbpSymbolsInitialized
Definition: kdb_symbols.c:32
#define DbgPrint
Definition: loader.c:25
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:65
PVOID DllBase
Definition: btrfs_drv.h:1926
static NTSTATUS KdbSymGetAddressInformation(IN PROSSYM_INFO RosSymInfo, IN ULONG_PTR RelativeAddress, OUT PULONG LineNumber OPTIONAL, OUT PCH FileName OPTIONAL, OUT PCH FunctionName OPTIONAL)
Get information for an address (source file, line number, function name)
Definition: kdb_symbols.c:212
#define FALSE
Definition: types.h:117
static WCHAR Address[46]
Definition: ping.c:68
Status
Definition: gdiplustypes.h:24
PVOID PatchInformation
Definition: ldrtypes.h:164
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PCHAR NTAPI KdbpSymUnicodeToAnsi(IN PUNICODE_STRING Unicode, OUT PCHAR Ansi, IN ULONG Length)
Definition: kdb_symbols.c:122
Definition: btrfs_drv.h:1922
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 LineNumber
Definition: acpixf.h:1216
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
#define NULL
Definition: types.h:112
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1274
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
BOOLEAN KdbpSymFindModule(IN PVOID Address OPTIONAL, IN LPCWSTR Name OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
Find a module...
Definition: kdb_symbols.c:84

Referenced by KdbpCliMainLoop(), KdbpCmdBackTrace(), KdbpCmdDisassembleX(), KdbpPrintAddressInCode(), and KeRosDumpStackFrameArray().

◆ KdbSymProcessSymbols()

VOID KdbSymProcessSymbols ( IN PLDR_DATA_TABLE_ENTRY  LdrEntry)

Definition at line 434 of file kdb_symbols.c.

436 {
437  if (!LoadSymbols)
438  {
439  LdrEntry->PatchInformation = NULL;
440  return;
441  }
442 
443  /* Remove symbol info if it already exists */
444  if (LdrEntry->PatchInformation)
445  KdbpSymRemoveCachedFile(LdrEntry->PatchInformation);
446 
447  /* Load new symbol information */
448  if (! RosSymCreateFromMem(LdrEntry->DllBase,
449  LdrEntry->SizeOfImage,
450  (PROSSYM_INFO*)&LdrEntry->PatchInformation))
451  {
452  /* Error loading symbol info, try to load it from file */
453  KdbpSymLoadModuleSymbols(&LdrEntry->FullDllName,
454  (PROSSYM_INFO*)&LdrEntry->PatchInformation);
455 
456  /* It already added symbols to cache */
457  }
458  else
459  {
460  /* Add file to cache */
461  KdbpSymAddCachedFile(&LdrEntry->FullDllName, LdrEntry->PatchInformation);
462  }
463 
464  DPRINT("Installed symbols: %wZ@%p-%p %p\n",
465  &LdrEntry->BaseDllName,
466  LdrEntry->DllBase,
467  (PVOID)(LdrEntry->SizeOfImage + (ULONG_PTR)LdrEntry->DllBase),
468  LdrEntry->PatchInformation);
469 
470 }
static VOID KdbpSymAddCachedFile(IN PUNICODE_STRING FileName, IN PROSSYM_INFO RosSymInfo)
Add a symbol file to the cache.
Definition: kdb_symbols.c:284
BOOLEAN RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
Definition: frommem.c:20
uint32_t ULONG_PTR
Definition: typedefs.h:65
void DPRINT(...)
Definition: polytest.cpp:61
static VOID KdbpSymLoadModuleSymbols(IN PUNICODE_STRING FileName, OUT PROSSYM_INFO *RosSymInfo)
Loads a symbol file.
Definition: kdb_symbols.c:366
#define NULL
Definition: types.h:112
static VOID KdbpSymRemoveCachedFile(IN PROSSYM_INFO RosSymInfo)
Remove a symbol file (reference) from the cache.
Definition: kdb_symbols.c:322
static BOOLEAN LoadSymbols
Definition: kdb_symbols.c:29

Referenced by KdbInitialize(), and KdSendPacket().

Variable Documentation

◆ KdbpSymbolsInitialized

BOOLEAN KdbpSymbolsInitialized = FALSE

Definition at line 32 of file kdb_symbols.c.

Referenced by KdbInitialize(), KdbSymGetAddressInformation(), and KdbSymPrintAddress().

◆ LoadSymbols

BOOLEAN LoadSymbols
static

◆ SymbolFileListHead

LIST_ENTRY SymbolFileListHead
static

◆ SymbolFileListLock

KSPIN_LOCK SymbolFileListLock
static