ReactOS  0.4.15-dev-5487-ge7bbbf0
kdb.h File Reference
#include "internal/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))
 
BOOLEAN NTAPI KdbRegisterCliCallback (PVOID Callback, BOOLEAN Deregister)
 
VOID KdbpCliInit (VOID)
 Called when KDB is initialized. More...
 
VOID KdbpCliMainLoop (IN BOOLEAN EnteredOnSingleStep)
 KDB Main Loop. More...
 
VOID KdbpCliInterpretInitFile (VOID)
 This function is called by KdbEnterDebuggerException... More...
 
VOID KdbpPager (_In_ PCHAR Buffer, _In_ ULONG BufLength)
 Prints the given string with, page by page. More...
 
VOID KdbpPrint (_In_ PSTR Format, _In_ ...)
 Prints the given string with printf-like formatting. More...
 
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. More...
 
PVOID KdbpRpnParseExpression (IN PCHAR Expression, OUT PLONG ErrOffset OPTIONAL, OUT PCHAR ErrMsg OPTIONAL)
 Parses the given expression and returns a "handle" to it. More...
 
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. More...
 
BOOLEAN KdbpSymFindModule (IN PVOID Address OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
 Find a module... More...
 
BOOLEAN KdbSymPrintAddress (IN PVOID Address, IN PCONTEXT Context)
 Print address... More...
 
VOID KdbSymProcessSymbols (_Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry, _In_ BOOLEAN Load)
 Load symbols from image mapping. If this fails,. More...
 
LONG KdbpGetNextBreakPointNr (IN ULONG Start OPTIONAL)
 Gets the number of the next breakpoint >= Start. More...
 
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. More...
 
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. More...
 
BOOLEAN KdbpDeleteBreakPoint (IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
 Deletes a breakpoint. More...
 
BOOLEAN KdbpEnableBreakPoint (IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
 Enables a breakpoint. More...
 
BOOLEAN KdbpDisableBreakPoint (IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
 Disables a breakpoint. More...
 
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. More...
 
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. More...
 
BOOLEAN KdbpAttachToThread (PVOID ThreadId)
 Switches to another thread context. More...
 
BOOLEAN KdbpAttachToProcess (PVOID ProcessId)
 Switches to another process/thread context. More...
 
VOID NTAPI KdbpGetCommandLineSettings (PCHAR p1)
 
KD_CONTINUE_TYPE KdbEnterDebuggerException (IN PEXCEPTION_RECORD64 ExceptionRecord, IN KPROCESSOR_MODE PreviousMode, IN OUT PCONTEXT Context, IN BOOLEAN FirstChance)
 
KD_CONTINUE_TYPE KdbEnterDebuggerFirstChanceException (IN OUT PKTRAP_FRAME TrapFrame)
 
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 262 of file kdb.h.

◆ KdbpGetCharSerial

#define KdbpGetCharSerial ( )    KdbpTryGetCharSerial(0)

Definition at line 266 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 {
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE

◆ _KDB_BREAKPOINT_TYPE

Enumerator
KdbBreakPointNone 
KdbBreakPointSoftware 
KdbBreakPointHardware 
KdbBreakPointTemporary 

Definition at line 9 of file kdb.h.

◆ _KDB_ENTER_CONDITION

Enumerator
KdbDoNotEnter 
KdbEnterAlways 
KdbEnterFromKmode 
KdbEnterFromUmode 

Definition at line 46 of file kdb.h.

47 {
enum _KDB_ENTER_CONDITION KDB_ENTER_CONDITION

◆ _KDB_OUTPUT_SETTINGS

Enumerator
KD_DEBUG_KDSERIAL 
KD_DEBUG_KDNOECHO 

Definition at line 55 of file kdb.h.

56 {
enum _KDB_OUTPUT_SETTINGS KDB_OUTPUT_SETTINGS

Function Documentation

◆ KbdDisableMouse()

VOID KbdDisableMouse ( VOID  )

◆ KbdEnableMouse()

VOID KbdEnableMouse ( VOID  )

◆ KdbEnterDebuggerException()

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

◆ KdbEnterDebuggerFirstChanceException()

KD_CONTINUE_TYPE KdbEnterDebuggerFirstChanceException ( IN OUT PKTRAP_FRAME  TrapFrame)

Definition at line 1627 of file kdb.c.

1629 {
1630  EXCEPTION_RECORD64 ExceptionRecord;
1631  KD_CONTINUE_TYPE Return;
1632  CONTEXT Context;
1633 
1634  /* Copy TrapFrame to Context */
1635  RtlZeroMemory(&Context, sizeof(CONTEXT));
1637 #ifdef CONTEXT_EXTENDED_REGISTERS
1638  Context.ContextFlags |= CONTEXT_EXTENDED_REGISTERS;
1639 #endif
1640  KeTrapFrameToContext(TrapFrame, NULL, &Context);
1641 
1642  /* Create ExceptionRecord (assume breakpoint) */
1643  RtlZeroMemory(&ExceptionRecord, sizeof(EXCEPTION_RECORD64));
1644  ExceptionRecord.ExceptionCode = STATUS_BREAKPOINT;
1645 
1646  /* Call real function */
1647  Return = KdbEnterDebuggerException(&ExceptionRecord,
1648  KernelMode,
1649  &Context,
1650  TRUE);
1651 
1652  /* Copy back Context to TrapFrame */
1653  KeContextToTrapFrame(&Context, NULL, TrapFrame, Context.ContextFlags, KernelMode);
1654 
1655  return Return;
1656 }
VOID NTAPI KeContextToTrapFrame(PCONTEXT Context, PKEXCEPTION_FRAME ExeptionFrame, PKTRAP_FRAME TrapFrame, ULONG ContextFlags, KPROCESSOR_MODE PreviousMode)
#define CONTEXT_CONTROL
Definition: nt_native.h:1369
#define CONTEXT_EXTENDED_REGISTERS
#define TRUE
Definition: types.h:120
#define CONTEXT_FLOATING_POINT
Definition: nt_native.h:1372
NTSTATUS ExceptionCode
Definition: rtltypes.h:190
#define CONTEXT_SEGMENTS
Definition: nt_native.h:1371
#define STATUS_BREAKPOINT
Definition: ntstatus.h:184
VOID NTAPI KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, IN OUT PCONTEXT Context)
Definition: context.c:169
#define CONTEXT_DEBUG_REGISTERS
Definition: nt_native.h:1373
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1038
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define CONTEXT_INTEGER
Definition: nt_native.h:1370
KD_CONTINUE_TYPE KdbEnterDebuggerException(IN PEXCEPTION_RECORD64 ExceptionRecord, IN KPROCESSOR_MODE PreviousMode, IN PCONTEXT Context, IN BOOLEAN FirstChance)
KDB Exception filter.
Definition: kdb.c:1265

◆ 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 {
1124  PETHREAD Thread;
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 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2709
struct _Entry Entry
Definition: kefuncs.h:629
BOOLEAN KdbpAttachToThread(PVOID ThreadId)
Switches to another thread context.
Definition: kdb.c:1039
PEPROCESS KdbCurrentProcess
Definition: kdb.c:54
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
LIST_ENTRY ThreadListHead
Definition: pstypes.h:1329
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID Cid
Definition: pstypes.h:1128
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
HANDLE UniqueThread
Definition: compat.h:826
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
Definition: typedefs.h:119
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
base of all file and directory entries
Definition: entries.h:82

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 {
1042  PETHREAD Thread = NULL;
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 */
1072  if (Thread != KdbOriginalThread)
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 */
1091  if (KdbCurrentProcess != Process)
1092  {
1093  if (KdbCurrentProcess != KdbOriginalProcess) /* detach from previously attached process */
1094  {
1096  }
1097 
1098  if (KdbOriginalProcess != Process)
1099  {
1101  }
1102 
1104  }
1105 
1107  return TRUE;
1108 }
#define TRUE
Definition: types.h:120
PETHREAD KdbOriginalThread
Definition: kdb.c:57
PEPROCESS KdbCurrentProcess
Definition: kdb.c:54
NTSTATUS NTAPI PsLookupThreadByThreadId(IN HANDLE ThreadId, OUT PETHREAD *Thread)
Definition: thread.c:643
KTHREAD Tcb
Definition: pstypes.h:1103
static VOID KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack, PKDB_KTRAP_FRAME KdbTrapFrame)
Definition: kdb.c:121
BOOLEAN NTAPI KeIsExecutingDpc(VOID)
Definition: dpc.c:947
static KDB_KTRAP_FRAME KdbThreadTrapFrame
Definition: kdb.c:60
PEPROCESS KdbOriginalProcess
Definition: kdb.c:55
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:704
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID KernelStack
Definition: ketypes.h:1615
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:58
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:756
static KAPC_STATE KdbApcState
Definition: kdb.c:61
#define NULL
Definition: types.h:112
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:59
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
PETHREAD KdbCurrentThread
Definition: kdb.c:56
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224

Referenced by KdbpAttachToProcess(), and KdbpCmdThread().

◆ KdbpCliInit()

VOID KdbpCliInit ( VOID  )

Called when KDB is initialized.

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

Definition at line 3790 of file kdb_cli.c.

3791 {
3792  NTSTATUS Status;
3796  FILE_STANDARD_INFORMATION FileStdInfo;
3797  HANDLE hFile = NULL;
3798  INT FileSize;
3799  PCHAR FileBuffer;
3800  ULONG OldEflags;
3801 
3802  /* Initialize the object attributes */
3803  RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3805  &FileName,
3807  NULL,
3808  NULL);
3809 
3810  /* Open the file */
3812  &ObjectAttributes, &Iosb, 0,
3815  if (!NT_SUCCESS(Status))
3816  {
3817  DPRINT("Could not open \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3818  return;
3819  }
3820 
3821  /* Get the size of the file */
3822  Status = ZwQueryInformationFile(hFile, &Iosb, &FileStdInfo, sizeof(FileStdInfo),
3824  if (!NT_SUCCESS(Status))
3825  {
3826  ZwClose(hFile);
3827  DPRINT("Could not query size of \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3828  return;
3829  }
3830  FileSize = FileStdInfo.EndOfFile.u.LowPart;
3831 
3832  /* Allocate memory for the file */
3833  FileBuffer = ExAllocatePool(PagedPool, FileSize + 1); /* add 1 byte for terminating '\0' */
3834  if (!FileBuffer)
3835  {
3836  ZwClose(hFile);
3837  DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize);
3838  return;
3839  }
3840 
3841  /* Load file into memory */
3842  Status = ZwReadFile(hFile, NULL, NULL, NULL, &Iosb, FileBuffer, FileSize, NULL, NULL);
3843  ZwClose(hFile);
3844 
3846  {
3847  ExFreePool(FileBuffer);
3848  DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3849  return;
3850  }
3851 
3852  FileSize = min(FileSize, (INT)Iosb.Information);
3853  FileBuffer[FileSize] = '\0';
3854 
3855  /* Enter critical section */
3856  OldEflags = __readeflags();
3857  _disable();
3858 
3859  /* Interpret the init file... */
3860  KdbInitFileBuffer = FileBuffer;
3861  //KdbEnter(); // FIXME
3863 
3864  /* Leave critical section */
3865  __writeeflags(OldEflags);
3866 
3867  ExFreePool(FileBuffer);
3868 }
struct _LARGE_INTEGER::@2253 u
signed char * PCHAR
Definition: retypes.h:7
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
int32_t INT
Definition: typedefs.h:58
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define L(x)
Definition: ntvdm.h:50
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
#define FILE_READ_DATA
Definition: nt_native.h:628
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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)
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1669
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define SYNCHRONIZE
Definition: nt_native.h:61
_In_ HANDLE hFile
Definition: mswsock.h:90
struct _FileName FileName
Definition: fatprocs.h:893
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define FileStandardInformation
Definition: propsheet.cpp:61
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
void __cdecl _disable(void)
Definition: intrin_arm.h:365
return Iosb
Definition: create.c:4402
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define DPRINT
Definition: sndvol32.h:71
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:155
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by IoInitSystem().

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

3742 {
3743  PCHAR p1, p2;
3744  INT_PTR i;
3745  CHAR c;
3746 
3747  /* Execute the commands in the init file */
3748  DPRINT("KDB: Executing KDBinit file...\n");
3749  p1 = KdbInitFileBuffer;
3750  while (p1[0] != '\0')
3751  {
3752  i = strcspn(p1, "\r\n");
3753  if (i > 0)
3754  {
3755  c = p1[i];
3756  p1[i] = '\0';
3757 
3758  /* Look for "break" command and comments */
3759  p2 = p1;
3760 
3761  while (isspace(p2[0]))
3762  p2++;
3763 
3764  if (strncmp(p2, "break", sizeof("break")-1) == 0 &&
3765  (p2[sizeof("break")-1] == '\0' || isspace(p2[sizeof("break")-1])))
3766  {
3767  /* break into the debugger */
3769  }
3770  else if (p2[0] != '#' && p2[0] != '\0') /* Ignore empty lines and comments */
3771  {
3772  KdbpDoCommand(p1);
3773  }
3774 
3775  p1[i] = c;
3776  }
3777 
3778  p1 += i;
3779  while (p1[0] == '\r' || p1[0] == '\n')
3780  p1++;
3781  }
3782  DPRINT("KDB: KDBinit executed\n");
3783 }
signed char * PCHAR
Definition: retypes.h:7
#define isspace(c)
Definition: acclib.h:69
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
char CHAR
Definition: xmlstorage.h:175
int32_t INT_PTR
Definition: typedefs.h:64
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3616
#define FALSE
Definition: types.h:117
VOID KdbpCliMainLoop(IN BOOLEAN EnteredOnSingleStep)
KDB Main Loop.
Definition: kdb_cli.c:3678
const GLubyte * c
Definition: glext.h:8905
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define c
Definition: ke_i.h:80
#define DPRINT
Definition: sndvol32.h:71
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:155

Referenced by KdbEnterDebuggerException().

◆ KdbpCliMainLoop()

VOID KdbpCliMainLoop ( IN BOOLEAN  EnteredOnSingleStep)

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3678 of file kdb_cli.c.

3680 {
3681  static CHAR Command[1024];
3682  BOOLEAN Continue;
3683 
3684  if (EnteredOnSingleStep)
3685  {
3687  {
3689  }
3690 
3691  KdbpPrint(": ");
3693  {
3694  KdbpPrint("<INVALID>");
3695  }
3696  KdbpPrint("\n");
3697  }
3698 
3699  /* Flush the input buffer */
3701  {
3702  while (KdbpTryGetCharSerial(1) != -1);
3703  }
3704  else
3705  {
3706  ULONG ScanCode;
3707  while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
3708  }
3709 
3710  /* Main loop */
3711  do
3712  {
3713  /* Reset the number of rows/cols printed */
3715 
3716  /* Print the prompt */
3717  KdbpPrint(KdbPromptString.Buffer);
3718 
3719  /* Read a command and remember it */
3720  KdbpReadCommand(Command, sizeof(Command));
3722 
3723  /* Reset the number of rows/cols printed and output aborted state */
3726 
3727  /* Call the command */
3728  Continue = KdbpDoCommand(Command);
3730  }
3731  while (Continue);
3732 }
static VOID KdbpReadCommand(OUT PCHAR Buffer, IN ULONG Size)
Reads a line of user-input.
Definition: kdb_cli.c:3344
static VOID KdbpCommandHistoryAppend(IN PCHAR Command)
Appends a command to the command history.
Definition: kdb_cli.c:3270
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PCONTEXT Context)
Print address...
Definition: kdb_symbols.c:148
ULONG KdbDebugState
Definition: kdb.c:52
UINT ScanCode
Definition: VirtualKey.c:24
char CHAR
Definition: xmlstorage.h:175
#define KeGetContextPc(Context)
Definition: ke.h:31
Definition: shell.h:41
CHAR KdbpTryGetCharSerial(ULONG Retry)
Definition: kdb_serial.c:19
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdb_keyboard.c:104
static ULONG KdbNumberOfRowsPrinted
Definition: kdb_cli.c:148
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:125
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3616
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:149
unsigned char BOOLEAN
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:58
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:150
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:140
STRING KdbPromptString
Definition: kdb_cli.c:167
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdbpCallMainLoop(), and KdbpCliInterpretInitFile().

◆ 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 }
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:28
#define TRUE
Definition: types.h:120
BOOLEAN KdbpDisableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Disables a breakpoint.
Definition: kdb.c:871
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224

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 }
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:28
#define TRUE
Definition: types.h:120
static ULONG KdbSwBreakPointCount
Definition: kdb.c:42
LONG NTSTATUS
Definition: precomp.h:26
ULONG Dr7
Definition: nt_native.h:1439
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:45
#define FALSE
Definition: types.h:117
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
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]
Definition: kdb.c:44
#define MAXULONG
Definition: typedefs.h:251
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:59
unsigned int ULONG
Definition: retypes.h:1
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
static ULONG KdbHwBreakPointCount
Definition: kdb.c:43

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 }
#define bfd_mach_i386_i386_intel_syntax
Definition: i386-dis.c:32
#define bfd_mach_i386_i386
Definition: i386-dis.c:33
static void KdbpMemoryError(int Status, uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:73
static struct _test_info info[]
Definition: SetCursorPos.c:19
static void KdbpPrintAddressInCode(uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:79
static WCHAR Address[46]
Definition: ping.c:68
int print_insn_i386(bfd_vma pc, struct disassemble_info *info)
Definition: i386-dis.c:2079
#define NULL
Definition: types.h:112
static int KdbpReadMemory(uintptr_t Addr, unsigned char *Data, unsigned int Length, struct disassemble_info *Ignored)
Definition: i386-dis.c:66
int KdbpPrintDisasm(void *Ignored, const char *fmt,...)
Definition: i386-dis.c:46

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 
760  KdbSwBreakPoints[KdbSwBreakPointCount++] = BreakPoint;
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:
824  case KdbAccessReadWrite:
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;
850  KdbHwBreakPoints[KdbHwBreakPointCount++] = BreakPoint;
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_SW_BREAKPOINT_COUNT
Definition: kdb.c:30
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:28
#define TRUE
Definition: types.h:120
static ULONG KdbSwBreakPointCount
Definition: kdb.c:42
LONG NTSTATUS
Definition: precomp.h:26
int32_t INT
Definition: typedefs.h:58
ULONG Dr7
Definition: nt_native.h:1439
ULONG Dr3
Definition: nt_native.h:1437
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:45
#define FALSE
Definition: types.h:117
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
ULONG Dr1
Definition: nt_native.h:1435
ULONG Dr2
Definition: nt_native.h:1436
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:58
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]
Definition: kdb.c:44
#define KDB_MAXIMUM_HW_BREAKPOINT_COUNT
Definition: kdb.c:29
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
ULONG Dr6
Definition: nt_native.h:1438
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:59
ULONG Dr0
Definition: nt_native.h:1434
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN Enabled
Definition: kdb.h:28
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
static ULONG KdbHwBreakPointCount
Definition: kdb.c:43

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 {
423  PKDB_BREAKPOINT bp;
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 }
BOOLEAN Global
Definition: kdb.h:30
#define TRUE
Definition: types.h:120
PCHAR ConditionExpression
Definition: kdb.h:32
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
union _KDB_BREAKPOINT::@1771 Data
UNICODE_STRING Global
Definition: symlink.c:37
#define FALSE
Definition: types.h:117
static WCHAR Address[46]
Definition: ping.c:68
ULONG_PTR Address
Definition: kdb.h:29
Type
Definition: Type.h:6
struct _KDB_BREAKPOINT::@1771::@1772 Hw
PEPROCESS Process
Definition: kdb.h:31
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
BOOLEAN Enabled
Definition: kdb.h:28
KDB_BREAKPOINT_TYPE Type
Definition: kdb.h:27

Referenced by KdbpCmdBreakPointList().

◆ KdbpGetCommandLineSettings()

VOID NTAPI KdbpGetCommandLineSettings ( PCHAR  p1)

Definition at line 1660 of file kdb.c.

1662 {
1663 #define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
1664 
1665  while (p1 && (p1 = strchr(p1, ' ')))
1666  {
1667  /* Skip other spaces */
1668  while (*p1 == ' ') ++p1;
1669 
1670  if (!_strnicmp(p1, "KDSERIAL", CONST_STR_LEN("KDSERIAL")))
1671  {
1672  p1 += CONST_STR_LEN("KDSERIAL");
1674  KdpDebugMode.Serial = TRUE;
1675  }
1676  else if (!_strnicmp(p1, "KDNOECHO", CONST_STR_LEN("KDNOECHO")))
1677  {
1678  p1 += CONST_STR_LEN("KDNOECHO");
1680  }
1681  else if (!_strnicmp(p1, "FIRSTCHANCE", CONST_STR_LEN("FIRSTCHANCE")))
1682  {
1683  p1 += CONST_STR_LEN("FIRSTCHANCE");
1685  }
1686  }
1687 }
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
ULONG KdbDebugState
Definition: kdb.c:52
#define TRUE
Definition: types.h:120
KDP_DEBUG_MODE KdpDebugMode
Definition: kdio.c:48
#define CONST_STR_LEN(x)
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
char * strchr(const char *String, int ch)
Definition: utclib.c:501

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 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static KDB_ENTER_CONDITION KdbEnterConditions[][2]
Definition: kdb.c:65
long LONG
Definition: pedump.c:60
IN ULONG IN UCHAR Condition
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12

Referenced by KdbpCmdSet().

◆ KdbpGetHexNumber()

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

Definition at line 468 of file kdb_cli.c.

471 {
472  char *endptr;
473 
474  /* Skip optional '0x' prefix */
475  if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
476  pszNum += 2;
477 
478  /* Make a number from the string (hex) */
479  *pulValue = strtoul(pszNum, &endptr, 16);
480 
481  return (*endptr == '\0');
482 }
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
107  info.mach = bfd_mach_i386_i386;
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 }
static void KdbpNopPrintAddress(uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:88
#define bfd_mach_i386_i386
Definition: i386-dis.c:33
static void KdbpMemoryError(int Status, uintptr_t Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:73
static struct _test_info info[]
Definition: SetCursorPos.c:19
static WCHAR Address[46]
Definition: ping.c:68
int print_insn_i386(bfd_vma pc, struct disassemble_info *info)
Definition: i386-dis.c:2079
#define bfd_mach_x86_64
Definition: i386-dis.c:31
#define NULL
Definition: types.h:112
static int KdbpReadMemory(uintptr_t Addr, unsigned char *Data, unsigned int Length, struct disassemble_info *Ignored)
Definition: i386-dis.c:66
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 }
Type
Definition: Type.h:6
Definition: partlist.h:33
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12

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 }
signed char * PCHAR
Definition: retypes.h:7
#define TAG_KDBG
Definition: tag.h:38
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
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:28
PEPROCESS KdbCurrentProcess
Definition: kdb.c:54
char CHAR
Definition: xmlstorage.h:175
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
UNICODE_STRING Global
Definition: symlink.c:37
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
static WCHAR Address[46]
Definition: ping.c:68
IN ULONG IN UCHAR Condition
BOOLEAN KdbpEnableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Enables a breakpoint.
Definition: kdb.c:704
#define ASSERT(a)
Definition: mode.c:44
Type
Definition: Type.h:6
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224

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

3209 {
3210  /* Call the internal function */
3211  KdbpPagerInternal(Buffer, BufLength, TRUE);
3212 }
#define TRUE
Definition: types.h:120
Definition: bufpool.h:45
VOID KdbpPagerInternal(_In_ PCHAR Buffer, _In_ ULONG BufLength, _In_ BOOLEAN DoPage)
Prints the given string with, page by page.
Definition: kdb_cli.c:2898

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

3227 {
3228  static CHAR Buffer[4096];
3229  ULONG Length;
3230  va_list ap;
3231 
3232  /* Check if the user has aborted output of the current command */
3233  if (KdbOutputAborted)
3234  return;
3235 
3236  /* Build the string */
3237  va_start(ap, Format);
3238  Length = _vsnprintf(Buffer, sizeof(Buffer) - 1, Format, ap);
3239  Buffer[Length] = '\0';
3240  va_end(ap);
3241 
3242  /* Actually print it */
3244 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
char CHAR
Definition: xmlstorage.h:175
#define va_end(ap)
Definition: acmsvcex.h:90
#define FALSE
Definition: types.h:117
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:150
VOID KdbpPagerInternal(_In_ PCHAR Buffer, _In_ ULONG BufLength, _In_ BOOLEAN DoPage)
Prints the given string with, page by page.
Definition: kdb_cli.c:2898
va_start(ap, x)
#define _vsnprintf
Definition: xmlstorage.h:202
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
unsigned int ULONG
Definition: retypes.h:1

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

3249 {
3250  ULONG i;
3251 
3252  if ((String == NULL) || (String->Buffer == NULL))
3253  {
3254  KdbpPrint("<NULL>");
3255  return;
3256  }
3257 
3258  for (i = 0; i < String->Length / sizeof(WCHAR); i++)
3259  {
3260  KdbpPrint("%c", (CHAR)String->Buffer[i]);
3261  }
3262 }
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdbpCmdMod().

◆ 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 
1111  ASSERT(Expression);
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 }
struct _RPN_STACK * PRPN_STACK
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
VOID RpnpDumpStack(IN PRPN_STACK Stack)
Dumps the given RPN stack content.
Definition: kdb_expr.c:250
#define TRUE
Definition: types.h:120
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
#define FALSE
Definition: types.h:117
_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
#define ASSERT(a)
Definition: mode.c:44
static struct @1775 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
#define NULL
Definition: types.h:112
static VOID RpnpClearStack(OUT PRPN_STACK Stack)
Clears the given RPN stack.
Definition: kdb_expr.c:325

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 
1205  ASSERT(Expression);
1206  ASSERT(TrapFrame);
1207  ASSERT(Result);
1208 
1209  /* Evaluate the stack */
1210  return RpnpEvaluateStack(Stack, TrapFrame, Result, ErrOffset, ErrMsg);
1211 }
struct _RPN_STACK * PRPN_STACK
PCWSTR Expression
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
_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
#define ASSERT(a)
Definition: mode.c:44
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

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 
1151  ASSERT(Expression);
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 }
struct _RPN_STACK * PRPN_STACK
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
#define TAG_KDBG
Definition: tag.h:38
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
RPN_OP Ops[RPN_OP_STACK_SIZE]
Definition: kdb_expr.c:98
VOID RpnpDumpStack(IN PRPN_STACK Stack)
Dumps the given RPN stack content.
Definition: kdb_expr.c:250
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
ULONG Size
Definition: kdb_expr.c:96
struct _RPN_STACK RPN_STACK
#define ASSERT(a)
Definition: mode.c:44
static struct @1775 RpnStack
ULONG Sp
Definition: kdb_expr.c:75
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ULONG Size
Definition: kdb_expr.c:74
#define NULL
Definition: types.h:112
#define CONST_STRCPY(dst, src)
Definition: kdb_expr.c:87
static VOID RpnpClearStack(OUT PRPN_STACK Stack)
Clears the given RPN stack.
Definition: kdb_expr.c:325

Referenced by KdbpInsertBreakPoint().

◆ KdbpSafeReadMemory()

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

Definition at line 1690 of file kdb.c.

1694 {
1695  return KdpCopyMemoryChunks((ULONG64)(ULONG_PTR)Src,
1696  Dest,
1697  Bytes,
1698  0,
1700  NULL);
1701 }
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
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned __int64 ULONG64
Definition: imports.h:198
#define MMDBG_COPY_UNSAFE
Definition: mm.h:77
#define NULL
Definition: types.h:112

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

1708 {
1709  return KdpCopyMemoryChunks((ULONG64)(ULONG_PTR)Dest,
1710  Src,
1711  Bytes,
1712  0,
1714  NULL);
1715 }
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
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define MMDBG_COPY_WRITE
Definition: mm.h:75
unsigned __int64 ULONG64
Definition: imports.h:198
#define MMDBG_COPY_UNSAFE
Definition: mm.h:77
#define NULL
Definition: types.h:112

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 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static KDB_ENTER_CONDITION KdbEnterConditions[][2]
Definition: kdb.c:65
long LONG
Definition: pedump.c:60
IN ULONG IN UCHAR Condition
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12

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;
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. */
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 }
#define TRUE
Definition: types.h:120
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:198
KSPIN_LOCK PsLoadedModuleSpinLock
Definition: sysldr.c:23
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
int Count
Definition: noreturn.cpp:7
ULONG CurrentProcess
Definition: shell.c:125
_In_ WDFCOLLECTION _In_ ULONG Index
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:21
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:221
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

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

◆ KdbpTryGetCharKeyboard()

CHAR KdbpTryGetCharKeyboard ( PULONG  ScanCode,
ULONG  Retry 
)

Definition at line 104 of file kdb_keyboard.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 }
#define shift
Definition: input.c:1756
UINT ScanCode
Definition: VirtualKey.c:24
unsigned char BOOLEAN
static unsigned char keyb_layout[2][128]
Definition: kdb_keyboard.c:38
#define KBD_STAT_OBF
Definition: kdb_keyboard.c:22
#define kbd_read_input()
Definition: kdb_keyboard.c:35
const GLubyte * c
Definition: glext.h:8905
#define kbd_read_status()
Definition: kdb_keyboard.c:36
_In_ PSCSI_REQUEST_BLOCK _Out_ NTSTATUS _Inout_ BOOLEAN * Retry
Definition: classpnp.h:310
UCHAR byte_t
Definition: kdb_keyboard.c:57
#define c
Definition: ke_i.h:80

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

◆ KdbpTryGetCharSerial()

CHAR KdbpTryGetCharSerial ( ULONG  Retry)

Definition at line 19 of file kdb_serial.c.

20 {
21  CHAR Result = -1;
22 
23  if (Retry == 0)
25  else
26  while (!KdPortGetByteEx(&SerialPortInfo, (PUCHAR)&Result) && Retry-- > 0);
27 
28  return Result;
29 }
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
_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
BOOLEAN NTAPI KdPortGetByteEx(PCPPORT PortInformation, PUCHAR ByteReceived)
_In_ PSCSI_REQUEST_BLOCK _Out_ NTSTATUS _Inout_ BOOLEAN * Retry
Definition: classpnp.h:310
CPPORT SerialPortInfo
Definition: kdio.c:34

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

◆ KdbRegisterCliCallback()

BOOLEAN NTAPI KdbRegisterCliCallback ( PVOID  Callback,
BOOLEAN  Deregister 
)

Definition at line 3535 of file kdb_cli.c.

3538 {
3539  ULONG i;
3540 
3541  /* Loop all entries */
3542  for (i = 0; i < _countof(KdbCliCallbacks); i++)
3543  {
3544  /* Check if deregistering was requested */
3545  if (Deregister)
3546  {
3547  /* Check if this entry is the one that was registered */
3548  if (KdbCliCallbacks[i] == Callback)
3549  {
3550  /* Delete it and report success */
3551  KdbCliCallbacks[i] = NULL;
3552  return TRUE;
3553  }
3554  }
3555  else
3556  {
3557  /* Check if this entry is free */
3558  if (KdbCliCallbacks[i] == NULL)
3559  {
3560  /* Set it and and report success */
3562  return TRUE;
3563  }
3564  }
3565  }
3566 
3567  /* Unsuccessful */
3568  return FALSE;
3569 }
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:139
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define _countof(array)
Definition: sndvol32.h:68
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdSystemDebugControl().

◆ 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 }
BOOLEAN NTAPI KdpPrintString(_In_ PSTRING Output)
Definition: kdprint.c:109
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
uint32_t ULONG_PTR
Definition: typedefs.h:65
PVOID DllBase
Definition: btrfs_drv.h:1880
#define FALSE
Definition: types.h:117
const WCHAR * str
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
BOOLEAN RosSymGetAddressInformation(PROSSYM_INFO RosSymInfo, ULONG_PTR RelativeAddress, ULONG *LineNumber, char *FileName, char *FunctionName)
Definition: find.c:94
static PCHAR NTAPI KdbpSymUnicodeToAnsi(IN PUNICODE_STRING Unicode, OUT PCHAR Ansi, IN ULONG Length)
Definition: kdb_symbols.c:114
PVOID PatchInformation
Definition: ldrtypes.h:164
std::wstring STRING
Definition: fontsub.cpp:33
Definition: btrfs_drv.h:1876
BOOLEAN KdbpSymFindModule(IN PVOID Address OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
Find a module...
Definition: kdb_symbols.c:75
struct _FileName FileName
Definition: fatprocs.h:893
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
unsigned short USHORT
Definition: pedump.c:61
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1278
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define KdpDprintf(...)
Definition: mmdbg.c:19

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 }
BOOLEAN RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymInfo)
Definition: frommem.c:20
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:198
VOID RosSymDelete(PROSSYM_INFO RosSymInfo)
Definition: delete.c:16
static LIST_ENTRY SymbolsToLoad
Definition: kdb_symbols.c:30
#define InsertTailList(ListHead, Entry)
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
static KSPIN_LOCK SymbolsToLoadLock
Definition: kdb_symbols.c:31
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:221
#define NULL
Definition: types.h:112
#define IO_NO_INCREMENT
Definition: iotypes.h:598
static BOOLEAN LoadSymbols
Definition: kdb_symbols.c:29
static KEVENT SymbolsToLoadEvent
Definition: kdb_symbols.c:32

Referenced by KdbInitialize(), and KdSendPacket().

Variable Documentation

◆ KdbCurrentProcess

◆ KdbCurrentThread

PETHREAD KdbCurrentThread

Definition at line 56 of file kdb.c.

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

◆ KdbCurrentTrapFrame

◆ KdbDebugState

ULONG KdbDebugState

◆ KdbInitFileBuffer

PCHAR KdbInitFileBuffer

Definition at line 155 of file kdb_cli.c.

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

◆ KdbLastBreakPointNr

LONG KdbLastBreakPointNr

Definition at line 49 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdBreakPointList().

◆ KdbNumSingleSteps

ULONG KdbNumSingleSteps

Definition at line 50 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().

◆ KdbSingleStepOver

BOOLEAN KdbSingleStepOver

Definition at line 51 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().