ReactOS 0.4.15-dev-7788-g1ad9096
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)
 This function is called by KdbEnterDebuggerException...
 
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

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 3551 of file kdb_cli.c.

3554{
3555 /* Saves the different symbol-loading status across boot phases */
3556 static ULONG LoadSymbols = 0;
3557
3558 if (BootPhase == 0)
3559 {
3560 /* Write out the functions that we support for now */
3561 DispatchTable->KdpPrintRoutine = KdbDebugPrint;
3562
3563 /* Check if we have a command line */
3565 {
3566 /* Get the KDBG Settings */
3568 }
3569
3570 /* Register for BootPhase 1 initialization and as a Provider */
3571 DispatchTable->KdpInitRoutine = KdbInitialize;
3572 InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
3573 }
3574 else if (BootPhase == 1)
3575 {
3576 /* Register for later BootPhase 2 reinitialization */
3577 DispatchTable->KdpInitRoutine = KdbInitialize;
3578
3579 /* Initialize Dmesg support */
3580
3581 /* Allocate a buffer for Dmesg log buffer. +1 for terminating null,
3582 * see kdbp_cli.c:KdbpCmdDmesg()/2 */
3583 KdpDmesgBuffer = ExAllocatePoolZero(NonPagedPool,
3585 TAG_KDBG);
3586 /* Ignore failure if KdpDmesgBuffer is NULL */
3589
3590 /* Initialize spinlock */
3592 }
3593
3594 /* Initialize symbols support in BootPhase 0 and 1 */
3595 if (BootPhase <= 1)
3596 {
3597 LoadSymbols <<= 1;
3598 LoadSymbols |= KdbSymInit(BootPhase);
3599 }
3600
3601 if (BootPhase == 1)
3602 {
3603 /* Announce ourselves */
3604 CHAR buffer[60];
3606 " KDBG debugger enabled - %s\r\n",
3607 !(LoadSymbols & 0x2) ? "No symbols loaded" :
3608 !(LoadSymbols & 0x1) ? "Kernel symbols loaded"
3609 : "Loading symbols");
3611 }
3612
3613 if (BootPhase >= 2)
3614 {
3615 /* I/O is now set up for disk access: Read KDB Data */
3617
3618 /* Schedule an I/O reinitialization if needed */
3621 {
3622 DispatchTable->KdpInitRoutine = KdbInitialize;
3623 }
3624 }
3625
3626 return STATUS_SUCCESS;
3627}
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:1621
BOOLEAN KdbSymInit(_In_ ULONG BootPhase)
Initializes the KDB symbols implementation.
Definition: kdb_symbols.c:343
static KSPIN_LOCK KdpDmesgLogSpinLock
Definition: kdb_cli.c:146
static VOID NTAPI KdbDebugPrint(_In_ PCCH String, _In_ ULONG Length)
Debug logger function.
Definition: kdb_cli.c:3491
static const ULONG KdpDmesgBufferSize
Definition: kdb_cli.c:140
static volatile ULONG KdpDmesgFreeBytes
Definition: kdb_cli.c:143
NTSTATUS NTAPI KdbInitialize(_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
Initializes the KDBG debugger.
Definition: kdb_cli.c:3551
static PCHAR KdpDmesgBuffer
Definition: kdb_cli.c:141
static volatile ULONG KdbDmesgTotalWritten
Definition: kdb_cli.c:144
NTSTATUS KdbpCliInit(VOID)
Called when KDB is initialized.
Definition: kdb_cli.c:3393
static BOOLEAN LoadSymbols
Definition: kdb_symbols.c:30
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
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:32
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2711
_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:3082
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:1329
CLIENT_ID Cid
Definition: pstypes.h:1128
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:947
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:1103
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.

Reads the KDBinit file from the SystemRoot\System32\drivers\etc directory and executes it.

Definition at line 3393 of file kdb_cli.c.

3394{
3399 FILE_STANDARD_INFORMATION FileStdInfo;
3400 HANDLE hFile = NULL;
3401 INT FileSize;
3402 PCHAR FileBuffer;
3403 ULONG OldEflags;
3404
3405 /* Don't load the KDBinit file if its buffer is already lying around */
3407 return STATUS_SUCCESS;
3408
3409 /* Initialize the object attributes */
3410 RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3412 &FileName,
3414 NULL,
3415 NULL);
3416
3417 /* Open the file */
3419 &ObjectAttributes, &Iosb, 0,
3422 if (!NT_SUCCESS(Status))
3423 {
3424 DPRINT("Could not open \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3425 return Status;
3426 }
3427
3428 /* Get the size of the file */
3429 Status = ZwQueryInformationFile(hFile, &Iosb,
3430 &FileStdInfo, sizeof(FileStdInfo),
3432 if (!NT_SUCCESS(Status))
3433 {
3434 ZwClose(hFile);
3435 DPRINT("Could not query size of \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3436 return Status;
3437 }
3438 FileSize = FileStdInfo.EndOfFile.u.LowPart;
3439
3440 /* Allocate memory for the file */
3441 FileBuffer = ExAllocatePool(PagedPool, FileSize + 1); /* add 1 byte for terminating '\0' */
3442 if (!FileBuffer)
3443 {
3444 ZwClose(hFile);
3445 DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize);
3446 return Status;
3447 }
3448
3449 /* Load file into memory */
3450 Status = ZwReadFile(hFile, NULL, NULL, NULL, &Iosb, FileBuffer, FileSize, NULL, NULL);
3451 ZwClose(hFile);
3452
3454 {
3455 ExFreePool(FileBuffer);
3456 DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3457 return Status;
3458 }
3459
3460 FileSize = min(FileSize, (INT)Iosb.Information);
3461 FileBuffer[FileSize] = '\0';
3462
3463 /* Enter critical section */
3464 OldEflags = __readeflags();
3465 _disable();
3466
3467 /* Interpret the init file... */
3468 KdbInitFileBuffer = FileBuffer;
3469 //KdbEnter(); // FIXME, see commit baa47fa5e
3471
3472 /* Leave critical section */
3473 __writeeflags(OldEflags);
3474
3475 ExFreePool(FileBuffer);
3476
3477 return STATUS_SUCCESS;
3478}
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
return Iosb
Definition: create.c:4402
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
struct _FileName FileName
Definition: fatprocs.h:896
#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
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1669
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:136
#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)
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 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:71
int32_t INT
Definition: typedefs.h:58
char * PCHAR
Definition: typedefs.h:51
struct _LARGE_INTEGER::@2290 u

Referenced by KdbInitialize().

◆ KdbpCliInterpretInitFile()

VOID KdbpCliInterpretInitFile ( VOID  )

This function is called by KdbEnterDebuggerException...

Used to interpret the init file in a context with a trapframe setup (KdbpCliInit call KdbEnter which will call KdbEnterDebuggerException which will call this function if KdbInitFileBuffer is not NULL.

Definition at line 3342 of file kdb_cli.c.

3343{
3344 PCHAR p1, p2;
3345 INT_PTR i;
3346 CHAR c;
3347
3348 /* Execute the commands in the init file */
3349 DPRINT("KDB: Executing KDBinit file...\n");
3350 p1 = KdbInitFileBuffer;
3351 while (p1[0] != '\0')
3352 {
3353 i = strcspn(p1, "\r\n");
3354 if (i > 0)
3355 {
3356 c = p1[i];
3357 p1[i] = '\0';
3358
3359 /* Look for "break" command and comments */
3360 p2 = p1;
3361
3362 while (isspace(p2[0]))
3363 p2++;
3364
3365 if (strncmp(p2, "break", sizeof("break")-1) == 0 &&
3366 (p2[sizeof("break")-1] == '\0' || isspace(p2[sizeof("break")-1])))
3367 {
3368 /* break into the debugger */
3370 }
3371 else if (p2[0] != '#' && p2[0] != '\0') /* Ignore empty lines and comments */
3372 {
3373 KdbpDoCommand(p1);
3374 }
3375
3376 p1[i] = c;
3377 }
3378
3379 p1 += i;
3380 while (p1[0] == '\r' || p1[0] == '\n')
3381 p1++;
3382 }
3383 DPRINT("KDB: KDBinit executed\n");
3384}
#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
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3206
VOID KdbpCliMainLoop(IN BOOLEAN EnteredOnSingleStep)
KDB Main Loop.
Definition: kdb_cli.c:3268
#define c
Definition: ke_i.h:80
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
int32_t INT_PTR
Definition: typedefs.h:64

Referenced by KdbEnterDebuggerException().

◆ KdbpCliMainLoop()

VOID KdbpCliMainLoop ( IN BOOLEAN  EnteredOnSingleStep)

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3268 of file kdb_cli.c.

3270{
3271 BOOLEAN Continue;
3272 SIZE_T CmdLen;
3273 static CHAR Command[1024];
3274 static CHAR LastCommand[1024] = "";
3275
3276 if (EnteredOnSingleStep)
3277 {
3279 {
3281 }
3282
3283 KdbpPrint(": ");
3285 {
3286 KdbpPrint("<INVALID>");
3287 }
3288 KdbpPrint("\n");
3289 }
3290
3291 /* Main loop */
3292 do
3293 {
3294 /* Reset the number of rows/cols printed */
3296
3297 /*
3298 * Print the prompt and read a command.
3299 * Repeat the last one if the user pressed Enter.
3300 * This reduces the risk of RSI when single-stepping!
3301 */
3302 // TEMP HACK! Issue an empty string instead of duplicating "kdb:>"
3303 CmdLen = KdbPrompt(/*KdbPromptStr.Buffer*/"", Command, sizeof(Command));
3304 if (CmdLen == 0)
3305 {
3306 /* Nothing received but the user didn't press Enter, retry */
3307 continue;
3308 }
3309 else if (CmdLen > 1) // i.e. (*Command != ANSI_NULL)
3310 {
3311 /* Save this new last command */
3313 RtlStringCbCopyA(LastCommand, sizeof(LastCommand), Command);
3314
3315 /* Remember it */
3317 }
3318 else if (KdbRepeatLastCommand)
3319 {
3320 /* The user directly pressed Enter */
3321 RtlStringCbCopyA(Command, sizeof(Command), LastCommand);
3322 }
3323
3324 /* Reset the number of rows/cols printed and output aborted state */
3327
3328 /* Call the command */
3329 Continue = KdbpDoCommand(Command);
3331 }
3332 while (Continue);
3333}
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
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:134
static ULONG KdbNumberOfRowsPrinted
Definition: kdb_cli.c:131
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:128
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:133
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3082
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:132
#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
VOID __cdecl KdbPrintf(_In_ PCSTR Format,...)
Definition: kdb_print.c:160

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
VOID KdbPuts(_In_ PCSTR String)
Definition: kdb_print.c:152
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

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:37
@ Enabled
Definition: mountmgr.h:159
PCHAR ConditionExpression
Definition: kdb.h:32
ULONG_PTR Address
Definition: kdb.h:29
union _KDB_BREAKPOINT::@1808 Data
PEPROCESS Process
Definition: kdb.h:31
KDB_BREAKPOINT_TYPE Type
Definition: kdb.h:27
struct _KDB_BREAKPOINT::@1808::@1809 Hw
BOOLEAN Global
Definition: kdb.h:30
_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 1621 of file kdb.c.

1623{
1624#define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
1625
1626 while (p1 && *p1)
1627 {
1628 /* Skip leading whitespace */
1629 while (*p1 == ' ') ++p1;
1630
1631 if (!_strnicmp(p1, "FIRSTCHANCE", CONST_STR_LEN("FIRSTCHANCE")))
1632 {
1633 p1 += CONST_STR_LEN("FIRSTCHANCE");
1635 }
1636
1637 /* Move on to the next option */
1638 p1 = strchr(p1, ' ');
1639 }
1640}
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 449 of file kdb_cli.c.

452{
453 char *endptr;
454
455 /* Skip optional '0x' prefix */
456 if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
457 pszNum += 2;
458
459 /* Make a number from the string (hex) */
460 *pulValue = strtoul(pszNum, &endptr, 16);
461
462 return (*endptr == '\0');
463}
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}
@ Start
Definition: partlist.h:33

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
#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 3064 of file kdb_cli.c.

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

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 3082 of file kdb_cli.c.

3085{
3086 static CHAR Buffer[4096];
3087 ULONG Length;
3088 va_list ap;
3089
3090 /* Check if the user has aborted output of the current command */
3091 if (KdbOutputAborted)
3092 return;
3093
3094 /* Build the string */
3095 va_start(ap, Format);
3096 Length = _vsnprintf(Buffer, sizeof(Buffer) - 1, Format, ap);
3097 Buffer[Length] = '\0';
3098 va_end(ap);
3099
3100 /* Actually print it */
3102}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
_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(), KdbpCliMainLoop(), KdbpCmdBackTrace(), KdbpCmdBreakPoint(), KdbpCmdBreakPointList(), KdbpCmdDisassembleX(), KdbpCmdDmesg(), KdbpCmdEnableDisableClearBreakPoint(), KdbpCmdEvalExpression(), KdbpCmdFilter(), KdbpCmdGdtLdtIdt(), KdbpCmdHelp(), KdbpCmdMod(), KdbpCmdPcr(), KdbpCmdProc(), KdbpCmdRegs(), KdbpCmdSet(), KdbpCmdStep(), KdbpCmdThread(), KdbpDoCommand(), KdbpEvaluateExpression(), and KdbpPrintUnicodeString().

◆ KdbpPrintUnicodeString()

VOID KdbpPrintUnicodeString ( _In_ PCUNICODE_STRING  String)

Definition at line 3105 of file kdb_cli.c.

3107{
3108 ULONG i;
3109
3110 if ((String == NULL) || (String->Buffer == NULL))
3111 {
3112 KdbpPrint("<NULL>");
3113 return;
3114 }
3115
3116 for (i = 0; i < String->Length / sizeof(WCHAR); i++)
3117 {
3118 KdbpPrint("%c", (CHAR)String->Buffer[i]);
3119 }
3120}
_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
#define ANSI_NULL
unsigned short USHORT
Definition: pedump.c:61
#define MAXUSHORT
Definition: typedefs.h:83

Referenced by KdbEnterDebuggerException(), KdbpDeleteBreakPoint(), KdbpDisableBreakPoint(), 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 VOID RpnpClearStack(OUT PRPN_STACK Stack)
Clears the given RPN stack.
Definition: kdb_expr.c:329
struct _RPN_STACK * PRPN_STACK
static struct @1812 RpnStack
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 1643 of file kdb.c.

1647{
1649 Dest,
1650 Bytes,
1651 0,
1653 NULL);
1654}
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 1657 of file kdb.c.

1661{
1663 Src,
1664 Bytes,
1665 0,
1667 NULL);
1668}
#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:1344
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_In_ WDFCOLLECTION _In_ ULONG Index

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

◆ KdbPuts()

VOID KdbPuts ( _In_ PCSTR  String)

◆ 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 3125 of file kdb_cli.c.

3128{
3129 ULONG i;
3130
3131 /* Loop all entries */
3132 for (i = 0; i < _countof(KdbCliCallbacks); i++)
3133 {
3134 /* Check if deregistering was requested */
3135 if (Deregister)
3136 {
3137 /* Check if this entry is the one that was registered */
3138 if (KdbCliCallbacks[i] == Callback)
3139 {
3140 /* Delete it and report success */
3142 return TRUE;
3143 }
3144 }
3145 else
3146 {
3147 /* Check if this entry is free */
3148 if (KdbCliCallbacks[i] == NULL)
3149 {
3150 /* Set it and and report success */
3152 return TRUE;
3153 }
3154 }
3155 }
3156
3157 /* Unsuccessful */
3158 return FALSE;
3159}
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:127
#define _countof(array)
Definition: sndvol32.h:68
_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
#define DPRINT1
Definition: precomp.h:8
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

PCHAR KdbInitFileBuffer
extern

Definition at line 136 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().