ReactOS 0.4.15-dev-5884-gab5aff5
kdb.h File Reference
#include "../kd/kd.h"
Include dependency graph for kdb.h:

Go to the source code of this file.

Classes

struct  _KDB_BREAKPOINT
 

Macros

#define KdbpGetCharKeyboard(ScanCode)   KdbpTryGetCharKeyboard(ScanCode, 0)
 
#define KdbpGetCharSerial()   KdbpTryGetCharSerial(0)
 

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 _KDB_OUTPUT_SETTINGS KDB_OUTPUT_SETTINGS
 

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  _KDB_OUTPUT_SETTINGS { KD_DEBUG_KDSERIAL = 1 , KD_DEBUG_KDNOECHO = 2 }
 

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)
 
SIZE_T KdbpReadCommand (_Out_ PCHAR Buffer, _In_ SIZE_T Size)
 Reads a line of user input from the terminal.
 
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 NTAPI KdbpGetCommandLineSettings (PCHAR 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)
 
CHAR KdbpTryGetCharKeyboard (PULONG ScanCode, ULONG Retry)
 
CHAR KdbpTryGetCharSerial (ULONG Retry)
 
VOID KbdDisableMouse (VOID)
 
VOID KbdEnableMouse (VOID)
 

Variables

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

Macro Definition Documentation

◆ KdbpGetCharKeyboard

#define KdbpGetCharKeyboard (   ScanCode)    KdbpTryGetCharKeyboard(ScanCode, 0)

Definition at line 297 of file kdb.h.

◆ KdbpGetCharSerial

#define KdbpGetCharSerial ( )    KdbpTryGetCharSerial(0)

Definition at line 301 of file kdb.h.

Typedef Documentation

◆ KDB_ACCESS_TYPE

◆ KDB_BREAKPOINT

◆ KDB_BREAKPOINT_TYPE

◆ KDB_ENTER_CONDITION

◆ KDB_KTRAP_FRAME

Definition at line 7 of file kdb.h.

◆ KDB_OUTPUT_SETTINGS

◆ PKDB_BREAKPOINT

◆ PKDB_KTRAP_FRAME

Definition at line 7 of file kdb.h.

Enumeration Type Documentation

◆ _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

◆ _KDB_OUTPUT_SETTINGS

Enumerator
KD_DEBUG_KDSERIAL 
KD_DEBUG_KDNOECHO 

Definition at line 55 of file kdb.h.

56{
@ KD_DEBUG_KDSERIAL
Definition: kdb.h:57
@ KD_DEBUG_KDNOECHO
Definition: kdb.h:58
enum _KDB_OUTPUT_SETTINGS KDB_OUTPUT_SETTINGS

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 152 of file kdb_cmdhist.c.

155{
156 if (Next)
157 return KdbpGetNextHistoryEntry(NextIndex);
158 else
159 return KdbpGetPrevHistoryEntry(NextIndex);
160}
static PCSTR KdbpGetPrevHistoryEntry(_Inout_ PLONG NextIndex)
Definition: kdb_cmdhist.c:109
static PCSTR KdbpGetNextHistoryEntry(_Inout_ PLONG NextIndex)
Definition: kdb_cmdhist.c:133

Referenced by KdbpReadCommand().

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

3846{
3847 /* Saves the different symbol-loading status across boot phases */
3848 static ULONG LoadSymbols = 0;
3849
3850 if (BootPhase == 0)
3851 {
3852 /* Write out the functions that we support for now */
3853 DispatchTable->KdpPrintRoutine = KdbDebugPrint;
3854
3855 /* Register for BootPhase 1 initialization and as a Provider */
3856 DispatchTable->KdpInitRoutine = KdbInitialize;
3857 InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
3858 }
3859 else if (BootPhase == 1)
3860 {
3861 /* Register for later BootPhase 2 reinitialization */
3862 DispatchTable->KdpInitRoutine = KdbInitialize;
3863
3864 /* Initialize Dmesg support */
3865
3866 /* Allocate a buffer for Dmesg log buffer. +1 for terminating null,
3867 * see kdbp_cli.c:KdbpCmdDmesg()/2 */
3868 KdpDmesgBuffer = ExAllocatePoolZero(NonPagedPool,
3870 TAG_KDBG);
3871 /* Ignore failure if KdpDmesgBuffer is NULL */
3874
3875 /* Initialize spinlock */
3877 }
3878
3879 /* Initialize symbols support in BootPhase 0 and 1 */
3880 if (BootPhase <= 1)
3881 {
3882 LoadSymbols <<= 1;
3883 LoadSymbols |= KdbSymInit(BootPhase);
3884 }
3885
3886 if (BootPhase == 1)
3887 {
3888 /* Announce ourselves */
3889 CHAR buffer[60];
3891 " KDBG debugger enabled - %s\r\n",
3892 !(LoadSymbols & 0x2) ? "No symbols loaded" :
3893 !(LoadSymbols & 0x1) ? "Kernel symbols loaded"
3894 : "Loading symbols");
3896 }
3897
3898 if (BootPhase >= 2)
3899 {
3900 /* I/O is now set up for disk access: Read KDB Data */
3902
3903 /* Schedule an I/O reinitialization if needed */
3906 {
3907 DispatchTable->KdpInitRoutine = KdbInitialize;
3908 }
3909 }
3910
3911 return STATUS_SUCCESS;
3912}
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:39
BOOLEAN KdbSymInit(_In_ ULONG BootPhase)
Initializes the KDB symbols implementation.
Definition: kdb_symbols.c:344
static KSPIN_LOCK KdpDmesgLogSpinLock
Definition: kdb_cli.c:160
static VOID NTAPI KdbDebugPrint(_In_ PCCH String, _In_ ULONG Length)
Debug logger function.
Definition: kdb_cli.c:3783
static const ULONG KdpDmesgBufferSize
Definition: kdb_cli.c:154
static volatile ULONG KdpDmesgFreeBytes
Definition: kdb_cli.c:157
NTSTATUS NTAPI KdbInitialize(_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
Initializes the KDBG debugger.
Definition: kdb_cli.c:3843
static PCHAR KdpDmesgBuffer
Definition: kdb_cli.c:155
static volatile ULONG KdbDmesgTotalWritten
Definition: kdb_cli.c:158
NTSTATUS KdbpCliInit(VOID)
Called when KDB is initialized.
Definition: kdb_cli.c:3685
static BOOLEAN LoadSymbols
Definition: kdb_symbols.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 1120 of file kdb.c.

1122{
1126
1127 /* Get a pointer to the process */
1129 {
1130 KdbpPrint("Invalid process id: 0x%08x\n", (ULONG_PTR)ProcessId);
1131 return FALSE;
1132 }
1133
1134 Entry = Process->ThreadListHead.Flink;
1137 {
1138 KdbpPrint("No threads in process 0x%p, cannot attach to process!\n", ProcessId);
1139 return FALSE;
1140 }
1141
1142 Thread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
1143
1145}
#define NULL
Definition: types.h:112
#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:54
BOOLEAN KdbpAttachToThread(PVOID ThreadId)
Switches to another thread context.
Definition: kdb.c:1039
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3219
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 1039 of file kdb.c.

1041{
1044
1045 /* Get a pointer to the thread */
1046 if (!NT_SUCCESS(PsLookupThreadByThreadId(ThreadId, &Thread)))
1047 {
1048 KdbpPrint("Invalid thread id: 0x%08x\n", (ULONG_PTR)ThreadId);
1049 return FALSE;
1050 }
1051 Process = Thread->ThreadsProcess;
1052
1054 {
1055 KdbpPrint("Cannot attach to thread within another process while executing a DPC.\n");
1057 return FALSE;
1058 }
1059
1060 /* Save the current thread's context (if we previously attached to a thread) */
1062 {
1064 /* Actually, we can't save the context, there's no guarantee that there was a trap frame */
1065 }
1066 else
1067 {
1069 }
1070
1071 /* Switch to the thread's context */
1073 {
1074 /* The thread we're attaching to isn't the thread on which we entered
1075 * kdb and so the thread we're attaching to is not running. There
1076 * is no guarantee that it actually has a trap frame. So we have to
1077 * peek directly at the registers which were saved on the stack when the
1078 * thread was preempted in the scheduler */
1082 }
1083 else /* Switching back to original thread */
1084 {
1086 }
1088
1089 /* Attach to the thread's process */
1092 {
1093 if (KdbCurrentProcess != KdbOriginalProcess) /* detach from previously attached process */
1094 {
1096 }
1097
1099 {
1101 }
1102
1104 }
1105
1107 return TRUE;
1108}
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI KeIsExecutingDpc(VOID)
Definition: dpc.c:947
PETHREAD KdbCurrentThread
Definition: kdb.c:56
PETHREAD KdbOriginalThread
Definition: kdb.c:57
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:58
static KDB_KTRAP_FRAME KdbThreadTrapFrame
Definition: kdb.c:60
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:59
PEPROCESS KdbOriginalProcess
Definition: kdb.c:55
static VOID KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack, PKDB_KTRAP_FRAME KdbTrapFrame)
Definition: kdb.c:121
static KAPC_STATE KdbApcState
Definition: kdb.c:61
#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:1615
#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 3685 of file kdb_cli.c.

3686{
3691 FILE_STANDARD_INFORMATION FileStdInfo;
3692 HANDLE hFile = NULL;
3693 INT FileSize;
3694 PCHAR FileBuffer;
3695 ULONG OldEflags;
3696
3697 /* Don't load the KDBinit file if its buffer is already lying around */
3699 return STATUS_SUCCESS;
3700
3701 /* Initialize the object attributes */
3702 RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3704 &FileName,
3706 NULL,
3707 NULL);
3708
3709 /* Open the file */
3711 &ObjectAttributes, &Iosb, 0,
3714 if (!NT_SUCCESS(Status))
3715 {
3716 DPRINT("Could not open \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3717 return Status;
3718 }
3719
3720 /* Get the size of the file */
3721 Status = ZwQueryInformationFile(hFile, &Iosb,
3722 &FileStdInfo, sizeof(FileStdInfo),
3724 if (!NT_SUCCESS(Status))
3725 {
3726 ZwClose(hFile);
3727 DPRINT("Could not query size of \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3728 return Status;
3729 }
3730 FileSize = FileStdInfo.EndOfFile.u.LowPart;
3731
3732 /* Allocate memory for the file */
3733 FileBuffer = ExAllocatePool(PagedPool, FileSize + 1); /* add 1 byte for terminating '\0' */
3734 if (!FileBuffer)
3735 {
3736 ZwClose(hFile);
3737 DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize);
3738 return Status;
3739 }
3740
3741 /* Load file into memory */
3742 Status = ZwReadFile(hFile, NULL, NULL, NULL, &Iosb, FileBuffer, FileSize, NULL, NULL);
3743 ZwClose(hFile);
3744
3746 {
3747 ExFreePool(FileBuffer);
3748 DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3749 return Status;
3750 }
3751
3752 FileSize = min(FileSize, (INT)Iosb.Information);
3753 FileBuffer[FileSize] = '\0';
3754
3755 /* Enter critical section */
3756 OldEflags = __readeflags();
3757 _disable();
3758
3759 /* Interpret the init file... */
3760 KdbInitFileBuffer = FileBuffer;
3761 //KdbEnter(); // FIXME, see commit baa47fa5e
3763
3764 /* Leave critical section */
3765 __writeeflags(OldEflags);
3766
3767 ExFreePool(FileBuffer);
3768
3769 return STATUS_SUCCESS;
3770}
#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:150
#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::@2272 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 3634 of file kdb_cli.c.

3635{
3636 PCHAR p1, p2;
3637 INT_PTR i;
3638 CHAR c;
3639
3640 /* Execute the commands in the init file */
3641 DPRINT("KDB: Executing KDBinit file...\n");
3642 p1 = KdbInitFileBuffer;
3643 while (p1[0] != '\0')
3644 {
3645 i = strcspn(p1, "\r\n");
3646 if (i > 0)
3647 {
3648 c = p1[i];
3649 p1[i] = '\0';
3650
3651 /* Look for "break" command and comments */
3652 p2 = p1;
3653
3654 while (isspace(p2[0]))
3655 p2++;
3656
3657 if (strncmp(p2, "break", sizeof("break")-1) == 0 &&
3658 (p2[sizeof("break")-1] == '\0' || isspace(p2[sizeof("break")-1])))
3659 {
3660 /* break into the debugger */
3662 }
3663 else if (p2[0] != '#' && p2[0] != '\0') /* Ignore empty lines and comments */
3664 {
3665 KdbpDoCommand(p1);
3666 }
3667
3668 p1[i] = c;
3669 }
3670
3671 p1 += i;
3672 while (p1[0] == '\r' || p1[0] == '\n')
3673 p1++;
3674 }
3675 DPRINT("KDB: KDBinit executed\n");
3676}
#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:3509
VOID KdbpCliMainLoop(IN BOOLEAN EnteredOnSingleStep)
KDB Main Loop.
Definition: kdb_cli.c:3571
#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 3571 of file kdb_cli.c.

3573{
3574 static CHAR Command[1024];
3575 BOOLEAN Continue;
3576
3577 if (EnteredOnSingleStep)
3578 {
3580 {
3582 }
3583
3584 KdbpPrint(": ");
3586 {
3587 KdbpPrint("<INVALID>");
3588 }
3589 KdbpPrint("\n");
3590 }
3591
3592 /* Flush the input buffer */
3594 {
3595 while (KdbpTryGetCharSerial(1) != -1);
3596 }
3597 else
3598 {
3600 while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
3601 }
3602
3603 /* Main loop */
3604 do
3605 {
3606 /* Reset the number of rows/cols printed */
3608
3609 /* Print the prompt */
3610 KdbpPrint(KdbPromptString.Buffer);
3611
3612 /* Read a command and remember it */
3615
3616 /* Reset the number of rows/cols printed and output aborted state */
3619
3620 /* Call the command */
3621 Continue = KdbpDoCommand(Command);
3623 }
3624 while (Continue);
3625}
unsigned char BOOLEAN
UINT ScanCode
Definition: VirtualKey.c:24
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:125
ULONG KdbDebugState
Definition: kdb.c:52
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PCONTEXT Context)
Print address...
Definition: kdb_symbols.c:148
VOID KdbpCommandHistoryAppend(_In_ PCSTR Command)
Appends a command to the command history.
Definition: kdb_cmdhist.c:37
static ULONG KdbNumberOfRowsPrinted
Definition: kdb_cli.c:143
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:140
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:145
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3219
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:144
SIZE_T KdbpReadCommand(_Out_ PCHAR Buffer, _In_ SIZE_T Size)
Reads a line of user input from the terminal.
Definition: kdb_cli.c:3275
STRING KdbPromptString
Definition: kdb_cli.c:162
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdps2kbd.c:104
#define KeGetContextPc(Context)
Definition: ke.h:31
CHAR KdbpTryGetCharSerial(ULONG Retry)
Definition: kdserial.c:16
Definition: shell.h:41

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
ULONG_PTR SIZE_T
Definition: typedefs.h:80

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 601 of file kdb.c.

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

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 871 of file kdb.c.

874{
875 ULONG i;
877
878 if (BreakPointNr < 0)
879 {
880 ASSERT(BreakPoint);
881 BreakPointNr = BreakPoint - KdbBreakPoints;
882 }
883
884 if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
885 {
886 KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
887 return FALSE;
888 }
889
890 if (!BreakPoint)
891 {
892 BreakPoint = KdbBreakPoints + BreakPointNr;
893 }
894
895 if (BreakPoint->Type == KdbBreakPointNone)
896 {
897 KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
898 return FALSE;
899 }
900
901 if (BreakPoint->Enabled == FALSE)
902 {
903 KdbpPrint("Breakpoint %d is not enabled.\n", BreakPointNr);
904 return TRUE;
905 }
906
907 if (BreakPoint->Type == KdbBreakPointSoftware ||
908 BreakPoint->Type == KdbBreakPointTemporary)
909 {
911 Status = KdbpOverwriteInstruction(BreakPoint->Process, BreakPoint->Address,
912 BreakPoint->Data.SavedInstruction, NULL);
913
914 if (!NT_SUCCESS(Status))
915 {
916 KdbpPrint("Couldn't restore original instruction.\n");
917 return FALSE;
918 }
919
920 for (i = 0; i < KdbSwBreakPointCount; i++)
921 {
922 if (KdbSwBreakPoints[i] == BreakPoint)
923 {
925 i = -1; /* if the last breakpoint is disabled dont break with i >= KdbSwBreakPointCount */
926 break;
927 }
928 }
929
930 if (i != MAXULONG) /* not found */
931 ASSERT(0);
932 }
933 else
934 {
935 ASSERT(BreakPoint->Type == KdbBreakPointHardware);
936
937 /* Clear the breakpoint. */
938 KdbTrapFrame.Dr7 &= ~(0x3 << (BreakPoint->Data.Hw.DebugReg * 2));
939 if ((KdbTrapFrame.Dr7 & 0xFF) == 0)
940 {
941 /* If no breakpoints are enabled then clear the exact match flags. */
942 KdbTrapFrame.Dr7 &= 0xFFFFFCFF;
943 }
944
945 for (i = 0; i < KdbHwBreakPointCount; i++)
946 {
947 if (KdbHwBreakPoints[i] == BreakPoint)
948 {
950 i = -1; /* if the last breakpoint is disabled dont break with i >= KdbHwBreakPointCount */
951 break;
952 }
953 }
954
955 if (i != MAXULONG) /* not found */
956 ASSERT(0);
957 }
958
959 BreakPoint->Enabled = FALSE;
960 if (BreakPoint->Type != KdbBreakPointTemporary)
961 KdbpPrint("Breakpoint %d disabled.\n", BreakPointNr);
962
963 return TRUE;
964}
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:45
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:157
static PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]
Definition: kdb.c:44
static ULONG KdbSwBreakPointCount
Definition: kdb.c:42
static ULONG KdbHwBreakPointCount
Definition: kdb.c:43
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 125 of file i386-dis.c.

126{
128
129 info.fprintf_func = KdbpPrintDisasm;
130 info.stream = NULL;
131 info.application_data = NULL;
133 info.arch = bfd_arch_i386;
135 info.insn_sets = 0;
136 info.flags = 0;
137 info.read_memory_func = KdbpReadMemory;
138 info.memory_error_func = KdbpMemoryError;
139 info.print_address_func = KdbpPrintAddressInCode;
140 info.symbol_at_address_func = NULL;
141 info.buffer = NULL;
142 info.buffer_vma = info.buffer_length = 0;
143 info.bytes_per_chunk = 0;
144 info.display_endian = BIG_ENDIAN_LITTLE;
145 info.disassembler_options = NULL;
146
147 return(print_insn_i386(Address, &info));
148}
static void KdbpPrintAddressInCode(uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:79
int print_insn_i386(bfd_vma pc, struct disassemble_info *info)
Definition: i386-dis.c:2079
int KdbpPrintDisasm(void *Ignored, const char *fmt,...)
Definition: i386-dis.c:46
@ bfd_target_unknown_flavour
Definition: i386-dis.c:19
#define bfd_mach_i386_i386
Definition: i386-dis.c:33
@ BIG_ENDIAN_LITTLE
Definition: i386-dis.c:27
static void KdbpMemoryError(int Status, uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:73
@ bfd_arch_i386
Definition: i386-dis.c:23
static int KdbpReadMemory(uintptr_t Addr, unsigned char *Data, unsigned int Length, struct disassemble_info *Ignored)
Definition: i386-dis.c:66
#define bfd_mach_i386_i386_intel_syntax
Definition: i386-dis.c:32
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 704 of file kdb.c.

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

422{
424
425 if (BreakPointNr >= RTL_NUMBER_OF(KdbBreakPoints) ||
426 KdbBreakPoints[BreakPointNr].Type == KdbBreakPointNone)
427 {
428 return FALSE;
429 }
430
431 bp = KdbBreakPoints + BreakPointNr;
432 if (Address)
433 *Address = bp->Address;
434
435 if (Type)
436 *Type = bp->Type;
437
438 if (bp->Type == KdbBreakPointHardware)
439 {
440 if (Size)
441 *Size = bp->Data.Hw.Size;
442
443 if (AccessType)
444 *AccessType = bp->Data.Hw.AccessType;
445
446 if (DebugReg && bp->Enabled)
447 *DebugReg = bp->Data.Hw.DebugReg;
448 }
449
450 if (Enabled)
451 *Enabled = bp->Enabled;
452
453 if (Global)
454 *Global = bp->Global;
455
456 if (Process)
457 *Process = bp->Process;
458
459 if (ConditionExpression)
460 *ConditionExpression = bp->ConditionExpression;
461
462 return TRUE;
463}
Type
Definition: Type.h:7
UNICODE_STRING Global
Definition: symlink.c:37
@ Enabled
Definition: mountmgr.h:159
union _KDB_BREAKPOINT::@1790 Data
struct _KDB_BREAKPOINT::@1790::@1791 Hw
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
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 NTAPI KdbpGetCommandLineSettings ( PCHAR  p1)

Definition at line 1628 of file kdb.c.

1630{
1631#define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
1632
1633 while (p1 && (p1 = strchr(p1, ' ')))
1634 {
1635 /* Skip other spaces */
1636 while (*p1 == ' ') ++p1;
1637
1638 if (!_strnicmp(p1, "KDSERIAL", CONST_STR_LEN("KDSERIAL")))
1639 {
1640 p1 += CONST_STR_LEN("KDSERIAL");
1643 }
1644 else if (!_strnicmp(p1, "KDNOECHO", CONST_STR_LEN("KDNOECHO")))
1645 {
1646 p1 += CONST_STR_LEN("KDNOECHO");
1648 }
1649 else if (!_strnicmp(p1, "FIRSTCHANCE", CONST_STR_LEN("FIRSTCHANCE")))
1650 {
1651 p1 += CONST_STR_LEN("FIRSTCHANCE");
1653 }
1654 }
1655}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
KDP_DEBUG_MODE KdpDebugMode
Definition: kdio.c:38
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:998
#define CONST_STR_LEN(x)
UCHAR Serial
Definition: kd.h:96

Referenced by KdDebuggerInitialize0().

◆ 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 976 of file kdb.c.

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

Referenced by KdbpCmdSet().

◆ KdbpGetHexNumber()

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

Definition at line 463 of file kdb_cli.c.

466{
467 char *endptr;
468
469 /* Skip optional '0x' prefix */
470 if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
471 pszNum += 2;
472
473 /* Make a number from the string (hex) */
474 *pulValue = strtoul(pszNum, &endptr, 16);
475
476 return (*endptr == '\0');
477}
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696

◆ KdbpGetInstLength()

LONG KdbpGetInstLength ( IN ULONG_PTR  Address)

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

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

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 384 of file kdb.c.

386{
387 for (; Start < RTL_NUMBER_OF(KdbBreakPoints); Start++)
388 {
389 if (KdbBreakPoints[Start].Type != KdbBreakPointNone)
390 return Start;
391 }
392
393 return -1;
394}
@ 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 480 of file kdb.c.

488{
489 LONG_PTR i;
491 PCHAR ConditionExpressionDup;
492 LONG ErrOffset;
493 CHAR ErrMsg[128];
494
496
498 {
499 if ((Address % Size) != 0)
500 {
501 KdbpPrint("Address (0x%p) must be aligned to a multiple of the size (%d)\n", Address, Size);
502 return STATUS_UNSUCCESSFUL;
503 }
504
505 if (AccessType == KdbAccessExec && Size != 1)
506 {
507 KdbpPrint("Size must be 1 for execution breakpoints.\n");
508 return STATUS_UNSUCCESSFUL;
509 }
510 }
511
512 if (KdbBreakPointCount == KDB_MAXIMUM_BREAKPOINT_COUNT)
513 {
514 return STATUS_UNSUCCESSFUL;
515 }
516
517 /* Parse conditon expression string and duplicate it */
518 if (ConditionExpression)
519 {
520 Condition = KdbpRpnParseExpression(ConditionExpression, &ErrOffset, ErrMsg);
521 if (!Condition)
522 {
523 if (ErrOffset >= 0)
524 KdbpPrint("Couldn't parse expression: %s at character %d\n", ErrMsg, ErrOffset);
525 else
526 KdbpPrint("Couldn't parse expression: %s", ErrMsg);
527
528 return STATUS_UNSUCCESSFUL;
529 }
530
531 i = strlen(ConditionExpression) + 1;
532 ConditionExpressionDup = ExAllocatePoolWithTag(NonPagedPool, i, TAG_KDBG);
533 RtlCopyMemory(ConditionExpressionDup, ConditionExpression, i);
534 }
535 else
536 {
537 Condition = NULL;
538 ConditionExpressionDup = NULL;
539 }
540
541 /* Find unused breakpoint */
543 {
544 for (i = RTL_NUMBER_OF(KdbBreakPoints) - 1; i >= 0; i--)
545 {
546 if (KdbBreakPoints[i].Type == KdbBreakPointNone)
547 break;
548 }
549 }
550 else
551 {
552 for (i = 0; i < (LONG)RTL_NUMBER_OF(KdbBreakPoints); i++)
553 {
554 if (KdbBreakPoints[i].Type == KdbBreakPointNone)
555 break;
556 }
557 }
558
559 ASSERT(i < (LONG)RTL_NUMBER_OF(KdbBreakPoints));
560
561 /* Set the breakpoint */
563 KdbBreakPoints[i].Type = Type;
564 KdbBreakPoints[i].Address = Address;
565 KdbBreakPoints[i].Enabled = FALSE;
566 KdbBreakPoints[i].Global = Global;
567 KdbBreakPoints[i].Process = KdbCurrentProcess;
568 KdbBreakPoints[i].ConditionExpression = ConditionExpressionDup;
569 KdbBreakPoints[i].Condition = Condition;
570
572 {
573 KdbBreakPoints[i].Data.Hw.Size = Size;
574 KdbBreakPoints[i].Data.Hw.AccessType = AccessType;
575 }
576
577 KdbBreakPointCount++;
578
580 KdbpPrint("Breakpoint %d inserted.\n", i);
581
582 /* Try to enable the breakpoint */
584
585 /* Return the breakpoint number */
586 if (BreakPointNr)
587 *BreakPointNr = i;
588
589 return STATUS_SUCCESS;
590}
#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:704
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:1142
__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 KdpDprintf internally (NOT DbgPrint!). Callers must already hold the debugger lock.

Note: BufLength should be greater then (KdbNumberOfRowsTerminal * KdbNumberOfColsTerminal).

Definition at line 3201 of file kdb_cli.c.

3204{
3205 /* Call the internal function */
3206 KdbpPagerInternal(Buffer, BufLength, TRUE);
3207}
VOID KdbpPagerInternal(_In_ PCHAR Buffer, _In_ ULONG BufLength, _In_ BOOLEAN DoPage)
Prints the given string with, page by page.
Definition: kdb_cli.c:2893

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

3222{
3223 static CHAR Buffer[4096];
3224 ULONG Length;
3225 va_list ap;
3226
3227 /* Check if the user has aborted output of the current command */
3228 if (KdbOutputAborted)
3229 return;
3230
3231 /* Build the string */
3232 va_start(ap, Format);
3233 Length = _vsnprintf(Buffer, sizeof(Buffer) - 1, Format, ap);
3234 Buffer[Length] = '\0';
3235 va_end(ap);
3236
3237 /* Actually print it */
3239}
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 KdbEnterDebuggerException(), KdbpAttachToProcess(), KdbpAttachToThread(), KdbpCliMainLoop(), KdbpCmdBackTrace(), KdbpCmdBreakPoint(), KdbpCmdBreakPointList(), KdbpCmdDisassembleX(), KdbpCmdDmesg(), KdbpCmdEnableDisableClearBreakPoint(), KdbpCmdEvalExpression(), KdbpCmdFilter(), KdbpCmdGdtLdtIdt(), KdbpCmdHelp(), KdbpCmdMod(), KdbpCmdPcr(), KdbpCmdProc(), KdbpCmdRegs(), KdbpCmdSet(), KdbpCmdStep(), KdbpCmdThread(), KdbpDeleteBreakPoint(), KdbpDisableBreakPoint(), KdbpDoCommand(), KdbpEnableBreakPoint(), KdbpEvaluateExpression(), KdbpInsertBreakPoint(), KdbpPrintUnicodeString(), and KdbpShouldStepOverInstruction().

◆ KdbpPrintUnicodeString()

VOID KdbpPrintUnicodeString ( _In_ PCUNICODE_STRING  String)

Definition at line 3242 of file kdb_cli.c.

3244{
3245 ULONG i;
3246
3247 if ((String == NULL) || (String->Buffer == NULL))
3248 {
3249 KdbpPrint("<NULL>");
3250 return;
3251 }
3252
3253 for (i = 0; i < String->Length / sizeof(WCHAR); i++)
3254 {
3255 KdbpPrint("%c", (CHAR)String->Buffer[i]);
3256 }
3257}
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by KdbpCmdMod().

◆ KdbpReadCommand()

SIZE_T KdbpReadCommand ( _Out_ PCHAR  Buffer,
_In_ SIZE_T  Size 
)

Reads a line of user input from the terminal.

Parameters
[out]BufferBuffer where to store the input. Trailing newlines are removed.
[in]SizeSize of Buffer.
Returns
Returns the number of characters stored, not counting the NULL terminator.
Note
Accepts only
newlines, \r is ignored.

Definition at line 3275 of file kdb_cli.c.

3278{
3279 PCHAR Orig = Buffer;
3280 ULONG ScanCode = 0;
3281 CHAR Key;
3282 BOOLEAN EchoOn;
3283 static CHAR LastCommand[1024];
3284 static CHAR NextKey = '\0';
3285 LONG CmdHistIndex = -1; // Start at end of history.
3286
3287 /* Bail out if the buffer is zero-sized */
3288 if (Size == 0)
3289 return 0;
3290
3291 EchoOn = ((KdbDebugState & KD_DEBUG_KDNOECHO) == 0);
3292
3293 for (;;)
3294 {
3296 {
3297 Key = (NextKey == '\0') ? KdbpGetCharSerial() : NextKey;
3298 NextKey = '\0';
3299 ScanCode = 0;
3300 if (Key == KEY_ESC) /* ESC */
3301 {
3303 if (Key == '[')
3304 {
3306
3307 switch (Key)
3308 {
3309 case 'A':
3311 break;
3312 case 'B':
3314 break;
3315 case 'C':
3316 break;
3317 case 'D':
3318 break;
3319 }
3320 }
3321 }
3322 }
3323 else
3324 {
3325 ScanCode = 0;
3326 Key = (NextKey == '\0') ? KdbpGetCharKeyboard(&ScanCode) : NextKey;
3327 NextKey = '\0';
3328 }
3329
3330 /* Check for return or newline */
3331 if ((Key == '\r') || (Key == '\n'))
3332 {
3333 if (Key == '\r')
3334 {
3335 /*
3336 * We might need to discard the next '\n' which most clients
3337 * should send after \r. Wait a bit to make sure we receive it.
3338 */
3340
3342 NextKey = KdbpTryGetCharSerial(5);
3343 else
3344 NextKey = KdbpTryGetCharKeyboard(&ScanCode, 5);
3345
3346 if (NextKey == '\n' || NextKey == -1) /* \n or no response at all */
3347 NextKey = '\0';
3348 }
3349
3350 KdpDprintf("\n");
3351
3352 /*
3353 * Repeat the last command if the user presses enter. Reduces the
3354 * risk of RSI when single-stepping.
3355 */
3356 if (Buffer != Orig)
3357 {
3359 *Buffer = '\0';
3360 RtlStringCbCopyA(LastCommand, sizeof(LastCommand), Orig);
3361 }
3362 else if (KdbRepeatLastCommand)
3363 RtlStringCbCopyA(Buffer, Size, LastCommand);
3364 else
3365 *Buffer = '\0';
3366
3367 return (SIZE_T)(Buffer - Orig);
3368 }
3369 else if (Key == KEY_BS || Key == KEY_DEL)
3370 {
3371 /* Erase the last character */
3372 if (Buffer > Orig)
3373 {
3374 Buffer--;
3375 *Buffer = '\0';
3376
3377 if (EchoOn)
3378 KdpDprintf("%c %c", KEY_BS, KEY_BS);
3379 else
3380 KdpDprintf(" %c", KEY_BS);
3381 }
3382 }
3383 else if (ScanCode == KEY_SCAN_UP || ScanCode == KEY_SCAN_DOWN)
3384 {
3385 PCSTR CmdHistory = KdbGetHistoryEntry(&CmdHistIndex,
3386 (ScanCode == KEY_SCAN_DOWN));
3387 if (CmdHistory)
3388 {
3389 SIZE_T i;
3390
3391 /* Erase the whole line */
3392 while (Buffer > Orig)
3393 {
3394 Buffer--;
3395 *Buffer = '\0';
3396
3397 if (EchoOn)
3398 KdpDprintf("%c %c", KEY_BS, KEY_BS);
3399 else
3400 KdpDprintf(" %c", KEY_BS);
3401 }
3402
3403 i = min(strlen(CmdHistory), Size - 1);
3404 memcpy(Orig, CmdHistory, i);
3405 Orig[i] = '\0';
3406 Buffer = Orig + i;
3407 KdpDprintf("%s", Orig);
3408 }
3409 }
3410 else
3411 {
3412 /* Don't accept any key if the buffer is full */
3413 if ((SIZE_T)(Buffer - Orig) >= (Size - 1))
3414 continue;
3415
3416 if (EchoOn)
3417 KdpDprintf("%c", Key);
3418
3419 *Buffer = Key;
3420 Buffer++;
3421 }
3422 }
3423}
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:81
PCSTR KdbGetHistoryEntry(_Inout_ PLONG NextIndex, _In_ BOOLEAN Next)
Definition: kdb_cmdhist.c:152
#define KdbpGetCharSerial()
Definition: kdb.h:301
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdb.h:297
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:146
#define KEY_SCAN_DOWN
Definition: kdb_cli.c:43
#define KEY_BS
Definition: kdb_cli.c:38
#define KEY_ESC
Definition: kdb_cli.c:39
#define KEY_SCAN_UP
Definition: kdb_cli.c:42
#define KEY_DEL
Definition: kdb_cli.c:40
#define KdpDprintf(...)
Definition: mmdbg.c:19
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
const char * PCSTR
Definition: typedefs.h:52

Referenced by KdbpCliMainLoop(), and KdReceivePacket().

◆ 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 1102 of file kdb_expr.c.

1108{
1110
1112 ASSERT(TrapFrame);
1113 ASSERT(Result);
1114
1115 /* Clear the stack and parse the expression */
1117 if (!RpnpParseExpression(Stack, Expression, NULL, 0, ErrOffset, ErrMsg))
1118 return FALSE;
1119
1120#ifdef DEBUG_RPN
1122#endif
1123
1124 /* Evaluate the stack */
1125 if (!RpnpEvaluateStack(Stack, TrapFrame, Result, ErrOffset, ErrMsg))
1126 return FALSE;
1127
1128 return TRUE;
1129}
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:422
static VOID RpnpClearStack(OUT PRPN_STACK Stack)
Clears the given RPN stack.
Definition: kdb_expr.c:325
struct _RPN_STACK * PRPN_STACK
static struct @1794 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:893
VOID RpnpDumpStack(IN PRPN_STACK Stack)
Dumps the given RPN stack content.
Definition: kdb_expr.c:250
_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:426

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 1196 of file kdb_expr.c.

1202{
1204
1206 ASSERT(TrapFrame);
1207 ASSERT(Result);
1208
1209 /* Evaluate the stack */
1210 return RpnpEvaluateStack(Stack, TrapFrame, Result, ErrOffset, ErrMsg);
1211}

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 1142 of file kdb_expr.c.

1146{
1147 LONG Size;
1149 PRPN_STACK NewStack;
1150
1152
1153 /* Clear the stack and parse the expression */
1155 if (!RpnpParseExpression(Stack, Expression, NULL, 0, ErrOffset, ErrMsg))
1156 return FALSE;
1157
1158#ifdef DEBUG_RPN
1160#endif
1161
1162 /* Duplicate the stack and return a pointer/handle to it */
1163 ASSERT(Stack->Sp >= 1);
1164 Size = sizeof (RPN_STACK) + (RTL_FIELD_SIZE(RPN_STACK, Ops[0]) * (Stack->Sp - 1));
1166
1167 if (!NewStack)
1168 {
1169 CONST_STRCPY(ErrMsg, "Out of memory");
1170
1171 if (ErrOffset)
1172 *ErrOffset = -1;
1173
1174 return NULL;
1175 }
1176
1177 memcpy(NewStack, Stack, Size);
1178 NewStack->Size = NewStack->Sp;
1179
1180 return NewStack;
1181}
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
RPN_OP Ops[RPN_OP_STACK_SIZE]
Definition: kdb_expr.c:98
struct _RPN_STACK RPN_STACK
ULONG Size
Definition: kdb_expr.c:96
#define CONST_STRCPY(dst, src)
Definition: kdb_expr.c:87
ULONG Size
Definition: kdb_expr.c:74
ULONG Sp
Definition: kdb_expr.c:75

Referenced by KdbpInsertBreakPoint().

◆ KdbpSafeReadMemory()

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

Definition at line 1658 of file kdb.c.

1662{
1664 Dest,
1665 Bytes,
1666 0,
1668 NULL);
1669}
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:50
_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 1672 of file kdb.c.

1676{
1678 Src,
1679 Bytes,
1680 0,
1682 NULL);
1683}
#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 998 of file kdb.c.

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

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

79{
80 LONG Count = 0;
81 PEPROCESS CurrentProcess;
82
83 /* First try to look up the module in the kernel module list. */
87 &Count,
88 Address,
89 Index,
90 pLdrEntry))
91 {
93 return TRUE;
94 }
96
97 /* That didn't succeed. Try the module list of the current process now. */
98 CurrentProcess = PsGetCurrentProcess();
99
100 if(!CurrentProcess || !CurrentProcess->Peb || !CurrentProcess->Peb->Ldr)
101 return FALSE;
102
103 return KdbpSymSearchModuleList(CurrentProcess->Peb->Ldr->InLoadOrderModuleList.Flink,
104 &CurrentProcess->Peb->Ldr->InLoadOrderModuleList,
105 &Count,
106 Address,
107 Index,
108 pLdrEntry);
109}
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:38
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().

◆ KdbpTryGetCharKeyboard()

CHAR KdbpTryGetCharKeyboard ( PULONG  ScanCode,
ULONG  Retry 
)

Definition at line 104 of file kdps2kbd.c.

105{
106 static byte_t last_key = 0;
107 static byte_t shift = 0;
108 char c;
109 BOOLEAN KeepRetrying = (Retry == 0);
110
111 while (KeepRetrying || Retry-- > 0)
112 {
113 while (kbd_read_status() & KBD_STAT_OBF)
114 {
115 byte_t scancode;
116
117 scancode = kbd_read_input();
118
119 /* check for SHIFT-keys */
120 if (((scancode & 0x7F) == 42) || ((scancode & 0x7F) == 54))
121 {
122 shift = !(scancode & 0x80);
123 continue;
124 }
125
126 /* ignore all other RELEASED-codes */
127 if (scancode & 0x80)
128 {
129 last_key = 0;
130 }
131 else if (last_key != scancode)
132 {
133 //printf("kbd: %d, %d, %c\n", scancode, last_key, keyb_layout[shift][scancode]);
134 last_key = scancode;
135 c = keyb_layout[shift][scancode];
136 *ScanCode = scancode;
137
138 if (c > 0)
139 return c;
140 }
141 }
142 }
143
144 return -1;
145}
_In_ PSCSI_REQUEST_BLOCK _Out_ NTSTATUS _Inout_ BOOLEAN * Retry
Definition: classpnp.h:312
#define KBD_STAT_OBF
Definition: kdps2kbd.c:22
#define kbd_read_status()
Definition: kdps2kbd.c:36
static unsigned char keyb_layout[2][128]
Definition: kdps2kbd.c:38
UCHAR byte_t
Definition: kdps2kbd.c:57
#define kbd_read_input()
Definition: kdps2kbd.c:35
#define shift
Definition: input.c:1755

Referenced by KdbpCliMainLoop(), KdbpPagerInternal(), and KdbpReadCommand().

◆ KdbpTryGetCharSerial()

CHAR KdbpTryGetCharSerial ( ULONG  Retry)

Definition at line 16 of file kdserial.c.

17{
18 CHAR Result = -1;
19
20 if (Retry == 0)
22 else
23 while (!KdPortGetByteEx(&SerialPortInfo, (PUCHAR)&Result) && Retry-- > 0);
24
25 return Result;
26}
BOOLEAN NTAPI KdPortGetByteEx(PCPPORT PortInformation, PUCHAR ByteReceived)
CPPORT SerialPortInfo
Definition: kdio.c:32
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by KdbpCliMainLoop(), KdbpPagerInternal(), and KdbpReadCommand().

◆ KdbRegisterCliCallback()

BOOLEAN NTAPI KdbRegisterCliCallback ( PVOID  Callback,
BOOLEAN  Deregister 
)

Definition at line 3428 of file kdb_cli.c.

3431{
3432 ULONG i;
3433
3434 /* Loop all entries */
3435 for (i = 0; i < _countof(KdbCliCallbacks); i++)
3436 {
3437 /* Check if deregistering was requested */
3438 if (Deregister)
3439 {
3440 /* Check if this entry is the one that was registered */
3441 if (KdbCliCallbacks[i] == Callback)
3442 {
3443 /* Delete it and report success */
3445 return TRUE;
3446 }
3447 }
3448 else
3449 {
3450 /* Check if this entry is free */
3451 if (KdbCliCallbacks[i] == NULL)
3452 {
3453 /* Set it and and report success */
3455 return TRUE;
3456 }
3457 }
3458 }
3459
3460 /* Unsuccessful */
3461 return FALSE;
3462}
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:139
#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 344 of file kdb_symbols.c.

346{
347#if 1 // FIXME: This is a workaround HACK!!
348 static BOOLEAN OrigLoadSymbols = FALSE;
349#endif
350
351 DPRINT("KdbSymInit() BootPhase=%d\n", BootPhase);
352
353 if (BootPhase == 0)
354 {
355 PSTR CommandLine;
356 SHORT Found = FALSE;
357 CHAR YesNo;
358
359 /* By default, load symbols in DBG builds, but not in REL builds */
360#if DBG
362#else
364#endif
365
366 /* Check the command line for LOADSYMBOLS, NOLOADSYMBOLS,
367 * LOADSYMBOLS={YES|NO}, NOLOADSYMBOLS={YES|NO} */
369 CommandLine = KeLoaderBlock->LoadOptions;
370 while (*CommandLine)
371 {
372 /* Skip any whitespace */
373 while (isspace(*CommandLine))
374 ++CommandLine;
375
376 Found = 0;
377 if (_strnicmp(CommandLine, "LOADSYMBOLS", 11) == 0)
378 {
379 Found = +1;
380 CommandLine += 11;
381 }
382 else if (_strnicmp(CommandLine, "NOLOADSYMBOLS", 13) == 0)
383 {
384 Found = -1;
385 CommandLine += 13;
386 }
387 if (Found != 0)
388 {
389 if (*CommandLine == '=')
390 {
391 ++CommandLine;
392 YesNo = toupper(*CommandLine);
393 if (YesNo == 'N' || YesNo == '0')
394 {
395 Found = -1 * Found;
396 }
397 }
398 LoadSymbols = (0 < Found);
399 }
400
401 /* Move on to the next option */
402 while (*CommandLine && !isspace(*CommandLine))
403 ++CommandLine;
404 }
405
406#if 1 // FIXME: This is a workaround HACK!!
407// Save the actual value of LoadSymbols but disable it for BootPhase 0.
408 OrigLoadSymbols = LoadSymbols;
410 return OrigLoadSymbols;
411#endif
412 }
413 else if (BootPhase == 1)
414 {
418 PLIST_ENTRY ListEntry;
419
420#if 1 // FIXME: This is a workaround HACK!!
421// Now, restore the actual value of LoadSymbols.
422 LoadSymbols = OrigLoadSymbols;
423#endif
424
425 /* Do not continue loading symbols if we have less than 96MB of RAM */
426 if (MmNumberOfPhysicalPages < (96 * 1024 * 1024 / PAGE_SIZE))
428
429 /* Continue this phase only if we need to load symbols */
430 if (!LoadSymbols)
431 return LoadSymbols;
432
433 /* Launch our worker thread */
437
440 NULL, NULL, NULL,
442 NULL);
443 if (!NT_SUCCESS(Status))
444 {
445 DPRINT1("Failed starting symbols loader thread: 0x%08x\n", Status);
447 return LoadSymbols;
448 }
449
451
453
454 for (ListEntry = PsLoadedModuleList.Flink;
455 ListEntry != &PsLoadedModuleList;
456 ListEntry = ListEntry->Flink)
457 {
458 PLDR_DATA_TABLE_ENTRY LdrEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
459 KdbSymProcessSymbols(LdrEntry, TRUE);
460 }
461
463 }
464
465 return LoadSymbols;
466}
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:31
VOID KdbSymProcessSymbols(_Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry, _In_ BOOLEAN Load)
Load symbols from image mapping. If this fails,.
Definition: kdb_symbols.c:298
static KEVENT SymbolsToLoadEvent
Definition: kdb_symbols.c:32
static KSTART_ROUTINE LoadSymbolsRoutine
Definition: kdb_symbols.c:196
static LIST_ENTRY SymbolsToLoad
Definition: kdb_symbols.c:30
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
#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:792

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

151{
152 PLDR_DATA_TABLE_ENTRY LdrEntry;
153 ULONG_PTR RelativeAddress;
154 BOOLEAN Printed = FALSE;
155 CHAR ModuleNameAnsi[64];
156
157 if (!KdbpSymFindModule(Address, -1, &LdrEntry))
158 return FALSE;
159
160 RelativeAddress = (ULONG_PTR)Address - (ULONG_PTR)LdrEntry->DllBase;
161
163 ModuleNameAnsi,
164 sizeof(ModuleNameAnsi));
165
166 if (LdrEntry->PatchInformation)
167 {
169 CHAR FileName[256];
170 CHAR FunctionName[256];
171
173 {
174 STRING str;
175 /* Use KdpPrintString because KdpDprintf is limited wrt string size */
176 KdpDprintf("<%s:%x (", ModuleNameAnsi, RelativeAddress);
177 str.Buffer = FileName;
178 str.Length = (USHORT)strnlen(FileName, sizeof(FileName));
179 str.MaximumLength = sizeof(FileName);
181 KdpDprintf(":%d (%s))>", LineNumber, FunctionName);
182
183 Printed = TRUE;
184 }
185 }
186
187 if (!Printed)
188 {
189 /* Just print module & address */
190 KdpDprintf("<%s:%x>", ModuleNameAnsi, RelativeAddress);
191 }
192
193 return TRUE;
194}
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
std::wstring STRING
Definition: fontsub.cpp:33
BOOLEAN NTAPI KdpPrintString(_In_ PSTRING Output)
Definition: kdprint.c:109
BOOLEAN KdbpSymFindModule(IN PVOID Address OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
Find a module...
Definition: kdb_symbols.c:75
static PCHAR NTAPI KdbpSymUnicodeToAnsi(IN PUNICODE_STRING Unicode, OUT PCHAR Ansi, IN ULONG Length)
Definition: kdb_symbols.c:114
unsigned short USHORT
Definition: pedump.c:61
BOOLEAN RosSymGetAddressInformation(PROSSYM_INFO RosSymInfo, ULONG_PTR RelativeAddress, ULONG *LineNumber, char *FileName, char *FunctionName)
Definition: find.c:94
const WCHAR * str
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 298 of file kdb_symbols.c.

301{
302 if (!LoadSymbols)
303 return;
304
305 /* Check if this is unload */
306 if (!Load)
307 {
308 /* Did we process it */
309 if (LdrEntry->PatchInformation)
310 {
311 RosSymDelete(LdrEntry->PatchInformation);
312 LdrEntry->PatchInformation = NULL;
313 }
314 return;
315 }
316
317 if (RosSymCreateFromMem(LdrEntry->DllBase, LdrEntry->SizeOfImage, (PROSSYM_INFO*)&LdrEntry->PatchInformation))
318 {
319 return;
320 }
321
322 /* Add a ref until we really process it */
323 LdrEntry->LoadCount++;
324
325 /* Tell our worker thread to read from it */
327 InsertTailList(&SymbolsToLoad, &LdrEntry->InInitializationOrderLinks);
329
331}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
VOID RosSymDelete(PROSSYM_INFO RosSymInfo)
Definition: delete.c:16
BOOLEAN RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
Definition: frommem.c:20
#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 56 of file kdb.c.

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

◆ KdbCurrentTrapFrame

◆ KdbDebugState

ULONG KdbDebugState
extern

◆ KdbInitFileBuffer

PCHAR KdbInitFileBuffer
extern

Definition at line 150 of file kdb_cli.c.

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

◆ KdbLastBreakPointNr

LONG KdbLastBreakPointNr
extern

Definition at line 49 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdBreakPointList().

◆ KdbNumSingleSteps

ULONG KdbNumSingleSteps
extern

Definition at line 50 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().

◆ KdbSingleStepOver

BOOLEAN KdbSingleStepOver
extern

Definition at line 51 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().