ReactOS 0.4.16-dev-306-g647d351
kdb.h File Reference
#include "../kd/kd.h"
Include dependency graph for kdb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _KDB_BREAKPOINT
 

Typedefs

typedef CONTEXT KDB_KTRAP_FRAME
 
typedef CONTEXTPKDB_KTRAP_FRAME
 
typedef enum _KDB_BREAKPOINT_TYPE KDB_BREAKPOINT_TYPE
 
typedef enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE
 
typedef struct _KDB_BREAKPOINT KDB_BREAKPOINT
 
typedef struct _KDB_BREAKPOINTPKDB_BREAKPOINT
 
typedef enum _KDB_ENTER_CONDITION KDB_ENTER_CONDITION
 
typedef enum _KD_CONTINUE_TYPE KD_CONTINUE_TYPE
 

Enumerations

enum  _KDB_BREAKPOINT_TYPE { KdbBreakPointNone = 0 , KdbBreakPointSoftware , KdbBreakPointHardware , KdbBreakPointTemporary }
 
enum  _KDB_ACCESS_TYPE { KdbAccessRead , KdbAccessWrite , KdbAccessReadWrite , KdbAccessExec }
 
enum  _KDB_ENTER_CONDITION { KdbDoNotEnter , KdbEnterAlways , KdbEnterFromKmode , KdbEnterFromUmode }
 
enum  _KD_CONTINUE_TYPE { kdContinue = 0 , kdDoNotHandleException , kdHandleException }
 

Functions

LONG KdbpDisassemble (IN ULONG_PTR Address, IN ULONG IntelSyntax)
 
LONG KdbpGetInstLength (IN ULONG_PTR Address)
 
VOID NTAPI KdbpStackSwitchAndCall (IN PVOID NewStack, IN VOID(*Function)(VOID))
 
NTSTATUS NTAPI KdbInitialize (_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
 Initializes the KDBG debugger.
 
BOOLEAN NTAPI KdbRegisterCliCallback (PVOID Callback, BOOLEAN Deregister)
 
NTSTATUS KdbpCliInit (VOID)
 Called when KDB is initialized.
 
VOID KdbpCliMainLoop (IN BOOLEAN EnteredOnSingleStep)
 KDB Main Loop.
 
VOID KdbpCliInterpretInitFile (VOID)
 Interprets the KDBinit file from the \SystemRoot\System32\drivers\etc directory, that has been loaded by KdbpCliInit().
 
VOID KdbpCommandHistoryAppend (_In_ PCSTR Command)
 Appends a command to the command history.
 
PCSTR KdbGetHistoryEntry (_Inout_ PLONG NextIndex, _In_ BOOLEAN Next)
 
VOID KdbpPager (_In_ PCHAR Buffer, _In_ ULONG BufLength)
 Prints the given string with, page by page.
 
VOID KdbpPrint (_In_ PSTR Format, _In_ ...)
 Prints the given string with printf-like formatting.
 
VOID KdbpPrintUnicodeString (_In_ PCUNICODE_STRING String)
 
BOOLEAN NTAPI KdbpGetHexNumber (IN PCHAR pszNum, OUT ULONG_PTR *pulValue)
 
BOOLEAN KdbpRpnEvaluateExpression (IN PCHAR Expression, IN PKDB_KTRAP_FRAME TrapFrame, OUT PULONGLONG Result, OUT PLONG ErrOffset OPTIONAL, OUT PCHAR ErrMsg OPTIONAL)
 Evaluates the given expression.
 
PVOID KdbpRpnParseExpression (IN PCHAR Expression, OUT PLONG ErrOffset OPTIONAL, OUT PCHAR ErrMsg OPTIONAL)
 Parses the given expression and returns a "handle" to it.
 
BOOLEAN KdbpRpnEvaluateParsedExpression (IN PVOID Expression, IN PKDB_KTRAP_FRAME TrapFrame, OUT PULONGLONG Result, OUT PLONG ErrOffset OPTIONAL, OUT PCHAR ErrMsg OPTIONAL)
 Evaluates the given expression and returns the result.
 
BOOLEAN KdbpSymFindModule (IN PVOID Address OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
 Find a module...
 
BOOLEAN KdbSymPrintAddress (IN PVOID Address, IN PCONTEXT Context)
 Print address...
 
VOID KdbSymProcessSymbols (_Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry, _In_ BOOLEAN Load)
 Load symbols from image mapping. If this fails,.
 
BOOLEAN KdbSymInit (_In_ ULONG BootPhase)
 Initializes the KDB symbols implementation.
 
LONG KdbpGetNextBreakPointNr (IN ULONG Start OPTIONAL)
 Gets the number of the next breakpoint >= Start.
 
BOOLEAN KdbpGetBreakPointInfo (IN ULONG BreakPointNr, OUT ULONG_PTR *Address OPTIONAL, OUT KDB_BREAKPOINT_TYPE *Type OPTIONAL, OUT UCHAR *Size OPTIONAL, OUT KDB_ACCESS_TYPE *AccessType OPTIONAL, OUT UCHAR *DebugReg OPTIONAL, OUT BOOLEAN *Enabled OPTIONAL, OUT BOOLEAN *Global OPTIONAL, OUT PEPROCESS *Process OPTIONAL, OUT PCHAR *ConditionExpression OPTIONAL)
 Returns information of the specified breakpoint.
 
NTSTATUS KdbpInsertBreakPoint (IN ULONG_PTR Address, IN KDB_BREAKPOINT_TYPE Type, IN UCHAR Size OPTIONAL, IN KDB_ACCESS_TYPE AccessType OPTIONAL, IN PCHAR ConditionExpression OPTIONAL, IN BOOLEAN Global, OUT PLONG BreakPointNr OPTIONAL)
 Inserts a breakpoint into the breakpoint array.
 
BOOLEAN KdbpDeleteBreakPoint (IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
 Deletes a breakpoint.
 
BOOLEAN KdbpEnableBreakPoint (IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
 Enables a breakpoint.
 
BOOLEAN KdbpDisableBreakPoint (IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
 Disables a breakpoint.
 
BOOLEAN KdbpGetEnterCondition (IN LONG ExceptionNr, IN BOOLEAN FirstChance, OUT KDB_ENTER_CONDITION *Condition)
 Gets the first or last chance enter-condition for exception nr. ExceptionNr.
 
BOOLEAN KdbpSetEnterCondition (IN LONG ExceptionNr, IN BOOLEAN FirstChance, IN KDB_ENTER_CONDITION Condition)
 Sets the first or last chance enter-condition for exception nr. ExceptionNr.
 
BOOLEAN KdbpAttachToThread (PVOID ThreadId)
 Switches to another thread context.
 
BOOLEAN KdbpAttachToProcess (PVOID ProcessId)
 Switches to another process/thread context.
 
VOID KdbpGetCommandLineSettings (_In_ PCSTR p1)
 
KD_CONTINUE_TYPE KdbEnterDebuggerException (IN PEXCEPTION_RECORD64 ExceptionRecord, IN KPROCESSOR_MODE PreviousMode, IN OUT PCONTEXT Context, IN BOOLEAN FirstChance)
 
BOOLEAN NTAPI KdpSafeReadMemory (IN ULONG_PTR Addr, IN LONG Len, OUT PVOID Value)
 
BOOLEAN NTAPI KdpSafeWriteMemory (IN ULONG_PTR Addr, IN LONG Len, IN ULONGLONG Value)
 
NTSTATUS KdbpSafeReadMemory (OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
 
NTSTATUS KdbpSafeWriteMemory (OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
 
VOID KbdDisableMouse (VOID)
 
VOID KbdEnableMouse (VOID)
 
VOID KdbPrintString (_In_ const CSTRING *Output)
 
USHORT KdbPromptString (_In_ const CSTRING *PromptString, _Inout_ PSTRING ResponseString)
 
VOID KdbPutsN (_In_ PCCH String, _In_ USHORT Length)
 
VOID KdbPuts (_In_ PCSTR String)
 
VOID __cdecl KdbPrintf (_In_ PCSTR Format,...)
 
SIZE_T KdbPrompt (_In_ PCSTR Prompt, _Out_ PCHAR Buffer, _In_ SIZE_T Size)
 

Variables

volatile PCHAR KdbInitFileBuffer
 
PEPROCESS KdbCurrentProcess
 
PETHREAD KdbCurrentThread
 
LONG KdbLastBreakPointNr
 
ULONG KdbNumSingleSteps
 
BOOLEAN KdbSingleStepOver
 
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
 

Typedef Documentation

◆ KD_CONTINUE_TYPE

◆ KDB_ACCESS_TYPE

◆ KDB_BREAKPOINT

◆ KDB_BREAKPOINT_TYPE

◆ KDB_ENTER_CONDITION

◆ KDB_KTRAP_FRAME

Definition at line 7 of file kdb.h.

◆ PKDB_BREAKPOINT

◆ PKDB_KTRAP_FRAME

Definition at line 7 of file kdb.h.

Enumeration Type Documentation

◆ _KD_CONTINUE_TYPE

Enumerator
kdContinue 
kdDoNotHandleException 
kdHandleException 

Definition at line 54 of file kdb.h.

55{
56 kdContinue = 0,
enum _KD_CONTINUE_TYPE KD_CONTINUE_TYPE
@ kdDoNotHandleException
Definition: kdb.h:57
@ kdContinue
Definition: kdb.h:56
@ kdHandleException
Definition: kdb.h:58

◆ _KDB_ACCESS_TYPE

Enumerator
KdbAccessRead 
KdbAccessWrite 
KdbAccessReadWrite 
KdbAccessExec 

Definition at line 17 of file kdb.h.

18{
@ KdbAccessExec
Definition: kdb.h:22
@ KdbAccessRead
Definition: kdb.h:19
@ KdbAccessReadWrite
Definition: kdb.h:21
@ KdbAccessWrite
Definition: kdb.h:20
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE

◆ _KDB_BREAKPOINT_TYPE

Enumerator
KdbBreakPointNone 
KdbBreakPointSoftware 
KdbBreakPointHardware 
KdbBreakPointTemporary 

Definition at line 9 of file kdb.h.

10{
@ KdbBreakPointSoftware
Definition: kdb.h:12
@ KdbBreakPointNone
Definition: kdb.h:11
@ KdbBreakPointTemporary
Definition: kdb.h:14
@ KdbBreakPointHardware
Definition: kdb.h:13
enum _KDB_BREAKPOINT_TYPE KDB_BREAKPOINT_TYPE

◆ _KDB_ENTER_CONDITION

Enumerator
KdbDoNotEnter 
KdbEnterAlways 
KdbEnterFromKmode 
KdbEnterFromUmode 

Definition at line 46 of file kdb.h.

47{
enum _KDB_ENTER_CONDITION KDB_ENTER_CONDITION
@ KdbDoNotEnter
Definition: kdb.h:48
@ KdbEnterFromUmode
Definition: kdb.h:51
@ KdbEnterAlways
Definition: kdb.h:49
@ KdbEnterFromKmode
Definition: kdb.h:50

Function Documentation

◆ KbdDisableMouse()

VOID KbdDisableMouse ( VOID  )

Definition at line 98 of file kdps2kbd.c.

99{
101}
static VOID KbdSendCommandToMouse(UCHAR Command)
Definition: kdps2kbd.c:62
#define MOU_DISAB
Definition: kdps2kbd.c:27

Referenced by KdbpInternalEnter(), and KdReceivePacket().

◆ KbdEnableMouse()

VOID KbdEnableMouse ( VOID  )

Definition at line 93 of file kdps2kbd.c.

94{
96}
#define MOU_ENAB
Definition: kdps2kbd.c:26

Referenced by KdbpInternalEnter(), and KdReceivePacket().

◆ KdbEnterDebuggerException()

KD_CONTINUE_TYPE KdbEnterDebuggerException ( IN PEXCEPTION_RECORD64  ExceptionRecord,
IN KPROCESSOR_MODE  PreviousMode,
IN OUT PCONTEXT  Context,
IN BOOLEAN  FirstChance 
)

◆ KdbGetHistoryEntry()

PCSTR KdbGetHistoryEntry ( _Inout_ PLONG  NextIndex,
_In_ BOOLEAN  Next 
)

Definition at line 24 of file kdprompt.c.

27{
28 /* Dummy function */
29 return NULL;
30}
#define NULL
Definition: types.h:112

Referenced by KdIoReadLine().

◆ KdbInitialize()

NTSTATUS NTAPI KdbInitialize ( _In_ PKD_DISPATCH_TABLE  DispatchTable,
_In_ ULONG  BootPhase 
)

Initializes the KDBG debugger.

Parameters
[in]DispatchTablePointer to the KD dispatch table.
[in]BootPhasePhase of initialization.
Returns
A status value.
Note
Also known as "KdpKdbgInit".

Definition at line 3554 of file kdb_cli.c.

3557{
3558 /* Saves the different symbol-loading status across boot phases */
3559 static ULONG LoadSymbols = 0;
3560
3561 if (BootPhase == 0)
3562 {
3563 /* Write out the functions that we support for now */
3564 DispatchTable->KdpPrintRoutine = KdbDebugPrint;
3565
3566 /* Check if we have a command line */
3568 {
3569 /* Get the KDBG Settings */
3571 }
3572
3573 /* Register for BootPhase 1 initialization and as a Provider */
3574 DispatchTable->KdpInitRoutine = KdbInitialize;
3575 InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
3576 }
3577 else if (BootPhase == 1)
3578 {
3579 /* Register for later BootPhase 2 reinitialization */
3580 DispatchTable->KdpInitRoutine = KdbInitialize;
3581
3582 /* Initialize Dmesg support */
3583
3584 /* Allocate a buffer for Dmesg log buffer. +1 for terminating null,
3585 * see kdbp_cli.c:KdbpCmdDmesg()/2 */
3588 TAG_KDBG);
3589 /* Ignore failure if KdpDmesgBuffer is NULL */
3592
3593 /* Initialize spinlock */
3595 }
3596
3597 /* Initialize symbols support in BootPhase 0 and 1 */
3598 if (BootPhase <= 1)
3599 {
3600 LoadSymbols <<= 1;
3601 LoadSymbols |= KdbSymInit(BootPhase);
3602 }
3603
3604 if (BootPhase == 1)
3605 {
3606 /* Announce ourselves */
3607 CHAR buffer[60];
3609 " KDBG debugger enabled - %s\r\n",
3610 !(LoadSymbols & 0x2) ? "No symbols loaded" :
3611 !(LoadSymbols & 0x1) ? "Kernel symbols loaded"
3612 : "Loading symbols");
3614 }
3615
3616 if (BootPhase >= 2)
3617 {
3618 /* I/O is now set up for disk access: load the KDBinit file */
3620
3621 /* Schedule an I/O reinitialization if needed */
3624 {
3625 DispatchTable->KdpInitRoutine = KdbInitialize;
3626 }
3627 }
3628
3629 return STATUS_SUCCESS;
3630}
LONG NTSTATUS
Definition: precomp.h:26
#define InsertTailList(ListHead, Entry)
#define NonPagedPool
Definition: env_spec_w32.h:307
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
Status
Definition: gdiplustypes.h:25
GLuint buffer
Definition: glext.h:5915
NTHALAPI VOID NTAPI HalDisplayString(PUCHAR String)
LIST_ENTRY KdProviders
Definition: kdio.c:47
VOID KdbpGetCommandLineSettings(_In_ PCSTR p1)
Definition: kdb.c:1635
BOOLEAN KdbSymInit(_In_ ULONG BootPhase)
Initializes the KDB symbols implementation.
Definition: kdb_symbols.c:343
static KSPIN_LOCK KdpDmesgLogSpinLock
Definition: kdb_cli.c:147
static VOID NTAPI KdbDebugPrint(_In_ PCCH String, _In_ ULONG Length)
Debug logger function.
Definition: kdb_cli.c:3494
static const ULONG KdpDmesgBufferSize
Definition: kdb_cli.c:141
static volatile ULONG KdpDmesgFreeBytes
Definition: kdb_cli.c:144
NTSTATUS NTAPI KdbInitialize(_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
Initializes the KDBG debugger.
Definition: kdb_cli.c:3554
static PCHAR KdpDmesgBuffer
Definition: kdb_cli.c:142
static volatile ULONG KdbDmesgTotalWritten
Definition: kdb_cli.c:145
NTSTATUS KdbpCliInit(VOID)
Called when KDB is initialized.
Definition: kdb_cli.c:3403
static BOOLEAN LoadSymbols
Definition: kdb_symbols.c:30
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
FORCEINLINE PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TAG_KDBG
Definition: tag.h:38
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ PWDFDEVICE_INIT _In_ PWDF_PDO_EVENT_CALLBACKS DispatchTable
Definition: wdfpdo.h:248
char CHAR
Definition: xmlstorage.h:175

Referenced by KdbInitialize().

◆ KdbpAttachToProcess()

BOOLEAN KdbpAttachToProcess ( PVOID  ProcessId)

Switches to another process/thread context.

This function switches to the first thread in the specified process.

Parameters
ProcessIdId of the process to switch to.
Return values
TRUESuccess.
FALSEFailure (i.e. invalid process id)

Definition at line 1117 of file kdb.c.

1119{
1123
1124 /* Get a pointer to the process */
1126 {
1127 KdbpPrint("Invalid process id: 0x%08x\n", (ULONG_PTR)ProcessId);
1128 return FALSE;
1129 }
1130
1131 Entry = Process->ThreadListHead.Flink;
1134 {
1135 KdbpPrint("No threads in process 0x%p, cannot attach to process!\n", ProcessId);
1136 return FALSE;
1137 }
1138
1139 Thread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
1140
1142}
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2712
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
PEPROCESS KdbCurrentProcess
Definition: kdb.c:52
BOOLEAN KdbpAttachToThread(PVOID ThreadId)
Switches to another thread context.
Definition: kdb.c:1036
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3081
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
base of all file and directory entries
Definition: entries.h:83
HANDLE UniqueThread
Definition: compat.h:826
LIST_ENTRY ThreadListHead
Definition: pstypes.h:1330
CLIENT_ID Cid
Definition: pstypes.h:1129
Definition: typedefs.h:120
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by KdbpCmdProc().

◆ KdbpAttachToThread()

BOOLEAN KdbpAttachToThread ( PVOID  ThreadId)

Switches to another thread context.

Parameters
ThreadIdId of the thread to switch to.
Return values
TRUESuccess.
FALSEFailure (i.e. invalid thread id)

Definition at line 1036 of file kdb.c.

1038{
1041
1042 /* Get a pointer to the thread */
1043 if (!NT_SUCCESS(PsLookupThreadByThreadId(ThreadId, &Thread)))
1044 {
1045 KdbpPrint("Invalid thread id: 0x%08x\n", (ULONG_PTR)ThreadId);
1046 return FALSE;
1047 }
1048 Process = Thread->ThreadsProcess;
1049
1051 {
1052 KdbpPrint("Cannot attach to thread within another process while executing a DPC.\n");
1054 return FALSE;
1055 }
1056
1057 /* Save the current thread's context (if we previously attached to a thread) */
1059 {
1061 /* Actually, we can't save the context, there's no guarantee that there was a trap frame */
1062 }
1063 else
1064 {
1066 }
1067
1068 /* Switch to the thread's context */
1070 {
1071 /* The thread we're attaching to isn't the thread on which we entered
1072 * kdb and so the thread we're attaching to is not running. There
1073 * is no guarantee that it actually has a trap frame. So we have to
1074 * peek directly at the registers which were saved on the stack when the
1075 * thread was preempted in the scheduler */
1079 }
1080 else /* Switching back to original thread */
1081 {
1083 }
1085
1086 /* Attach to the thread's process */
1089 {
1090 if (KdbCurrentProcess != KdbOriginalProcess) /* detach from previously attached process */
1091 {
1093 }
1094
1096 {
1098 }
1099
1101 }
1102
1104 return TRUE;
1105}
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI KeIsExecutingDpc(VOID)
Definition: dpc.c:965
PETHREAD KdbCurrentThread
Definition: kdb.c:54
PETHREAD KdbOriginalThread
Definition: kdb.c:55
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:56
static KDB_KTRAP_FRAME KdbThreadTrapFrame
Definition: kdb.c:58
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:57
PEPROCESS KdbOriginalProcess
Definition: kdb.c:53
static VOID KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack, PKDB_KTRAP_FRAME KdbTrapFrame)
Definition: kdb.c:119
static KAPC_STATE KdbApcState
Definition: kdb.c:59
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS NTAPI PsLookupThreadByThreadId(IN HANDLE ThreadId, OUT PETHREAD *Thread)
Definition: thread.c:643
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:704
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:756
KTHREAD Tcb
Definition: pstypes.h:1104
PVOID KernelStack
Definition: ketypes.h:1675
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by KdbpAttachToProcess(), and KdbpCmdThread().

◆ KdbpCliInit()

NTSTATUS KdbpCliInit ( VOID  )

Called when KDB is initialized.

Loads the KDBinit file from the \SystemRoot\System32\drivers\etc directory and interprets it, by calling back into the debugger.

Definition at line 3403 of file kdb_cli.c.

3404{
3409 FILE_STANDARD_INFORMATION FileStdInfo;
3410 HANDLE hFile = NULL;
3412 PCHAR FileBuffer;
3413
3414 /* Don't load the KDBinit file if its buffer is already lying around */
3416 return STATUS_SUCCESS;
3417
3418 /* Initialize the object attributes */
3419 RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3421 &FileName,
3423 NULL,
3424 NULL);
3425
3426 /* Open the file */
3428 &ObjectAttributes, &Iosb, 0,
3431 if (!NT_SUCCESS(Status))
3432 {
3433 DPRINT("Could not open %wZ (Status 0x%lx)\n", &FileName, Status);
3434 return Status;
3435 }
3436
3437 /* Get the size of the file */
3438 Status = ZwQueryInformationFile(hFile, &Iosb,
3439 &FileStdInfo, sizeof(FileStdInfo),
3441 if (!NT_SUCCESS(Status))
3442 {
3443 ZwClose(hFile);
3444 DPRINT1("Could not query size of %wZ (Status 0x%lx)\n", &FileName, Status);
3445 return Status;
3446 }
3447 FileSize = FileStdInfo.EndOfFile.u.LowPart;
3448
3449 /* Allocate memory for the file (add 1 byte for terminating NUL) */
3450 FileBuffer = ExAllocatePool(NonPagedPool, FileSize + 1);
3451 if (!FileBuffer)
3452 {
3453 ZwClose(hFile);
3454 DPRINT1("Could not allocate %lu bytes for KDBinit file\n", FileSize);
3455 return Status;
3456 }
3457
3458 /* Load file into memory */
3459 Status = ZwReadFile(hFile, NULL, NULL, NULL, &Iosb,
3460 FileBuffer, FileSize, NULL, NULL);
3461 ZwClose(hFile);
3462
3464 {
3465 ExFreePool(FileBuffer);
3466 DPRINT1("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3467 return Status;
3468 }
3469
3470 FileSize = min(FileSize, (ULONG)Iosb.Information);
3471 FileBuffer[FileSize] = ANSI_NULL;
3472
3473 /* Interpret the KDBinit file by calling back into the debugger */
3477
3478 ExFreePool(FileBuffer);
3479
3480 return STATUS_SUCCESS;
3481}
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
return Iosb
Definition: create.c:4402
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
struct _FileName FileName
Definition: fatprocs.h:897
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
volatile PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:137
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define min(a, b)
Definition: monoChain.cc:55
_In_ HANDLE hFile
Definition: mswsock.h:90
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 DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ANSI_NULL
#define L(x)
Definition: ntvdm.h:50
#define FileStandardInformation
Definition: propsheet.cpp:61
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define DPRINT
Definition: sndvol32.h:73
char * PCHAR
Definition: typedefs.h:51
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)
struct _LARGE_INTEGER::@2303 u

Referenced by KdbInitialize().

◆ KdbpCliInterpretInitFile()

VOID KdbpCliInterpretInitFile ( VOID  )

Interprets the KDBinit file from the \SystemRoot\System32\drivers\etc directory, that has been loaded by KdbpCliInit().

This function is used to interpret the init file in the debugger context with a trap frame set up. KdbpCliInit() enters the debugger by calling DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C). In turn, this will call KdbEnterDebuggerException() which will finally call this function if KdbInitFileBuffer is not NULL.

Definition at line 3351 of file kdb_cli.c.

3352{
3353 PCHAR p1, p2;
3354
3356 if (!p1)
3357 return;
3358
3359 /* Execute the commands in the init file */
3360 KdbPuts("KDB: Executing KDBinit file...\n");
3361 while (p1[0] != '\0')
3362 {
3363 size_t i = strcspn(p1, "\r\n");
3364 if (i > 0)
3365 {
3366 CHAR c = p1[i];
3367 p1[i] = '\0';
3368
3369 /* Look for "break" command and comments */
3370 p2 = p1;
3371 while (isspace(p2[0]))
3372 p2++;
3373
3374 if (strncmp(p2, "break", sizeof("break")-1) == 0 &&
3375 (p2[sizeof("break")-1] == '\0' || isspace(p2[sizeof("break")-1])))
3376 {
3377 /* Run the interactive debugger loop */
3379 }
3380 else if (p2[0] != '#' && p2[0] != '\0') /* Ignore empty lines and comments */
3381 {
3382 /* Invoke the command */
3383 KdbpDoCommand(p1);
3384 }
3385
3386 p1[i] = c;
3387 }
3388
3389 p1 += i;
3390 while (p1[0] == '\r' || p1[0] == '\n')
3391 p1++;
3392 }
3393 KdbPuts("KDB: KDBinit executed\n");
3394}
#define isspace(c)
Definition: acclib.h:69
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
const GLubyte * c
Definition: glext.h:8905
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
VOID KdbPuts(_In_ PCSTR String)
Definition: kdb_print.c:152
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3205
VOID KdbpCliMainLoop(IN BOOLEAN EnteredOnSingleStep)
KDB Main Loop.
Definition: kdb_cli.c:3274
#define c
Definition: ke_i.h:80
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)

Referenced by KdbEnterDebuggerException().

◆ KdbpCliMainLoop()

VOID KdbpCliMainLoop ( IN BOOLEAN  EnteredOnSingleStep)

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3274 of file kdb_cli.c.

3276{
3277 BOOLEAN Continue = TRUE;
3278 static CHAR Command[1024];
3279 static CHAR LastCommand[1024] = "";
3280
3281// FIXME HACK: SYSREG SUPPORT CORE-19807 -- Emit a backtrace.
3282// TODO: Remove once SYSREG "bt" command emission is fixed!
3283#if 1
3284 KdbpDoCommand("bt");
3285#endif
3286
3287 if (EnteredOnSingleStep)
3288 {
3291
3292 KdbPuts(": ");
3294 KdbPuts("<INVALID>");
3295 KdbPuts("\n");
3296 }
3297 else
3298 {
3299 /* Preceding this message is one of the "Entered debugger..." banners */
3300 // KdbPuts("\nEntered debugger\n");
3301 KdbPuts("\nType \"help\" for a list of commands.\n");
3302 }
3303
3304 /* Main loop */
3305 while (Continue)
3306 {
3307 /*
3308 * Print the prompt and read a command.
3309 * Repeat the last one if the user pressed Enter.
3310 * This reduces the risk of RSI when single-stepping!
3311 */
3312 // TEMP HACK! Issue an empty string instead of duplicating "kdb:>"
3313 SIZE_T CmdLen = KdbPrompt(/*KdbPromptStr.Buffer*/"", Command, sizeof(Command));
3314 if (CmdLen == 0)
3315 {
3316 /* Nothing received but the user didn't press Enter, retry */
3317 continue;
3318 }
3319 else if (CmdLen > 1) // i.e. (*Command != ANSI_NULL)
3320 {
3321 /* Save this new last command */
3323 RtlStringCbCopyA(LastCommand, sizeof(LastCommand), Command);
3324
3325 /* Remember it */
3327 }
3328 else if (KdbRepeatLastCommand)
3329 {
3330 /* The user directly pressed Enter */
3331 RtlStringCbCopyA(Command, sizeof(Command), LastCommand);
3332 }
3333
3334 /* Invoke the command */
3335 Continue = KdbpDoCommand(Command);
3336 }
3337}
unsigned char BOOLEAN
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:124
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PCONTEXT Context)
Print address...
Definition: kdb_symbols.c:149
VOID KdbpCommandHistoryAppend(_In_ PCSTR Command)
Appends a command to the command history.
Definition: kdb_cmdhist.c:37
VOID __cdecl KdbPrintf(_In_ PCSTR Format,...)
Definition: kdb_print.c:160
SIZE_T KdbPrompt(_In_ PCSTR Prompt, _Out_ PCHAR Buffer, _In_ SIZE_T Size)
Definition: kdb_print.c:182
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:135
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:129
#define KeGetContextPc(Context)
Definition: ke.h:31
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
Definition: shell.h:41
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by KdbpCallMainLoop(), and KdbpCliInterpretInitFile().

◆ KdbpCommandHistoryAppend()

VOID KdbpCommandHistoryAppend ( _In_ PCSTR  Command)

Appends a command to the command history.

Parameters
[in]CommandPointer to the command to append to the history.

Definition at line 37 of file kdb_cmdhist.c.

39{
41 SIZE_T Length2 = 0;
42 LONG i;
44
46
47 /*
48 * Do not append the string if:
49 * - it is empty (just the NULL terminator);
50 * - or the last command is the same.
51 */
52 if (Length1 <= 1 ||
55 {
56 return;
57 }
58
59 /* Calculate Length1 and Length2 */
63 {
67 }
68
69 /* Remove previous commands until there is enough space to append the new command */
71 {
72 if ((Length2 > 0 &&
75 (Length2 <= 0 &&
78 {
80 }
81
82 i--;
83 if (i < 0)
85
87 break;
88 }
89
90 /* Make sure the new command history entry is free */
94 {
96 }
97
98 /* Append command */
102 if (Length2 > 0)
103 {
105 }
106}
INT Length2
Definition: FsRtlDissect.c:16
INT Length1
Definition: FsRtlDissect.c:15
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: bufpool.h:45
static LONG KdbCommandHistoryBufferIndex
Definition: kdb_cmdhist.c:25
static LONG KdbCommandHistoryIndex
Definition: kdb_cmdhist.c:26
static CHAR KdbCommandHistoryBuffer[2048]
Definition: kdb_cmdhist.c:22
static PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8]
Definition: kdb_cmdhist.c:24
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
long LONG
Definition: pedump.c:60

Referenced by KdbpCliMainLoop().

◆ KdbpDeleteBreakPoint()

BOOLEAN KdbpDeleteBreakPoint ( IN LONG BreakPointNr  OPTIONAL,
IN OUT PKDB_BREAKPOINT BreakPoint  OPTIONAL 
)

Deletes a breakpoint.

Parameters
BreakPointNrNumber of the breakpoint to delete. Can be -1
BreakPointBreakpoint to delete. Can be NULL.
Return values
TRUESuccess.
FALSEFailure (invalid breakpoint number)

Definition at line 599 of file kdb.c.

602{
603 if (BreakPointNr < 0)
604 {
605 ASSERT(BreakPoint);
606 BreakPointNr = BreakPoint - KdbBreakPoints;
607 }
608
609 if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
610 {
611 KdbPrintf("Invalid breakpoint: %d\n", BreakPointNr);
612 return FALSE;
613 }
614
615 if (!BreakPoint)
616 {
617 BreakPoint = KdbBreakPoints + BreakPointNr;
618 }
619
620 if (BreakPoint->Type == KdbBreakPointNone)
621 {
622 KdbPrintf("Invalid breakpoint: %d\n", BreakPointNr);
623 return FALSE;
624 }
625
626 if (BreakPoint->Enabled && !KdbpDisableBreakPoint(-1, BreakPoint))
627 return FALSE;
628
629 if (BreakPoint->Type != KdbBreakPointTemporary)
630 KdbPrintf("Breakpoint %d deleted.\n", BreakPointNr);
631
632 BreakPoint->Type = KdbBreakPointNone;
633 KdbBreakPointCount--;
634
635 return TRUE;
636}
BOOLEAN KdbpDisableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Disables a breakpoint.
Definition: kdb.c:868
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:27

Referenced by KdbEnterDebuggerException(), and KdbpCmdEnableDisableClearBreakPoint().

◆ KdbpDisableBreakPoint()

BOOLEAN KdbpDisableBreakPoint ( IN LONG BreakPointNr  OPTIONAL,
IN OUT PKDB_BREAKPOINT BreakPoint  OPTIONAL 
)

Disables a breakpoint.

Parameters
BreakPointNrNumber of the breakpoint to disable. Can be -1
BreakPointBreakpoint to disable. Can be NULL.
Return values
TRUESuccess.
FALSEFailure.
See also
KdbpEnableBreakPoint

Definition at line 868 of file kdb.c.

871{
872 ULONG i;
874
875 if (BreakPointNr < 0)
876 {
877 ASSERT(BreakPoint);
878 BreakPointNr = BreakPoint - KdbBreakPoints;
879 }
880
881 if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
882 {
883 KdbPrintf("Invalid breakpoint: %d\n", BreakPointNr);
884 return FALSE;
885 }
886
887 if (!BreakPoint)
888 {
889 BreakPoint = KdbBreakPoints + BreakPointNr;
890 }
891
892 if (BreakPoint->Type == KdbBreakPointNone)
893 {
894 KdbPrintf("Invalid breakpoint: %d\n", BreakPointNr);
895 return FALSE;
896 }
897
898 if (BreakPoint->Enabled == FALSE)
899 {
900 KdbPrintf("Breakpoint %d is not enabled.\n", BreakPointNr);
901 return TRUE;
902 }
903
904 if (BreakPoint->Type == KdbBreakPointSoftware ||
905 BreakPoint->Type == KdbBreakPointTemporary)
906 {
908 Status = KdbpOverwriteInstruction(BreakPoint->Process, BreakPoint->Address,
909 BreakPoint->Data.SavedInstruction, NULL);
910
911 if (!NT_SUCCESS(Status))
912 {
913 KdbPuts("Couldn't restore original instruction.\n");
914 return FALSE;
915 }
916
917 for (i = 0; i < KdbSwBreakPointCount; i++)
918 {
919 if (KdbSwBreakPoints[i] == BreakPoint)
920 {
922 i = -1; /* if the last breakpoint is disabled dont break with i >= KdbSwBreakPointCount */
923 break;
924 }
925 }
926
927 if (i != MAXULONG) /* not found */
928 ASSERT(0);
929 }
930 else
931 {
932 ASSERT(BreakPoint->Type == KdbBreakPointHardware);
933
934 /* Clear the breakpoint. */
935 KdbTrapFrame.Dr7 &= ~(0x3 << (BreakPoint->Data.Hw.DebugReg * 2));
936 if ((KdbTrapFrame.Dr7 & 0xFF) == 0)
937 {
938 /* If no breakpoints are enabled then clear the exact match flags. */
939 KdbTrapFrame.Dr7 &= 0xFFFFFCFF;
940 }
941
942 for (i = 0; i < KdbHwBreakPointCount; i++)
943 {
944 if (KdbHwBreakPoints[i] == BreakPoint)
945 {
947 i = -1; /* if the last breakpoint is disabled dont break with i >= KdbHwBreakPointCount */
948 break;
949 }
950 }
951
952 if (i != MAXULONG) /* not found */
953 ASSERT(0);
954 }
955
956 BreakPoint->Enabled = FALSE;
957 if (BreakPoint->Type != KdbBreakPointTemporary)
958 KdbPrintf("Breakpoint %d disabled.\n", BreakPointNr);
959
960 return TRUE;
961}
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:44
static NTSTATUS KdbpOverwriteInstruction(IN PEPROCESS Process, IN ULONG_PTR Address, IN UCHAR NewInst, OUT PUCHAR OldInst OPTIONAL)
Overwrites the instruction at Address with NewInst and stores the old instruction in *OldInst.
Definition: kdb.c:155
static PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]
Definition: kdb.c:43
static ULONG KdbSwBreakPointCount
Definition: kdb.c:41
static ULONG KdbHwBreakPointCount
Definition: kdb.c:42
ULONG Dr7
Definition: nt_native.h:1439
#define MAXULONG
Definition: typedefs.h:251

Referenced by KdbpCmdEnableDisableClearBreakPoint(), and KdbpDeleteBreakPoint().

◆ KdbpDisassemble()

LONG KdbpDisassemble ( IN ULONG_PTR  Address,
IN ULONG  IntelSyntax 
)

Definition at line 124 of file i386-dis.c.

125{
127
128 info.fprintf_func = KdbpPrintDisasm;
129 info.stream = NULL;
130 info.application_data = NULL;
132 info.arch = bfd_arch_i386;
134 info.insn_sets = 0;
135 info.flags = 0;
136 info.read_memory_func = KdbpReadMemory;
137 info.memory_error_func = KdbpMemoryError;
138 info.print_address_func = KdbpPrintAddressInCode;
139 info.symbol_at_address_func = NULL;
140 info.buffer = NULL;
141 info.buffer_vma = info.buffer_length = 0;
142 info.bytes_per_chunk = 0;
143 info.display_endian = BIG_ENDIAN_LITTLE;
144 info.disassembler_options = NULL;
145
146 return(print_insn_i386(Address, &info));
147}
static void KdbpPrintAddressInCode(uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:78
int print_insn_i386(bfd_vma pc, struct disassemble_info *info)
Definition: i386-dis.c:2078
int KdbpPrintDisasm(void *Ignored, const char *fmt,...)
Definition: i386-dis.c:45
@ bfd_target_unknown_flavour
Definition: i386-dis.c:18
#define bfd_mach_i386_i386
Definition: i386-dis.c:32
@ BIG_ENDIAN_LITTLE
Definition: i386-dis.c:26
static void KdbpMemoryError(int Status, uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:72
@ bfd_arch_i386
Definition: i386-dis.c:22
static int KdbpReadMemory(uintptr_t Addr, unsigned char *Data, unsigned int Length, struct disassemble_info *Ignored)
Definition: i386-dis.c:65
#define bfd_mach_i386_i386_intel_syntax
Definition: i386-dis.c:31
static WCHAR Address[46]
Definition: ping.c:68

Referenced by KdbpCliMainLoop(), and KdbpCmdDisassembleX().

◆ KdbpEnableBreakPoint()

BOOLEAN KdbpEnableBreakPoint ( IN LONG BreakPointNr  OPTIONAL,
IN OUT PKDB_BREAKPOINT BreakPoint  OPTIONAL 
)

Enables a breakpoint.

Parameters
BreakPointNrNumber of the breakpoint to enable Can be -1.
BreakPointBreakpoint to enable. Can be NULL.
Return values
TRUESuccess.
FALSEFailure.
See also
KdbpDisableBreakPoint

Definition at line 702 of file kdb.c.

705{
707 INT i;
708 ULONG ul;
709
710 if (BreakPointNr < 0)
711 {
712 ASSERT(BreakPoint);
713 BreakPointNr = BreakPoint - KdbBreakPoints;
714 }
715
716 if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
717 {
718 KdbPrintf("Invalid breakpoint: %d\n", BreakPointNr);
719 return FALSE;
720 }
721
722 if (!BreakPoint)
723 {
724 BreakPoint = KdbBreakPoints + BreakPointNr;
725 }
726
727 if (BreakPoint->Type == KdbBreakPointNone)
728 {
729 KdbPrintf("Invalid breakpoint: %d\n", BreakPointNr);
730 return FALSE;
731 }
732
733 if (BreakPoint->Enabled)
734 {
735 KdbPrintf("Breakpoint %d is already enabled.\n", BreakPointNr);
736 return TRUE;
737 }
738
739 if (BreakPoint->Type == KdbBreakPointSoftware ||
740 BreakPoint->Type == KdbBreakPointTemporary)
741 {
743 {
744 KdbPrintf("Maximum number of SW breakpoints (%d) used. "
745 "Disable another breakpoint in order to enable this one.\n",
747 return FALSE;
748 }
749
750 Status = KdbpOverwriteInstruction(BreakPoint->Process, BreakPoint->Address,
751 0xCC, &BreakPoint->Data.SavedInstruction);
752 if (!NT_SUCCESS(Status))
753 {
754 KdbPrintf("Couldn't access memory at 0x%p\n", BreakPoint->Address);
755 return FALSE;
756 }
757
759 }
760 else
761 {
762 if (BreakPoint->Data.Hw.AccessType == KdbAccessExec)
763 ASSERT(BreakPoint->Data.Hw.Size == 1);
764
765 ASSERT((BreakPoint->Address % BreakPoint->Data.Hw.Size) == 0);
766
768 {
769 KdbPrintf("Maximum number of HW breakpoints (%d) already used. "
770 "Disable another breakpoint in order to enable this one.\n",
772 return FALSE;
773 }
774
775 /* Find unused hw breakpoint */
777 for (i = 0; i < KDB_MAXIMUM_HW_BREAKPOINT_COUNT; i++)
778 {
779 if ((KdbTrapFrame.Dr7 & (0x3 << (i * 2))) == 0)
780 break;
781 }
782
784
785 /* Set the breakpoint address. */
786 switch (i)
787 {
788 case 0:
789 KdbTrapFrame.Dr0 = BreakPoint->Address;
790 break;
791 case 1:
792 KdbTrapFrame.Dr1 = BreakPoint->Address;
793 break;
794 case 2:
795 KdbTrapFrame.Dr2 = BreakPoint->Address;
796 break;
797 case 3:
798 KdbTrapFrame.Dr3 = BreakPoint->Address;
799 break;
800 }
801
802 /* Enable the global breakpoint */
803 KdbTrapFrame.Dr7 |= (0x2 << (i * 2));
804
805 /* Enable the exact match bits. */
806 KdbTrapFrame.Dr7 |= 0x00000300;
807
808 /* Clear existing state. */
809 KdbTrapFrame.Dr7 &= ~(0xF << (16 + (i * 4)));
810
811 /* Set the breakpoint type. */
812 switch (BreakPoint->Data.Hw.AccessType)
813 {
814 case KdbAccessExec:
815 ul = 0;
816 break;
817 case KdbAccessWrite:
818 ul = 1;
819 break;
820 case KdbAccessRead:
822 ul = 3;
823 break;
824 default:
825 ASSERT(0);
826 return TRUE;
827 break;
828 }
829
830 KdbTrapFrame.Dr7 |= (ul << (16 + (i * 4)));
831
832 /* Set the breakpoint length. */
833 KdbTrapFrame.Dr7 |= ((BreakPoint->Data.Hw.Size - 1) << (18 + (i * 4)));
834
835 /* Update KdbCurrentTrapFrame - values are taken from there by the CLI */
837 {
844 }
845
846 BreakPoint->Data.Hw.DebugReg = i;
848 }
849
850 BreakPoint->Enabled = TRUE;
851 if (BreakPoint->Type != KdbBreakPointTemporary)
852 KdbPrintf("Breakpoint %d enabled.\n", BreakPointNr);
853
854 return TRUE;
855}
#define KDB_MAXIMUM_HW_BREAKPOINT_COUNT
Definition: kdb.c:28
#define KDB_MAXIMUM_SW_BREAKPOINT_COUNT
Definition: kdb.c:29
ULONG Dr3
Definition: nt_native.h:1437
ULONG Dr1
Definition: nt_native.h:1435
ULONG Dr6
Definition: nt_native.h:1438
ULONG Dr0
Definition: nt_native.h:1434
ULONG Dr2
Definition: nt_native.h:1436
BOOLEAN Enabled
Definition: kdb.h:28
int32_t INT
Definition: typedefs.h:58

Referenced by KdbpCmdEnableDisableClearBreakPoint(), and KdbpInsertBreakPoint().

◆ KdbpGetBreakPointInfo()

BOOLEAN KdbpGetBreakPointInfo ( IN ULONG  BreakPointNr,
OUT ULONG_PTR *Address  OPTIONAL,
OUT KDB_BREAKPOINT_TYPE *Type  OPTIONAL,
OUT UCHAR *Size  OPTIONAL,
OUT KDB_ACCESS_TYPE *AccessType  OPTIONAL,
OUT UCHAR *DebugReg  OPTIONAL,
OUT BOOLEAN *Enabled  OPTIONAL,
OUT BOOLEAN *Global  OPTIONAL,
OUT PEPROCESS *Process  OPTIONAL,
OUT PCHAR *ConditionExpression  OPTIONAL 
)

Returns information of the specified breakpoint.

Parameters
BreakPointNrNumber of the breakpoint to return information of.
AddressReceives the address of the breakpoint.
TypeReceives the type of the breakpoint (hardware or software)
SizeSize - for memory breakpoints.
AccessTypeAccess type - for hardware breakpoints.
DebugRegDebug register - for enabled hardware breakpoints.
EnabledWhether the breakpoint is enabled or not.
ProcessThe owning process of the breakpoint.
ConditionExpressionThe expression which was given as condition for the bp.
Returns
NULL on failure, pointer to a KDB_BREAKPOINT struct on success.

Definition at line 409 of file kdb.c.

420{
422
423 if (BreakPointNr >= RTL_NUMBER_OF(KdbBreakPoints) ||
424 KdbBreakPoints[BreakPointNr].Type == KdbBreakPointNone)
425 {
426 return FALSE;
427 }
428
429 bp = KdbBreakPoints + BreakPointNr;
430 if (Address)
431 *Address = bp->Address;
432
433 if (Type)
434 *Type = bp->Type;
435
436 if (bp->Type == KdbBreakPointHardware)
437 {
438 if (Size)
439 *Size = bp->Data.Hw.Size;
440
441 if (AccessType)
442 *AccessType = bp->Data.Hw.AccessType;
443
444 if (DebugReg && bp->Enabled)
445 *DebugReg = bp->Data.Hw.DebugReg;
446 }
447
448 if (Enabled)
449 *Enabled = bp->Enabled;
450
451 if (Global)
452 *Global = bp->Global;
453
454 if (Process)
455 *Process = bp->Process;
456
457 if (ConditionExpression)
458 *ConditionExpression = bp->ConditionExpression;
459
460 return TRUE;
461}
Type
Definition: Type.h:7
UNICODE_STRING Global
Definition: symlink.c:46
@ Enabled
Definition: mountmgr.h:179
PCHAR ConditionExpression
Definition: kdb.h:32
ULONG_PTR Address
Definition: kdb.h:29
PEPROCESS Process
Definition: kdb.h:31
KDB_BREAKPOINT_TYPE Type
Definition: kdb.h:27
union _KDB_BREAKPOINT::@1822 Data
BOOLEAN Global
Definition: kdb.h:30
struct _KDB_BREAKPOINT::@1822::@1823 Hw
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by KdbpCmdBreakPointList().

◆ KdbpGetCommandLineSettings()

VOID KdbpGetCommandLineSettings ( _In_ PCSTR  p1)

Definition at line 1635 of file kdb.c.

1637{
1638#define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
1639
1640 while (p1 && *p1)
1641 {
1642 /* Skip leading whitespace */
1643 while (*p1 == ' ') ++p1;
1644
1645 if (!_strnicmp(p1, "FIRSTCHANCE", CONST_STR_LEN("FIRSTCHANCE")))
1646 {
1647 p1 += CONST_STR_LEN("FIRSTCHANCE");
1649 }
1650
1651 /* Move on to the next option */
1652 p1 = strchr(p1, ' ');
1653 }
1654}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
BOOLEAN KdbpSetEnterCondition(IN LONG ExceptionNr, IN BOOLEAN FirstChance, IN KDB_ENTER_CONDITION Condition)
Sets the first or last chance enter-condition for exception nr. ExceptionNr.
Definition: kdb.c:995
#define CONST_STR_LEN(x)

Referenced by KdbInitialize().

◆ KdbpGetEnterCondition()

BOOLEAN KdbpGetEnterCondition ( IN LONG  ExceptionNr,
IN BOOLEAN  FirstChance,
OUT KDB_ENTER_CONDITION Condition 
)

Gets the first or last chance enter-condition for exception nr. ExceptionNr.

Parameters
ExceptionNrNumber of the exception to get condition of.
FirstChanceWhether to get first or last chance condition.
ConditionReceives the condition setting.
Return values
TRUESuccess.
FALSEFailure (invalid exception nr)

Definition at line 973 of file kdb.c.

977{
978 if (ExceptionNr >= (LONG)RTL_NUMBER_OF(KdbEnterConditions))
979 return FALSE;
980
981 *Condition = KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1];
982 return TRUE;
983}
static KDB_ENTER_CONDITION KdbEnterConditions[][2]
Definition: kdb.c:63
IN ULONG IN UCHAR Condition

Referenced by KdbpCmdSet().

◆ KdbpGetHexNumber()

BOOLEAN NTAPI KdbpGetHexNumber ( IN PCHAR  pszNum,
OUT ULONG_PTR pulValue 
)

Definition at line 450 of file kdb_cli.c.

453{
454 char *endptr;
455
456 /* Skip optional '0x' prefix */
457 if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
458 pszNum += 2;
459
460 /* Make a number from the string (hex) */
461 *pulValue = strtoul(pszNum, &endptr, 16);
462
463 return (*endptr == '\0');
464}
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696

◆ KdbpGetInstLength()

LONG KdbpGetInstLength ( IN ULONG_PTR  Address)

Definition at line 94 of file i386-dis.c.

95{
97
98 info.fprintf_func = KdbpNopPrintDisasm;
99 info.stream = NULL;
100 info.application_data = NULL;
102 info.arch = bfd_arch_i386;
103#ifdef _M_AMD64
104 info.mach = bfd_mach_x86_64;
105#else
107#endif
108 info.insn_sets = 0;
109 info.flags = 0;
110 info.read_memory_func = KdbpReadMemory;
111 info.memory_error_func = KdbpMemoryError;
112 info.print_address_func = KdbpNopPrintAddress;
113 info.symbol_at_address_func = NULL;
114 info.buffer = NULL;
115 info.buffer_vma = info.buffer_length = 0;
116 info.bytes_per_chunk = 0;
117 info.display_endian = BIG_ENDIAN_LITTLE;
118 info.disassembler_options = NULL;
119
120 return(print_insn_i386(Address, &info));
121}
#define bfd_mach_x86_64
Definition: i386-dis.c:30
static void KdbpNopPrintAddress(uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:87
int KdbpNopPrintDisasm(void *Ignored, const char *fmt,...)
Definition: i386-dis.c:59

Referenced by KdbpStepOverInstruction().

◆ KdbpGetNextBreakPointNr()

LONG KdbpGetNextBreakPointNr ( IN ULONG Start  OPTIONAL)

Gets the number of the next breakpoint >= Start.

Parameters
StartBreakpoint number to start searching at. -1 if no more breakpoints are found.
Returns
Breakpoint number (-1 if no more breakpoints are found)

Definition at line 382 of file kdb.c.

384{
385 for (; Start < RTL_NUMBER_OF(KdbBreakPoints); Start++)
386 {
387 if (KdbBreakPoints[Start].Type != KdbBreakPointNone)
388 return Start;
389 }
390
391 return -1;
392}
return pTarget Start()

Referenced by KdbpCmdBreakPointList().

◆ KdbpInsertBreakPoint()

NTSTATUS KdbpInsertBreakPoint ( IN ULONG_PTR  Address,
IN KDB_BREAKPOINT_TYPE  Type,
IN UCHAR Size  OPTIONAL,
IN KDB_ACCESS_TYPE AccessType  OPTIONAL,
IN PCHAR ConditionExpression  OPTIONAL,
IN BOOLEAN  Global,
OUT PLONG BreakPointNr  OPTIONAL 
)

Inserts a breakpoint into the breakpoint array.

The Process of the breakpoint is set to KdbCurrentProcess

Parameters
AddressAddress at which to set the breakpoint.
TypeType of breakpoint (hardware or software)
SizeSize of breakpoint (for hardware/memory breakpoints)
AccessTypeAccess type (for hardware breakpoins)
ConditionExpressionExpression which must evaluate to true for conditional breakpoints.
GlobalWether the breakpoint is global or local to a process.
BreakPointNumberReceives the breakpoint number on success
Returns
NTSTATUS

Definition at line 478 of file kdb.c.

486{
487 LONG_PTR i;
489 PCHAR ConditionExpressionDup;
490 LONG ErrOffset;
491 CHAR ErrMsg[128];
492
494
496 {
497 if ((Address % Size) != 0)
498 {
499 KdbPrintf("Address (0x%p) must be aligned to a multiple of the size (%d)\n", Address, Size);
500 return STATUS_UNSUCCESSFUL;
501 }
502
503 if (AccessType == KdbAccessExec && Size != 1)
504 {
505 KdbPuts("Size must be 1 for execution breakpoints.\n");
506 return STATUS_UNSUCCESSFUL;
507 }
508 }
509
510 if (KdbBreakPointCount == KDB_MAXIMUM_BREAKPOINT_COUNT)
511 {
512 return STATUS_UNSUCCESSFUL;
513 }
514
515 /* Parse condition expression string and duplicate it */
516 if (ConditionExpression)
517 {
518 Condition = KdbpRpnParseExpression(ConditionExpression, &ErrOffset, ErrMsg);
519 if (!Condition)
520 {
521 if (ErrOffset >= 0)
522 KdbPrintf("Couldn't parse expression: %s at character %d\n", ErrMsg, ErrOffset);
523 else
524 KdbPrintf("Couldn't parse expression: %s", ErrMsg);
525
526 return STATUS_UNSUCCESSFUL;
527 }
528
529 i = strlen(ConditionExpression) + 1;
530 ConditionExpressionDup = ExAllocatePoolWithTag(NonPagedPool, i, TAG_KDBG);
531 RtlCopyMemory(ConditionExpressionDup, ConditionExpression, i);
532 }
533 else
534 {
535 Condition = NULL;
536 ConditionExpressionDup = NULL;
537 }
538
539 /* Find unused breakpoint */
541 {
542 for (i = RTL_NUMBER_OF(KdbBreakPoints) - 1; i >= 0; i--)
543 {
544 if (KdbBreakPoints[i].Type == KdbBreakPointNone)
545 break;
546 }
547 }
548 else
549 {
550 for (i = 0; i < (LONG)RTL_NUMBER_OF(KdbBreakPoints); i++)
551 {
552 if (KdbBreakPoints[i].Type == KdbBreakPointNone)
553 break;
554 }
555 }
556
557 ASSERT(i < (LONG)RTL_NUMBER_OF(KdbBreakPoints));
558
559 /* Set the breakpoint */
561 KdbBreakPoints[i].Type = Type;
562 KdbBreakPoints[i].Address = Address;
563 KdbBreakPoints[i].Enabled = FALSE;
564 KdbBreakPoints[i].Global = Global;
565 KdbBreakPoints[i].Process = KdbCurrentProcess;
566 KdbBreakPoints[i].ConditionExpression = ConditionExpressionDup;
567 KdbBreakPoints[i].Condition = Condition;
568
570 {
571 KdbBreakPoints[i].Data.Hw.Size = Size;
572 KdbBreakPoints[i].Data.Hw.AccessType = AccessType;
573 }
574
575 KdbBreakPointCount++;
576
578 KdbPrintf("Breakpoint %d inserted.\n", i);
579
580 /* Try to enable the breakpoint */
582
583 /* Return the breakpoint number */
584 if (BreakPointNr)
585 *BreakPointNr = i;
586
587 return STATUS_SUCCESS;
588}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
BOOLEAN KdbpEnableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Enables a breakpoint.
Definition: kdb.c:702
PVOID KdbpRpnParseExpression(IN PCHAR Expression, OUT PLONG ErrOffset OPTIONAL, OUT PCHAR ErrMsg OPTIONAL)
Parses the given expression and returns a "handle" to it.
Definition: kdb_expr.c:1146
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
static int ErrMsg(int Error)
Definition: shlextdbg.cpp:71
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by KdbpCmdBreakPoint(), KdbpStepIntoInstruction(), and KdbpStepOverInstruction().

◆ KdbpPager()

VOID KdbpPager ( _In_ PCHAR  Buffer,
_In_ ULONG  BufLength 
)

Prints the given string with, page by page.

Parameters
BufferCharacters buffer to print.
BufferLenBuffer size.
Note
Doesn't correctly handle \t and terminal escape sequences when calculating the number of lines required to print a single line from the Buffer in the terminal. Maximum length of buffer is limited only by memory size. Uses KdbPrintf internally.

Note: BufLength should be greater than (KdTermSize.cx * KdTermSize.cy).

Definition at line 3063 of file kdb_cli.c.

3066{
3067 /* Call the internal function */
3068 KdbpPagerInternal(Buffer, BufLength, TRUE);
3069}
static VOID KdbpPagerInternal(_In_ PCHAR Buffer, _In_ ULONG BufLength, _In_ BOOLEAN DoPage)
Prints the given string with, page by page.
Definition: kdb_cli.c:2887

Referenced by KdbpCmdDmesg().

◆ KdbpPrint()

VOID KdbpPrint ( _In_ PSTR  Format,
_In_ ...   
)

Prints the given string with printf-like formatting.

Parameters
FormatFormat of the string/arguments.
...Variable number of arguments matching the format specified in Format.
Note
Doesn't correctly handle \t and terminal escape sequences when calculating the number of lines required to print a single line from the Buffer in the terminal. Prints maximum 4096 chars, because of its buffer size.

Definition at line 3081 of file kdb_cli.c.

3084{
3085 static CHAR Buffer[4096];
3086 ULONG Length;
3087 va_list ap;
3088
3089 /* Check if the user has aborted output of the current command */
3090 if (KdbOutputAborted)
3091 return;
3092
3093 /* Build the string */
3094 va_start(ap, Format);
3095 Length = _vsnprintf(Buffer, sizeof(Buffer) - 1, Format, ap);
3096 Buffer[Length] = '\0';
3097 va_end(ap);
3098
3099 /* Actually print it */
3101}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:134
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
#define _vsnprintf
Definition: xmlstorage.h:202

Referenced by KdbpAttachToProcess(), KdbpAttachToThread(), KdbpCmdBackTrace(), KdbpCmdBreakPoint(), KdbpCmdBreakPointList(), KdbpCmdDisassembleX(), KdbpCmdDmesg(), KdbpCmdEnableDisableClearBreakPoint(), KdbpCmdEvalExpression(), KdbpCmdFilter(), KdbpCmdGdtLdtIdt(), KdbpCmdHelp(), KdbpCmdMod(), KdbpCmdPcr(), KdbpCmdProc(), KdbpCmdRegs(), KdbpCmdSet(), KdbpCmdStep(), KdbpCmdThread(), KdbpEvaluateExpression(), and KdbpPrintUnicodeString().

◆ KdbpPrintUnicodeString()

VOID KdbpPrintUnicodeString ( _In_ PCUNICODE_STRING  String)

Definition at line 3104 of file kdb_cli.c.

3106{
3107 ULONG i;
3108
3109 if ((String == NULL) || (String->Buffer == NULL))
3110 {
3111 KdbpPrint("<NULL>");
3112 return;
3113 }
3114
3115 for (i = 0; i < String->Length / sizeof(WCHAR); i++)
3116 {
3117 KdbpPrint("%c", (CHAR)String->Buffer[i]);
3118 }
3119}
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3081
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by KdbpCmdMod().

◆ KdbPrintf()

VOID __cdecl KdbPrintf ( _In_ PCSTR  Format,
  ... 
)

Definition at line 160 of file kdb_print.c.

163{
164 va_list ap;
166 CHAR Buffer[1024];
167
168 /* Format the string */
171 sizeof(Buffer),
172 Format,
173 ap);
174 Length = min(Length, MAXUSHORT - sizeof(ANSI_NULL));
175 va_end(ap);
176
177 /* Send it to the debugger directly */
179}
VOID KdbPutsN(_In_ PCCH String, _In_ USHORT Length)
Definition: kdb_print.c:140
unsigned short USHORT
Definition: pedump.c:61
#define MAXUSHORT
Definition: typedefs.h:83

Referenced by KdbEnterDebuggerException(), KdbpCliMainLoop(), KdbpDeleteBreakPoint(), KdbpDisableBreakPoint(), KdbpDoCommand(), KdbpEnableBreakPoint(), KdbpInsertBreakPoint(), KdbpPagerInternal(), KdbpPrintAddressInCode(), KdbpShouldStepOverInstruction(), KdbSymPrintAddress(), KdReceivePacket(), and KdSendPacket().

◆ KdbPrintString()

VOID KdbPrintString ( _In_ const CSTRING Output)

Definition at line 64 of file kdb_print.c.

66{
67 DBGKD_DEBUG_IO DebugIo;
69
71 &DebugIo, &Header, &Data);
72}
Definition: Header.h:9
std::wstring STRING
Definition: fontsub.cpp:33
static VOID KdbPrintStringWorker(_In_ const CSTRING *Output, _In_ ULONG ApiNumber, _Inout_ PDBGKD_DEBUG_IO DebugIo, _Inout_ PSTRING Header, _Inout_ PSTRING Data)
Definition: kdb_print.c:25
@ Output
Definition: arc.h:85
#define DbgKdPrintStringApi
Definition: windbgkd.h:122

Referenced by KdbPutsN().

◆ KdbPrompt()

SIZE_T KdbPrompt ( _In_ PCSTR  Prompt,
_Out_ PCHAR  Buffer,
_In_ SIZE_T  Size 
)

Definition at line 182 of file kdb_print.c.

186{
187 CSTRING PromptString;
188 STRING ResponseBuffer;
189
190 PromptString.Buffer = Prompt;
191 PromptString.Length = PromptString.MaximumLength =
192 (USHORT)strnlen(Prompt, MAXUSHORT - sizeof(ANSI_NULL));
193
194 ResponseBuffer.Buffer = Buffer;
195 ResponseBuffer.Length = 0;
196 ResponseBuffer.MaximumLength = (USHORT)min(Size, MAXUSHORT);
197
198 return KdbPromptString(&PromptString, &ResponseBuffer);
199}
USHORT KdbPromptString(_In_ const CSTRING *PromptString, _Inout_ PSTRING ResponseString)
Definition: kdb_print.c:125
USHORT MaximumLength
Definition: umtypes.h:158
CONST CHAR * Buffer
Definition: umtypes.h:159
USHORT Length
Definition: umtypes.h:157

Referenced by KdbpCliMainLoop().

◆ KdbPromptString()

USHORT KdbPromptString ( _In_ const CSTRING PromptString,
_Inout_ PSTRING  ResponseString 
)

Definition at line 125 of file kdb_print.c.

128{
129 /* Enter prompt loop: send the prompt and receive the response */
130 ResponseString->Length = 0;
131 while (KdbPromptStringWorker(PromptString, ResponseString))
132 {
133 /* Loop while we need to resend */
134 }
135 return ResponseString->Length;
136}
static BOOLEAN KdbPromptStringWorker(_In_ const CSTRING *PromptString, _Inout_ PSTRING ResponseString)
Definition: kdb_print.c:75

Referenced by KdbPrompt().

◆ KdbpRpnEvaluateExpression()

BOOLEAN KdbpRpnEvaluateExpression ( IN PCHAR  Expression,
IN PKDB_KTRAP_FRAME  TrapFrame,
OUT PULONGLONG  Result,
OUT PLONG ErrOffset  OPTIONAL,
OUT PCHAR ErrMsg  OPTIONAL 
)

Evaluates the given expression.

Parameters
ExpressionExpression to evaluate.
TrapFrameRegister values.
ResultVariable which receives the result on success.
ErrOffsetVariable which receives character offset on parse error (-1 on other errors)
ErrMsgBuffer which receives an error message on failure (128 bytes)
Return values
TRUESuccess.
FALSEFailure.

Definition at line 1106 of file kdb_expr.c.

1112{
1114
1116 ASSERT(TrapFrame);
1117 ASSERT(Result);
1118
1119 /* Clear the stack and parse the expression */
1121 if (!RpnpParseExpression(Stack, Expression, NULL, 0, ErrOffset, ErrMsg))
1122 return FALSE;
1123
1124#ifdef DEBUG_RPN
1125 RpnpDumpStack(Stack);
1126#endif
1127
1128 /* Evaluate the stack */
1129 if (!RpnpEvaluateStack(Stack, TrapFrame, Result, ErrOffset, ErrMsg))
1130 return FALSE;
1131
1132 return TRUE;
1133}
PCWSTR Expression
static BOOLEAN RpnpParseExpression(IN PRPN_STACK Stack, IN PCHAR Expression, OUT PCHAR *End OPTIONAL, IN ULONG CharacterOffset, OUT PLONG ErrOffset OPTIONAL, OUT PCHAR ErrMsg OPTIONAL)
Parses an expression.
Definition: kdb_expr.c:426
static struct @1826 RpnStack
static VOID RpnpClearStack(OUT PRPN_STACK Stack)
Clears the given RPN stack.
Definition: kdb_expr.c:329
struct _RPN_STACK * PRPN_STACK
static BOOLEAN RpnpEvaluateStack(IN PRPN_STACK Stack, IN PKDB_KTRAP_FRAME TrapFrame, OUT PULONGLONG Result, OUT PLONG ErrOffset OPTIONAL, OUT PCHAR ErrMsg OPTIONAL)
Evaluates the RPN op stack and returns the result.
Definition: kdb_expr.c:897
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_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:409

Referenced by KdbpEvaluateExpression().

◆ KdbpRpnEvaluateParsedExpression()

BOOLEAN KdbpRpnEvaluateParsedExpression ( IN PVOID  Expression,
IN PKDB_KTRAP_FRAME  TrapFrame,
OUT PULONGLONG  Result,
OUT PLONG ErrOffset  OPTIONAL,
OUT PCHAR ErrMsg  OPTIONAL 
)

Evaluates the given expression and returns the result.

Parameters
ExpressionExpression "handle" returned by KdbpRpnParseExpression.
TrapFrameRegister values.
ResultVariable which receives the result on success.
ErrOffsetVariable which receives character offset on parse error (-1 on other errors)
ErrMsgBuffer which receives an error message on failure (128 bytes)
Returns
"Handle" for the expression, NULL on failure.
See also
KdbpRpnParseExpression

Definition at line 1200 of file kdb_expr.c.

1206{
1208
1210 ASSERT(TrapFrame);
1211 ASSERT(Result);
1212
1213 /* Evaluate the stack */
1214 return RpnpEvaluateStack(Stack, TrapFrame, Result, ErrOffset, ErrMsg);
1215}

Referenced by KdbEnterDebuggerException().

◆ KdbpRpnParseExpression()

PVOID KdbpRpnParseExpression ( IN PCHAR  Expression,
OUT PLONG ErrOffset  OPTIONAL,
OUT PCHAR ErrMsg  OPTIONAL 
)

Parses the given expression and returns a "handle" to it.

Parameters
ExpressionExpression to evaluate.
ErrOffsetVariable which receives character offset on parse error (-1 on other errors)
ErrMsgBuffer which receives an error message on failure (128 bytes)
Returns
"Handle" for the expression, NULL on failure.
See also
KdbpRpnEvaluateExpression

Definition at line 1146 of file kdb_expr.c.

1150{
1151 LONG Size;
1153 PRPN_STACK NewStack;
1154
1156
1157 /* Clear the stack and parse the expression */
1159 if (!RpnpParseExpression(Stack, Expression, NULL, 0, ErrOffset, ErrMsg))
1160 return FALSE;
1161
1162#ifdef DEBUG_RPN
1163 RpnpDumpStack(Stack);
1164#endif
1165
1166 /* Duplicate the stack and return a pointer/handle to it */
1167 ASSERT(Stack->Sp >= 1);
1168 Size = sizeof (RPN_STACK) + (RTL_FIELD_SIZE(RPN_STACK, Ops[0]) * (Stack->Sp - 1));
1170
1171 if (!NewStack)
1172 {
1173 CONST_STRCPY(ErrMsg, "Out of memory");
1174
1175 if (ErrOffset)
1176 *ErrOffset = -1;
1177
1178 return NULL;
1179 }
1180
1181 memcpy(NewStack, Stack, Size);
1182 NewStack->Size = NewStack->Sp;
1183
1184 return NewStack;
1185}
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:86
RPN_OP Ops[RPN_OP_STACK_SIZE]
Definition: kdb_expr.c:100
struct _RPN_STACK RPN_STACK
ULONG Size
Definition: kdb_expr.c:98
#define CONST_STRCPY(dst, src)
Definition: kdb_expr.c:89
ULONG Size
Definition: kdb_expr.c:76
ULONG Sp
Definition: kdb_expr.c:77

Referenced by KdbpInsertBreakPoint().

◆ KdbpSafeReadMemory()

NTSTATUS KdbpSafeReadMemory ( OUT PVOID  Dest,
IN PVOID  Src,
IN ULONG  Bytes 
)

Definition at line 1657 of file kdb.c.

1661{
1663 Dest,
1664 Bytes,
1665 0,
1667 NULL);
1668}
NTSTATUS NTAPI KdpCopyMemoryChunks(_In_ ULONG64 Address, _In_ PVOID Buffer, _In_ ULONG TotalSize, _In_ ULONG ChunkSize, _In_ ULONG Flags, _Out_opt_ PULONG ActualSize)
Definition: kdapi.c:55
_In_ UINT Bytes
Definition: mmcopy.h:9
unsigned __int64 ULONG64
Definition: imports.h:198
#define MMDBG_COPY_UNSAFE
Definition: mm.h:77

Referenced by KdbpCmdBackTrace(), KdbpCmdDisassembleX(), KdbpCmdGdtLdtIdt(), KdbpCmdThread(), KdbpOverwriteInstruction(), KdbpReadMemory(), KdbpShouldStepOverInstruction(), KdbpStepIntoInstruction(), and RpnpEvaluateStack().

◆ KdbpSafeWriteMemory()

NTSTATUS KdbpSafeWriteMemory ( OUT PVOID  Dest,
IN PVOID  Src,
IN ULONG  Bytes 
)

Definition at line 1671 of file kdb.c.

1675{
1677 Src,
1678 Bytes,
1679 0,
1681 NULL);
1682}
#define MMDBG_COPY_WRITE
Definition: mm.h:75

Referenced by KdbpOverwriteInstruction().

◆ KdbpSetEnterCondition()

BOOLEAN KdbpSetEnterCondition ( IN LONG  ExceptionNr,
IN BOOLEAN  FirstChance,
IN KDB_ENTER_CONDITION  Condition 
)

Sets the first or last chance enter-condition for exception nr. ExceptionNr.

Parameters
ExceptionNrNumber of the exception to set condition of (-1 for all)
FirstChanceWhether to set first or last chance condition.
ConditionThe new condition setting.
Return values
TRUESuccess.
FALSEFailure (invalid exception nr)

Definition at line 995 of file kdb.c.

999{
1000 if (ExceptionNr < 0)
1001 {
1002 for (ExceptionNr = 0; ExceptionNr < (LONG)RTL_NUMBER_OF(KdbEnterConditions); ExceptionNr++)
1003 {
1004 if (ExceptionNr == 1 || ExceptionNr == 8 ||
1005 ExceptionNr == 9 || ExceptionNr == 15) /* Reserved exceptions */
1006 {
1007 continue;
1008 }
1009
1010 KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1] = Condition;
1011 }
1012 }
1013 else
1014 {
1015 if (ExceptionNr >= (LONG)RTL_NUMBER_OF(KdbEnterConditions) ||
1016 ExceptionNr == 1 || ExceptionNr == 8 || /* Do not allow changing of the debug */
1017 ExceptionNr == 9 || ExceptionNr == 15) /* trap or reserved exceptions */
1018 {
1019 return FALSE;
1020 }
1021
1022 KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1] = Condition;
1023 }
1024
1025 return TRUE;
1026}

Referenced by KdbpCmdSet(), and KdbpGetCommandLineSettings().

◆ KdbpStackSwitchAndCall()

VOID NTAPI KdbpStackSwitchAndCall ( IN PVOID  NewStack,
IN VOID(*)(VOID Function 
)

Referenced by KdbpInternalEnter().

◆ KdbpSymFindModule()

BOOLEAN KdbpSymFindModule ( IN PVOID Address  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.

80{
81 LONG Count = 0;
82 PEPROCESS CurrentProcess;
83
84 /* First try to look up the module in the kernel module list. */
88 &Count,
89 Address,
90 Index,
91 pLdrEntry))
92 {
94 return TRUE;
95 }
97
98 /* That didn't succeed. Try the module list of the current process now. */
99 CurrentProcess = PsGetCurrentProcess();
100
101 if(!CurrentProcess || !CurrentProcess->Peb || !CurrentProcess->Peb->Ldr)
102 return FALSE;
103
104 return KdbpSymSearchModuleList(CurrentProcess->Peb->Ldr->InLoadOrderModuleList.Flink,
105 &CurrentProcess->Peb->Ldr->InLoadOrderModuleList,
106 &Count,
107 Address,
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 INT Index, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
Definition: kdb_symbols.c:39
int Count
Definition: noreturn.cpp:7
KSPIN_LOCK PsLoadedModuleSpinLock
Definition: sysldr.c:23
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:21
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
struct _PEB * Peb
Definition: pstypes.h:1345
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_In_ WDFCOLLECTION _In_ ULONG Index

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

◆ KdbPuts()

◆ KdbPutsN()

VOID KdbPutsN ( _In_ PCCH  String,
_In_ USHORT  Length 
)

Definition at line 140 of file kdb_print.c.

143{
145
146 Output.Buffer = String;
147 Output.Length = Output.MaximumLength = Length;
149}
VOID KdbPrintString(_In_ const CSTRING *Output)
Definition: kdb_print.c:64

Referenced by KdbPrintf(), and KdbPuts().

◆ KdbRegisterCliCallback()

BOOLEAN NTAPI KdbRegisterCliCallback ( PVOID  Callback,
BOOLEAN  Deregister 
)

Definition at line 3124 of file kdb_cli.c.

3127{
3128 ULONG i;
3129
3130 /* Loop all entries */
3131 for (i = 0; i < _countof(KdbCliCallbacks); i++)
3132 {
3133 /* Check if deregistering was requested */
3134 if (Deregister)
3135 {
3136 /* Check if this entry is the one that was registered */
3137 if (KdbCliCallbacks[i] == Callback)
3138 {
3139 /* Delete it and report success */
3141 return TRUE;
3142 }
3143 }
3144 else
3145 {
3146 /* Check if this entry is free */
3147 if (KdbCliCallbacks[i] == NULL)
3148 {
3149 /* Set it and and report success */
3151 return TRUE;
3152 }
3153 }
3154 }
3155
3156 /* Unsuccessful */
3157 return FALSE;
3158}
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:128
#define _countof(array)
Definition: sndvol32.h:70
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458

Referenced by KdSystemDebugControl().

◆ KdbSymInit()

BOOLEAN KdbSymInit ( _In_ ULONG  BootPhase)

Initializes the KDB symbols implementation.

Parameters
[in]BootPhasePhase of initialization.
Returns
TRUE if symbols are to be loaded at this given BootPhase; FALSE if not.

Definition at line 343 of file kdb_symbols.c.

345{
346#if 1 // FIXME: This is a workaround HACK!!
347 static BOOLEAN OrigLoadSymbols = FALSE;
348#endif
349
350 DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase);
351
352 if (BootPhase == 0)
353 {
354 PSTR CommandLine;
355 SHORT Found = FALSE;
356 CHAR YesNo;
357
358 /* By default, load symbols in DBG builds, but not in REL builds
359 or anything other than x86, because they only work on x86
360 and can cause the system to hang on x64. */
361#if DBG && defined(_M_IX86)
363#else
365#endif
366
367 /* Check the command line for LOADSYMBOLS, NOLOADSYMBOLS,
368 * LOADSYMBOLS={YES|NO}, NOLOADSYMBOLS={YES|NO} */
370 CommandLine = KeLoaderBlock->LoadOptions;
371 while (*CommandLine)
372 {
373 /* Skip any whitespace */
374 while (isspace(*CommandLine))
375 ++CommandLine;
376
377 Found = 0;
378 if (_strnicmp(CommandLine, "LOADSYMBOLS", 11) == 0)
379 {
380 Found = +1;
381 CommandLine += 11;
382 }
383 else if (_strnicmp(CommandLine, "NOLOADSYMBOLS", 13) == 0)
384 {
385 Found = -1;
386 CommandLine += 13;
387 }
388 if (Found != 0)
389 {
390 if (*CommandLine == '=')
391 {
392 ++CommandLine;
393 YesNo = toupper(*CommandLine);
394 if (YesNo == 'N' || YesNo == '0')
395 {
396 Found = -1 * Found;
397 }
398 }
399 LoadSymbols = (0 < Found);
400 }
401
402 /* Move on to the next option */
403 while (*CommandLine && !isspace(*CommandLine))
404 ++CommandLine;
405 }
406
407#if 1 // FIXME: This is a workaround HACK!!
408// Save the actual value of LoadSymbols but disable it for BootPhase 0.
409 OrigLoadSymbols = LoadSymbols;
411 return OrigLoadSymbols;
412#endif
413 }
414 else if (BootPhase == 1)
415 {
419 PLIST_ENTRY ListEntry;
420
421#if 1 // FIXME: This is a workaround HACK!!
422// Now, restore the actual value of LoadSymbols.
423 LoadSymbols = OrigLoadSymbols;
424#endif
425
426 /* Do not continue loading symbols if we have less than 96MB of RAM */
427 if (MmNumberOfPhysicalPages < (96 * 1024 * 1024 / PAGE_SIZE))
429
430 /* Continue this phase only if we need to load symbols */
431 if (!LoadSymbols)
432 return LoadSymbols;
433
434 /* Launch our worker thread */
438
441 NULL, NULL, NULL,
443 NULL);
444 if (!NT_SUCCESS(Status))
445 {
446 DPRINT1("Failed starting symbols loader thread: 0x%08x\n", Status);
448 return LoadSymbols;
449 }
450
452
454
455 for (ListEntry = PsLoadedModuleList.Flink;
456 ListEntry != &PsLoadedModuleList;
457 ListEntry = ListEntry->Flink)
458 {
459 PLDR_DATA_TABLE_ENTRY LdrEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
460 KdbSymProcessSymbols(LdrEntry, TRUE);
461 }
462
464 }
465
466 return LoadSymbols;
467}
int toupper(int c)
Definition: utclib.c:881
return Found
Definition: dirsup.c:1270
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static KSPIN_LOCK SymbolsToLoadLock
Definition: kdb_symbols.c:32
VOID KdbSymProcessSymbols(_Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry, _In_ BOOLEAN Load)
Load symbols from image mapping. If this fails,.
Definition: kdb_symbols.c:297
static KEVENT SymbolsToLoadEvent
Definition: kdb_symbols.c:33
static KSTART_ROUTINE LoadSymbolsRoutine
Definition: kdb_symbols.c:195
static LIST_ENTRY SymbolsToLoad
Definition: kdb_symbols.c:31
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
@ SynchronizationEvent
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
short SHORT
Definition: pedump.c:59
VOID RosSymInitKernelMode(VOID)
Definition: initkm.c:32
Definition: btrfs_drv.h:1876
char * PSTR
Definition: typedefs.h:51
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by KdbInitialize().

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

152{
153 PLDR_DATA_TABLE_ENTRY LdrEntry;
154 ULONG_PTR RelativeAddress;
155 BOOLEAN Printed = FALSE;
156 CHAR ModuleNameAnsi[64];
157
158 if (!KdbpSymFindModule(Address, -1, &LdrEntry))
159 return FALSE;
160
161 RelativeAddress = (ULONG_PTR)Address - (ULONG_PTR)LdrEntry->DllBase;
162
164 ModuleNameAnsi,
165 sizeof(ModuleNameAnsi));
166
167 if (LdrEntry->PatchInformation)
168 {
170 CHAR FileName[256];
171 CHAR FunctionName[256];
172
174 RelativeAddress,
175 &LineNumber,
176 FileName,
178 {
179 KdbPrintf("<%s:%x (%s:%d (%s))>",
180 ModuleNameAnsi, RelativeAddress,
182 Printed = TRUE;
183 }
184 }
185
186 if (!Printed)
187 {
188 /* Just print module & address */
189 KdbPrintf("<%s:%x>", ModuleNameAnsi, RelativeAddress);
190 }
191
192 return TRUE;
193}
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:1220
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:1279
#define ULONG_PTR
Definition: config.h:101
BOOLEAN KdbpSymFindModule(IN PVOID Address OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
Find a module...
Definition: kdb_symbols.c:76
static PCHAR NTAPI KdbpSymUnicodeToAnsi(IN PUNICODE_STRING Unicode, OUT PCHAR Ansi, IN ULONG Length)
Definition: kdb_symbols.c:115
BOOLEAN RosSymGetAddressInformation(PROSSYM_INFO RosSymInfo, ULONG_PTR RelativeAddress, ULONG *LineNumber, char *FileName, char *FunctionName)
Definition: find.c:94
PVOID DllBase
Definition: btrfs_drv.h:1880
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
PVOID PatchInformation
Definition: ldrtypes.h:164

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

◆ KdbSymProcessSymbols()

VOID KdbSymProcessSymbols ( _Inout_ PLDR_DATA_TABLE_ENTRY  LdrEntry,
_In_ BOOLEAN  Load 
)

Load symbols from image mapping. If this fails,.

Parameters
LdrEntryThe entry to load symbols from

Definition at line 297 of file kdb_symbols.c.

300{
301 if (!LoadSymbols)
302 return;
303
304 /* Check if this is unload */
305 if (!Load)
306 {
307 /* Did we process it */
308 if (LdrEntry->PatchInformation)
309 {
310 RosSymDelete(LdrEntry->PatchInformation);
311 LdrEntry->PatchInformation = NULL;
312 }
313 return;
314 }
315
316 if (RosSymCreateFromMem(LdrEntry->DllBase, LdrEntry->SizeOfImage, (PROSSYM_INFO*)&LdrEntry->PatchInformation))
317 {
318 return;
319 }
320
321 /* Add a ref until we really process it */
322 LdrEntry->LoadCount++;
323
324 /* Tell our worker thread to read from it */
326 InsertTailList(&SymbolsToLoad, &LdrEntry->InInitializationOrderLinks);
328
330}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
VOID RosSymDelete(PROSSYM_INFO RosSymInfo)
Definition: delete.c:15
BOOLEAN RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
Definition: frommem.c:19
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by KdbSymInit(), and KdSendPacket().

◆ KdpSafeReadMemory()

BOOLEAN NTAPI KdpSafeReadMemory ( IN ULONG_PTR  Addr,
IN LONG  Len,
OUT PVOID  Value 
)

◆ KdpSafeWriteMemory()

BOOLEAN NTAPI KdpSafeWriteMemory ( IN ULONG_PTR  Addr,
IN LONG  Len,
IN ULONGLONG  Value 
)

Variable Documentation

◆ KdbCurrentProcess

◆ KdbCurrentThread

PETHREAD KdbCurrentThread
extern

Definition at line 54 of file kdb.c.

Referenced by KdbEnterDebuggerException(), KdbpAttachToThread(), KdbpCmdProc(), and KdbpCmdThread().

◆ KdbCurrentTrapFrame

◆ KdbInitFileBuffer

volatile PCHAR KdbInitFileBuffer
extern

Definition at line 137 of file kdb_cli.c.

Referenced by KdbEnterDebuggerException(), KdbpCliInit(), and KdbpCliInterpretInitFile().

◆ KdbLastBreakPointNr

LONG KdbLastBreakPointNr
extern

Definition at line 48 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdBreakPointList().

◆ KdbNumSingleSteps

ULONG KdbNumSingleSteps
extern

Definition at line 49 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().

◆ KdbSingleStepOver

BOOLEAN KdbSingleStepOver
extern

Definition at line 50 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().