ReactOS  0.4.14-dev-317-g96040ec
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 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 PKTRAP_FRAME Context)
 Print address... More...
 
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 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 464 of file kdb_symbols.c.

467 {
468  /* Nothing here */
469 }

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 479 of file kdb_symbols.c.

482 {
483  PCHAR p1, p2;
484  SHORT Found = FALSE;
485  CHAR YesNo;
486  PLDR_DATA_TABLE_ENTRY LdrEntry;
487 
488  DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase);
489 
490  LoadSymbols = FALSE;
491 
492 #if DBG
493  /* Load symbols only if we have 96Mb of RAM or more */
494  if (MmNumberOfPhysicalPages >= 0x6000)
495  LoadSymbols = TRUE;
496 #endif
497 
498  if (BootPhase == 0)
499  {
500  /* Write out the functions that we support for now */
501  DispatchTable->KdpInitRoutine = KdpKdbgInit;
502  DispatchTable->KdpPrintRoutine = KdbDebugPrint;
503 
504  /* Register as a Provider */
505  InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
506 
507  /* Perform actual initialization of symbol module */
508  //NtoskrnlModuleObject->PatchInformation = NULL;
509  //LdrHalModuleObject->PatchInformation = NULL;
510 
513 
514  /* Check the command line for /LOADSYMBOLS, /NOLOADSYMBOLS,
515  * /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */
518  while('\0' != *p1 && NULL != (p2 = strchr(p1, '/')))
519  {
520  p2++;
521  Found = 0;
522  if (0 == _strnicmp(p2, "LOADSYMBOLS", 11))
523  {
524  Found = +1;
525  p2 += 11;
526  }
527  else if (0 == _strnicmp(p2, "NOLOADSYMBOLS", 13))
528  {
529  Found = -1;
530  p2 += 13;
531  }
532  if (0 != Found)
533  {
534  while (isspace(*p2))
535  {
536  p2++;
537  }
538  if ('=' == *p2)
539  {
540  p2++;
541  while (isspace(*p2))
542  {
543  p2++;
544  }
545  YesNo = toupper(*p2);
546  if ('N' == YesNo || 'F' == YesNo || '0' == YesNo)
547  {
548  Found = -1 * Found;
549  }
550  }
551  LoadSymbols = (0 < Found);
552  }
553  p1 = p2;
554  }
555 
557  }
558  else if (BootPhase == 1)
559  {
560  /* Load symbols for NTOSKRNL.EXE.
561  It is always the first module in PsLoadedModuleList. KeLoaderBlock can't be used here as its content is just temporary. */
562  LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
563  KdbSymProcessSymbols(LdrEntry);
564 
565  /* Also load them for HAL.DLL. */
566  LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
567  KdbSymProcessSymbols(LdrEntry);
568 
570  }
571 }
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
#define TRUE
Definition: types.h:120
VOID NTAPI KdpKdbgInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdbg.c:21
char CHAR
Definition: xmlstorage.h:175
#define InsertTailList(ListHead, Entry)
LIST_ENTRY KdProviders
Definition: kdinit.c:29
static KSPIN_LOCK SymbolFileListLock
Definition: kdb_symbols.c:31
short SHORT
Definition: pedump.c:59
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:416
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:464
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
int toupper(int c)
Definition: utclib.c:881
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID KdbSymProcessSymbols(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: kdb_symbols.c:424
Definition: btrfs_drv.h:1853
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static LSA_DISPATCH_TABLE DispatchTable
Definition: authpackage.c:164
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static BOOLEAN LoadSymbols
Definition: kdb_symbols.c:29
static LIST_ENTRY SymbolFileListHead
Definition: kdb_symbols.c:30

◆ 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 276 of file kdb_symbols.c.

279 {
280  PIMAGE_SYMBOL_INFO_CACHE CacheEntry;
281  KIRQL Irql;
282 
283  DPRINT("Adding symbol file: RosSymInfo = %p\n", RosSymInfo);
284 
285  /* allocate entry */
287  ASSERT(CacheEntry);
288  RtlZeroMemory(CacheEntry, sizeof (IMAGE_SYMBOL_INFO_CACHE));
289 
290  /* fill entry */
292  FileName->Length,
293  TAG_KDBS);
294  RtlCopyUnicodeString(&CacheEntry->FileName, FileName);
295  ASSERT(CacheEntry->FileName.Buffer);
296  CacheEntry->RefCount = 1;
297  CacheEntry->RosSymInfo = RosSymInfo;
301 }
#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 KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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:261
#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 234 of file kdb_symbols.c.

236 {
237  PIMAGE_SYMBOL_INFO_CACHE Current;
238  PLIST_ENTRY CurrentEntry;
239  KIRQL Irql;
240 
241  DPRINT("Looking for cached symbol file %wZ\n", FileName);
242 
244 
245  CurrentEntry = SymbolFileListHead.Flink;
246  while (CurrentEntry != (&SymbolFileListHead))
247  {
248  Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry);
249 
250  DPRINT("Current->FileName %wZ FileName %wZ\n", &Current->FileName, FileName);
251  if (RtlEqualUnicodeString(&Current->FileName, FileName, TRUE))
252  {
253  Current->RefCount++;
255  DPRINT("Found cached file!\n");
256  return Current->RosSymInfo;
257  }
258 
259  CurrentEntry = CurrentEntry->Flink;
260  }
261 
263 
264  DPRINT("Cached file not found!\n");
265  return NULL;
266 }
#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
smooth NULL
Definition: ftsmooth.c:416
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:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
Definition: typedefs.h:117
#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 76 of file kdb_symbols.c.

81 {
82  LONG Count = 0;
84 
85  /* First try to look up the module in the kernel module list. */
88  &Count,
89  Address,
90  Name,
91  Index,
92  pLdrEntry))
93  {
94  return TRUE;
95  }
96 
97  /* That didn't succeed. Try the module list of the current process now. */
99 
100  if(!CurrentProcess || !CurrentProcess->Peb || !CurrentProcess->Peb->Ldr)
101  return FALSE;
102 
103  return KdbpSymSearchModuleList(CurrentProcess->Peb->Ldr->InLoadOrderModuleList.Flink,
104  &CurrentProcess->Peb->Ldr->InLoadOrderModuleList,
105  &Count,
106  Address,
107  Name,
108  Index,
109  pLdrEntry);
110 }
#define TRUE
Definition: types.h:120
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:37
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
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:119
ULONG CurrentProcess
Definition: shell.c:125
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
static const UCHAR Index[8]
Definition: usbohci.c:18

Referenced by KdbSymPrintAddress().

◆ 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 358 of file kdb_symbols.c.

361 {
366 
367  /* Allow KDB to break on module load */
368  KdbModuleLoaded(FileName);
369 
370  if (!LoadSymbols)
371  {
372  *RosSymInfo = NULL;
373  return;
374  }
375 
376  /* Try to find cached (already loaded) symbol file */
377  *RosSymInfo = KdbpSymFindCachedFile(FileName);
378  if (*RosSymInfo)
379  {
380  DPRINT("Found cached symbol file %wZ\n", FileName);
381  return;
382  }
383 
384  /* Open the file */
386  FileName,
387  0,
388  NULL,
389  NULL);
390 
391  DPRINT("Attempting to open image: %wZ\n", FileName);
392 
396  &IoStatusBlock,
399  if (!NT_SUCCESS(Status))
400  {
401  DPRINT("Could not open image file: %wZ\n", FileName);
402  return;
403  }
404 
405  DPRINT("Loading symbols from %wZ...\n", FileName);
406 
407  if (!RosSymCreateFromFile(&FileHandle, RosSymInfo))
408  {
409  DPRINT("Failed to load symbols from %wZ\n", FileName);
410  return;
411  }
412 
414 
415  DPRINT("Symbols loaded.\n");
416 
417  /* add file to cache */
418  KdbpSymAddCachedFile(FileName, *RosSymInfo);
419 
420  DPRINT("Installed symbols: %wZ %p\n", FileName, *RosSymInfo);
421 }
static VOID KdbpSymAddCachedFile(IN PUNICODE_STRING FileName, IN PROSSYM_INFO RosSymInfo)
Add a symbol file to the cache.
Definition: kdb_symbols.c:276
#define FILE_READ_ACCESS
Definition: nt_native.h:610
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
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 FILE_SHARE_READ
Definition: compat.h:125
HANDLE FileHandle
Definition: stats.c:38
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static PROSSYM_INFO KdbpSymFindCachedFile(IN PUNICODE_STRING FileName)
Find cached symbol file.
Definition: kdb_symbols.c:234
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
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#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 314 of file kdb_symbols.c.

316 {
317  PIMAGE_SYMBOL_INFO_CACHE Current;
318  PLIST_ENTRY CurrentEntry;
319  KIRQL Irql;
320 
322 
323  CurrentEntry = SymbolFileListHead.Flink;
324  while (CurrentEntry != (&SymbolFileListHead))
325  {
326  Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry);
327 
328  if (Current->RosSymInfo == RosSymInfo) /* found */
329  {
330  ASSERT(Current->RefCount > 0);
331  Current->RefCount--;
332  if (Current->RefCount < 1)
333  {
334  RemoveEntryList(&Current->ListEntry);
335  RosSymDelete(Current->RosSymInfo);
336  ExFreePool(Current);
337  }
338 
340  return;
341  }
342 
343  CurrentEntry = CurrentEntry->Flink;
344  }
345 
347  DPRINT1("Warning: Removing unknown symbol file: RosSymInfo = %p\n", RosSymInfo);
348 }
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:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:117
#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 37 of file kdb_symbols.c.

45 {
46  while (current_entry && current_entry != end_entry)
47  {
48  *pLdrEntry = CONTAINING_RECORD(current_entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
49 
50  if ((Address && Address >= (PVOID)(*pLdrEntry)->DllBase && Address < (PVOID)((ULONG_PTR)(*pLdrEntry)->DllBase + (*pLdrEntry)->SizeOfImage)) ||
51  (Name && !_wcsnicmp((*pLdrEntry)->BaseDllName.Buffer, Name, (*pLdrEntry)->BaseDllName.Length / sizeof(WCHAR))) ||
52  (Index >= 0 && (*Count)++ == Index))
53  {
54  return TRUE;
55  }
56 
57  current_entry = current_entry->Flink;
58  }
59 
60  return FALSE;
61 }
#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)
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: btrfs_drv.h:1853

Referenced by KdbpSymFindModule().

◆ KdbpSymUnicodeToAnsi()

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

Definition at line 114 of file kdb_symbols.c.

117 {
118  PCHAR p;
119  PWCHAR pw;
120  ULONG i;
121 
122  /* Set length and normalize it */
123  i = Unicode->Length / sizeof(WCHAR);
124  i = min(i, Length - 1);
125 
126  /* Set source and destination, and copy */
127  pw = Unicode->Buffer;
128  p = Ansi;
129  while (i--) *p++ = (CHAR)*pw++;
130 
131  /* Null terminate and return */
132  *p = ANSI_NULL;
133  return Ansi;
134 }
signed char * PCHAR
Definition: retypes.h:7
uint16_t * PWCHAR
Definition: typedefs.h:54
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 ANSI_NULL
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#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()

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)

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 204 of file kdb_symbols.c.

210 {
211  if (!KdbpSymbolsInitialized ||
212  !RosSymInfo ||
213  !RosSymGetAddressInformation(RosSymInfo, RelativeAddress, LineNumber, FileName, FunctionName))
214  {
215  return STATUS_UNSUCCESSFUL;
216  }
217 
218  return STATUS_SUCCESS;
219 }
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:1206
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:1264
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by KdbSymPrintAddress().

◆ KdbSymPrintAddress()

BOOLEAN KdbSymPrintAddress ( IN PVOID  Address,
IN PKTRAP_FRAME  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 148 of file kdb_symbols.c.

151 {
152  PLDR_DATA_TABLE_ENTRY LdrEntry;
153  ULONG_PTR RelativeAddress;
156  CHAR FileName[256];
157  CHAR FunctionName[256];
158  CHAR ModuleNameAnsi[64];
159 
160  if (!KdbpSymbolsInitialized || !KdbpSymFindModule(Address, NULL, -1, &LdrEntry))
161  return FALSE;
162 
164  ModuleNameAnsi,
165  sizeof(ModuleNameAnsi));
166 
167  RelativeAddress = (ULONG_PTR)Address - (ULONG_PTR)LdrEntry->DllBase;
169  RelativeAddress,
170  &LineNumber,
171  FileName,
172  FunctionName);
173  if (NT_SUCCESS(Status))
174  {
175  DbgPrint("<%s:%x (%s:%d (%s))>",
176  ModuleNameAnsi, RelativeAddress, FileName, LineNumber, FunctionName);
177  }
178  else
179  {
180  DbgPrint("<%s:%x>", ModuleNameAnsi, RelativeAddress);
181  }
182 
183  return TRUE;
184 }
BOOLEAN KdbpSymbolsInitialized
Definition: kdb_symbols.c:32
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
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:204
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID DllBase
Definition: btrfs_drv.h:1857
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
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:114
Definition: btrfs_drv.h:1853
Status
Definition: gdiplustypes.h:24
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:1206
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
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:1264
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:76

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

◆ KdbSymProcessSymbols()

VOID KdbSymProcessSymbols ( IN PLDR_DATA_TABLE_ENTRY  LdrEntry)

Definition at line 424 of file kdb_symbols.c.

426 {
427  if (!LoadSymbols)
428  {
429  LdrEntry->PatchInformation = NULL;
430  return;
431  }
432 
433  /* Remove symbol info if it already exists */
434  if (LdrEntry->PatchInformation)
435  KdbpSymRemoveCachedFile(LdrEntry->PatchInformation);
436 
437  /* Load new symbol information */
438  if (! RosSymCreateFromMem(LdrEntry->DllBase,
439  LdrEntry->SizeOfImage,
440  (PROSSYM_INFO*)&LdrEntry->PatchInformation))
441  {
442  /* Error loading symbol info, try to load it from file */
443  KdbpSymLoadModuleSymbols(&LdrEntry->FullDllName,
444  (PROSSYM_INFO*)&LdrEntry->PatchInformation);
445 
446  /* It already added symbols to cache */
447  }
448  else
449  {
450  /* Add file to cache */
451  KdbpSymAddCachedFile(&LdrEntry->FullDllName, LdrEntry->PatchInformation);
452  }
453 
454  DPRINT("Installed symbols: %wZ@%p-%p %p\n",
455  &LdrEntry->BaseDllName,
456  LdrEntry->DllBase,
457  (PVOID)(LdrEntry->SizeOfImage + (ULONG_PTR)LdrEntry->DllBase),
458  LdrEntry->PatchInformation);
459 
460 }
static VOID KdbpSymAddCachedFile(IN PUNICODE_STRING FileName, IN PROSSYM_INFO RosSymInfo)
Add a symbol file to the cache.
Definition: kdb_symbols.c:276
BOOLEAN RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
Definition: frommem.c:20
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
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:358
static VOID KdbpSymRemoveCachedFile(IN PROSSYM_INFO RosSymInfo)
Remove a symbol file (reference) from the cache.
Definition: kdb_symbols.c:314
static BOOLEAN LoadSymbols
Definition: kdb_symbols.c:29

Referenced by KdbInitialize(), and KdpEnterDebuggerException().

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