ReactOS  0.4.11-dev-195-gef016bf
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 1173 of file kdb.c.

Referenced by KdbpCmdProc().

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;
1188  ObDereferenceObject(Process);
1189  if (Entry == &KdbCurrentProcess->ThreadListHead)
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 
1197  return KdbpAttachToThread(Thread->Cid.UniqueThread);
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
#define FALSE
Definition: types.h:117
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
CLIENT_ID Cid
Definition: pstypes.h:1059
_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:2468
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
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.

Referenced by KdbpAttachToProcess(), and KdbpCmdThread().

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 
1106  if (KeIsExecutingDpc() && Process != KdbCurrentProcess)
1107  {
1108  KdbpPrint("Cannot attach to thread within another process while executing a DPC.\n");
1109  ObDereferenceObject(Thread);
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  {
1153  KeStackAttachProcess(&Process->Pcb, &KdbApcState);
1154  }
1155 
1157  }
1158 
1159  ObDereferenceObject(Thread);
1160  return TRUE;
1161 }
#define TRUE
Definition: types.h:120
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: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
#define FALSE
Definition: types.h:117
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:24
_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:2468
KPROCESS Pcb
Definition: pstypes.h:1193
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
VOID KdbpCliInit ( VOID  )

Called when KDB is initialized.

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

Definition at line 3583 of file kdb_cli.c.

3584 {
3585  NTSTATUS Status;
3589  FILE_STANDARD_INFORMATION FileStdInfo;
3590  HANDLE hFile = NULL;
3591  INT FileSize;
3592  PCHAR FileBuffer;
3593  ULONG OldEflags;
3594 
3595  /* Initialize the object attributes */
3596  RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3597  InitializeObjectAttributes(&ObjectAttributes, &FileName, 0, NULL, NULL);
3598 
3599  /* Open the file */
3600  Status = ZwOpenFile(&hFile, FILE_READ_DATA | SYNCHRONIZE,
3601  &ObjectAttributes, &Iosb, 0,
3604  if (!NT_SUCCESS(Status))
3605  {
3606  DPRINT("Could not open \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3607  return;
3608  }
3609 
3610  /* Get the size of the file */
3611  Status = ZwQueryInformationFile(hFile, &Iosb, &FileStdInfo, sizeof (FileStdInfo),
3613  if (!NT_SUCCESS(Status))
3614  {
3615  ZwClose(hFile);
3616  DPRINT("Could not query size of \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3617  return;
3618  }
3619  FileSize = FileStdInfo.EndOfFile.u.LowPart;
3620 
3621  /* Allocate memory for the file */
3622  FileBuffer = ExAllocatePool(PagedPool, FileSize + 1); /* add 1 byte for terminating '\0' */
3623  if (!FileBuffer)
3624  {
3625  ZwClose(hFile);
3626  DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize);
3627  return;
3628  }
3629 
3630  /* Load file into memory */
3631  Status = ZwReadFile(hFile, NULL, NULL, NULL, &Iosb, FileBuffer, FileSize, NULL, NULL);
3632  ZwClose(hFile);
3633 
3634  if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
3635  {
3636  ExFreePool(FileBuffer);
3637  DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3638  return;
3639  }
3640 
3641  FileSize = min(FileSize, (INT)Iosb.Information);
3642  FileBuffer[FileSize] = '\0';
3643 
3644  /* Enter critical section */
3645  OldEflags = __readeflags();
3646  _disable();
3647 
3648  /* Interpret the init file... */
3650  KdbEnter();
3652 
3653  /* Leave critical section */
3654  __writeeflags(OldEflags);
3655 
3656  ExFreePool(FileBuffer);
3657 }
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)
static SIZE_T FileSize
Definition: cabinet.c:52
static PUCHAR FileBuffer
Definition: cabinet.c:50
int32_t INT
Definition: typedefs.h:56
#define STATUS_END_OF_FILE
Definition: shellext.h:50
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1560
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:416
LARGE_INTEGER EndOfFile
Definition: nt_native.h:948
void DPRINT(...)
Definition: polytest.cpp:61
LONG NTSTATUS
Definition: precomp.h:26
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
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:1087
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1555
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#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
DWORD *typedef HANDLE
Definition: winlogon.h:61
#define min(a, b)
Definition: monoChain.cc:55
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
struct _LARGE_INTEGER::@2192 u
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:121
#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 3534 of file kdb_cli.c.

Referenced by KdbEnterDebuggerException().

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

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3456 of file kdb_cli.c.

Referenced by KdbpCallMainLoop(), and KdbpCliInterpretInitFile().

3458 {
3459  static CHAR Command[1024];
3460  BOOLEAN Continue;
3461 
3462  if (EnteredOnSingleStep)
3463  {
3465  {
3466  KdbpPrint("<%x>", KdbCurrentTrapFrame->Tf.Eip);
3467  }
3468 
3469  KdbpPrint(": ");
3471  {
3472  KdbpPrint("<INVALID>");
3473  }
3474  KdbpPrint("\n");
3475  }
3476 
3477  /* Flush the input buffer */
3479  {
3480  while (KdbpTryGetCharSerial(1) != -1);
3481  }
3482  else
3483  {
3484  ULONG ScanCode;
3485  while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
3486  }
3487 
3488  /* Main loop */
3489  do
3490  {
3491  /* Reset the number of rows/cols printed */
3493 
3494  /* Print the prompt */
3495  KdbpPrint("kdb:> ");
3496 
3497  /* Read a command and remember it */
3498  KdbpReadCommand(Command, sizeof (Command));
3499  KdbpCommandHistoryAppend(Command);
3500 
3501  /* Reset the number of rows/cols printed and output aborted state */
3504 
3505  /* Call the command */
3506  Continue = KdbpDoCommand(Command);
3508  }
3509  while (Continue);
3510 }
DWORD *typedef PVOID
Definition: winlogon.h:61
static VOID KdbpReadCommand(OUT PCHAR Buffer, IN ULONG Size)
Reads a line of user-input.
Definition: kdb_cli.c:3122
static VOID KdbpCommandHistoryAppend(IN PCHAR Command)
Appends a command to the command history.
Definition: kdb_cli.c:3048
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:114
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3394
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:115
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
unsigned char BOOLEAN
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:116
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:106
volatile int Continue
Definition: gdblib.c:102
ULONG Eip
Definition: ketypes.h:265
KTRAP_FRAME Tf
Definition: kdb.h:14
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:2468
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 3517 of file kdb_cli.c.

3519 {
3520  if (!KdbBreakOnModuleLoad)
3521  return;
3522 
3523  KdbpPrint("Module %wZ loaded.\n", Name);
3525 }
static BOOLEAN KdbBreakOnModuleLoad
Definition: kdb_cli.c:107
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
#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:2468
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.

Referenced by KdbEnterDebuggerException(), and KdbpCmdEnableDisableClearBreakPoint().

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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
BOOLEAN KdbpDisableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Disables a breakpoint.
Definition: kdb.c:924
#define FALSE
Definition: types.h:117
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2468
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 924 of file kdb.c.

Referenced by KdbpCmdEnableDisableClearBreakPoint(), and KdbpDeleteBreakPoint().

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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
static ULONG KdbSwBreakPointCount
Definition: kdb.c:35
static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]
Definition: kdb.c:38
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
static NTSTATUS KdbpOverwriteInstruction(IN PEPROCESS Process, IN ULONG_PTR Address, IN UCHAR NewInst, OUT PUCHAR OldInst OPTIONAL)
Overwrites the instruction at Address with NewInst and stores the old instruction in *OldInst...
Definition: kdb.c:210
smooth NULL
Definition: ftsmooth.c:416
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
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:2468
Status
Definition: gdiplustypes.h:24
#define MAXULONG
Definition: typedefs.h:250
KTRAP_FRAME Tf
Definition: kdb.h:14
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
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:416
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 757 of file kdb.c.

Referenced by KdbpCmdEnableDisableClearBreakPoint(), and KdbpInsertBreakPoint().

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 
839  ASSERT(i < KDB_MAXIMUM_HW_BREAKPOINT_COUNT);
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
static ULONG KdbSwBreakPointCount
Definition: kdb.c:35
int32_t INT
Definition: typedefs.h:56
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
#define FALSE
Definition: types.h:117
static NTSTATUS KdbpOverwriteInstruction(IN PEPROCESS Process, IN ULONG_PTR Address, IN UCHAR NewInst, OUT PUCHAR OldInst OPTIONAL)
Overwrites the instruction at Address with NewInst and stores the old instruction in *OldInst...
Definition: kdb.c:210
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
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:2468
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:14
static KDB_KTRAP_FRAME KdbTrapFrame
Definition: kdb.c:52
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 464 of file kdb.c.

Referenced by KdbpCmdBreakPointList().

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
PVOID ULONG Address
Definition: oprghdlr.h:14
Type
Definition: Type.h:6
BOOLEAN Global
Definition: kdb.h:43
PCHAR ConditionExpression
Definition: kdb.h:45
UNICODE_STRING Global
Definition: symlink.c:37
#define FALSE
Definition: types.h:117
ULONG_PTR Address
Definition: kdb.h:42
UINTN Size
Definition: acefiex.h:555
union _KDB_BREAKPOINT::@1734 Data
struct _KDB_BREAKPOINT::@1734::@1735 Hw
PEPROCESS Process
Definition: kdb.h:44
#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: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 1704 of file kdb.c.

Referenced by KdInitSystem().

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

Referenced by KdbpCmdSet().

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
#define FALSE
Definition: types.h:117
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
BOOLEAN NTAPI KdbpGetHexNumber ( IN PCHAR  pszNum,
OUT ULONG_PTR pulValue 
)

Definition at line 419 of file kdb_cli.c.

422 {
423  char *endptr;
424 
425  /* Skip optional '0x' prefix */
426  if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
427  pszNum += 2;
428 
429  /* Make a number from the string (hex) */
430  *pulValue = strtoul(pszNum, &endptr, 16);
431 
432  return (*endptr == '\0');
433 }
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:416
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 437 of file kdb.c.

Referenced by KdbpCmdBreakPointList().

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

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

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 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TAG_KDBG
Definition: kdb.h:7
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
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
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
ULONG_PTR Address
Definition: kdb.h:42
PVOID Condition
Definition: kdb.h:46
IN ULONG IN UCHAR Condition
UINTN Size
Definition: acefiex.h:555
BOOLEAN KdbpEnableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Enables a breakpoint.
Definition: kdb.c:757
union _KDB_BREAKPOINT::@1734 Data
#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:2468
struct _KDB_BREAKPOINT::@1734::@1735 Hw
PEPROCESS Process
Definition: kdb.h:44
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
BOOLEAN Enabled
Definition: kdb.h:41
static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]
Definition: kdb.c:34
return STATUS_SUCCESS
Definition: btrfs.c:2710
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 2468 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().

2471 {
2472  static CHAR Buffer[4096];
2473  static BOOLEAN TerminalInitialized = FALSE;
2474  static BOOLEAN TerminalConnected = FALSE;
2475  static BOOLEAN TerminalReportsSize = TRUE;
2476  CHAR c = '\0';
2477  PCHAR p, p2;
2478  ULONG Length;
2479  ULONG i, j;
2480  LONG RowsPrintedByTerminal;
2481  ULONG ScanCode;
2482  va_list ap;
2483 
2484  /* Check if the user has aborted output of the current command */
2485  if (KdbOutputAborted)
2486  return;
2487 
2488  /* Initialize the terminal */
2489  if (!TerminalInitialized)
2490  {
2491  DbgPrint("\x1b[7h"); /* Enable linewrap */
2492 
2493  /* Query terminal type */
2494  /*DbgPrint("\x1b[Z");*/
2495  DbgPrint("\x05");
2496 
2497  TerminalInitialized = TRUE;
2498  Length = 0;
2499  KeStallExecutionProcessor(100000);
2500 
2501  for (;;)
2502  {
2503  c = KdbpTryGetCharSerial(5000);
2504  if (c == -1)
2505  break;
2506 
2507  Buffer[Length++] = c;
2508  if (Length >= (sizeof (Buffer) - 1))
2509  break;
2510  }
2511 
2512  Buffer[Length] = '\0';
2513  if (Length > 0)
2514  TerminalConnected = TRUE;
2515  }
2516 
2517  /* Get number of rows and columns in terminal */
2518  if ((KdbNumberOfRowsTerminal < 0) || (KdbNumberOfColsTerminal < 0) ||
2519  (KdbNumberOfRowsPrinted) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
2520  {
2521  if ((KdbDebugState & KD_DEBUG_KDSERIAL) && TerminalConnected && TerminalReportsSize)
2522  {
2523  /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
2524  TerminalReportsSize = FALSE;
2525  KeStallExecutionProcessor(100000);
2526  DbgPrint("\x1b[18t");
2527  c = KdbpTryGetCharSerial(5000);
2528 
2529  if (c == KEY_ESC)
2530  {
2531  c = KdbpTryGetCharSerial(5000);
2532  if (c == '[')
2533  {
2534  Length = 0;
2535 
2536  for (;;)
2537  {
2538  c = KdbpTryGetCharSerial(5000);
2539  if (c == -1)
2540  break;
2541 
2542  Buffer[Length++] = c;
2543  if (isalpha(c) || Length >= (sizeof (Buffer) - 1))
2544  break;
2545  }
2546 
2547  Buffer[Length] = '\0';
2548  if (Buffer[0] == '8' && Buffer[1] == ';')
2549  {
2550  for (i = 2; (i < Length) && (Buffer[i] != ';'); i++);
2551 
2552  if (Buffer[i] == ';')
2553  {
2554  Buffer[i++] = '\0';
2555 
2556  /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
2557  KdbNumberOfRowsTerminal = strtoul(Buffer + 2, NULL, 0);
2558  KdbNumberOfColsTerminal = strtoul(Buffer + i, NULL, 0);
2559  TerminalReportsSize = TRUE;
2560  }
2561  }
2562  }
2563  /* Clear further characters */
2564  while ((c = KdbpTryGetCharSerial(5000)) != -1);
2565  }
2566  }
2567 
2568  if (KdbNumberOfRowsTerminal <= 0)
2569  {
2570  /* Set number of rows to the default. */
2571  KdbNumberOfRowsTerminal = 23; //24; //Mna.: 23 for SCREEN debugport
2572  }
2573  else if (KdbNumberOfColsTerminal <= 0)
2574  {
2575  /* Set number of cols to the default. */
2576  KdbNumberOfColsTerminal = 75; //80; //Mna.: 75 for SCREEN debugport
2577  }
2578  }
2579 
2580  /* Get the string */
2581  va_start(ap, Format);
2582  Length = _vsnprintf(Buffer, sizeof (Buffer) - 1, Format, ap);
2583  Buffer[Length] = '\0';
2584  va_end(ap);
2585 
2586  p = Buffer;
2587  while (p[0] != '\0')
2588  {
2589  i = strcspn(p, "\n");
2590 
2591  /* Calculate the number of lines which will be printed in the terminal
2592  * when outputting the current line
2593  */
2594  if (i > 0)
2595  RowsPrintedByTerminal = (i + KdbNumberOfColsPrinted - 1) / KdbNumberOfColsTerminal;
2596  else
2597  RowsPrintedByTerminal = 0;
2598 
2599  if (p[i] == '\n')
2600  RowsPrintedByTerminal++;
2601 
2602  /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
2603 
2604  /* Display a prompt if we printed one screen full of text */
2605  if (KdbNumberOfRowsTerminal > 0 &&
2606  (LONG)(KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
2607  {
2609 
2610  if (KdbNumberOfColsPrinted > 0)
2611  DbgPrint("\n");
2612 
2613  DbgPrint("--- Press q to abort, any other key to continue ---");
2614  RowsPrintedByTerminal++; /* added by Mna. */
2615 
2616  if (KdbDebugState & KD_DEBUG_KDSERIAL)
2617  c = KdbpGetCharSerial();
2618  else
2619  c = KdbpGetCharKeyboard(&ScanCode);
2620 
2621  if (c == '\r')
2622  {
2623  /* Try to read '\n' which might follow '\r' - if \n is not received here
2624  * it will be interpreted as "return" when the next command should be read.
2625  */
2626  if (KdbDebugState & KD_DEBUG_KDSERIAL)
2627  c = KdbpTryGetCharSerial(5);
2628  else
2629  c = KdbpTryGetCharKeyboard(&ScanCode, 5);
2630  }
2631 
2632  DbgPrint("\n");
2633  if (c == 'q')
2634  {
2636  return;
2637  }
2638 
2641  }
2642 
2643  /* Insert a NUL after the line and print only the current line. */
2644  if (p[i] == '\n' && p[i + 1] != '\0')
2645  {
2646  c = p[i + 1];
2647  p[i + 1] = '\0';
2648  }
2649  else
2650  {
2651  c = '\0';
2652  }
2653 
2654  /* Remove escape sequences from the line if there's no terminal connected */
2655  if (!TerminalConnected)
2656  {
2657  while ((p2 = strrchr(p, '\x1b'))) /* Look for escape character */
2658  {
2659  if (p2[1] == '[')
2660  {
2661  j = 2;
2662  while (!isalpha(p2[j++]));
2663  strcpy(p2, p2 + j);
2664  }
2665  else
2666  {
2667  strcpy(p2, p2 + 1);
2668  }
2669  }
2670  }
2671 
2672  DbgPrint("%s", p);
2673 
2674  if (c != '\0')
2675  p[i + 1] = c;
2676 
2677  /* Set p to the start of the next line and
2678  * remember the number of rows/cols printed
2679  */
2680  p += i;
2681  if (p[0] == '\n')
2682  {
2683  p++;
2685  }
2686  else
2687  {
2688  ASSERT(p[0] == '\0');
2690  }
2691 
2692  KdbNumberOfRowsPrinted += RowsPrintedByTerminal;
2693  }
2694 }
signed char * PCHAR
Definition: retypes.h:7
#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
#define TRUE
Definition: types.h:120
ULONG ScanCode
Definition: api.c:39
ULONG KdbDebugState
Definition: kdb.c:45
#define DbgPrint
Definition: loader.c:25
#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 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)
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
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:114
const GLfloat * p2
Definition: s_aatritemp.h:44
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define va_end(ap)
Definition: acmsvcex.h:90
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:115
long LONG
Definition: pedump.c:60
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:117
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
unsigned char BOOLEAN
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:116
const GLubyte * c
Definition: glext.h:8905
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:118
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:119
VOID UINTN Length
Definition: acefiex.h:744
#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
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
#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
static struct @1737 RpnStack
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID RpnpDumpStack(IN PRPN_STACK Stack)
Dumps the given RPN stack content.
Definition: kdb_expr.c:238
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
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
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
static struct @1737 RpnStack
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
#define FALSE
Definition: types.h:117
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
#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
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 1734 of file kdb.c.

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

1738 {
1739  BOOLEAN Result = TRUE;
1740 
1741  switch (Bytes)
1742  {
1743  case 1:
1744  case 2:
1745  case 4:
1746  case 8:
1747  Result = KdpSafeReadMemory((ULONG_PTR)Src, Bytes, Dest);
1748  break;
1749 
1750  default:
1751  {
1752  ULONG_PTR Start, End, Write;
1753 
1754  for (Start = (ULONG_PTR)Src,
1755  End = Start + Bytes,
1756  Write = (ULONG_PTR)Dest;
1757  Result && (Start < End);
1758  Start++, Write++)
1759  if (!KdpSafeReadMemory(Start, 1, (PVOID)Write))
1760  Result = FALSE;
1761 
1762  break;
1763  }
1764  }
1765 
1766  return Result ? STATUS_SUCCESS : STATUS_ACCESS_VIOLATION;
1767 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TRUE
Definition: types.h:120
_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
static BOOL Write(PBYTE Address, PBYTE Data, SIZE_T Size)
Definition: vmhorizon.c:15
uint32_t ULONG_PTR
Definition: typedefs.h:63
BOOLEAN NTAPI KdpSafeReadMemory(ULONG_PTR Addr, LONG Len, PVOID Value)
Definition: kdmemsup.c:157
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
Definition: partlist.h:32
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS KdbpSafeWriteMemory ( OUT PVOID  Dest,
IN PVOID  Src,
IN ULONG  Bytes 
)

Definition at line 1770 of file kdb.c.

Referenced by KdbpOverwriteInstruction().

1774 {
1775  BOOLEAN Result = TRUE;
1776  ULONG_PTR Start, End, Write;
1777 
1778  for (Start = (ULONG_PTR)Src,
1779  End = Start + Bytes,
1780  Write = (ULONG_PTR)Dest;
1781  Result && (Start < End);
1782  Start++, Write++)
1783  if (!KdpSafeWriteMemory(Write, 1, *((PCHAR)Start)))
1784  Result = FALSE;
1785 
1786  return Result ? STATUS_SUCCESS : STATUS_ACCESS_VIOLATION;
1787 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
_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
static BOOL Write(PBYTE Address, PBYTE Data, SIZE_T Size)
Definition: vmhorizon.c:15
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
Definition: partlist.h:32
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
return STATUS_SUCCESS
Definition: btrfs.c:2710
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.

Referenced by KdbpCmdSet(), and KdbpGetCommandLineSettings().

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
#define FALSE
Definition: types.h:117
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
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 }
#define TRUE
Definition: types.h:120
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
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define PsGetCurrentProcess
Definition: psfuncs.h:17
struct _PEB * Peb
Definition: pstypes.h:1275
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
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
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:1668
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 121 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().