ReactOS  0.4.15-dev-1070-ge1a01de
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 466 of file kdb_symbols.c.

469 {
470  /* Nothing here */
471 }

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

484 {
485  PCHAR p1, p2;
486  SHORT Found = FALSE;
487  CHAR YesNo;
488  PLDR_DATA_TABLE_ENTRY LdrEntry;
489 
490  DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase);
491 
492  LoadSymbols = FALSE;
493 
494 #if DBG
495  /* Load symbols only if we have 96Mb of RAM or more */
496  if (MmNumberOfPhysicalPages >= 0x6000)
497  LoadSymbols = TRUE;
498 #endif
499 
500  if (BootPhase == 0)
501  {
502  /* Write out the functions that we support for now */
503  DispatchTable->KdpInitRoutine = KdpKdbgInit;
504  DispatchTable->KdpPrintRoutine = KdbDebugPrint;
505 
506  /* Register as a Provider */
507  InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
508 
509  /* Perform actual initialization of symbol module */
510  //NtoskrnlModuleObject->PatchInformation = NULL;
511  //LdrHalModuleObject->PatchInformation = NULL;
512 
515 
516  /* Check the command line for /LOADSYMBOLS, /NOLOADSYMBOLS,
517  * /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */
520  while('\0' != *p1 && NULL != (p2 = strchr(p1, '/')))
521  {
522  p2++;
523  Found = 0;
524  if (0 == _strnicmp(p2, "LOADSYMBOLS", 11))
525  {
526  Found = +1;
527  p2 += 11;
528  }
529  else if (0 == _strnicmp(p2, "NOLOADSYMBOLS", 13))
530  {
531  Found = -1;
532  p2 += 13;
533  }
534  if (0 != Found)
535  {
536  while (isspace(*p2))
537  {
538  p2++;
539  }
540  if ('=' == *p2)
541  {
542  p2++;
543  while (isspace(*p2))
544  {
545  p2++;
546  }
547  YesNo = toupper(*p2);
548  if ('N' == YesNo || 'F' == YesNo || '0' == YesNo)
549  {
550  Found = -1 * Found;
551  }
552  }
553  LoadSymbols = (0 < Found);
554  }
555  p1 = p2;
556  }
557 
559  }
560  else if (BootPhase == 1)
561  {
562  /* Load symbols for NTOSKRNL.EXE.
563  It is always the first module in PsLoadedModuleList. KeLoaderBlock can't be used here as its content is just temporary. */
564  LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
565  KdbSymProcessSymbols(LdrEntry);
566 
567  /* Also load them for HAL.DLL. */
568  LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
569  KdbSymProcessSymbols(LdrEntry);
570 
572  }
573 }
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)
LIST_ENTRY KdProviders
Definition: kdinit.c:29
#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
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:466
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
int toupper(int c)
Definition: utclib.c:881
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID KdbSymProcessSymbols(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: kdb_symbols.c:426
Definition: btrfs_drv.h:1922
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: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 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:121
#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
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 }
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
#define TRUE
Definition: types.h:120
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1223
#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
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  BOOLEAN Result;
367 
368  /* Allow KDB to break on module load */
369  KdbModuleLoaded(FileName);
370 
371  if (!LoadSymbols)
372  {
373  *RosSymInfo = NULL;
374  return;
375  }
376 
377  /* Try to find cached (already loaded) symbol file */
378  *RosSymInfo = KdbpSymFindCachedFile(FileName);
379  if (*RosSymInfo)
380  {
381  DPRINT("Found cached symbol file %wZ\n", FileName);
382  return;
383  }
384 
385  /* Open the file */
387  FileName,
388  0,
389  NULL,
390  NULL);
391 
392  DPRINT("Attempting to open image: %wZ\n", FileName);
393 
397  &IoStatusBlock,
400  if (!NT_SUCCESS(Status))
401  {
402  DPRINT("Could not open image file: %wZ\n", FileName);
403  return;
404  }
405 
406  DPRINT("Loading symbols from %wZ...\n", FileName);
407 
408  Result = RosSymCreateFromFile(&FileHandle, RosSymInfo);
410 
411  if (!Result)
412  {
413  DPRINT("Failed to load symbols from %wZ\n", FileName);
414  return;
415  }
416 
417  DPRINT("Symbols loaded.\n");
418 
419  /* add file to cache */
420  KdbpSymAddCachedFile(FileName, *RosSymInfo);
421 
422  DPRINT("Installed symbols: %wZ %p\n", FileName, *RosSymInfo);
423 }
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:136
HANDLE FileHandle
Definition: stats.c:38
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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
#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)
Status
Definition: gdiplustypes.h:24
#define SYNCHRONIZE
Definition: nt_native.h:61
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:121
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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 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:1223
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const UCHAR Index[8]
Definition: usbohci.c:18
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 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:56
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: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
return STATUS_SUCCESS
Definition: btrfs.c:3014

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 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
#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
#define FALSE
Definition: types.h:117
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
Status
Definition: gdiplustypes.h:24
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
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:76

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

◆ KdbSymProcessSymbols()

VOID KdbSymProcessSymbols ( IN PLDR_DATA_TABLE_ENTRY  LdrEntry)

Definition at line 426 of file kdb_symbols.c.

428 {
429  if (!LoadSymbols)
430  {
431  LdrEntry->PatchInformation = NULL;
432  return;
433  }
434 
435  /* Remove symbol info if it already exists */
436  if (LdrEntry->PatchInformation)
437  KdbpSymRemoveCachedFile(LdrEntry->PatchInformation);
438 
439  /* Load new symbol information */
440  if (! RosSymCreateFromMem(LdrEntry->DllBase,
441  LdrEntry->SizeOfImage,
442  (PROSSYM_INFO*)&LdrEntry->PatchInformation))
443  {
444  /* Error loading symbol info, try to load it from file */
445  KdbpSymLoadModuleSymbols(&LdrEntry->FullDllName,
446  (PROSSYM_INFO*)&LdrEntry->PatchInformation);
447 
448  /* It already added symbols to cache */
449  }
450  else
451  {
452  /* Add file to cache */
453  KdbpSymAddCachedFile(&LdrEntry->FullDllName, LdrEntry->PatchInformation);
454  }
455 
456  DPRINT("Installed symbols: %wZ@%p-%p %p\n",
457  &LdrEntry->BaseDllName,
458  LdrEntry->DllBase,
459  (PVOID)(LdrEntry->SizeOfImage + (ULONG_PTR)LdrEntry->DllBase),
460  LdrEntry->PatchInformation);
461 
462 }
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:65
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