ReactOS  0.4.14-dev-342-gdc047f9
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_KTRAP_FRAME
 
struct  _KDB_BREAKPOINT
 

Macros

#define TAG_KDBS   'SBDK'
 
#define TAG_KDBG   'GBDK'
 
#define KdbpGetCharKeyboard(ScanCode)   KdbpTryGetCharKeyboard(ScanCode, 0)
 
#define KdbpGetCharSerial()   KdbpTryGetCharSerial(0)
 

Typedefs

typedef struct _KDB_KTRAP_FRAME KDB_KTRAP_FRAME
 
typedef struct _KDB_KTRAP_FRAMEPKDB_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 Address, IN ULONG IntelSyntax)
 
LONG KdbpGetInstLength (IN ULONG Address)
 
VOID NTAPI KdbpStackSwitchAndCall (IN PVOID NewStack, IN VOID(*Function)(VOID))
 
VOID KdbpCliInit (VOID)
 Called when KDB is initialized. More...
 
VOID KdbpCliMainLoop (IN BOOLEAN EnteredOnSingleStep)
 KDB Main Loop. More...
 
VOID KdbpCliModuleLoaded (IN PUNICODE_STRING Name)
 Called when a module is loaded. More...
 
VOID KdbpCliInterpretInitFile (VOID)
 This function is called by KdbEnterDebuggerException... More...
 
VOID KdbpPrint (IN PCHAR Format, IN ... OPTIONAL)
 Prints the given string with printf-like formatting. More...
 
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 LPCWSTR Name OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
 Find a module... 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 (PEXCEPTION_RECORD ExceptionRecord, KPROCESSOR_MODE PreviousMode, PCONTEXT Context, PKTRAP_FRAME TrapFrame, BOOLEAN FirstChance)
 
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 KdbEnter (VOID)
 
VOID DbgRDebugInit (VOID)
 
VOID DbgShowFiles (VOID)
 
VOID DbgEnableFile (PCH Filename)
 
VOID DbgDisableFile (PCH Filename)
 
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 251 of file kdb.h.

◆ KdbpGetCharSerial

#define KdbpGetCharSerial ( )    KdbpTryGetCharSerial(0)

Definition at line 255 of file kdb.h.

◆ TAG_KDBG

#define TAG_KDBG   'GBDK'

Definition at line 8 of file kdb.h.

◆ TAG_KDBS

#define TAG_KDBS   'SBDK'

Definition at line 7 of file kdb.h.

Typedef Documentation

◆ KDB_ACCESS_TYPE

◆ KDB_BREAKPOINT

◆ KDB_BREAKPOINT_TYPE

◆ KDB_ENTER_CONDITION

◆ KDB_KTRAP_FRAME

◆ KDB_OUTPUT_SETTINGS

◆ PKDB_BREAKPOINT

◆ PKDB_KTRAP_FRAME

Enumeration Type Documentation

◆ _KDB_ACCESS_TYPE

Enumerator
KdbAccessRead 
KdbAccessWrite 
KdbAccessReadWrite 
KdbAccessExec 

Definition at line 31 of file kdb.h.

32 {
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE

◆ _KDB_BREAKPOINT_TYPE

Enumerator
KdbBreakPointNone 
KdbBreakPointSoftware 
KdbBreakPointHardware 
KdbBreakPointTemporary 

Definition at line 23 of file kdb.h.

◆ _KDB_ENTER_CONDITION

Enumerator
KdbDoNotEnter 
KdbEnterAlways 
KdbEnterFromKmode 
KdbEnterFromUmode 

Definition at line 60 of file kdb.h.

61 {
enum _KDB_ENTER_CONDITION KDB_ENTER_CONDITION

◆ _KDB_OUTPUT_SETTINGS

Enumerator
KD_DEBUG_KDSERIAL 
KD_DEBUG_KDNOECHO 

Definition at line 69 of file kdb.h.

70 {
enum _KDB_OUTPUT_SETTINGS KDB_OUTPUT_SETTINGS

Function Documentation

◆ DbgDisableFile()

VOID DbgDisableFile ( PCH  Filename)

◆ DbgEnableFile()

VOID DbgEnableFile ( PCH  Filename)

◆ DbgRDebugInit()

VOID DbgRDebugInit ( VOID  )

◆ DbgShowFiles()

VOID DbgShowFiles ( VOID  )

◆ KbdDisableMouse()

VOID KbdDisableMouse ( VOID  )

Referenced by KdbpInternalEnter(), and KdpPrompt().

◆ KbdEnableMouse()

VOID KbdEnableMouse ( VOID  )

Referenced by KdbpInternalEnter(), and KdpPrompt().

◆ KdbEnter()

VOID KdbEnter ( VOID  )

Referenced by KdbpCliInit().

◆ KdbEnterDebuggerException()

KD_CONTINUE_TYPE KdbEnterDebuggerException ( PEXCEPTION_RECORD  ExceptionRecord,
KPROCESSOR_MODE  PreviousMode,
PCONTEXT  Context,
PKTRAP_FRAME  TrapFrame,
BOOLEAN  FirstChance 
)

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

1175 {
1177  PETHREAD Thread;
1179 
1180  /* Get a pointer to the process */
1182  {
1183  KdbpPrint("Invalid process id: 0x%08x\n", (ULONG_PTR)ProcessId);
1184  return FALSE;
1185  }
1186 
1187  Entry = Process->ThreadListHead.Flink;
1190  {
1191  KdbpPrint("No threads in process 0x%p, cannot attach to process!\n", ProcessId);
1192  return FALSE;
1193  }
1194 
1195  Thread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
1196 
1198 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
struct _Entry Entry
Definition: kefuncs.h:640
BOOLEAN KdbpAttachToThread(PVOID ThreadId)
Switches to another thread context.
Definition: kdb.c:1092
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY ThreadListHead
Definition: pstypes.h:1260
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:1059
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2615
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
HANDLE UniqueThread
Definition: compat.h:483
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
Definition: typedefs.h:117
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
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 1092 of file kdb.c.

1094 {
1095  PETHREAD Thread = NULL;
1097 
1098  /* Get a pointer to the thread */
1099  if (!NT_SUCCESS(PsLookupThreadByThreadId(ThreadId, &Thread)))
1100  {
1101  KdbpPrint("Invalid thread id: 0x%08x\n", (ULONG_PTR)ThreadId);
1102  return FALSE;
1103  }
1104  Process = Thread->ThreadsProcess;
1105 
1107  {
1108  KdbpPrint("Cannot attach to thread within another process while executing a DPC.\n");
1110  return FALSE;
1111  }
1112 
1113  /* Save the current thread's context (if we previously attached to a thread) */
1115  {
1117  /* Actually, we can't save the context, there's no guarantee that there was a trap frame */
1118  }
1119  else
1120  {
1122  }
1123 
1124  /* Switch to the thread's context */
1125  if (Thread != KdbOriginalThread)
1126  {
1127  /* The thread we're attaching to isn't the thread on which we entered
1128  * kdb and so the thread we're attaching to is not running. There
1129  * is no guarantee that it actually has a trap frame. So we have to
1130  * peek directly at the registers which were saved on the stack when the
1131  * thread was preempted in the scheduler */
1135  }
1136  else /* Switching back to original thread */
1137  {
1139  }
1141 
1142  /* Attach to the thread's process */
1144  if (KdbCurrentProcess != Process)
1145  {
1146  if (KdbCurrentProcess != KdbOriginalProcess) /* detach from previously attached process */
1147  {
1149  }
1150 
1151  if (KdbOriginalProcess != Process)
1152  {
1154  }
1155 
1157  }
1158 
1160  return TRUE;
1161 }
#define TRUE
Definition: types.h:120
PETHREAD KdbOriginalThread
Definition: kdb.c:50
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
NTSTATUS NTAPI PsLookupThreadByThreadId(IN HANDLE ThreadId, OUT PETHREAD *Thread)
Definition: thread.c:643
KTHREAD Tcb
Definition: pstypes.h:1034
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
static VOID KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack, PKDB_KTRAP_FRAME KdbTrapFrame)
Definition: kdb.c:174
BOOLEAN NTAPI KeIsExecutingDpc(VOID)
Definition: dpc.c:946
static KDB_KTRAP_FRAME KdbThreadTrapFrame
Definition: kdb.c:53
PEPROCESS KdbOriginalProcess
Definition: kdb.c:48
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
#define PsGetCurrentProcess
Definition: psfuncs.h:17
smooth NULL
Definition: ftsmooth.c:416
PVOID KernelStack
Definition: ketypes.h:1565
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2615
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
static KAPC_STATE KdbApcState
Definition: kdb.c:54
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:52
_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:49

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

3733 {
3734  NTSTATUS Status;
3738  FILE_STANDARD_INFORMATION FileStdInfo;
3739  HANDLE hFile = NULL;
3740  INT FileSize;
3741  PCHAR FileBuffer;
3742  ULONG OldEflags;
3743 
3744  /* Initialize the object attributes */
3745  RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3747 
3748  /* Open the file */
3750  &ObjectAttributes, &Iosb, 0,
3753  if (!NT_SUCCESS(Status))
3754  {
3755  DPRINT("Could not open \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3756  return;
3757  }
3758 
3759  /* Get the size of the file */
3760  Status = ZwQueryInformationFile(hFile, &Iosb, &FileStdInfo, sizeof (FileStdInfo),
3762  if (!NT_SUCCESS(Status))
3763  {
3764  ZwClose(hFile);
3765  DPRINT("Could not query size of \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3766  return;
3767  }
3768  FileSize = FileStdInfo.EndOfFile.u.LowPart;
3769 
3770  /* Allocate memory for the file */
3771  FileBuffer = ExAllocatePool(PagedPool, FileSize + 1); /* add 1 byte for terminating '\0' */
3772  if (!FileBuffer)
3773  {
3774  ZwClose(hFile);
3775  DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize);
3776  return;
3777  }
3778 
3779  /* Load file into memory */
3780  Status = ZwReadFile(hFile, NULL, NULL, NULL, &Iosb, FileBuffer, FileSize, NULL, NULL);
3781  ZwClose(hFile);
3782 
3784  {
3785  ExFreePool(FileBuffer);
3786  DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3787  return;
3788  }
3789 
3790  FileSize = min(FileSize, (INT)Iosb.Information);
3791  FileBuffer[FileSize] = '\0';
3792 
3793  /* Enter critical section */
3794  OldEflags = __readeflags();
3795  _disable();
3796 
3797  /* Interpret the init file... */
3798  KdbInitFileBuffer = FileBuffer;
3799  KdbEnter();
3801 
3802  /* Leave critical section */
3803  __writeeflags(OldEflags);
3804 
3805  ExFreePool(FileBuffer);
3806 }
signed char * PCHAR
Definition: retypes.h:7
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
VOID KdbEnter(VOID)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
int32_t INT
Definition: typedefs.h:56
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _LARGE_INTEGER::@2219 u
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)
static const WCHAR L[]
Definition: oid.c:1250
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1550
#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
Status
Definition: gdiplustypes.h:24
struct _FileName FileName
Definition: fatprocs.h:884
#define min(a, b)
Definition: monoChain.cc:55
#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
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
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:124
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

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

3684 {
3685  PCHAR p1, p2;
3686  INT i;
3687  CHAR c;
3688 
3689  /* Execute the commands in the init file */
3690  DPRINT("KDB: Executing KDBinit file...\n");
3691  p1 = KdbInitFileBuffer;
3692  while (p1[0] != '\0')
3693  {
3694  i = strcspn(p1, "\r\n");
3695  if (i > 0)
3696  {
3697  c = p1[i];
3698  p1[i] = '\0';
3699 
3700  /* Look for "break" command and comments */
3701  p2 = p1;
3702 
3703  while (isspace(p2[0]))
3704  p2++;
3705 
3706  if (strncmp(p2, "break", sizeof("break")-1) == 0 &&
3707  (p2[sizeof("break")-1] == '\0' || isspace(p2[sizeof("break")-1])))
3708  {
3709  /* break into the debugger */
3711  }
3712  else if (p2[0] != '#' && p2[0] != '\0') /* Ignore empty lines and comments */
3713  {
3714  KdbpDoCommand(p1);
3715  }
3716 
3717  p1[i] = c;
3718  }
3719 
3720  p1 += i;
3721  while (p1[0] == '\r' || p1[0] == '\n')
3722  p1++;
3723  }
3724  DPRINT("KDB: KDBinit executed\n");
3725 }
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
Definition: typedefs.h:56
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3543
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void DPRINT(...)
Definition: polytest.cpp:61
VOID KdbpCliMainLoop(IN BOOLEAN EnteredOnSingleStep)
KDB Main Loop.
Definition: kdb_cli.c:3605
const GLubyte * c
Definition: glext.h:8905
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define c
Definition: ke_i.h:80
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:124

Referenced by KdbEnterDebuggerException().

◆ KdbpCliMainLoop()

VOID KdbpCliMainLoop ( IN BOOLEAN  EnteredOnSingleStep)

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3605 of file kdb_cli.c.

3607 {
3608  static CHAR Command[1024];
3609  BOOLEAN Continue;
3610 
3611  if (EnteredOnSingleStep)
3612  {
3614  {
3615  KdbpPrint("<%08x>", KdbCurrentTrapFrame->Tf.Eip);
3616  }
3617 
3618  KdbpPrint(": ");
3620  {
3621  KdbpPrint("<INVALID>");
3622  }
3623  KdbpPrint("\n");
3624  }
3625 
3626  /* Flush the input buffer */
3628  {
3629  while (KdbpTryGetCharSerial(1) != -1);
3630  }
3631  else
3632  {
3633  ULONG ScanCode;
3634  while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
3635  }
3636 
3637  /* Main loop */
3638  do
3639  {
3640  /* Reset the number of rows/cols printed */
3642 
3643  /* Print the prompt */
3644  KdbpPrint("kdb:> ");
3645 
3646  /* Read a command and remember it */
3647  KdbpReadCommand(Command, sizeof (Command));
3649 
3650  /* Reset the number of rows/cols printed and output aborted state */
3653 
3654  /* Call the command */
3657  }
3658  while (Continue);
3659 }
static VOID KdbpReadCommand(OUT PCHAR Buffer, IN ULONG Size)
Reads a line of user-input.
Definition: kdb_cli.c:3271
static VOID KdbpCommandHistoryAppend(IN PCHAR Command)
Appends a command to the command history.
Definition: kdb_cli.c:3197
ULONG ScanCode
Definition: api.c:39
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PKTRAP_FRAME Context)
Print address...
Definition: kdb_symbols.c:148
ULONG KdbDebugState
Definition: kdb.c:45
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2615
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:117
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3543
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:118
unsigned char BOOLEAN
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:119
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:109
volatile int Continue
Definition: gdblib.c:102
ULONG Eip
Definition: ketypes.h:267
KTRAP_FRAME Tf
Definition: kdb.h:15
unsigned int ULONG
Definition: retypes.h:1
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:123

Referenced by KdbpCallMainLoop(), and KdbpCliInterpretInitFile().

◆ KdbpCliModuleLoaded()

VOID KdbpCliModuleLoaded ( IN PUNICODE_STRING  Name)

Called when a module is loaded.

Parameters
NameFilename of the module which was loaded.

Definition at line 3666 of file kdb_cli.c.

3668 {
3669  if (!KdbBreakOnModuleLoad)
3670  return;
3671 
3672  KdbpPrint("Module %wZ loaded.\n", Name);
3674 }
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2615
static BOOLEAN KdbBreakOnModuleLoad
Definition: kdb_cli.c:110
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)

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

657 {
658  if (BreakPointNr < 0)
659  {
660  ASSERT(BreakPoint);
661  BreakPointNr = BreakPoint - KdbBreakPoints;
662  }
663 
664  if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
665  {
666  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
667  return FALSE;
668  }
669 
670  if (!BreakPoint)
671  {
672  BreakPoint = KdbBreakPoints + BreakPointNr;
673  }
674 
675  if (BreakPoint->Type == KdbBreakPointNone)
676  {
677  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
678  return FALSE;
679  }
680 
681  if (BreakPoint->Enabled && !KdbpDisableBreakPoint(-1, BreakPoint))
682  return FALSE;
683 
684  if (BreakPoint->Type != KdbBreakPointTemporary)
685  KdbpPrint("Breakpoint %d deleted.\n", BreakPointNr);
686 
687  BreakPoint->Type = KdbBreakPointNone;
689 
690  return TRUE;
691 }
#define TRUE
Definition: types.h:120
static ULONG KdbBreakPointCount
Definition: kdb.c:33
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:21
BOOLEAN KdbpDisableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Disables a breakpoint.
Definition: kdb.c:924
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2615
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34

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

927 {
928  ULONG i;
930 
931  if (BreakPointNr < 0)
932  {
933  ASSERT(BreakPoint);
934  BreakPointNr = BreakPoint - KdbBreakPoints;
935  }
936 
937  if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
938  {
939  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
940  return FALSE;
941  }
942 
943  if (!BreakPoint)
944  {
945  BreakPoint = KdbBreakPoints + BreakPointNr;
946  }
947 
948  if (BreakPoint->Type == KdbBreakPointNone)
949  {
950  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
951  return FALSE;
952  }
953 
954  if (BreakPoint->Enabled == FALSE)
955  {
956  KdbpPrint("Breakpoint %d is not enabled.\n", BreakPointNr);
957  return TRUE;
958  }
959 
960  if (BreakPoint->Type == KdbBreakPointSoftware ||
961  BreakPoint->Type == KdbBreakPointTemporary)
962  {
964  Status = KdbpOverwriteInstruction(BreakPoint->Process, BreakPoint->Address,
965  BreakPoint->Data.SavedInstruction, NULL);
966 
967  if (!NT_SUCCESS(Status))
968  {
969  KdbpPrint("Couldn't restore original instruction.\n");
970  return FALSE;
971  }
972 
973  for (i = 0; i < KdbSwBreakPointCount; i++)
974  {
975  if (KdbSwBreakPoints[i] == BreakPoint)
976  {
978  i = -1; /* if the last breakpoint is disabled dont break with i >= KdbSwBreakPointCount */
979  break;
980  }
981  }
982 
983  if (i != MAXULONG) /* not found */
984  ASSERT(0);
985  }
986  else
987  {
988  ASSERT(BreakPoint->Type == KdbBreakPointHardware);
989 
990  /* Clear the breakpoint. */
991  KdbTrapFrame.Tf.Dr7 &= ~(0x3 << (BreakPoint->Data.Hw.DebugReg * 2));
992  if ((KdbTrapFrame.Tf.Dr7 & 0xFF) == 0)
993  {
994  /* If no breakpoints are enabled then clear the exact match flags. */
995  KdbTrapFrame.Tf.Dr7 &= 0xFFFFFCFF;
996  }
997 
998  for (i = 0; i < KdbHwBreakPointCount; i++)
999  {
1000  if (KdbHwBreakPoints[i] == BreakPoint)
1001  {
1003  i = -1; /* if the last breakpoint is disabled dont break with i >= KdbHwBreakPointCount */
1004  break;
1005  }
1006  }
1007 
1008  if (i != MAXULONG) /* not found */
1009  ASSERT(0);
1010  }
1011 
1012  BreakPoint->Enabled = FALSE;
1013  if (BreakPoint->Type != KdbBreakPointTemporary)
1014  KdbpPrint("Breakpoint %d disabled.\n", BreakPointNr);
1015 
1016  return TRUE;
1017 }
#define TRUE
Definition: types.h:120
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:21
static ULONG KdbSwBreakPointCount
Definition: kdb.c:35
LONG NTSTATUS
Definition: precomp.h:26
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:38
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 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:210
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]
Definition: kdb.c:37
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2615
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define MAXULONG
Definition: typedefs.h:250
KTRAP_FRAME Tf
Definition: kdb.h:15
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:52
unsigned int ULONG
Definition: retypes.h:1
UINT64 Dr7
Definition: ketypes.h:347
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
static ULONG KdbHwBreakPointCount
Definition: kdb.c:36

Referenced by KdbpCmdEnableDisableClearBreakPoint(), and KdbpDeleteBreakPoint().

◆ KdbpDisassemble()

LONG KdbpDisassemble ( IN ULONG  Address,
IN ULONG  IntelSyntax 
)

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

124 {
126 
127  info.fprintf_func = KdbpPrintDisasm;
128  info.stream = NULL;
129  info.application_data = NULL;
131  info.arch = bfd_arch_i386;
133  info.insn_sets = 0;
134  info.flags = 0;
135  info.read_memory_func = KdbpReadMemory;
136  info.memory_error_func = KdbpMemoryError;
137  info.print_address_func = KdbpPrintAddressInCode;
138  info.symbol_at_address_func = NULL;
139  info.buffer = NULL;
140  info.buffer_vma = info.buffer_length = 0;
141  info.bytes_per_chunk = 0;
142  info.display_endian = BIG_ENDIAN_LITTLE;
143  info.disassembler_options = NULL;
144 
145  return(print_insn_i386(Address, &info));
146 }
int KdbpPrintDisasm(void *Ignored, const char *fmt,...)
Definition: i386-dis.c:48
struct _test_info info[]
Definition: SetCursorPos.c:19
#define bfd_mach_i386_i386
Definition: i386-dis.c:33
static void KdbpPrintAddressInCode(ULONG_PTR Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:81
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
static int KdbpReadMemory(ULONG_PTR Addr, unsigned char *Data, unsigned int Length, struct disassemble_info *Ignored)
Definition: i386-dis.c:68
#define bfd_mach_i386_i386_intel_syntax
Definition: i386-dis.c:32
int print_insn_i386(bfd_vma pc, struct disassemble_info *info)
Definition: i386-dis.c:2016
static void KdbpMemoryError(int Status, ULONG_PTR Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:75

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

760 {
762  INT i;
763  ULONG ul;
764 
765  if (BreakPointNr < 0)
766  {
767  ASSERT(BreakPoint);
768  BreakPointNr = BreakPoint - KdbBreakPoints;
769  }
770 
771  if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
772  {
773  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
774  return FALSE;
775  }
776 
777  if (!BreakPoint)
778  {
779  BreakPoint = KdbBreakPoints + BreakPointNr;
780  }
781 
782  if (BreakPoint->Type == KdbBreakPointNone)
783  {
784  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
785  return FALSE;
786  }
787 
788  if (BreakPoint->Enabled)
789  {
790  KdbpPrint("Breakpoint %d is already enabled.\n", BreakPointNr);
791  return TRUE;
792  }
793 
794  if (BreakPoint->Type == KdbBreakPointSoftware ||
795  BreakPoint->Type == KdbBreakPointTemporary)
796  {
798  {
799  KdbpPrint("Maximum number of SW breakpoints (%d) used. "
800  "Disable another breakpoint in order to enable this one.\n",
802  return FALSE;
803  }
804 
805  Status = KdbpOverwriteInstruction(BreakPoint->Process, BreakPoint->Address,
806  0xCC, &BreakPoint->Data.SavedInstruction);
807  if (!NT_SUCCESS(Status))
808  {
809  KdbpPrint("Couldn't access memory at 0x%p\n", BreakPoint->Address);
810  return FALSE;
811  }
812 
813  KdbSwBreakPoints[KdbSwBreakPointCount++] = BreakPoint;
814  }
815  else
816  {
817  if (BreakPoint->Data.Hw.AccessType == KdbAccessExec)
818  ASSERT(BreakPoint->Data.Hw.Size == 1);
819 
820  ASSERT((BreakPoint->Address % BreakPoint->Data.Hw.Size) == 0);
821 
823  {
824  KdbpPrint("Maximum number of HW breakpoints (%d) already used. "
825  "Disable another breakpoint in order to enable this one.\n",
827 
828  return FALSE;
829  }
830 
831  /* Find unused hw breakpoint */
833  for (i = 0; i < KDB_MAXIMUM_HW_BREAKPOINT_COUNT; i++)
834  {
835  if ((KdbTrapFrame.Tf.Dr7 & (0x3 << (i * 2))) == 0)
836  break;
837  }
838 
840 
841  /* Set the breakpoint address. */
842  switch (i)
843  {
844  case 0:
845  KdbTrapFrame.Tf.Dr0 = BreakPoint->Address;
846  break;
847  case 1:
848  KdbTrapFrame.Tf.Dr1 = BreakPoint->Address;
849  break;
850  case 2:
851  KdbTrapFrame.Tf.Dr2 = BreakPoint->Address;
852  break;
853  case 3:
854  KdbTrapFrame.Tf.Dr3 = BreakPoint->Address;
855  break;
856  }
857 
858  /* Enable the global breakpoint */
859  KdbTrapFrame.Tf.Dr7 |= (0x2 << (i * 2));
860 
861  /* Enable the exact match bits. */
862  KdbTrapFrame.Tf.Dr7 |= 0x00000300;
863 
864  /* Clear existing state. */
865  KdbTrapFrame.Tf.Dr7 &= ~(0xF << (16 + (i * 4)));
866 
867  /* Set the breakpoint type. */
868  switch (BreakPoint->Data.Hw.AccessType)
869  {
870  case KdbAccessExec:
871  ul = 0;
872  break;
873  case KdbAccessWrite:
874  ul = 1;
875  break;
876  case KdbAccessRead:
877  case KdbAccessReadWrite:
878  ul = 3;
879  break;
880  default:
881  ASSERT(0);
882  return TRUE;
883  break;
884  }
885 
886  KdbTrapFrame.Tf.Dr7 |= (ul << (16 + (i * 4)));
887 
888  /* Set the breakpoint length. */
889  KdbTrapFrame.Tf.Dr7 |= ((BreakPoint->Data.Hw.Size - 1) << (18 + (i * 4)));
890 
891  /* Update KdbCurrentTrapFrame - values are taken from there by the CLI */
893  {
900  }
901 
902  BreakPoint->Data.Hw.DebugReg = i;
903  KdbHwBreakPoints[KdbHwBreakPointCount++] = BreakPoint;
904  }
905 
906  BreakPoint->Enabled = TRUE;
907  if (BreakPoint->Type != KdbBreakPointTemporary)
908  KdbpPrint("Breakpoint %d enabled.\n", BreakPointNr);
909 
910  return TRUE;
911 }
#define KDB_MAXIMUM_SW_BREAKPOINT_COUNT
Definition: kdb.c:23
#define TRUE
Definition: types.h:120
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:21
static ULONG KdbSwBreakPointCount
Definition: kdb.c:35
LONG NTSTATUS
Definition: precomp.h:26
int32_t INT
Definition: typedefs.h:56
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:38
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
UINT64 Dr2
Definition: ketypes.h:344
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:210
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]
Definition: kdb.c:37
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2615
UINT64 Dr6
Definition: ketypes.h:346
UINT64 Dr3
Definition: ketypes.h:345
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
UINT64 Dr1
Definition: ketypes.h:343
UINT64 Dr0
Definition: ketypes.h:342
#define KDB_MAXIMUM_HW_BREAKPOINT_COUNT
Definition: kdb.c:22
Status
Definition: gdiplustypes.h:24
KTRAP_FRAME Tf
Definition: kdb.h:15
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:52
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN Enabled
Definition: kdb.h:42
UINT64 Dr7
Definition: ketypes.h:347
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
static ULONG KdbHwBreakPointCount
Definition: kdb.c:36

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

475 {
476  PKDB_BREAKPOINT bp;
477 
478  if (BreakPointNr >= RTL_NUMBER_OF(KdbBreakPoints) ||
479  KdbBreakPoints[BreakPointNr].Type == KdbBreakPointNone)
480  {
481  return FALSE;
482  }
483 
484  bp = KdbBreakPoints + BreakPointNr;
485  if (Address)
486  *Address = bp->Address;
487 
488  if (Type)
489  *Type = bp->Type;
490 
491  if (bp->Type == KdbBreakPointHardware)
492  {
493  if (Size)
494  *Size = bp->Data.Hw.Size;
495 
496  if (AccessType)
497  *AccessType = bp->Data.Hw.AccessType;
498 
499  if (DebugReg && bp->Enabled)
500  *DebugReg = bp->Data.Hw.DebugReg;
501  }
502 
503  if (Enabled)
504  *Enabled = bp->Enabled;
505 
506  if (Global)
507  *Global = bp->Global;
508 
509  if (Process)
510  *Process = bp->Process;
511 
512  if (ConditionExpression)
513  *ConditionExpression = bp->ConditionExpression;
514 
515  return TRUE;
516 }
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
BOOLEAN Global
Definition: kdb.h:44
PCHAR ConditionExpression
Definition: kdb.h:46
UNICODE_STRING Global
Definition: symlink.c:37
static WCHAR Address[46]
Definition: ping.c:68
ULONG_PTR Address
Definition: kdb.h:43
union _KDB_BREAKPOINT::@1761 Data
struct _KDB_BREAKPOINT::@1761::@1762 Hw
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
PEPROCESS Process
Definition: kdb.h:45
#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:42
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
KDB_BREAKPOINT_TYPE Type
Definition: kdb.h:41

Referenced by KdbpCmdBreakPointList().

◆ KdbpGetCommandLineSettings()

VOID NTAPI KdbpGetCommandLineSettings ( PCHAR  p1)

Definition at line 1704 of file kdb.c.

1706 {
1707 #define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
1708 
1709  while (p1 && (p1 = strchr(p1, ' ')))
1710  {
1711  /* Skip other spaces */
1712  while (*p1 == ' ') ++p1;
1713 
1714  if (!_strnicmp(p1, "KDSERIAL", CONST_STR_LEN("KDSERIAL")))
1715  {
1716  p1 += CONST_STR_LEN("KDSERIAL");
1718  KdpDebugMode.Serial = TRUE;
1719  }
1720  else if (!_strnicmp(p1, "KDNOECHO", CONST_STR_LEN("KDNOECHO")))
1721  {
1722  p1 += CONST_STR_LEN("KDNOECHO");
1724  }
1725  else if (!_strnicmp(p1, "FIRSTCHANCE", CONST_STR_LEN("FIRSTCHANCE")))
1726  {
1727  p1 += CONST_STR_LEN("FIRSTCHANCE");
1729  }
1730  }
1731 }
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:1051
#define TRUE
Definition: types.h:120
KDP_DEBUG_MODE KdpDebugMode
Definition: kdinit.c:25
ULONG KdbDebugState
Definition: kdb.c:45
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
#define CONST_STR_LEN(x)
char * strchr(const char *String, int ch)
Definition: utclib.c:501

Referenced by KdInitSystem().

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

1033 {
1034  if (ExceptionNr >= (LONG)RTL_NUMBER_OF(KdbEnterConditions))
1035  return FALSE;
1036 
1037  *Condition = KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1];
1038  return TRUE;
1039 }
#define TRUE
Definition: types.h:120
static KDB_ENTER_CONDITION KdbEnterConditions[][2]
Definition: kdb.c:58
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 425 of file kdb_cli.c.

428 {
429  char *endptr;
430 
431  /* Skip optional '0x' prefix */
432  if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
433  pszNum += 2;
434 
435  /* Make a number from the string (hex) */
436  *pulValue = strtoul(pszNum, &endptr, 16);
437 
438  return (*endptr == '\0');
439 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696

◆ KdbpGetInstLength()

LONG KdbpGetInstLength ( IN ULONG  Address)

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

98 {
100 
101  info.fprintf_func = KdbpNopPrintDisasm;
102  info.stream = NULL;
103  info.application_data = NULL;
105  info.arch = bfd_arch_i386;
106  info.mach = bfd_mach_x86_64;
107  info.insn_sets = 0;
108  info.flags = 0;
109  info.read_memory_func = KdbpReadMemory;
110  info.memory_error_func = KdbpMemoryError;
111  info.print_address_func = KdbpNopPrintAddress;
112  info.symbol_at_address_func = NULL;
113  info.buffer = NULL;
114  info.buffer_vma = info.buffer_length = 0;
115  info.bytes_per_chunk = 0;
116  info.display_endian = BIG_ENDIAN_LITTLE;
117  info.disassembler_options = NULL;
118 
119  return(print_insn_i386(Address, &info));
120 }
static void KdbpNopPrintAddress(ULONG_PTR Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:90
struct _test_info info[]
Definition: SetCursorPos.c:19
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
static int KdbpReadMemory(ULONG_PTR Addr, unsigned char *Data, unsigned int Length, struct disassemble_info *Ignored)
Definition: i386-dis.c:68
#define bfd_mach_x86_64
Definition: i386-dis.c:31
int print_insn_i386(bfd_vma pc, struct disassemble_info *info)
Definition: i386-dis.c:2016
static void KdbpMemoryError(int Status, ULONG_PTR Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:75
int KdbpNopPrintDisasm(void *Ignored, const char *fmt,...)
Definition: i386-dis.c:62

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

439 {
441  {
443  return Start;
444  }
445 
446  return -1;
447 }
Type
Definition: Type.h:6
Definition: partlist.h:33
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34

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

541 {
542  LONG i;
544  PCHAR ConditionExpressionDup;
545  LONG ErrOffset;
546  CHAR ErrMsg[128];
547 
549 
551  {
552  if ((Address % Size) != 0)
553  {
554  KdbpPrint("Address (0x%p) must be aligned to a multiple of the size (%d)\n", Address, Size);
555  return STATUS_UNSUCCESSFUL;
556  }
557 
558  if (AccessType == KdbAccessExec && Size != 1)
559  {
560  KdbpPrint("Size must be 1 for execution breakpoints.\n");
561  return STATUS_UNSUCCESSFUL;
562  }
563  }
564 
566  {
567  return STATUS_UNSUCCESSFUL;
568  }
569 
570  /* Parse conditon expression string and duplicate it */
571  if (ConditionExpression)
572  {
573  Condition = KdbpRpnParseExpression(ConditionExpression, &ErrOffset, ErrMsg);
574  if (!Condition)
575  {
576  if (ErrOffset >= 0)
577  KdbpPrint("Couldn't parse expression: %s at character %d\n", ErrMsg, ErrOffset);
578  else
579  KdbpPrint("Couldn't parse expression: %s", ErrMsg);
580 
581  return STATUS_UNSUCCESSFUL;
582  }
583 
584  i = strlen(ConditionExpression) + 1;
585  ConditionExpressionDup = ExAllocatePoolWithTag(NonPagedPool, i, TAG_KDBG);
586  RtlCopyMemory(ConditionExpressionDup, ConditionExpression, i);
587  }
588  else
589  {
590  Condition = NULL;
591  ConditionExpressionDup = NULL;
592  }
593 
594  /* Find unused breakpoint */
596  {
597  for (i = RTL_NUMBER_OF(KdbBreakPoints) - 1; i >= 0; i--)
598  {
600  break;
601  }
602  }
603  else
604  {
605  for (i = 0; i < (LONG)RTL_NUMBER_OF(KdbBreakPoints); i++)
606  {
608  break;
609  }
610  }
611 
613 
614  /* Set the breakpoint */
621  KdbBreakPoints[i].ConditionExpression = ConditionExpressionDup;
623 
625  {
626  KdbBreakPoints[i].Data.Hw.Size = Size;
627  KdbBreakPoints[i].Data.Hw.AccessType = AccessType;
628  }
629 
631 
633  KdbpPrint("Breakpoint %d inserted.\n", i);
634 
635  /* Try to enable the breakpoint */
637 
638  /* Return the breakpoint number */
639  if (BreakPointNr)
640  *BreakPointNr = i;
641 
642  return STATUS_SUCCESS;
643 }
#define TAG_KDBG
Definition: kdb.h:8
signed char * PCHAR
Definition: retypes.h:7
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
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:1131
Type
Definition: Type.h:6
BOOLEAN Global
Definition: kdb.h:44
static ULONG KdbBreakPointCount
Definition: kdb.c:33
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:21
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
char CHAR
Definition: xmlstorage.h:175
PCHAR ConditionExpression
Definition: kdb.h:46
UNICODE_STRING Global
Definition: symlink.c:37
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
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
ULONG_PTR Address
Definition: kdb.h:43
PVOID Condition
Definition: kdb.h:47
IN ULONG IN UCHAR Condition
union _KDB_BREAKPOINT::@1761 Data
BOOLEAN KdbpEnableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Enables a breakpoint.
Definition: kdb.c:757
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2615
struct _KDB_BREAKPOINT::@1761::@1762 Hw
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
PEPROCESS Process
Definition: kdb.h:45
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
BOOLEAN Enabled
Definition: kdb.h:42
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
KDB_BREAKPOINT_TYPE Type
Definition: kdb.h:41

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

◆ KdbpPrint()

VOID KdbpPrint ( IN PCHAR  Format,
IN ...  OPTIONAL 
)

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

2618 {
2619  static CHAR Buffer[4096];
2620  static BOOLEAN TerminalInitialized = FALSE;
2621  static BOOLEAN TerminalConnected = FALSE;
2622  static BOOLEAN TerminalReportsSize = TRUE;
2623  CHAR c = '\0';
2624  PCHAR p, p2;
2625  ULONG Length;
2626  ULONG i, j;
2627  LONG RowsPrintedByTerminal;
2628  ULONG ScanCode;
2629  va_list ap;
2630 
2631  /* Check if the user has aborted output of the current command */
2632  if (KdbOutputAborted)
2633  return;
2634 
2635  /* Initialize the terminal */
2636  if (!TerminalInitialized)
2637  {
2638  DbgPrint("\x1b[7h"); /* Enable linewrap */
2639 
2640  /* Query terminal type */
2641  /*DbgPrint("\x1b[Z");*/
2642  DbgPrint("\x05");
2643 
2644  TerminalInitialized = TRUE;
2645  Length = 0;
2646  KeStallExecutionProcessor(100000);
2647 
2648  for (;;)
2649  {
2650  c = KdbpTryGetCharSerial(5000);
2651  if (c == -1)
2652  break;
2653 
2654  Buffer[Length++] = c;
2655  if (Length >= (sizeof (Buffer) - 1))
2656  break;
2657  }
2658 
2659  Buffer[Length] = '\0';
2660  if (Length > 0)
2661  TerminalConnected = TRUE;
2662  }
2663 
2664  /* Get number of rows and columns in terminal */
2665  if ((KdbNumberOfRowsTerminal < 0) || (KdbNumberOfColsTerminal < 0) ||
2666  (KdbNumberOfRowsPrinted) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
2667  {
2668  if ((KdbDebugState & KD_DEBUG_KDSERIAL) && TerminalConnected && TerminalReportsSize)
2669  {
2670  /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
2671  TerminalReportsSize = FALSE;
2672  KeStallExecutionProcessor(100000);
2673  DbgPrint("\x1b[18t");
2674  c = KdbpTryGetCharSerial(5000);
2675 
2676  if (c == KEY_ESC)
2677  {
2678  c = KdbpTryGetCharSerial(5000);
2679  if (c == '[')
2680  {
2681  Length = 0;
2682 
2683  for (;;)
2684  {
2685  c = KdbpTryGetCharSerial(5000);
2686  if (c == -1)
2687  break;
2688 
2689  Buffer[Length++] = c;
2690  if (isalpha(c) || Length >= (sizeof (Buffer) - 1))
2691  break;
2692  }
2693 
2694  Buffer[Length] = '\0';
2695  if (Buffer[0] == '8' && Buffer[1] == ';')
2696  {
2697  for (i = 2; (i < Length) && (Buffer[i] != ';'); i++);
2698 
2699  if (Buffer[i] == ';')
2700  {
2701  Buffer[i++] = '\0';
2702 
2703  /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
2706  TerminalReportsSize = TRUE;
2707  }
2708  }
2709  }
2710  /* Clear further characters */
2711  while ((c = KdbpTryGetCharSerial(5000)) != -1);
2712  }
2713  }
2714 
2715  if (KdbNumberOfRowsTerminal <= 0)
2716  {
2717  /* Set number of rows to the default. */
2718  KdbNumberOfRowsTerminal = 23; //24; //Mna.: 23 for SCREEN debugport
2719  }
2720  else if (KdbNumberOfColsTerminal <= 0)
2721  {
2722  /* Set number of cols to the default. */
2723  KdbNumberOfColsTerminal = 75; //80; //Mna.: 75 for SCREEN debugport
2724  }
2725  }
2726 
2727  /* Get the string */
2728  va_start(ap, Format);
2729  Length = _vsnprintf(Buffer, sizeof (Buffer) - 1, Format, ap);
2730  Buffer[Length] = '\0';
2731  va_end(ap);
2732 
2733  p = Buffer;
2734  while (p[0] != '\0')
2735  {
2736  i = strcspn(p, "\n");
2737 
2738  /* Calculate the number of lines which will be printed in the terminal
2739  * when outputting the current line
2740  */
2741  if (i > 0)
2742  RowsPrintedByTerminal = (i + KdbNumberOfColsPrinted - 1) / KdbNumberOfColsTerminal;
2743  else
2744  RowsPrintedByTerminal = 0;
2745 
2746  if (p[i] == '\n')
2747  RowsPrintedByTerminal++;
2748 
2749  /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
2750 
2751  /* Display a prompt if we printed one screen full of text */
2752  if (KdbNumberOfRowsTerminal > 0 &&
2753  (LONG)(KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
2754  {
2756 
2757  if (KdbNumberOfColsPrinted > 0)
2758  DbgPrint("\n");
2759 
2760  DbgPrint("--- Press q to abort, any other key to continue ---");
2761  RowsPrintedByTerminal++; /* added by Mna. */
2762 
2764  c = KdbpGetCharSerial();
2765  else
2767 
2768  if (c == '\r')
2769  {
2770  /* Try to read '\n' which might follow '\r' - if \n is not received here
2771  * it will be interpreted as "return" when the next command should be read.
2772  */
2774  c = KdbpTryGetCharSerial(5);
2775  else
2777  }
2778 
2779  DbgPrint("\n");
2780  if (c == 'q')
2781  {
2783  return;
2784  }
2785 
2788  }
2789 
2790  /* Insert a NUL after the line and print only the current line. */
2791  if (p[i] == '\n' && p[i + 1] != '\0')
2792  {
2793  c = p[i + 1];
2794  p[i + 1] = '\0';
2795  }
2796  else
2797  {
2798  c = '\0';
2799  }
2800 
2801  /* Remove escape sequences from the line if there's no terminal connected */
2802  if (!TerminalConnected)
2803  {
2804  while ((p2 = strrchr(p, '\x1b'))) /* Look for escape character */
2805  {
2806  size_t len = strlen(p2);
2807  if (p2[1] == '[')
2808  {
2809  j = 2;
2810  while (!isalpha(p2[j++]));
2811  memmove(p2, p2 + j, len + 1 - j);
2812  }
2813  else
2814  {
2815  memmove(p2, p2 + 1, len);
2816  }
2817  }
2818  }
2819 
2820  DbgPrint("%s", p);
2821 
2822  if (c != '\0')
2823  p[i + 1] = c;
2824 
2825  /* Set p to the start of the next line and
2826  * remember the number of rows/cols printed
2827  */
2828  p += i;
2829  if (p[0] == '\n')
2830  {
2831  p++;
2833  }
2834  else
2835  {
2836  ASSERT(p[0] == '\0');
2838  }
2839 
2840  KdbNumberOfRowsPrinted += RowsPrintedByTerminal;
2841  }
2842 }
signed char * PCHAR
Definition: retypes.h:7
#define KEY_ESC
Definition: kdb_cli.c:39
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
ULONG ScanCode
Definition: api.c:39
ULONG KdbDebugState
Definition: kdb.c:45
#define DbgPrint
Definition: loader.c:25
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdb.h:251
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
char CHAR
Definition: xmlstorage.h:175
#define isalpha(c)
Definition: acclib.h:74
#define KdbpGetCharSerial()
Definition: kdb.h:255
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
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:117
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 va_end(ap)
Definition: acmsvcex.h:90
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:118
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:120
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
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 GLint GLint j
Definition: glfuncs.h:250
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:119
const GLubyte * c
Definition: glext.h:8905
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:121
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:122
GLenum GLsizei len
Definition: glext.h:6722
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define _vsnprintf
Definition: xmlstorage.h:202
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
#define c
Definition: ke_i.h:80
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99

Referenced by KdbEnterDebuggerException(), KdbpAttachToProcess(), KdbpAttachToThread(), KdbpCliMainLoop(), KdbpCliModuleLoaded(), KdbpCmdBackTrace(), KdbpCmdBreakPoint(), KdbpCmdBreakPointList(), KdbpCmdDisassembleX(), KdbpCmdDmesg(), KdbpCmdEnableDisableClearBreakPoint(), KdbpCmdEvalExpression(), KdbpCmdFilter(), KdbpCmdGdtLdtIdt(), KdbpCmdHelp(), KdbpCmdMod(), KdbpCmdPcr(), KdbpCmdProc(), KdbpCmdRegs(), KdbpCmdSet(), KdbpCmdStep(), KdbpCmdThread(), KdbpCmdTss(), KdbpDeleteBreakPoint(), KdbpDisableBreakPoint(), KdbpDoCommand(), KdbpEnableBreakPoint(), KdbpEvaluateExpression(), KdbpInsertBreakPoint(), KdbpReadCommand(), and KdbpShouldStepOverInstruction().

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

1097 {
1098  PRPN_STACK Stack = (PRPN_STACK)&RpnStack;
1099 
1100  ASSERT(Expression);
1101  ASSERT(TrapFrame);
1102  ASSERT(Result);
1103 
1104  /* Clear the stack and parse the expression */
1105  RpnpClearStack(Stack);
1106  if (!RpnpParseExpression(Stack, Expression, NULL, 0, ErrOffset, ErrMsg))
1107  return FALSE;
1108 
1109 #ifdef DEBUG_RPN
1110  RpnpDumpStack(Stack);
1111 #endif
1112 
1113  /* Evaluate the stack */
1114  if (!RpnpEvaluateStack(Stack, TrapFrame, Result, ErrOffset, ErrMsg))
1115  return FALSE;
1116 
1117  return TRUE;
1118 }
struct _RPN_STACK * PRPN_STACK
PCWSTR Expression
#define TRUE
Definition: types.h:120
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:410
VOID RpnpDumpStack(IN PRPN_STACK Stack)
Dumps the given RPN stack content.
Definition: kdb_expr.c:238
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:882
static VOID RpnpClearStack(OUT PRPN_STACK Stack)
Clears the given RPN stack.
Definition: kdb_expr.c:313
static struct @1764 RpnStack

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

1191 {
1192  PRPN_STACK Stack = (PRPN_STACK)Expression;
1193 
1194  ASSERT(Expression);
1195  ASSERT(TrapFrame);
1196  ASSERT(Result);
1197 
1198  /* Evaluate the stack */
1199  return RpnpEvaluateStack(Stack, TrapFrame, Result, ErrOffset, ErrMsg);
1200 }
struct _RPN_STACK * PRPN_STACK
PCWSTR Expression
_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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:882

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

1135 {
1136  LONG Size;
1137  PRPN_STACK Stack = (PRPN_STACK)&RpnStack;
1138  PRPN_STACK NewStack;
1139 
1140  ASSERT(Expression);
1141 
1142  /* Clear the stack and parse the expression */
1143  RpnpClearStack(Stack);
1144  if (!RpnpParseExpression(Stack, Expression, NULL, 0, ErrOffset, ErrMsg))
1145  return FALSE;
1146 
1147 #ifdef DEBUG_RPN
1148  RpnpDumpStack(Stack);
1149 #endif
1150 
1151  /* Duplicate the stack and return a pointer/handle to it */
1152  ASSERT(Stack->Sp >= 1);
1153  Size = sizeof (RPN_STACK) + (RTL_FIELD_SIZE(RPN_STACK, Ops[0]) * (Stack->Sp - 1));
1155 
1156  if (!NewStack)
1157  {
1158  CONST_STRCPY(ErrMsg, "Out of memory");
1159 
1160  if (ErrOffset)
1161  *ErrOffset = -1;
1162 
1163  return NULL;
1164  }
1165 
1166  memcpy(NewStack, Stack, Size);
1167  NewStack->Size = NewStack->Sp;
1168 
1169  return NewStack;
1170 }
#define TAG_KDBG
Definition: kdb.h:8
struct _RPN_STACK * PRPN_STACK
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
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:410
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:238
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
ULONG Size
Definition: kdb_expr.c:96
struct _RPN_STACK RPN_STACK
ULONG Sp
Definition: kdb_expr.c:75
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG Size
Definition: kdb_expr.c:74
#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:313
static struct @1764 RpnStack

Referenced by KdbpInsertBreakPoint().

◆ KdbpSafeReadMemory()

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

Definition at line 1817 of file kdb.c.

1821 {
1822  return KdpCopyMemoryChunks((ULONG64)(ULONG_PTR)Src,
1823  Dest,
1824  Bytes,
1825  0,
1827  NULL);
1828 }
_In_ UINT Bytes
Definition: mmcopy.h:9
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI KdpCopyMemoryChunks(IN ULONG64 Address, IN PVOID Buffer, IN ULONG TotalSize, IN ULONG ChunkSize, IN ULONG Flags, OUT PULONG ActualSize OPTIONAL)
Definition: kdb.c:1738
unsigned __int64 ULONG64
Definition: imports.h:198
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55

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

◆ KdbpSafeWriteMemory()

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

Definition at line 1831 of file kdb.c.

1835 {
1836  return KdpCopyMemoryChunks((ULONG64)(ULONG_PTR)Dest,
1837  Src,
1838  Bytes,
1839  0,
1841  NULL);
1842 }
_In_ UINT Bytes
Definition: mmcopy.h:9
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
#define MMDBG_COPY_WRITE
Definition: mm.h:53
NTSTATUS NTAPI KdpCopyMemoryChunks(IN ULONG64 Address, IN PVOID Buffer, IN ULONG TotalSize, IN ULONG ChunkSize, IN ULONG Flags, OUT PULONG ActualSize OPTIONAL)
Definition: kdb.c:1738
unsigned __int64 ULONG64
Definition: imports.h:198
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55

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

1055 {
1056  if (ExceptionNr < 0)
1057  {
1058  for (ExceptionNr = 0; ExceptionNr < (LONG)RTL_NUMBER_OF(KdbEnterConditions); ExceptionNr++)
1059  {
1060  if (ExceptionNr == 1 || ExceptionNr == 8 ||
1061  ExceptionNr == 9 || ExceptionNr == 15) /* Reserved exceptions */
1062  {
1063  continue;
1064  }
1065 
1066  KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1] = Condition;
1067  }
1068  }
1069  else
1070  {
1071  if (ExceptionNr >= (LONG)RTL_NUMBER_OF(KdbEnterConditions) ||
1072  ExceptionNr == 1 || ExceptionNr == 8 || /* Do not allow changing of the debug */
1073  ExceptionNr == 9 || ExceptionNr == 15) /* trap or reserved exceptions */
1074  {
1075  return FALSE;
1076  }
1077 
1078  KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1] = Condition;
1079  }
1080 
1081  return TRUE;
1082 }
#define TRUE
Definition: types.h:120
static KDB_ENTER_CONDITION KdbEnterConditions[][2]
Definition: kdb.c:58
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 LPCWSTR Name  OPTIONAL,
IN INT Index  OPTIONAL,
OUT PLDR_DATA_TABLE_ENTRY pLdrEntry 
)

Find a module...

Parameters
AddressIf Address is not NULL the module containing Address is searched.
NameIf Name is not NULL the module named Name will be searched.
IndexIf Index is >= 0 the Index'th module will be returned.
pLdrEntryPointer to a PLDR_DATA_TABLE_ENTRY which is filled.
Return values
TRUEModule was found, pLdrEntry was filled.
FALSENo module was found.

Definition at line 76 of file kdb_symbols.c.

81 {
82  LONG Count = 0;
84 
85  /* First try to look up the module in the kernel module list. */
88  &Count,
89  Address,
90  Name,
91  Index,
92  pLdrEntry))
93  {
94  return TRUE;
95  }
96 
97  /* That didn't succeed. Try the module list of the current process now. */
99 
100  if(!CurrentProcess || !CurrentProcess->Peb || !CurrentProcess->Peb->Ldr)
101  return FALSE;
102 
103  return KdbpSymSearchModuleList(CurrentProcess->Peb->Ldr->InLoadOrderModuleList.Flink,
104  &CurrentProcess->Peb->Ldr->InLoadOrderModuleList,
105  &Count,
106  Address,
107  Name,
108  Index,
109  pLdrEntry);
110 }
#define TRUE
Definition: types.h:120
static BOOLEAN KdbpSymSearchModuleList(IN PLIST_ENTRY current_entry, IN PLIST_ENTRY end_entry, IN PLONG Count, IN PVOID Address, IN LPCWSTR Name, IN INT Index, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
Definition: kdb_symbols.c:37
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
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:119
ULONG CurrentProcess
Definition: shell.c:125
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
static const UCHAR Index[8]
Definition: usbohci.c:18

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

◆ 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:1668
ULONG ScanCode
Definition: api.c:39
unsigned char BOOLEAN
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
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
UCHAR byte_t
Definition: kdb_keyboard.c:57
#define c
Definition: ke_i.h:80

Referenced by KdbpCliMainLoop(), KdbpPager(), KdbpPrint(), KdbpReadCommand(), and KdpPrompt().

◆ 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
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
BOOLEAN NTAPI KdPortGetByteEx(PCPPORT PortInformation, PUCHAR ByteReceived)
CPPORT SerialPortInfo
Definition: kdio.c:31

Referenced by KdbpCliMainLoop(), KdbpPager(), KdbpPrint(), KdbpReadCommand(), and KdpPrompt().

Variable Documentation

◆ KdbCurrentProcess

◆ KdbCurrentThread

PETHREAD KdbCurrentThread

Definition at line 49 of file kdb.c.

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

◆ KdbCurrentTrapFrame

◆ KdbDebugState

ULONG KdbDebugState

◆ KdbInitFileBuffer

PCHAR KdbInitFileBuffer

Definition at line 124 of file kdb_cli.c.

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

◆ KdbLastBreakPointNr

LONG KdbLastBreakPointNr

Definition at line 42 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdBreakPointList().

◆ KdbNumSingleSteps

ULONG KdbNumSingleSteps

Definition at line 43 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().

◆ KdbSingleStepOver

BOOLEAN KdbSingleStepOver

Definition at line 44 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().