ReactOS  r74223
kdb.h File Reference

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

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

Definition at line 250 of file kdb.h.

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

#define KdbpGetCharSerial ( )    KdbpTryGetCharSerial(0)

Definition at line 254 of file kdb.h.

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

#define TAG_KDBG   'GBDK'

Definition at line 7 of file kdb.h.

Referenced by KdbpInsertBreakPoint(), and KdbpRpnParseExpression().

#define TAG_KDBS   'SBDK'

Definition at line 6 of file kdb.h.

Referenced by KdbpSymAddCachedFile().

Typedef Documentation

Enumeration Type Documentation

Enumerator
KdbAccessRead 
KdbAccessWrite 
KdbAccessReadWrite 
KdbAccessExec 

Definition at line 30 of file kdb.h.

31 {
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE
Enumerator
KdbBreakPointNone 
KdbBreakPointSoftware 
KdbBreakPointHardware 
KdbBreakPointTemporary 

Definition at line 22 of file kdb.h.

Enumerator
KdbDoNotEnter 
KdbEnterAlways 
KdbEnterFromKmode 
KdbEnterFromUmode 

Definition at line 59 of file kdb.h.

60 {
enum _KDB_ENTER_CONDITION KDB_ENTER_CONDITION
Enumerator
KD_DEBUG_KDSERIAL 
KD_DEBUG_KDNOECHO 

Definition at line 68 of file kdb.h.

69 {
enum _KDB_OUTPUT_SETTINGS KDB_OUTPUT_SETTINGS

Function Documentation

VOID DbgDisableFile ( PCH  Filename)
VOID DbgEnableFile ( PCH  Filename)
VOID DbgRDebugInit ( VOID  )
VOID DbgShowFiles ( VOID  )
VOID KbdDisableMouse ( VOID  )

Referenced by KdbpInternalEnter(), and KdpPrompt().

VOID KbdEnableMouse ( VOID  )

Referenced by KdbpInternalEnter(), and KdpPrompt().

VOID KdbEnter ( VOID  )

Referenced by KdbpCliInit().

KD_CONTINUE_TYPE KdbEnterDebuggerException ( PEXCEPTION_RECORD  ExceptionRecord,
KPROCESSOR_MODE  PreviousMode,
PCONTEXT  Context,
PKTRAP_FRAME  TrapFrame,
BOOLEAN  FirstChance 
)
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 1200 of file kdb.c.

Referenced by KdbpCmdProc().

1202 {
1204  PETHREAD Thread;
1206 
1207  /* Get a pointer to the process */
1209  {
1210  KdbpPrint("Invalid process id: 0x%08x\n", (ULONG_PTR)ProcessId);
1211  return FALSE;
1212  }
1213 
1214  Entry = Process->ThreadListHead.Flink;
1215  ObDereferenceObject(Process);
1216  if (Entry == &KdbCurrentProcess->ThreadListHead)
1217  {
1218  KdbpPrint("No threads in process 0x%p, cannot attach to process!\n", ProcessId);
1219  return FALSE;
1220  }
1221 
1222  Thread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
1223 
1224  return KdbpAttachToThread(Thread->Cid.UniqueThread);
1225 }
struct _Entry Entry
Definition: kefuncs.h:640
BOOLEAN KdbpAttachToThread(PVOID ThreadId)
Switches to another thread context.
Definition: kdb.c:1119
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
_In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ PEPROCESS ProcessId
Definition: iotypes.h:1451
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
uint32_t ULONG_PTR
Definition: typedefs.h:64
smooth NULL
Definition: ftsmooth.c:464
LIST_ENTRY ThreadListHead
Definition: pstypes.h:1206
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
CLIENT_ID Cid
Definition: pstypes.h:1005
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
HANDLE UniqueThread
Definition: compat.h:475
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
Definition: typedefs.h:118
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define FALSE
Definition: numbers.c:16
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
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 1119 of file kdb.c.

Referenced by KdbpAttachToProcess(), and KdbpCmdThread().

1121 {
1122  PETHREAD Thread = NULL;
1124 
1125  /* Get a pointer to the thread */
1126  if (!NT_SUCCESS(PsLookupThreadByThreadId(ThreadId, &Thread)))
1127  {
1128  KdbpPrint("Invalid thread id: 0x%08x\n", (ULONG_PTR)ThreadId);
1129  return FALSE;
1130  }
1131  Process = Thread->ThreadsProcess;
1132 
1133  if (KeIsExecutingDpc() && Process != KdbCurrentProcess)
1134  {
1135  KdbpPrint("Cannot attach to thread within another process while executing a DPC.\n");
1136  ObDereferenceObject(Thread);
1137  return FALSE;
1138  }
1139 
1140  /* Save the current thread's context (if we previously attached to a thread) */
1142  {
1144  /* Actually, we can't save the context, there's no guarantee that there was a trap frame */
1145  }
1146  else
1147  {
1149  }
1150 
1151  /* Switch to the thread's context */
1152  if (Thread != KdbOriginalThread)
1153  {
1154  /* The thread we're attaching to isn't the thread on which we entered
1155  * kdb and so the thread we're attaching to is not running. There
1156  * is no guarantee that it actually has a trap frame. So we have to
1157  * peek directly at the registers which were saved on the stack when the
1158  * thread was preempted in the scheduler */
1162  }
1163  else /* Switching back to original thread */
1164  {
1166  }
1168 
1169  /* Attach to the thread's process */
1171  if (KdbCurrentProcess != Process)
1172  {
1173  if (KdbCurrentProcess != KdbOriginalProcess) /* detach from previously attached process */
1174  {
1176  }
1177 
1178  if (KdbOriginalProcess != Process)
1179  {
1180  KeStackAttachProcess(&Process->Pcb, &KdbApcState);
1181  }
1182 
1184  }
1185 
1186  ObDereferenceObject(Thread);
1187  return TRUE;
1188 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
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:980
#define TRUE
Definition: numbers.c:17
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
static VOID KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack, PKDB_KTRAP_FRAME KdbTrapFrame)
Definition: kdb.c:201
BOOLEAN NTAPI KeIsExecutingDpc(VOID)
Definition: dpc.c:930
static KDB_KTRAP_FRAME KdbThreadTrapFrame
Definition: kdb.c:53
PEPROCESS KdbOriginalProcess
Definition: kdb.c:48
uint32_t ULONG_PTR
Definition: typedefs.h:64
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:649
#define PsGetCurrentProcess
Definition: psfuncs.h:17
smooth NULL
Definition: ftsmooth.c:464
PVOID KernelStack
Definition: ketypes.h:939
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
KPROCESS Pcb
Definition: pstypes.h:1139
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:701
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
#define FALSE
Definition: numbers.c:16
VOID KdbpCliInit ( VOID  )

Called when KDB is initialized.

Reads the KDBinit file from the SystemRoot directory and executes it.

Definition at line 3577 of file kdb_cli.c.

3578 {
3579  NTSTATUS Status;
3583  FILE_STANDARD_INFORMATION FileStdInfo;
3584  HANDLE hFile = NULL;
3585  INT FileSize;
3586  PCHAR FileBuffer;
3587  ULONG OldEflags;
3588 
3589  /* Initialize the object attributes */
3590  RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3591  InitializeObjectAttributes(&ObjectAttributes, &FileName, 0, NULL, NULL);
3592 
3593  /* Open the file */
3594  Status = ZwOpenFile(&hFile, FILE_READ_DATA | SYNCHRONIZE,
3595  &ObjectAttributes, &Iosb, 0,
3598  if (!NT_SUCCESS(Status))
3599  {
3600  DPRINT("Could not open \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3601  return;
3602  }
3603 
3604  /* Get the size of the file */
3605  Status = ZwQueryInformationFile(hFile, &Iosb, &FileStdInfo, sizeof (FileStdInfo),
3607  if (!NT_SUCCESS(Status))
3608  {
3609  ZwClose(hFile);
3610  DPRINT("Could not query size of \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3611  return;
3612  }
3613  FileSize = FileStdInfo.EndOfFile.u.LowPart;
3614 
3615  /* Allocate memory for the file */
3616  FileBuffer = ExAllocatePool(PagedPool, FileSize + 1); /* add 1 byte for terminating '\0' */
3617  if (!FileBuffer)
3618  {
3619  ZwClose(hFile);
3620  DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize);
3621  return;
3622  }
3623 
3624  /* Load file into memory */
3625  Status = ZwReadFile(hFile, 0, 0, 0, &Iosb, FileBuffer, FileSize, 0, 0);
3626  ZwClose(hFile);
3627 
3628  if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
3629  {
3630  ExFreePool(FileBuffer);
3631  DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3632  return;
3633  }
3634 
3635  FileSize = min(FileSize, (INT)Iosb.Information);
3636  FileBuffer[FileSize] = '\0';
3637 
3638  /* Enter critical section */
3639  OldEflags = __readeflags();
3640  _disable();
3641 
3642  /* Interpret the init file... */
3644  KdbEnter();
3646 
3647  /* Leave critical section */
3648  __writeeflags(OldEflags);
3649 
3650  ExFreePool(FileBuffer);
3651 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
VOID KdbEnter(VOID)
Definition: bidi.c:75
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
static SIZE_T FileSize
Definition: cabinet.c:51
#define STATUS_END_OF_FILE
Definition: udferr_usr.h:139
struct _LARGE_INTEGER::@1855 u
static PUCHAR FileBuffer
Definition: cabinet.c:49
int32_t INT
Definition: typedefs.h:57
_Must_inspect_result_ _Out_ PIO_STATUS_BLOCK Iosb
Definition: fltkernel.h:1761
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1456
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: nt_native.h:737
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:464
LARGE_INTEGER EndOfFile
Definition: nt_native.h:948
void DPRINT(...)
Definition: polytest.cpp:61
struct _FileName FileName
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:1451
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:479
#define SYNCHRONIZE
Definition: nt_native.h:61
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: nt_native.h:740
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
DWORD *typedef HANDLE
Definition: winlogon.h:52
LONG NTSTATUS
Definition: DriverTester.h:11
#define min(a, b)
Definition: monoChain.cc:55
signed char * PCHAR
Definition: retypes.h:7
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:118
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
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 3528 of file kdb_cli.c.

Referenced by KdbEnterDebuggerException().

3529 {
3530  PCHAR p1, p2;
3531  INT i;
3532  CHAR c;
3533 
3534  /* Execute the commands in the init file */
3535  DPRINT("KDB: Executing KDBinit file...\n");
3536  p1 = KdbInitFileBuffer;
3537  while (p1[0] != '\0')
3538  {
3539  i = strcspn(p1, "\r\n");
3540  if (i > 0)
3541  {
3542  c = p1[i];
3543  p1[i] = '\0';
3544 
3545  /* Look for "break" command and comments */
3546  p2 = p1;
3547 
3548  while (isspace(p2[0]))
3549  p2++;
3550 
3551  if (strncmp(p2, "break", sizeof("break")-1) == 0 &&
3552  (p2[sizeof("break")-1] == '\0' || isspace(p2[sizeof("break")-1])))
3553  {
3554  /* break into the debugger */
3556  }
3557  else if (p2[0] != '#' && p2[0] != '\0') /* Ignore empty lines and comments */
3558  {
3559  KdbpDoCommand(p1);
3560  }
3561 
3562  p1[i] = c;
3563  }
3564 
3565  p1 += i;
3566  while (p1[0] == '\r' || p1[0] == '\n')
3567  p1++;
3568  }
3569  DPRINT("KDB: KDBinit executed\n");
3570 }
#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:57
const GLfloat * p2
Definition: s_aatritemp.h:44
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3388
GLenum GLclampf GLint i
Definition: glfuncs.h:14
void DPRINT(...)
Definition: polytest.cpp:61
VOID KdbpCliMainLoop(IN BOOLEAN EnteredOnSingleStep)
KDB Main Loop.
Definition: kdb_cli.c:3450
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
signed char * PCHAR
Definition: retypes.h:7
#define FALSE
Definition: numbers.c:16
#define c
Definition: ke_i.h:80
const GLfloat * p1
Definition: s_aatritemp.h:43
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:118
VOID KdbpCliMainLoop ( IN BOOLEAN  EnteredOnSingleStep)

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3450 of file kdb_cli.c.

Referenced by KdbpCallMainLoop(), and KdbpCliInterpretInitFile().

3452 {
3453  static CHAR Command[1024];
3454  BOOLEAN Continue;
3455 
3456  if (EnteredOnSingleStep)
3457  {
3459  {
3460  KdbpPrint("<%x>", KdbCurrentTrapFrame->Tf.Eip);
3461  }
3462 
3463  KdbpPrint(": ");
3465  {
3466  KdbpPrint("<INVALID>");
3467  }
3468  KdbpPrint("\n");
3469  }
3470 
3471  /* Flush the input buffer */
3473  {
3474  while (KdbpTryGetCharSerial(1) != -1);
3475  }
3476  else
3477  {
3478  ULONG ScanCode;
3479  while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
3480  }
3481 
3482  /* Main loop */
3483  do
3484  {
3485  /* Reset the number of rows/cols printed */
3487 
3488  /* Print the prompt */
3489  KdbpPrint("kdb:> ");
3490 
3491  /* Read a command and remember it */
3492  KdbpReadCommand(Command, sizeof (Command));
3493  KdbpCommandHistoryAppend(Command);
3494 
3495  /* Reset the number of rows/cols printed and output aborted state */
3498 
3499  /* Call the command */
3500  Continue = KdbpDoCommand(Command);
3502  }
3503  while (Continue);
3504 }
DWORD *typedef PVOID
Definition: winlogon.h:52
static VOID KdbpReadCommand(OUT PCHAR Buffer, IN ULONG Size)
Reads a line of user-input.
Definition: kdb_cli.c:3116
static VOID KdbpCommandHistoryAppend(IN PCHAR Command)
Appends a command to the command history.
Definition: kdb_cli.c:3042
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
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:111
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3388
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:112
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
unsigned char BOOLEAN
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:113
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:103
volatile int Continue
Definition: gdblib.c:102
ULONG Eip
Definition: ketypes.h:265
KTRAP_FRAME Tf
Definition: kdb.h:14
#define FALSE
Definition: numbers.c:16
unsigned int ULONG
Definition: retypes.h:1
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:123
VOID KdbpCliModuleLoaded ( IN PUNICODE_STRING  Name)

Called when a module is loaded.

Parameters
NameFilename of the module which was loaded.

Definition at line 3511 of file kdb_cli.c.

3513 {
3514  if (!KdbBreakOnModuleLoad)
3515  return;
3516 
3517  KdbpPrint("Module %wZ loaded.\n", Name);
3519 }
static BOOLEAN KdbBreakOnModuleLoad
Definition: kdb_cli.c:104
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
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 681 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdEnableDisableClearBreakPoint().

684 {
685  if (BreakPointNr < 0)
686  {
687  ASSERT(BreakPoint);
688  BreakPointNr = BreakPoint - KdbBreakPoints;
689  }
690 
691  if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
692  {
693  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
694  return FALSE;
695  }
696 
697  if (!BreakPoint)
698  {
699  BreakPoint = KdbBreakPoints + BreakPointNr;
700  }
701 
702  if (BreakPoint->Type == KdbBreakPointNone)
703  {
704  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
705  return FALSE;
706  }
707 
708  if (BreakPoint->Enabled && !KdbpDisableBreakPoint(-1, BreakPoint))
709  return FALSE;
710 
711  if (BreakPoint->Type != KdbBreakPointTemporary)
712  KdbpPrint("Breakpoint %d deleted.\n", BreakPointNr);
713 
714  BreakPoint->Type = KdbBreakPointNone;
716 
717  return TRUE;
718 }
static ULONG KdbBreakPointCount
Definition: kdb.c:33
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:21
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define TRUE
Definition: numbers.c:17
BOOLEAN KdbpDisableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Disables a breakpoint.
Definition: kdb.c:951
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
#define FALSE
Definition: numbers.c:16
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
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 951 of file kdb.c.

Referenced by KdbpCmdEnableDisableClearBreakPoint(), and KdbpDeleteBreakPoint().

954 {
955  ULONG i;
957 
958  if (BreakPointNr < 0)
959  {
960  ASSERT(BreakPoint);
961  BreakPointNr = BreakPoint - KdbBreakPoints;
962  }
963 
964  if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
965  {
966  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
967  return FALSE;
968  }
969 
970  if (!BreakPoint)
971  {
972  BreakPoint = KdbBreakPoints + BreakPointNr;
973  }
974 
975  if (BreakPoint->Type == KdbBreakPointNone)
976  {
977  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
978  return FALSE;
979  }
980 
981  if (BreakPoint->Enabled == FALSE)
982  {
983  KdbpPrint("Breakpoint %d is not enabled.\n", BreakPointNr);
984  return TRUE;
985  }
986 
987  if (BreakPoint->Type == KdbBreakPointSoftware ||
988  BreakPoint->Type == KdbBreakPointTemporary)
989  {
991  Status = KdbpOverwriteInstruction(BreakPoint->Process, BreakPoint->Address,
992  BreakPoint->Data.SavedInstruction, NULL);
993 
994  if (!NT_SUCCESS(Status))
995  {
996  KdbpPrint("Couldn't restore original instruction.\n");
997  return FALSE;
998  }
999 
1000  for (i = 0; i < KdbSwBreakPointCount; i++)
1001  {
1002  if (KdbSwBreakPoints[i] == BreakPoint)
1003  {
1005  i = -1; /* if the last breakpoint is disabled dont break with i >= KdbSwBreakPointCount */
1006  break;
1007  }
1008  }
1009 
1010  if (i != MAXULONG) /* not found */
1011  ASSERT(0);
1012  }
1013  else
1014  {
1015  ASSERT(BreakPoint->Type == KdbBreakPointHardware);
1016 
1017  /* Clear the breakpoint. */
1018  KdbTrapFrame.Tf.Dr7 &= ~(0x3 << (BreakPoint->Data.Hw.DebugReg * 2));
1019  if ((KdbTrapFrame.Tf.Dr7 & 0xFF) == 0)
1020  {
1021  /* If no breakpoints are enabled then clear the exact match flags. */
1022  KdbTrapFrame.Tf.Dr7 &= 0xFFFFFCFF;
1023  }
1024 
1025  for (i = 0; i < KdbHwBreakPointCount; i++)
1026  {
1027  if (KdbHwBreakPoints[i] == BreakPoint)
1028  {
1030  i = -1; /* if the last breakpoint is disabled dont break with i >= KdbHwBreakPointCount */
1031  break;
1032  }
1033  }
1034 
1035  if (i != MAXULONG) /* not found */
1036  ASSERT(0);
1037  }
1038 
1039  BreakPoint->Enabled = FALSE;
1040  if (BreakPoint->Type != KdbBreakPointTemporary)
1041  KdbpPrint("Breakpoint %d disabled.\n", BreakPointNr);
1042 
1043  return TRUE;
1044 }
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:21
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
static ULONG KdbSwBreakPointCount
Definition: kdb.c:35
#define TRUE
Definition: numbers.c:17
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:38
GLenum GLclampf GLint i
Definition: glfuncs.h:14
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:237
smooth NULL
Definition: ftsmooth.c:464
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:2462
Status
Definition: gdiplustypes.h:24
#define MAXULONG
Definition: typedefs.h:251
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
LONG NTSTATUS
Definition: DriverTester.h:11
KTRAP_FRAME Tf
Definition: kdb.h:14
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:52
#define FALSE
Definition: numbers.c:16
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
LONG KdbpDisassemble ( IN ULONG  Address,
IN ULONG  IntelSyntax 
)

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

Referenced by KdbpCliMainLoop(), and KdbpCmdDisassembleX().

124 {
126 
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;
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
PVOID ULONG Address
Definition: oprghdlr.h:14
unsigned long flags
Definition: dis-asm.h:102
int bytes_per_chunk
Definition: dis-asm.h:152
char * disassembler_options
Definition: dis-asm.h:176
#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
fprintf_ftype fprintf_func
Definition: dis-asm.h:62
bfd_vma buffer_vma
Definition: dis-asm.h:138
smooth NULL
Definition: ftsmooth.c:464
unsigned long mach
Definition: dis-asm.h:74
static int KdbpReadMemory(ULONG_PTR Addr, unsigned char *Data, unsigned int Length, struct disassemble_info *Ignored)
Definition: i386-dis.c:68
bfd_byte * buffer
Definition: dis-asm.h:137
PTR application_data
Definition: dis-asm.h:64
enum bfd_flavour flavour
Definition: dis-asm.h:70
enum bfd_architecture arch
Definition: dis-asm.h:72
const XML_Char XML_Encoding * info
Definition: expat.h:530
#define bfd_mach_i386_i386_intel_syntax
Definition: i386-dis.c:32
enum bfd_endian display_endian
Definition: dis-asm.h:153
unsigned long insn_sets
Definition: dis-asm.h:82
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
unsigned int buffer_length
Definition: dis-asm.h:139
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 784 of file kdb.c.

Referenced by KdbpCmdEnableDisableClearBreakPoint(), and KdbpInsertBreakPoint().

787 {
789  INT i;
790  ULONG ul;
791 
792  if (BreakPointNr < 0)
793  {
794  ASSERT(BreakPoint);
795  BreakPointNr = BreakPoint - KdbBreakPoints;
796  }
797 
798  if (BreakPointNr < 0 || BreakPointNr >= KDB_MAXIMUM_BREAKPOINT_COUNT)
799  {
800  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
801  return FALSE;
802  }
803 
804  if (!BreakPoint)
805  {
806  BreakPoint = KdbBreakPoints + BreakPointNr;
807  }
808 
809  if (BreakPoint->Type == KdbBreakPointNone)
810  {
811  KdbpPrint("Invalid breakpoint: %d\n", BreakPointNr);
812  return FALSE;
813  }
814 
815  if (BreakPoint->Enabled)
816  {
817  KdbpPrint("Breakpoint %d is already enabled.\n", BreakPointNr);
818  return TRUE;
819  }
820 
821  if (BreakPoint->Type == KdbBreakPointSoftware ||
822  BreakPoint->Type == KdbBreakPointTemporary)
823  {
825  {
826  KdbpPrint("Maximum number of SW breakpoints (%d) used. "
827  "Disable another breakpoint in order to enable this one.\n",
829  return FALSE;
830  }
831 
832  Status = KdbpOverwriteInstruction(BreakPoint->Process, BreakPoint->Address,
833  0xCC, &BreakPoint->Data.SavedInstruction);
834  if (!NT_SUCCESS(Status))
835  {
836  KdbpPrint("Couldn't access memory at 0x%p\n", BreakPoint->Address);
837  return FALSE;
838  }
839 
840  KdbSwBreakPoints[KdbSwBreakPointCount++] = BreakPoint;
841  }
842  else
843  {
844  if (BreakPoint->Data.Hw.AccessType == KdbAccessExec)
845  ASSERT(BreakPoint->Data.Hw.Size == 1);
846 
847  ASSERT((BreakPoint->Address % BreakPoint->Data.Hw.Size) == 0);
848 
850  {
851  KdbpPrint("Maximum number of HW breakpoints (%d) already used. "
852  "Disable another breakpoint in order to enable this one.\n",
854 
855  return FALSE;
856  }
857 
858  /* Find unused hw breakpoint */
860  for (i = 0; i < KDB_MAXIMUM_HW_BREAKPOINT_COUNT; i++)
861  {
862  if ((KdbTrapFrame.Tf.Dr7 & (0x3 << (i * 2))) == 0)
863  break;
864  }
865 
866  ASSERT(i < KDB_MAXIMUM_HW_BREAKPOINT_COUNT);
867 
868  /* Set the breakpoint address. */
869  switch (i)
870  {
871  case 0:
872  KdbTrapFrame.Tf.Dr0 = BreakPoint->Address;
873  break;
874  case 1:
875  KdbTrapFrame.Tf.Dr1 = BreakPoint->Address;
876  break;
877  case 2:
878  KdbTrapFrame.Tf.Dr2 = BreakPoint->Address;
879  break;
880  case 3:
881  KdbTrapFrame.Tf.Dr3 = BreakPoint->Address;
882  break;
883  }
884 
885  /* Enable the global breakpoint */
886  KdbTrapFrame.Tf.Dr7 |= (0x2 << (i * 2));
887 
888  /* Enable the exact match bits. */
889  KdbTrapFrame.Tf.Dr7 |= 0x00000300;
890 
891  /* Clear existing state. */
892  KdbTrapFrame.Tf.Dr7 &= ~(0xF << (16 + (i * 4)));
893 
894  /* Set the breakpoint type. */
895  switch (BreakPoint->Data.Hw.AccessType)
896  {
897  case KdbAccessExec:
898  ul = 0;
899  break;
900  case KdbAccessWrite:
901  ul = 1;
902  break;
903  case KdbAccessRead:
904  case KdbAccessReadWrite:
905  ul = 3;
906  break;
907  default:
908  ASSERT(0);
909  return TRUE;
910  break;
911  }
912 
913  KdbTrapFrame.Tf.Dr7 |= (ul << (16 + (i * 4)));
914 
915  /* Set the breakpoint length. */
916  KdbTrapFrame.Tf.Dr7 |= ((BreakPoint->Data.Hw.Size - 1) << (18 + (i * 4)));
917 
918  /* Update KdbCurrentTrapFrame - values are taken from there by the CLI */
920  {
927  }
928 
929  BreakPoint->Data.Hw.DebugReg = i;
930  KdbHwBreakPoints[KdbHwBreakPointCount++] = BreakPoint;
931  }
932 
933  BreakPoint->Enabled = TRUE;
934  if (BreakPoint->Type != KdbBreakPointTemporary)
935  KdbpPrint("Breakpoint %d enabled.\n", BreakPointNr);
936 
937  return TRUE;
938 }
#define KDB_MAXIMUM_SW_BREAKPOINT_COUNT
Definition: kdb.c:23
#define KDB_MAXIMUM_BREAKPOINT_COUNT
Definition: kdb.c:21
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
static ULONG KdbSwBreakPointCount
Definition: kdb.c:35
#define TRUE
Definition: numbers.c:17
int32_t INT
Definition: typedefs.h:57
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:38
GLenum GLclampf GLint i
Definition: glfuncs.h:14
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:237
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
static PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]
Definition: kdb.c:37
UINT64 Dr6
Definition: ketypes.h:346
UINT64 Dr3
Definition: ketypes.h:345
UINT64 Dr1
Definition: ketypes.h:343
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
UINT64 Dr0
Definition: ketypes.h:342
#define KDB_MAXIMUM_HW_BREAKPOINT_COUNT
Definition: kdb.c:22
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
LONG NTSTATUS
Definition: DriverTester.h:11
KTRAP_FRAME Tf
Definition: kdb.h:14
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:52
#define FALSE
Definition: numbers.c:16
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN Enabled
Definition: kdb.h:41
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
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 491 of file kdb.c.

Referenced by KdbpCmdBreakPointList().

502 {
503  PKDB_BREAKPOINT bp;
504 
505  if (BreakPointNr >= RTL_NUMBER_OF(KdbBreakPoints) ||
506  KdbBreakPoints[BreakPointNr].Type == KdbBreakPointNone)
507  {
508  return FALSE;
509  }
510 
511  bp = KdbBreakPoints + BreakPointNr;
512  if (Address)
513  *Address = bp->Address;
514 
515  if (Type)
516  *Type = bp->Type;
517 
518  if (bp->Type == KdbBreakPointHardware)
519  {
520  if (Size)
521  *Size = bp->Data.Hw.Size;
522 
523  if (AccessType)
524  *AccessType = bp->Data.Hw.AccessType;
525 
526  if (DebugReg && bp->Enabled)
527  *DebugReg = bp->Data.Hw.DebugReg;
528  }
529 
530  if (Enabled)
531  *Enabled = bp->Enabled;
532 
533  if (Global)
534  *Global = bp->Global;
535 
536  if (Process)
537  *Process = bp->Process;
538 
539  if (ConditionExpression)
540  *ConditionExpression = bp->ConditionExpression;
541 
542  return TRUE;
543 }
PVOID ULONG Address
Definition: oprghdlr.h:14
Type
Definition: Type.h:6
BOOLEAN Global
Definition: kdb.h:43
PCHAR ConditionExpression
Definition: kdb.h:45
#define TRUE
Definition: numbers.c:17
UNICODE_STRING Global
Definition: symlink.c:37
struct _KDB_BREAKPOINT::@1506::@1507 Hw
ULONG_PTR Address
Definition: kdb.h:42
UINTN Size
Definition: acefiex.h:550
PEPROCESS Process
Definition: kdb.h:44
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
BOOL Enabled
union _KDB_BREAKPOINT::@1506 Data
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define FALSE
Definition: numbers.c:16
BOOLEAN Enabled
Definition: kdb.h:41
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
KDB_BREAKPOINT_TYPE Type
Definition: kdb.h:40
VOID NTAPI KdbpGetCommandLineSettings ( PCHAR  p1)

Definition at line 1731 of file kdb.c.

Referenced by KdInitSystem().

1733 {
1734 #define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
1735 
1736  while (p1 && (p1 = strchr(p1, ' ')))
1737  {
1738  /* Skip other spaces */
1739  while (*p1 == ' ') ++p1;
1740 
1741  if (!_strnicmp(p1, "KDSERIAL", CONST_STR_LEN("KDSERIAL")))
1742  {
1743  p1 += CONST_STR_LEN("KDSERIAL");
1745  KdpDebugMode.Serial = TRUE;
1746  }
1747  else if (!_strnicmp(p1, "KDNOECHO", CONST_STR_LEN("KDNOECHO")))
1748  {
1749  p1 += CONST_STR_LEN("KDNOECHO");
1751  }
1752  else if (!_strnicmp(p1, "FIRSTCHANCE", CONST_STR_LEN("FIRSTCHANCE")))
1753  {
1754  p1 += CONST_STR_LEN("FIRSTCHANCE");
1756  }
1757  }
1758 }
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:1078
KDP_DEBUG_MODE KdpDebugMode
Definition: kdinit.c:25
ULONG KdbDebugState
Definition: kdb.c:45
#define TRUE
Definition: numbers.c:17
_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
const GLfloat * p1
Definition: s_aatritemp.h:43
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 1056 of file kdb.c.

Referenced by KdbpCmdSet().

1060 {
1061  if (ExceptionNr >= (LONG)RTL_NUMBER_OF(KdbEnterConditions))
1062  return FALSE;
1063 
1064  *Condition = KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1];
1065  return TRUE;
1066 }
#define TRUE
Definition: numbers.c:17
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
#define FALSE
Definition: numbers.c:16
BOOLEAN NTAPI KdbpGetHexNumber ( IN PCHAR  pszNum,
OUT ULONG_PTR pulValue 
)

Definition at line 413 of file kdb_cli.c.

416 {
417  char *endptr;
418 
419  /* Skip optional '0x' prefix */
420  if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
421  pszNum += 2;
422 
423  /* Make a number from the string (hex) */
424  *pulValue = strtoul(pszNum, &endptr, 16);
425 
426  return (*endptr == '\0');
427 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
LONG KdbpGetInstLength ( IN ULONG  Address)

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

Referenced by KdbpStepOverInstruction().

98 {
100 
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;
117  info.disassembler_options = NULL;
118 
119  return(print_insn_i386(Address, &info));
120 }
PVOID ULONG Address
Definition: oprghdlr.h:14
unsigned long flags
Definition: dis-asm.h:102
static void KdbpNopPrintAddress(ULONG_PTR Addr, struct disassemble_info *Ignored)
Definition: i386-dis.c:90
int bytes_per_chunk
Definition: dis-asm.h:152
char * disassembler_options
Definition: dis-asm.h:176
fprintf_ftype fprintf_func
Definition: dis-asm.h:62
bfd_vma buffer_vma
Definition: dis-asm.h:138
smooth NULL
Definition: ftsmooth.c:464
unsigned long mach
Definition: dis-asm.h:74
static int KdbpReadMemory(ULONG_PTR Addr, unsigned char *Data, unsigned int Length, struct disassemble_info *Ignored)
Definition: i386-dis.c:68
bfd_byte * buffer
Definition: dis-asm.h:137
PTR application_data
Definition: dis-asm.h:64
enum bfd_flavour flavour
Definition: dis-asm.h:70
#define bfd_mach_x86_64
Definition: i386-dis.c:31
enum bfd_architecture arch
Definition: dis-asm.h:72
const XML_Char XML_Encoding * info
Definition: expat.h:530
enum bfd_endian display_endian
Definition: dis-asm.h:153
unsigned long insn_sets
Definition: dis-asm.h:82
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
unsigned int buffer_length
Definition: dis-asm.h:139
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 464 of file kdb.c.

Referenced by KdbpCmdBreakPointList().

466 {
468  {
470  return Start;
471  }
472 
473  return -1;
474 }
Type
Definition: Type.h:6
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
Definition: partlist.h:39
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 560 of file kdb.c.

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

568 {
569  LONG i;
571  PCHAR ConditionExpressionDup;
572  LONG ErrOffset;
573  CHAR ErrMsg[128];
574 
576 
578  {
579  if ((Address % Size) != 0)
580  {
581  KdbpPrint("Address (0x%p) must be aligned to a multiple of the size (%d)\n", Address, Size);
582  return STATUS_UNSUCCESSFUL;
583  }
584 
585  if (AccessType == KdbAccessExec && Size != 1)
586  {
587  KdbpPrint("Size must be 1 for execution breakpoints.\n");
588  return STATUS_UNSUCCESSFUL;
589  }
590  }
591 
593  {
594  return STATUS_UNSUCCESSFUL;
595  }
596 
597  /* Parse conditon expression string and duplicate it */
598  if (ConditionExpression)
599  {
600  Condition = KdbpRpnParseExpression(ConditionExpression, &ErrOffset, ErrMsg);
601  if (!Condition)
602  {
603  if (ErrOffset >= 0)
604  KdbpPrint("Couldn't parse expression: %s at character %d\n", ErrMsg, ErrOffset);
605  else
606  KdbpPrint("Couldn't parse expression: %s", ErrMsg);
607 
608  return STATUS_UNSUCCESSFUL;
609  }
610 
611  i = strlen(ConditionExpression) + 1;
612  ConditionExpressionDup = ExAllocatePoolWithTag(NonPagedPool, i, TAG_KDBG);
613  RtlCopyMemory(ConditionExpressionDup, ConditionExpression, i);
614  }
615  else
616  {
617  Condition = NULL;
618  ConditionExpressionDup = NULL;
619  }
620 
621  /* Find unused breakpoint */
623  {
624  for (i = RTL_NUMBER_OF(KdbBreakPoints) - 1; i >= 0; i--)
625  {
627  break;
628  }
629  }
630  else
631  {
632  for (i = 0; i < (LONG)RTL_NUMBER_OF(KdbBreakPoints); i++)
633  {
635  break;
636  }
637  }
638 
640 
641  /* Set the breakpoint */
648  KdbBreakPoints[i].ConditionExpression = ConditionExpressionDup;
650 
652  {
653  KdbBreakPoints[i].Data.Hw.Size = Size;
654  KdbBreakPoints[i].Data.Hw.AccessType = AccessType;
655  }
656 
658 
660  KdbpPrint("Breakpoint %d inserted.\n", i);
661 
662  /* Try to enable the breakpoint */
664 
665  /* Return the breakpoint number */
666  if (BreakPointNr)
667  *BreakPointNr = i;
668 
669  return STATUS_SUCCESS;
670 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define TAG_KDBG
Definition: kdb.h:7
#define STATUS_SUCCESS
Definition: contextmenu.cpp:55
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
PVOID ULONG Address
Definition: oprghdlr.h:14
Type
Definition: Type.h:6
BOOLEAN Global
Definition: kdb.h:43
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
char CHAR
Definition: xmlstorage.h:175
PCHAR ConditionExpression
Definition: kdb.h:45
UNICODE_STRING Global
Definition: symlink.c:37
GLenum GLclampf GLint i
Definition: glfuncs.h:14
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:464
struct _KDB_BREAKPOINT::@1506::@1507 Hw
ULONG_PTR Address
Definition: kdb.h:42
PVOID Condition
Definition: kdb.h:46
IN ULONG IN UCHAR Condition
UINTN Size
Definition: acefiex.h:550
BOOLEAN KdbpEnableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Enables a breakpoint.
Definition: kdb.c:784
#define LONG
Definition: msvc.h:36
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
PEPROCESS Process
Definition: kdb.h:44
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
union _KDB_BREAKPOINT::@1506 Data
signed char * PCHAR
Definition: retypes.h:7
#define FALSE
Definition: numbers.c:16
BOOLEAN Enabled
Definition: kdb.h:41
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
KDB_BREAKPOINT_TYPE Type
Definition: kdb.h:40
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 2462 of file kdb_cli.c.

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().

2465 {
2466  static CHAR Buffer[4096];
2467  static BOOLEAN TerminalInitialized = FALSE;
2468  static BOOLEAN TerminalConnected = FALSE;
2469  static BOOLEAN TerminalReportsSize = TRUE;
2470  CHAR c = '\0';
2471  PCHAR p, p2;
2472  ULONG Length;
2473  ULONG i, j;
2474  LONG RowsPrintedByTerminal;
2475  ULONG ScanCode;
2476  va_list ap;
2477 
2478  /* Check if the user has aborted output of the current command */
2479  if (KdbOutputAborted)
2480  return;
2481 
2482  /* Initialize the terminal */
2483  if (!TerminalInitialized)
2484  {
2485  DbgPrint("\x1b[7h"); /* Enable linewrap */
2486 
2487  /* Query terminal type */
2488  /*DbgPrint("\x1b[Z");*/
2489  DbgPrint("\x05");
2490 
2491  TerminalInitialized = TRUE;
2492  Length = 0;
2493  KeStallExecutionProcessor(100000);
2494 
2495  for (;;)
2496  {
2497  c = KdbpTryGetCharSerial(5000);
2498  if (c == -1)
2499  break;
2500 
2501  Buffer[Length++] = c;
2502  if (Length >= (sizeof (Buffer) - 1))
2503  break;
2504  }
2505 
2506  Buffer[Length] = '\0';
2507  if (Length > 0)
2508  TerminalConnected = TRUE;
2509  }
2510 
2511  /* Get number of rows and columns in terminal */
2512  if ((KdbNumberOfRowsTerminal < 0) || (KdbNumberOfColsTerminal < 0) ||
2513  (KdbNumberOfRowsPrinted) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
2514  {
2515  if ((KdbDebugState & KD_DEBUG_KDSERIAL) && TerminalConnected && TerminalReportsSize)
2516  {
2517  /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
2518  TerminalReportsSize = FALSE;
2519  KeStallExecutionProcessor(100000);
2520  DbgPrint("\x1b[18t");
2521  c = KdbpTryGetCharSerial(5000);
2522 
2523  if (c == KEY_ESC)
2524  {
2525  c = KdbpTryGetCharSerial(5000);
2526  if (c == '[')
2527  {
2528  Length = 0;
2529 
2530  for (;;)
2531  {
2532  c = KdbpTryGetCharSerial(5000);
2533  if (c == -1)
2534  break;
2535 
2536  Buffer[Length++] = c;
2537  if (isalpha(c) || Length >= (sizeof (Buffer) - 1))
2538  break;
2539  }
2540 
2541  Buffer[Length] = '\0';
2542  if (Buffer[0] == '8' && Buffer[1] == ';')
2543  {
2544  for (i = 2; (i < Length) && (Buffer[i] != ';'); i++);
2545 
2546  if (Buffer[i] == ';')
2547  {
2548  Buffer[i++] = '\0';
2549 
2550  /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
2551  KdbNumberOfRowsTerminal = strtoul(Buffer + 2, NULL, 0);
2552  KdbNumberOfColsTerminal = strtoul(Buffer + i, NULL, 0);
2553  TerminalReportsSize = TRUE;
2554  }
2555  }
2556  }
2557  /* Clear further characters */
2558  while ((c = KdbpTryGetCharSerial(5000)) != -1);
2559  }
2560  }
2561 
2562  if (KdbNumberOfRowsTerminal <= 0)
2563  {
2564  /* Set number of rows to the default. */
2565  KdbNumberOfRowsTerminal = 23; //24; //Mna.: 23 for SCREEN debugport
2566  }
2567  else if (KdbNumberOfColsTerminal <= 0)
2568  {
2569  /* Set number of cols to the default. */
2570  KdbNumberOfColsTerminal = 75; //80; //Mna.: 75 for SCREEN debugport
2571  }
2572  }
2573 
2574  /* Get the string */
2575  va_start(ap, Format);
2576  Length = _vsnprintf(Buffer, sizeof (Buffer) - 1, Format, ap);
2577  Buffer[Length] = '\0';
2578  va_end(ap);
2579 
2580  p = Buffer;
2581  while (p[0] != '\0')
2582  {
2583  i = strcspn(p, "\n");
2584 
2585  /* Calculate the number of lines which will be printed in the terminal
2586  * when outputting the current line
2587  */
2588  if (i > 0)
2589  RowsPrintedByTerminal = (i + KdbNumberOfColsPrinted - 1) / KdbNumberOfColsTerminal;
2590  else
2591  RowsPrintedByTerminal = 0;
2592 
2593  if (p[i] == '\n')
2594  RowsPrintedByTerminal++;
2595 
2596  /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
2597 
2598  /* Display a prompt if we printed one screen full of text */
2599  if (KdbNumberOfRowsTerminal > 0 &&
2600  (LONG)(KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
2601  {
2603 
2604  if (KdbNumberOfColsPrinted > 0)
2605  DbgPrint("\n");
2606 
2607  DbgPrint("--- Press q to abort, any other key to continue ---");
2608  RowsPrintedByTerminal++; /* added by Mna. */
2609 
2610  if (KdbDebugState & KD_DEBUG_KDSERIAL)
2611  c = KdbpGetCharSerial();
2612  else
2613  c = KdbpGetCharKeyboard(&ScanCode);
2614 
2615  if (c == '\r')
2616  {
2617  /* Try to read '\n' which might follow '\r' - if \n is not received here
2618  * it will be interpreted as "return" when the next command should be read.
2619  */
2620  if (KdbDebugState & KD_DEBUG_KDSERIAL)
2621  c = KdbpTryGetCharSerial(5);
2622  else
2623  c = KdbpTryGetCharKeyboard(&ScanCode, 5);
2624  }
2625 
2626  DbgPrint("\n");
2627  if (c == 'q')
2628  {
2630  return;
2631  }
2632 
2635  }
2636 
2637  /* Insert a NUL after the line and print only the current line. */
2638  if (p[i] == '\n' && p[i + 1] != '\0')
2639  {
2640  c = p[i + 1];
2641  p[i + 1] = '\0';
2642  }
2643  else
2644  {
2645  c = '\0';
2646  }
2647 
2648  /* Remove escape sequences from the line if there's no terminal connected */
2649  if (!TerminalConnected)
2650  {
2651  while ((p2 = strrchr(p, '\x1b'))) /* Look for escape character */
2652  {
2653  if (p2[1] == '[')
2654  {
2655  j = 2;
2656  while (!isalpha(p2[j++]));
2657  strcpy(p2, p2 + j);
2658  }
2659  else
2660  {
2661  strcpy(p2, p2 + 1);
2662  }
2663  }
2664  }
2665 
2666  DbgPrint("%s", p);
2667 
2668  if (c != '\0')
2669  p[i + 1] = c;
2670 
2671  /* Set p to the start of the next line and
2672  * remember the number of rows/cols printed
2673  */
2674  p += i;
2675  if (p[0] == '\n')
2676  {
2677  p++;
2679  }
2680  else
2681  {
2682  ASSERT(p[0] == '\0');
2684  }
2685 
2686  KdbNumberOfRowsPrinted += RowsPrintedByTerminal;
2687  }
2688 }
#define KEY_ESC
Definition: kdb_cli.c:39
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
ULONG ScanCode
Definition: api.c:39
ULONG KdbDebugState
Definition: kdb.c:45
#define DbgPrint
Definition: loader.c:26
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdb.h:250
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
char CHAR
Definition: xmlstorage.h:175
#define TRUE
Definition: numbers.c:17
#define isalpha(c)
Definition: acclib.h:74
#define KdbpGetCharSerial()
Definition: kdb.h:254
_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:111
const GLfloat * p2
Definition: s_aatritemp.h:44
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define va_end(ap)
Definition: acmsvcex.h:90
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:112
long LONG
Definition: pedump.c:60
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:114
smooth NULL
Definition: ftsmooth.c:464
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
unsigned char BOOLEAN
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:113
const GLubyte * c
Definition: glext.h:8905
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:115
UINTN VOID * Buffer
Definition: acefiex.h:370
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:116
VOID UINTN Length
Definition: acefiex.h:718
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define _vsnprintf
Definition: xmlstorage.h:202
signed char * PCHAR
Definition: retypes.h:7
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
#define FALSE
Definition: numbers.c:16
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define c
Definition: ke_i.h:80
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99
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.

Referenced by KdbpEvaluateExpression().

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
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID RpnpDumpStack(IN PRPN_STACK Stack)
Dumps the given RPN stack content.
Definition: kdb_expr.c:238
#define TRUE
Definition: numbers.c:17
_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
smooth NULL
Definition: ftsmooth.c:464
static struct @1509 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:882
#define FALSE
Definition: numbers.c:16
static VOID RpnpClearStack(OUT PRPN_STACK Stack)
Clears the given RPN stack.
Definition: kdb_expr.c:313
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.

Referenced by KdbEnterDebuggerException().

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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
_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
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
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.

Referenced by KdbpInsertBreakPoint().

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));
1154  NewStack = ExAllocatePoolWithTag(NonPagedPool, Size, TAG_KDBG);
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:7
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
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:464
ULONG Size
Definition: kdb_expr.c:96
struct _RPN_STACK RPN_STACK
static struct @1509 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 CONST_STRCPY(dst, src)
Definition: kdb_expr.c:87
#define FALSE
Definition: numbers.c:16
static VOID RpnpClearStack(OUT PRPN_STACK Stack)
Clears the given RPN stack.
Definition: kdb_expr.c:313
NTSTATUS KdbpSafeReadMemory ( OUT PVOID  Dest,
IN PVOID  Src,
IN ULONG  Bytes 
)

Definition at line 1761 of file kdb.c.

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

1765 {
1766  BOOLEAN Result = TRUE;
1767 
1768  switch (Bytes)
1769  {
1770  case 1:
1771  case 2:
1772  case 4:
1773  case 8:
1774  Result = KdpSafeReadMemory((ULONG_PTR)Src, Bytes, Dest);
1775  break;
1776 
1777  default:
1778  {
1779  ULONG_PTR Start, End, Write;
1780 
1781  for (Start = (ULONG_PTR)Src,
1782  End = Start + Bytes,
1783  Write = (ULONG_PTR)Dest;
1784  Result && (Start < End);
1785  Start++, Write++)
1786  if (!KdpSafeReadMemory(Start, 1, (PVOID)Write))
1787  Result = FALSE;
1788 
1789  break;
1790  }
1791  }
1792 
1793  return Result ? STATUS_SUCCESS : STATUS_ACCESS_VIOLATION;
1794 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define STATUS_SUCCESS
Definition: contextmenu.cpp:55
#define TRUE
Definition: numbers.c:17
_In_ UINT Bytes
Definition: mmcopy.h:9
_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
uint32_t ULONG_PTR
Definition: typedefs.h:64
BOOLEAN NTAPI KdpSafeReadMemory(ULONG_PTR Addr, LONG Len, PVOID Value)
Definition: kdmemsup.c:157
static void Write(HANDLE file, LPCVOID buffer, DWORD size)
Definition: db.cpp:236
unsigned char BOOLEAN
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define FALSE
Definition: numbers.c:16
Definition: partlist.h:39
NTSTATUS KdbpSafeWriteMemory ( OUT PVOID  Dest,
IN PVOID  Src,
IN ULONG  Bytes 
)

Definition at line 1797 of file kdb.c.

Referenced by KdbpOverwriteInstruction().

1801 {
1802  BOOLEAN Result = TRUE;
1803  ULONG_PTR Start, End, Write;
1804 
1805  for (Start = (ULONG_PTR)Src,
1806  End = Start + Bytes,
1807  Write = (ULONG_PTR)Dest;
1808  Result && (Start < End);
1809  Start++, Write++)
1810  if (!KdpSafeWriteMemory(Write, 1, *((PCHAR)Start)))
1811  Result = FALSE;
1812 
1813  return Result ? STATUS_SUCCESS : STATUS_ACCESS_VIOLATION;
1814 }
#define STATUS_SUCCESS
Definition: contextmenu.cpp:55
#define TRUE
Definition: numbers.c:17
_In_ UINT Bytes
Definition: mmcopy.h:9
BOOLEAN NTAPI KdpSafeWriteMemory(ULONG_PTR Addr, LONG Len, ULONGLONG Value)
Definition: kdmemsup.c:193
_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
uint32_t ULONG_PTR
Definition: typedefs.h:64
static void Write(HANDLE file, LPCVOID buffer, DWORD size)
Definition: db.cpp:236
unsigned char BOOLEAN
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
signed char * PCHAR
Definition: retypes.h:7
#define FALSE
Definition: numbers.c:16
Definition: partlist.h:39
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 1078 of file kdb.c.

Referenced by KdbpCmdSet(), and KdbpGetCommandLineSettings().

1082 {
1083  if (ExceptionNr < 0)
1084  {
1085  for (ExceptionNr = 0; ExceptionNr < (LONG)RTL_NUMBER_OF(KdbEnterConditions); ExceptionNr++)
1086  {
1087  if (ExceptionNr == 1 || ExceptionNr == 8 ||
1088  ExceptionNr == 9 || ExceptionNr == 15) /* Reserved exceptions */
1089  {
1090  continue;
1091  }
1092 
1093  KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1] = Condition;
1094  }
1095  }
1096  else
1097  {
1098  if (ExceptionNr >= (LONG)RTL_NUMBER_OF(KdbEnterConditions) ||
1099  ExceptionNr == 1 || ExceptionNr == 8 || /* Do not allow changing of the debug */
1100  ExceptionNr == 9 || ExceptionNr == 15) /* trap or reserved exceptions */
1101  {
1102  return FALSE;
1103  }
1104 
1105  KdbEnterConditions[ExceptionNr][FirstChance ? 0 : 1] = Condition;
1106  }
1107 
1108  return TRUE;
1109 }
#define TRUE
Definition: numbers.c:17
static KDB_ENTER_CONDITION KdbEnterConditions[][2]
Definition: kdb.c:58
long LONG
Definition: pedump.c:60
IN ULONG IN UCHAR Condition
#define LONG
Definition: msvc.h:36
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define FALSE
Definition: numbers.c:16
VOID NTAPI KdbpStackSwitchAndCall ( IN PVOID  NewStack,
IN VOID(*)(VOID Function 
)

Referenced by KdbpInternalEnter().

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.

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

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. */
98  CurrentProcess = PsGetCurrentProcess();
99 
100  if(!CurrentProcess || !CurrentProcess->Peb || !CurrentProcess->Peb->Ldr)
101  return FALSE;
102 
103  return KdbpSymSearchModuleList(CurrentProcess->Peb->Ldr->InLoadOrderModuleList.Flink,
104  &CurrentProcess->Peb->Ldr->InLoadOrderModuleList,
105  &Count,
106  Address,
107  Name,
108  Index,
109  pLdrEntry);
110 }
PVOID ULONG Address
Definition: oprghdlr.h:14
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
#define TRUE
Definition: numbers.c:17
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
_Must_inspect_result_ _In_ ULONG Index
Definition: fltkernel.h:1824
long LONG
Definition: pedump.c:60
#define PsGetCurrentProcess
Definition: psfuncs.h:17
struct _PEB * Peb
Definition: pstypes.h:1221
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
ULONG CurrentProcess
Definition: shell.c:125
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
#define FALSE
Definition: numbers.c:16
CHAR KdbpTryGetCharKeyboard ( PULONG  ScanCode,
ULONG  Retry 
)

Definition at line 104 of file kdb_keyboard.c.

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

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:1590
ULONG ScanCode
Definition: api.c:39
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
unsigned char BOOLEAN
#define kbd_read_input()
Definition: kdb_keyboard.c:35
#define kbd_read_status()
Definition: kdb_keyboard.c:36
UCHAR byte_t
Definition: kdb_keyboard.c:57
#define c
Definition: ke_i.h:80
CHAR KdbpTryGetCharSerial ( ULONG  Retry)

Definition at line 19 of file kdb_serial.c.

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

20 {
21  CHAR Result = -1;
22 
23  if (Retry == 0)
24  while (!KdPortGetByteEx(&SerialPortInfo, (PUCHAR)&Result));
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

Variable Documentation

PEPROCESS KdbCurrentProcess

Definition at line 47 of file kdb.c.

Referenced by KdbpCmdProc(), KdbpCmdThread(), and KdbpInsertBreakPoint().

PETHREAD KdbCurrentThread

Definition at line 49 of file kdb.c.

Referenced by KdbpCmdProc(), and KdbpCmdThread().

PKDB_KTRAP_FRAME KdbCurrentTrapFrame
ULONG KdbDebugState
PCHAR KdbInitFileBuffer

Definition at line 118 of file kdb_cli.c.

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

LONG KdbLastBreakPointNr

Definition at line 42 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdBreakPointList().

ULONG KdbNumSingleSteps

Definition at line 43 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().

BOOLEAN KdbSingleStepOver

Definition at line 44 of file kdb.c.

Referenced by KdbEnterDebuggerException(), and KdbpCmdStep().