ReactOS  r75907
kdb_cli.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kdb_cli.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define KEY_BS   8
 
#define KEY_ESC   27
 
#define KEY_DEL   127
 
#define KEY_SCAN_UP   72
 
#define KEY_SCAN_DOWN   80
 
#define KEYSC_END   0x004f
 
#define KEYSC_PAGEUP   0x0049
 
#define KEYSC_PAGEDOWN   0x0051
 
#define KEYSC_HOME   0x0047
 
#define KEYSC_ARROWUP   0x0048
 
#define KDB_ENTER_CONDITION_TO_STRING(cond)
 
#define KDB_ACCESS_TYPE_TO_STRING(type)
 
#define NPX_STATE_TO_STRING(state)
 

Functions

static BOOLEAN KdbpCmdEvalExpression (ULONG Argc, PCHAR Argv[])
 Evaluates an expression and displays the result. More...
 
static BOOLEAN KdbpCmdDisassembleX (ULONG Argc, PCHAR Argv[])
 Disassembles 10 instructions at eip or given address or displays 16 dwords from memory at given address. More...
 
static BOOLEAN KdbpCmdRegs (ULONG Argc, PCHAR Argv[])
 Displays CPU registers. More...
 
static BOOLEAN KdbpCmdBackTrace (ULONG Argc, PCHAR Argv[])
 Displays a backtrace. More...
 
static BOOLEAN KdbpCmdContinue (ULONG Argc, PCHAR Argv[])
 Continues execution of the system/leaves KDB. More...
 
static BOOLEAN KdbpCmdStep (ULONG Argc, PCHAR Argv[])
 Continues execution of the system/leaves KDB. More...
 
static BOOLEAN KdbpCmdBreakPointList (ULONG Argc, PCHAR Argv[])
 Lists breakpoints. More...
 
static BOOLEAN KdbpCmdEnableDisableClearBreakPoint (ULONG Argc, PCHAR Argv[])
 Enables, disables or clears a breakpoint. More...
 
static BOOLEAN KdbpCmdBreakPoint (ULONG Argc, PCHAR Argv[])
 Sets a software or hardware (memory) breakpoint at the given address. More...
 
static BOOLEAN KdbpCmdThread (ULONG Argc, PCHAR Argv[])
 Lists threads or switches to another thread context. More...
 
static BOOLEAN KdbpCmdProc (ULONG Argc, PCHAR Argv[])
 Lists processes or switches to another process context. More...
 
static BOOLEAN KdbpCmdMod (ULONG Argc, PCHAR Argv[])
 Lists loaded modules or the one containing the specified address. More...
 
static BOOLEAN KdbpCmdGdtLdtIdt (ULONG Argc, PCHAR Argv[])
 Displays GDT, LDT or IDTd. More...
 
static BOOLEAN KdbpCmdPcr (ULONG Argc, PCHAR Argv[])
 Displays the KPCR. More...
 
static BOOLEAN KdbpCmdTss (ULONG Argc, PCHAR Argv[])
 Displays the TSS. More...
 
static BOOLEAN KdbpCmdBugCheck (ULONG Argc, PCHAR Argv[])
 Bugchecks the system. More...
 
static BOOLEAN KdbpCmdReboot (ULONG Argc, PCHAR Argv[])
 
static BOOLEAN KdbpCmdFilter (ULONG Argc, PCHAR Argv[])
 Display list of active debug channels. More...
 
static BOOLEAN KdbpCmdSet (ULONG Argc, PCHAR Argv[])
 Sets or displays a config variables value. More...
 
static BOOLEAN KdbpCmdHelp (ULONG Argc, PCHAR Argv[])
 Displays help screen. More...
 
static BOOLEAN KdbpCmdDmesg (ULONG Argc, PCHAR Argv[])
 Display debug messages on screen, with paging. More...
 
BOOLEAN ExpKdbgExtPool (ULONG Argc, PCHAR Argv[])
 
static BOOLEAN KdbpGetComponentId (IN PCCH ComponentName, OUT PULONG ComponentId)
 Transform a component name to an integer. More...
 
static BOOLEAN KdbpEvaluateExpression (IN PCHAR Expression, IN LONG ErrOffset, OUT PULONGLONG Result)
 Evaluates an expression... More...
 
BOOLEAN NTAPI KdbpGetHexNumber (IN PCHAR pszNum, OUT ULONG_PTR *pulValue)
 
static BOOLEAN KdbpTrapFrameFromPrevTss (PKTRAP_FRAME TrapFrame)
 
VOID __cdecl KiTrap02 (VOID)
 
VOID FASTCALL KiTrap03Handler (IN PKTRAP_FRAME)
 
VOID __cdecl KiTrap08 (VOID)
 
VOID __cdecl KiTrap09 (VOID)
 
static BOOLEAN KdbpInNmiOrDoubleFaultHandler (ULONG_PTR Address)
 
VOID KdbpPager (IN PCHAR Buffer, IN ULONG BufLength)
 Prints the given string with, page by page. More...
 
VOID KdbpPrint (IN PCHAR Format, IN...OPTIONAL)
 Prints the given string with printf-like formatting. More...
 
voidmemrchr (const void *s, int c, size_t n)
 
PCHAR CountOnePageUp (PCHAR Buffer, ULONG BufLength, PCHAR pCurPos)
 Calculate pointer position for N lines upper of current position. More...
 
static VOID KdbpCommandHistoryAppend (IN PCHAR Command)
 Appends a command to the command history. More...
 
static VOID KdbpReadCommand (OUT PCHAR Buffer, IN ULONG Size)
 Reads a line of user-input. More...
 
BOOLEAN NTAPI KdbRegisterCliCallback (PVOID Callback, BOOLEAN Deregister)
 
static BOOLEAN KdbpInvokeCliCallbacks (IN PCHAR Command, IN ULONG Argc, IN PCH Argv[])
 Invokes registered CLI callbacks until one of them handled the Command. More...
 
static BOOLEAN KdbpDoCommand (IN PCHAR Command)
 Parses command line and executes command if found. 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 KdbpCliInit (VOID)
 Called when KDB is initialized. More...
 
VOID NTAPI KdpSerialDebugPrint (LPSTR Message, ULONG Length)
 
ULONG NTAPI KdpPrompt (IN LPSTR InString, IN USHORT InStringLength, OUT LPSTR OutString, IN USHORT OutStringLength)
 

Variables

static PKDBG_CLI_ROUTINE KdbCliCallbacks [10]
 
static BOOLEAN KdbUseIntelSyntax = FALSE
 
static BOOLEAN KdbBreakOnModuleLoad = FALSE
 
static CHAR KdbCommandHistoryBuffer [2048]
 
static PCHAR KdbCommandHistory [sizeof(KdbCommandHistoryBuffer)/8] = { NULL }
 
static LONG KdbCommandHistoryBufferIndex = 0
 
static LONG KdbCommandHistoryIndex = 0
 
static ULONG KdbNumberOfRowsPrinted = 0
 
static ULONG KdbNumberOfColsPrinted = 0
 
static BOOLEAN KdbOutputAborted = FALSE
 
static BOOLEAN KdbRepeatLastCommand = FALSE
 
static LONG KdbNumberOfRowsTerminal = -1
 
static LONG KdbNumberOfColsTerminal = -1
 
PCHAR KdbInitFileBuffer = NULL
 
BOOLEAN KdbpBugCheckRequested = FALSE
 
volatile BOOLEAN KdbpIsInDmesgMode
 
const ULONG KdpDmesgBufferSize
 
PCHAR KdpDmesgBuffer
 
volatile ULONG KdpDmesgCurrentPosition
 
volatile ULONG KdpDmesgFreeBytes
 
volatile ULONG KdbDmesgTotalWritten
 
struct {
   PCHAR   Name
 
   PCHAR   Syntax
 
   PCHAR   Help
 
   BOOLEAN(*   Fn )(ULONG Argc, PCHAR Argv[])
 
KdbDebuggerCommands []
 
STRING KdpPromptString = RTL_CONSTANT_STRING("kdb:> ")
 
KSPIN_LOCK KdpSerialSpinLock
 

Macro Definition Documentation

#define KDB_ACCESS_TYPE_TO_STRING (   type)
Value:
((type) == KdbAccessRead ? "read" : \
((type) == KdbAccessWrite ? "write" : \
((type) == KdbAccessReadWrite ? "rdwr" : "exec")))
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545

Definition at line 57 of file kdb_cli.c.

Referenced by KdbpCmdBreakPointList().

#define KDB_ENTER_CONDITION_TO_STRING (   cond)
Value:
((cond) == KdbDoNotEnter ? "never" : \
((cond) == KdbEnterAlways ? "always" : \
((cond) == KdbEnterFromKmode ? "kmode" : "umode")))

Definition at line 52 of file kdb_cli.c.

Referenced by KdbpCmdSet().

#define KEY_BS   8

Definition at line 38 of file kdb_cli.c.

Referenced by KdbpReadCommand().

#define KEY_DEL   127

Definition at line 40 of file kdb_cli.c.

Referenced by KdbpReadCommand().

#define KEY_ESC   27

Definition at line 39 of file kdb_cli.c.

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

#define KEY_SCAN_DOWN   80

Definition at line 43 of file kdb_cli.c.

Referenced by KdbpReadCommand().

#define KEY_SCAN_UP   72

Definition at line 42 of file kdb_cli.c.

Referenced by KdbpReadCommand().

#define KEYSC_ARROWUP   0x0048

Definition at line 50 of file kdb_cli.c.

Referenced by KdbpPager().

#define KEYSC_END   0x004f

Definition at line 46 of file kdb_cli.c.

Referenced by KdbpPager().

#define KEYSC_HOME   0x0047

Definition at line 49 of file kdb_cli.c.

Referenced by KdbpPager().

#define KEYSC_PAGEDOWN   0x0051

Definition at line 48 of file kdb_cli.c.

#define KEYSC_PAGEUP   0x0049

Definition at line 47 of file kdb_cli.c.

Referenced by KdbpPager().

#define NDEBUG

Definition at line 33 of file kdb_cli.c.

#define NPX_STATE_TO_STRING (   state)
Value:
((state) == NPX_STATE_LOADED ? "Loaded" : \
((state) == NPX_STATE_NOT_LOADED ? "Not loaded" : "Unknown"))
#define NPX_STATE_NOT_LOADED
Definition: asm.h:262
static int state
Definition: maze.c:121
#define NPX_STATE_LOADED
Definition: asm.h:263

Definition at line 62 of file kdb_cli.c.

Referenced by KdbpCmdThread().

Function Documentation

PCHAR CountOnePageUp ( PCHAR  Buffer,
ULONG  BufLength,
PCHAR  pCurPos 
)

Calculate pointer position for N lines upper of current position.

Parameters
BufferCharacters buffer to operate on.
BufLengthBuffer size.
Note
Calculate pointer position for N lines upper of current displaying position within the given buffer.

Used by KdbpPager(). Now N lines count is hardcoded to KdbNumberOfRowsTerminal.

Definition at line 2724 of file kdb_cli.c.

Referenced by KdbpPager().

2725 {
2726  PCHAR p;
2727  // p0 is initial guess of Page Start
2729  PCHAR p0 = pCurPos - p0len;
2730  PCHAR prev_p = p0, p1;
2731  ULONG j;
2732 
2733  if (pCurPos < Buffer)
2734  pCurPos = Buffer;
2735  ASSERT(pCurPos <= Buffer + BufLength);
2736 
2737  p = memrchr(p0, '\n', p0len);
2738  if (NULL == p)
2739  p = p0;
2740  for (j = KdbNumberOfRowsTerminal; j--; )
2741  {
2742  int linesCnt;
2743  p1 = memrchr(p0, '\n', p-p0);
2744  prev_p = p;
2745  p = p1;
2746  if (NULL == p)
2747  {
2748  p = prev_p;
2749  if (NULL == p)
2750  p = p0;
2751  break;
2752  }
2753  linesCnt = (KdbNumberOfColsTerminal+prev_p-p-2) / KdbNumberOfColsTerminal;
2754  if (linesCnt > 1)
2755  j -= linesCnt-1;
2756  }
2757 
2758  ASSERT(p != 0);
2759  ++p;
2760  return p;
2761 }
signed char * PCHAR
Definition: retypes.h:7
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
void * memrchr(const void *s, int c, size_t n)
Definition: kdb_cli.c:2696
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
smooth NULL
Definition: ftsmooth.c:513
const GLfloat * p0
Definition: s_aatritemp.h:42
Definition: bufpool.h:45
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:115
UINTN VOID * Buffer
Definition: acefiex.h:370
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:116
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
const GLfloat * p1
Definition: s_aatritemp.h:43
BOOLEAN ExpKdbgExtPool ( ULONG  Argc,
PCHAR  Argv[] 
)
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 }
signed char * PCHAR
Definition: retypes.h:7
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
struct _LARGE_INTEGER::@2052 u
static PUCHAR FileBuffer
Definition: cabinet.c:49
int32_t INT
Definition: typedefs.h:57
#define STATUS_END_OF_FILE
Definition: shellext.h:48
_Must_inspect_result_ _Out_ PIO_STATUS_BLOCK Iosb
Definition: fltkernel.h:1761
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1456
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:513
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:492
#define SYNCHRONIZE
Definition: nt_native.h:61
_In_ HANDLE hFile
Definition: mswsock.h:90
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
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c: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 }
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: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
#define FALSE
Definition: types.h:117
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
#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
#define FALSE
Definition: types.h:117
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
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
_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:2462
static BOOLEAN KdbpCmdBackTrace ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays a backtrace.

Definition at line 1058 of file kdb_cli.c.

1061 {
1062  ULONG ul;
1063  ULONGLONG Result = 0;
1066  KTRAP_FRAME TrapFrame;
1067 
1068  if (Argc >= 2)
1069  {
1070  /* Check for [L count] part */
1071  ul = 0;
1072 
1073  if (strcmp(Argv[Argc-2], "L") == 0)
1074  {
1075  ul = strtoul(Argv[Argc-1], NULL, 0);
1076  if (ul > 0)
1077  {
1078  Argc -= 2;
1079  }
1080  }
1081  else if (Argv[Argc-1][0] == 'L')
1082  {
1083  ul = strtoul(Argv[Argc-1] + 1, NULL, 0);
1084  if (ul > 0)
1085  {
1086  Argc--;
1087  }
1088  }
1089 
1090  /* Put the remaining arguments back together */
1091  Argc--;
1092  for (ul = 1; ul < Argc; ul++)
1093  {
1094  Argv[ul][strlen(Argv[ul])] = ' ';
1095  }
1096  Argc++;
1097  }
1098 
1099  /* Check if frame addr or thread id is given. */
1100  if (Argc > 1)
1101  {
1102  if (Argv[1][0] == '*')
1103  {
1104  Argv[1]++;
1105 
1106  /* Evaluate the expression */
1107  if (!KdbpEvaluateExpression(Argv[1], sizeof("kdb:> ")-1 + (Argv[1]-Argv[0]), &Result))
1108  return TRUE;
1109 
1110  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1111  KdbpPrint("Warning: Address %I64x is beeing truncated\n",Result);
1112 
1113  Frame = (ULONG_PTR)Result;
1114  }
1115  else
1116  {
1117  KdbpPrint("Thread backtrace not supported yet!\n");
1118  return TRUE;
1119  }
1120  }
1121  else
1122  {
1123  KdbpPrint("Eip:\n");
1124 
1125  /* Try printing the function at EIP */
1127  KdbpPrint("<%08x>\n", KdbCurrentTrapFrame->Tf.Eip);
1128  else
1129  KdbpPrint("\n");
1130  }
1131 
1132  TrapFrame = KdbCurrentTrapFrame->Tf;
1133  KdbpPrint("Frames:\n");
1134 
1135  for (;;)
1136  {
1137  BOOLEAN GotNextFrame;
1138 
1139  if (Frame == 0)
1140  break;
1141 
1142  if (!NT_SUCCESS(KdbpSafeReadMemory(&Address, (PVOID)(Frame + sizeof(ULONG_PTR)), sizeof (ULONG_PTR))))
1143  {
1144  KdbpPrint("Couldn't access memory at 0x%p!\n", Frame + sizeof(ULONG_PTR));
1145  break;
1146  }
1147 
1148  if ((GotNextFrame = NT_SUCCESS(KdbpSafeReadMemory(&Frame, (PVOID)Frame, sizeof (ULONG_PTR)))))
1149  TrapFrame.Ebp = Frame;
1150 
1151  /* Print the location of the call instruction */
1152  if (!KdbSymPrintAddress((PVOID)(Address - 5), &TrapFrame))
1153  KdbpPrint("<%08x>\n", Address);
1154  else
1155  KdbpPrint("\n");
1156 
1157  if (KdbOutputAborted) break;
1158 
1159  if (Address == 0)
1160  break;
1161 
1162  if (KdbpInNmiOrDoubleFaultHandler(Address))
1163  {
1164  if ((GotNextFrame = KdbpTrapFrameFromPrevTss(&TrapFrame)))
1165  {
1166  Address = TrapFrame.Eip;
1167  Frame = TrapFrame.Ebp;
1168 
1169  if (!KdbSymPrintAddress((PVOID)Address, &TrapFrame))
1170  KdbpPrint("<%08x>\n", Address);
1171  else
1172  KdbpPrint("\n");
1173  }
1174  }
1175 
1176  if (!GotNextFrame)
1177  {
1178  KdbpPrint("Couldn't access memory at 0x%p!\n", Frame);
1179  break;
1180  }
1181  }
1182 
1183  return TRUE;
1184 }
DWORD *typedef PVOID
Definition: winlogon.h:52
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PKTRAP_FRAME Context)
Print address...
Definition: kdb_symbols.c:148
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static BOOLEAN KdbpEvaluateExpression(IN PCHAR Expression, IN LONG ErrOffset, OUT PULONGLONG Result)
Evaluates an expression...
Definition: kdb_cli.c:386
_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
smooth NULL
Definition: ftsmooth.c:513
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
unsigned char BOOLEAN
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:113
uint64_t ULONGLONG
Definition: typedefs.h:66
static BOOLEAN KdbpInNmiOrDoubleFaultHandler(ULONG_PTR Address)
Definition: kdb_cli.c:1048
ULONG Eip
Definition: ketypes.h:265
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1761
KTRAP_FRAME Tf
Definition: kdb.h:14
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ULONG_PTR
Definition: config.h:101
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
static BOOLEAN KdbpTrapFrameFromPrevTss(PKTRAP_FRAME TrapFrame)
Definition: kdb_cli.c:976
ULONG Ebp
Definition: ketypes.h:263
static BOOLEAN KdbpCmdBreakPoint ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Sets a software or hardware (memory) breakpoint at the given address.

Definition at line 1368 of file kdb_cli.c.

1369 {
1370  ULONGLONG Result = 0;
1373  UCHAR Size = 0;
1374  KDB_ACCESS_TYPE AccessType = 0;
1375  ULONG AddressArgIndex, i;
1376  LONG ConditionArgIndex;
1377  BOOLEAN Global = TRUE;
1378 
1379  if (Argv[0][2] == 'x') /* software breakpoint */
1380  {
1381  if (Argc < 2)
1382  {
1383  KdbpPrint("bpx: Address argument required.\n");
1384  return TRUE;
1385  }
1386 
1387  AddressArgIndex = 1;
1388  Type = KdbBreakPointSoftware;
1389  }
1390  else /* memory breakpoint */
1391  {
1392  ASSERT(Argv[0][2] == 'm');
1393 
1394  if (Argc < 2)
1395  {
1396  KdbpPrint("bpm: Access type argument required (one of r, w, rw, x)\n");
1397  return TRUE;
1398  }
1399 
1400  if (_stricmp(Argv[1], "x") == 0)
1401  AccessType = KdbAccessExec;
1402  else if (_stricmp(Argv[1], "r") == 0)
1403  AccessType = KdbAccessRead;
1404  else if (_stricmp(Argv[1], "w") == 0)
1405  AccessType = KdbAccessWrite;
1406  else if (_stricmp(Argv[1], "rw") == 0)
1407  AccessType = KdbAccessReadWrite;
1408  else
1409  {
1410  KdbpPrint("bpm: Unknown access type '%s'\n", Argv[1]);
1411  return TRUE;
1412  }
1413 
1414  if (Argc < 3)
1415  {
1416  KdbpPrint("bpm: %s argument required.\n", AccessType == KdbAccessExec ? "Address" : "Memory size");
1417  return TRUE;
1418  }
1419 
1420  AddressArgIndex = 3;
1421  if (_stricmp(Argv[2], "byte") == 0)
1422  Size = 1;
1423  else if (_stricmp(Argv[2], "word") == 0)
1424  Size = 2;
1425  else if (_stricmp(Argv[2], "dword") == 0)
1426  Size = 4;
1427  else if (AccessType == KdbAccessExec)
1428  {
1429  Size = 1;
1430  AddressArgIndex--;
1431  }
1432  else
1433  {
1434  KdbpPrint("bpm: Unknown memory size '%s'\n", Argv[2]);
1435  return TRUE;
1436  }
1437 
1438  if (Argc <= AddressArgIndex)
1439  {
1440  KdbpPrint("bpm: Address argument required.\n");
1441  return TRUE;
1442  }
1443 
1444  Type = KdbBreakPointHardware;
1445  }
1446 
1447  /* Put the arguments back together */
1448  ConditionArgIndex = -1;
1449  for (i = AddressArgIndex; i < (Argc-1); i++)
1450  {
1451  if (strcmp(Argv[i+1], "IF") == 0) /* IF found */
1452  {
1453  ConditionArgIndex = i + 2;
1454  if ((ULONG)ConditionArgIndex >= Argc)
1455  {
1456  KdbpPrint("%s: IF requires condition expression.\n", Argv[0]);
1457  return TRUE;
1458  }
1459 
1460  for (i = ConditionArgIndex; i < (Argc-1); i++)
1461  Argv[i][strlen(Argv[i])] = ' ';
1462 
1463  break;
1464  }
1465 
1466  Argv[i][strlen(Argv[i])] = ' ';
1467  }
1468 
1469  /* Evaluate the address expression */
1470  if (!KdbpEvaluateExpression(Argv[AddressArgIndex],
1471  sizeof("kdb:> ")-1 + (Argv[AddressArgIndex]-Argv[0]),
1472  &Result))
1473  {
1474  return TRUE;
1475  }
1476 
1477  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1478  KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv[0],Result);
1479 
1480  Address = (ULONG_PTR)Result;
1481 
1482  KdbpInsertBreakPoint(Address, Type, Size, AccessType,
1483  (ConditionArgIndex < 0) ? NULL : Argv[ConditionArgIndex],
1484  Global, NULL);
1485 
1486  return TRUE;
1487 }
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
Type
Definition: Type.h:6
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static BOOLEAN KdbpEvaluateExpression(IN PCHAR Expression, IN LONG ErrOffset, OUT PULONGLONG Result)
Evaluates an expression...
Definition: kdb_cli.c:386
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
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.
Definition: kdb.c:560
#define _stricmp
Definition: cat.c:22
UNICODE_STRING Global
Definition: symlink.c:37
uint32_t ULONG_PTR
Definition: typedefs.h:64
GLenum GLclampf GLint i
Definition: glfuncs.h:14
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:513
UINTN Size
Definition: acefiex.h:555
unsigned char BOOLEAN
uint64_t ULONGLONG
Definition: typedefs.h:66
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE
unsigned char UCHAR
Definition: xmlstorage.h:181
enum _KDB_BREAKPOINT_TYPE KDB_BREAKPOINT_TYPE
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ULONG_PTR
Definition: config.h:101
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
static BOOLEAN KdbpCmdBreakPointList ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists breakpoints.

Definition at line 1230 of file kdb_cli.c.

1233 {
1234  LONG l;
1235  ULONG_PTR Address = 0;
1237  KDB_ACCESS_TYPE AccessType = 0;
1238  UCHAR Size = 0;
1239  UCHAR DebugReg = 0;
1240  BOOLEAN Enabled = FALSE;
1241  BOOLEAN Global = FALSE;
1243  PCHAR str1, str2, ConditionExpr, GlobalOrLocal;
1244  CHAR Buffer[20];
1245 
1246  l = KdbpGetNextBreakPointNr(0);
1247  if (l < 0)
1248  {
1249  KdbpPrint("No breakpoints.\n");
1250  return TRUE;
1251  }
1252 
1253  KdbpPrint("Breakpoints:\n");
1254  do
1255  {
1256  if (!KdbpGetBreakPointInfo(l, &Address, &Type, &Size, &AccessType, &DebugReg,
1257  &Enabled, &Global, &Process, &ConditionExpr))
1258  {
1259  continue;
1260  }
1261 
1262  if (l == KdbLastBreakPointNr)
1263  {
1264  str1 = "\x1b[1m*";
1265  str2 = "\x1b[0m";
1266  }
1267  else
1268  {
1269  str1 = " ";
1270  str2 = "";
1271  }
1272 
1273  if (Global)
1274  {
1275  GlobalOrLocal = " global";
1276  }
1277  else
1278  {
1279  GlobalOrLocal = Buffer;
1280  sprintf(Buffer, " PID 0x%08lx",
1281  (ULONG)(Process ? Process->UniqueProcessId : INVALID_HANDLE_VALUE));
1282  }
1283 
1284  if (Type == KdbBreakPointSoftware || Type == KdbBreakPointTemporary)
1285  {
1286  KdbpPrint(" %s%03d BPX 0x%08x%s%s%s%s%s\n",
1287  str1, l, Address,
1288  Enabled ? "" : " disabled",
1289  GlobalOrLocal,
1290  ConditionExpr ? " IF " : "",
1291  ConditionExpr ? ConditionExpr : "",
1292  str2);
1293  }
1294  else if (Type == KdbBreakPointHardware)
1295  {
1296  if (!Enabled)
1297  {
1298  KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s disabled%s%s%s%s\n", str1, l, Address,
1299  KDB_ACCESS_TYPE_TO_STRING(AccessType),
1300  Size == 1 ? "byte" : (Size == 2 ? "word" : "dword"),
1301  GlobalOrLocal,
1302  ConditionExpr ? " IF " : "",
1303  ConditionExpr ? ConditionExpr : "",
1304  str2);
1305  }
1306  else
1307  {
1308  KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s DR%d%s%s%s%s\n", str1, l, Address,
1309  KDB_ACCESS_TYPE_TO_STRING(AccessType),
1310  Size == 1 ? "byte" : (Size == 2 ? "word" : "dword"),
1311  DebugReg,
1312  GlobalOrLocal,
1313  ConditionExpr ? " IF " : "",
1314  ConditionExpr ? ConditionExpr : "",
1315  str2);
1316  }
1317  }
1318  }
1319  while ((l = KdbpGetNextBreakPointNr(l+1)) >= 0);
1320 
1321  return TRUE;
1322 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
Type
Definition: Type.h:6
#define KDB_ACCESS_TYPE_TO_STRING(type)
Definition: kdb_cli.c:57
char CHAR
Definition: xmlstorage.h:175
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
UNICODE_STRING Global
Definition: symlink.c:37
HANDLE UniqueProcessId
Definition: pstypes.h:1199
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:513
Definition: bufpool.h:45
UINTN Size
Definition: acefiex.h:555
r l[0]
Definition: byte_order.h:167
unsigned char BOOLEAN
LONG KdbpGetNextBreakPointNr(IN ULONG Start OPTIONAL)
Gets the number of the next breakpoint >= Start.
Definition: kdb.c:464
UINTN VOID * Buffer
Definition: acefiex.h:370
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE
unsigned char UCHAR
Definition: xmlstorage.h:181
enum _KDB_BREAKPOINT_TYPE KDB_BREAKPOINT_TYPE
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.
Definition: kdb.c:491
LONG KdbLastBreakPointNr
Definition: kdb.c:42
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
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
static BOOLEAN KdbpCmdBugCheck ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Bugchecks the system.

Definition at line 2171 of file kdb_cli.c.

2174 {
2175  /* Set the flag and quit looping */
2177 
2178  return FALSE;
2179 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN KdbpBugCheckRequested
Definition: kdb_cli.c:119
static BOOLEAN KdbpCmdContinue ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Continues execution of the system/leaves KDB.

Definition at line 1189 of file kdb_cli.c.

1192 {
1193  /* Exit the main loop */
1194  return FALSE;
1195 }
#define FALSE
Definition: types.h:117
static BOOLEAN KdbpCmdDisassembleX ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Disassembles 10 instructions at eip or given address or displays 16 dwords from memory at given address.

Definition at line 715 of file kdb_cli.c.

718 {
719  ULONG Count;
720  ULONG ul;
721  INT i;
722  ULONGLONG Result = 0;
724  LONG InstLen;
725 
726  if (Argv[0][0] == 'x') /* display memory */
727  Count = 16;
728  else /* disassemble */
729  Count = 10;
730 
731  if (Argc >= 2)
732  {
733  /* Check for [L count] part */
734  ul = 0;
735  if (strcmp(Argv[Argc-2], "L") == 0)
736  {
737  ul = strtoul(Argv[Argc-1], NULL, 0);
738  if (ul > 0)
739  {
740  Count = ul;
741  Argc -= 2;
742  }
743  }
744  else if (Argv[Argc-1][0] == 'L')
745  {
746  ul = strtoul(Argv[Argc-1] + 1, NULL, 0);
747  if (ul > 0)
748  {
749  Count = ul;
750  Argc--;
751  }
752  }
753 
754  /* Put the remaining arguments back together */
755  Argc--;
756  for (ul = 1; ul < Argc; ul++)
757  {
758  Argv[ul][strlen(Argv[ul])] = ' ';
759  }
760  Argc++;
761  }
762 
763  /* Evaluate the expression */
764  if (Argc > 1)
765  {
766  if (!KdbpEvaluateExpression(Argv[1], sizeof("kdb:> ")-1 + (Argv[1]-Argv[0]), &Result))
767  return TRUE;
768 
769  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
770  KdbpPrint("Warning: Address %I64x is beeing truncated\n",Result);
771 
772  Address = (ULONG_PTR)Result;
773  }
774  else if (Argv[0][0] == 'x')
775  {
776  KdbpPrint("x: Address argument required.\n");
777  return TRUE;
778  }
779 
780  if (Argv[0][0] == 'x')
781  {
782  /* Display dwords */
783  ul = 0;
784 
785  while (Count > 0)
786  {
787  if (!KdbSymPrintAddress((PVOID)Address, NULL))
788  KdbpPrint("<%x>:", Address);
789  else
790  KdbpPrint(":");
791 
792  i = min(4, Count);
793  Count -= i;
794 
795  while (--i >= 0)
796  {
797  if (!NT_SUCCESS(KdbpSafeReadMemory(&ul, (PVOID)Address, sizeof(ul))))
798  KdbpPrint(" ????????");
799  else
800  KdbpPrint(" %08x", ul);
801 
802  Address += sizeof(ul);
803  }
804 
805  KdbpPrint("\n");
806  }
807  }
808  else
809  {
810  /* Disassemble */
811  while (Count-- > 0)
812  {
813  if (!KdbSymPrintAddress((PVOID)Address, NULL))
814  KdbpPrint("<%08x>: ", Address);
815  else
816  KdbpPrint(": ");
817 
818  InstLen = KdbpDisassemble(Address, KdbUseIntelSyntax);
819  if (InstLen < 0)
820  {
821  KdbpPrint("<INVALID>\n");
822  return TRUE;
823  }
824 
825  KdbpPrint("\n");
826  Address += InstLen;
827  }
828  }
829 
830  return TRUE;
831 }
DWORD *typedef PVOID
Definition: winlogon.h:52
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PKTRAP_FRAME Context)
Print address...
Definition: kdb_symbols.c:148
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static BOOLEAN KdbpEvaluateExpression(IN PCHAR Expression, IN LONG ErrOffset, OUT PULONGLONG Result)
Evaluates an expression...
Definition: kdb_cli.c:386
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
_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
int32_t INT
Definition: typedefs.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:64
GLenum GLclampf GLint i
Definition: glfuncs.h:14
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:513
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
uint64_t ULONGLONG
Definition: typedefs.h:66
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:103
ULONG Eip
Definition: ketypes.h:265
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1761
KTRAP_FRAME Tf
Definition: kdb.h:14
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ULONG_PTR
Definition: config.h:101
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
static BOOLEAN KdbpCmdDmesg ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Display debug messages on screen, with paging.

Keys for per-page view: Home, End, PageUp, Arrow Up, PageDown, all others are as PageDown.

Definition at line 2203 of file kdb_cli.c.

2206 {
2207  ULONG beg, end;
2208 
2209  KdbpIsInDmesgMode = TRUE; /* Toggle logging flag */
2210  if (!KdpDmesgBuffer)
2211  {
2212  KdbpPrint("Dmesg: error, buffer is not allocated! /DEBUGPORT=SCREEN kernel param required for dmesg.\n");
2213  return TRUE;
2214  }
2215 
2216  KdbpPrint("*** Dmesg *** TotalWritten=%lu, BufferSize=%lu, CurrentPosition=%lu\n",
2218 
2219  // Pass data to the pager:
2221  beg = (end + KdpDmesgFreeBytes) % KdpDmesgBufferSize;
2222 
2223  // no roll-overs, and overwritten=lost bytes
2225  {
2226  // show buffer (KdpDmesgBuffer + beg, num)
2228  }
2229  else
2230  {
2231  // show 2 buffers: (KdpDmesgBuffer + beg, KdpDmesgBufferSize - beg)
2232  // and: (KdpDmesgBuffer, end)
2234  KdbpPrint("*** Dmesg: buffer rollup ***\n");
2235  KdbpPager(KdpDmesgBuffer, end);
2236  }
2237  KdbpPrint("*** Dmesg: end of output ***\n");
2238 
2239  KdbpIsInDmesgMode = FALSE; /* Toggle logging flag */
2240 
2241  return TRUE;
2242 }
PCHAR KdpDmesgBuffer
Definition: kdio.c:41
volatile BOOLEAN KdbpIsInDmesgMode
Definition: kdio.c:46
#define TRUE
Definition: types.h:120
const ULONG KdpDmesgBufferSize
Definition: kdio.c:40
GLuint GLuint end
Definition: gl.h:1545
volatile ULONG KdbDmesgTotalWritten
Definition: kdio.c:44
#define FALSE
Definition: types.h:117
volatile ULONG KdpDmesgCurrentPosition
Definition: kdio.c:42
VOID KdbpPager(IN PCHAR Buffer, IN ULONG BufLength)
Prints the given string with, page by page.
Definition: kdb_cli.c:2776
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
volatile ULONG KdpDmesgFreeBytes
Definition: kdio.c:43
static BOOLEAN KdbpCmdEnableDisableClearBreakPoint ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Enables, disables or clears a breakpoint.

Definition at line 1327 of file kdb_cli.c.

1330 {
1331  PCHAR pend;
1332  ULONG BreakPointNr;
1333 
1334  if (Argc < 2)
1335  {
1336  KdbpPrint("%s: argument required\n", Argv[0]);
1337  return TRUE;
1338  }
1339 
1340  pend = Argv[1];
1341  BreakPointNr = strtoul(Argv[1], &pend, 0);
1342  if (pend == Argv[1] || *pend != '\0')
1343  {
1344  KdbpPrint("%s: integer argument required\n", Argv[0]);
1345  return TRUE;
1346  }
1347 
1348  if (Argv[0][1] == 'e') /* enable */
1349  {
1350  KdbpEnableBreakPoint(BreakPointNr, NULL);
1351  }
1352  else if (Argv [0][1] == 'd') /* disable */
1353  {
1354  KdbpDisableBreakPoint(BreakPointNr, NULL);
1355  }
1356  else /* clear */
1357  {
1358  ASSERT(Argv[0][1] == 'c');
1359  KdbpDeleteBreakPoint(BreakPointNr, NULL);
1360  }
1361 
1362  return TRUE;
1363 }
BOOLEAN KdbpDeleteBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Deletes a breakpoint.
Definition: kdb.c:681
signed char * PCHAR
Definition: retypes.h:7
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
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:951
smooth NULL
Definition: ftsmooth.c:513
BOOLEAN KdbpEnableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Enables a breakpoint.
Definition: kdb.c:784
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
static BOOLEAN KdbpCmdEvalExpression ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Evaluates an expression and displays the result.

Definition at line 432 of file kdb_cli.c.

435 {
436  ULONG i, len;
437  ULONGLONG Result = 0;
438  ULONG ul;
439  LONG l = 0;
440  BOOLEAN Ok;
441 
442  if (Argc < 2)
443  {
444  KdbpPrint("?: Argument required\n");
445  return TRUE;
446  }
447 
448  /* Put the arguments back together */
449  Argc--;
450  for (i = 1; i < Argc; i++)
451  {
452  len = strlen(Argv[i]);
453  Argv[i][len] = ' ';
454  }
455 
456  /* Evaluate the expression */
457  Ok = KdbpEvaluateExpression(Argv[1], sizeof("kdb:> ")-1 + (Argv[1]-Argv[0]), &Result);
458  if (Ok)
459  {
460  if (Result > 0x00000000ffffffffLL)
461  {
462  if (Result & 0x8000000000000000LL)
463  KdbpPrint("0x%016I64x %20I64u %20I64d\n", Result, Result, Result);
464  else
465  KdbpPrint("0x%016I64x %20I64u\n", Result, Result);
466  }
467  else
468  {
469  ul = (ULONG)Result;
470 
471  if (ul <= 0xff && ul >= 0x80)
472  l = (LONG)((CHAR)ul);
473  else if (ul <= 0xffff && ul >= 0x8000)
474  l = (LONG)((SHORT)ul);
475  else
476  l = (LONG)ul;
477 
478  if (l < 0)
479  KdbpPrint("0x%08lx %10lu %10ld\n", ul, ul, l);
480  else
481  KdbpPrint("0x%08lx %10lu\n", ul, ul);
482  }
483  }
484 
485  return TRUE;
486 }
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static BOOLEAN KdbpEvaluateExpression(IN PCHAR Expression, IN LONG ErrOffset, OUT PULONGLONG Result)
Evaluates an expression...
Definition: kdb_cli.c:386
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
GLenum GLclampf GLint i
Definition: glfuncs.h:14
long LONG
Definition: pedump.c:60
short SHORT
Definition: pedump.c:59
r l[0]
Definition: byte_order.h:167
unsigned char BOOLEAN
uint64_t ULONGLONG
Definition: typedefs.h:66
#define LONG
Definition: msvc.h:36
GLenum GLsizei len
Definition: glext.h:6722
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
static BOOLEAN KdbpCmdFilter ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Display list of active debug channels.

Definition at line 629 of file kdb_cli.c.

632 {
634  ULONG set = DPFLTR_MASK, clear = DPFLTR_MASK;
635  PCHAR pend;
636  LPCSTR opt, p;
637 
638  static struct
639  {
640  LPCSTR Name;
641  ULONG Level;
642  }
643  debug_classes[] =
644  {
645  { "error", 1 << DPFLTR_ERROR_LEVEL },
646  { "warning", 1 << DPFLTR_WARNING_LEVEL },
647  { "trace", 1 << DPFLTR_TRACE_LEVEL },
648  { "info", 1 << DPFLTR_INFO_LEVEL },
649  };
650 
651  for (i = 1; i < Argc; i++)
652  {
653  opt = Argv[i];
654  p = opt + strcspn(opt, "+-");
655  if (!p[0]) p = opt; /* assume it's a debug channel name */
656 
657  if (p > opt)
658  {
659  for (j = 0; j < sizeof(debug_classes) / sizeof(debug_classes[0]); j++)
660  {
662  if (len != (p - opt))
663  continue;
664  if (_strnicmp(opt, debug_classes[j].Name, len) == 0) /* found it */
665  {
666  if (*p == '+')
667  set |= debug_classes[j].Level;
668  else
669  clear |= debug_classes[j].Level;
670  break;
671  }
672  }
673  if (j == sizeof(debug_classes) / sizeof(debug_classes[0]))
674  {
675  Level = strtoul(opt, &pend, 0);
676  if (pend != p)
677  {
678  KdbpPrint("filter: bad class name '%.*s'\n", p - opt, opt);
679  continue;
680  }
681  if (*p == '+')
682  set |= Level;
683  else
684  clear |= Level;
685  }
686  }
687  else
688  {
689  if (*p == '-')
690  clear = MAXULONG;
691  else
692  set = MAXULONG;
693  }
694  if (*p == '+' || *p == '-')
695  p++;
696 
697  if (!KdbpGetComponentId(p, &ComponentId))
698  {
699  KdbpPrint("filter: '%s' is not a valid component name!\n", p);
700  return TRUE;
701  }
702 
703  /* Get current mask value */
704  NtSetDebugFilterState(ComponentId, set, TRUE);
705  NtSetDebugFilterState(ComponentId, clear, FALSE);
706  }
707 
708  return TRUE;
709 }
signed char * PCHAR
Definition: retypes.h:7
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
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
#define DPFLTR_INFO_LEVEL
Definition: kdtypes.h:33
PCHAR Name
Definition: kdb_cli.c:132
#define DPFLTR_MASK
Definition: kdtypes.h:34
static BOOLEAN KdbpGetComponentId(IN PCCH ComponentName, OUT PULONG ComponentId)
Transform a component name to an integer.
Definition: kdb_cli.c:200
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
#define DPFLTR_WARNING_LEVEL
Definition: kdtypes.h:31
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
_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)
const char * LPCSTR
Definition: xmlstorage.h:183
static const char *const debug_classes[]
Definition: debug.c:50
#define DPFLTR_ERROR_LEVEL
Definition: shimdbg.c:14
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
GLenum GLsizei len
Definition: glext.h:6722
#define MAXULONG
Definition: typedefs.h:251
ULONG_PTR SIZE_T
Definition: typedefs.h:79
unsigned int ULONG
Definition: retypes.h:1
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1256
GLfloat GLfloat p
Definition: glext.h:8902
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
Definition: _set.h:46
#define DPFLTR_TRACE_LEVEL
Definition: kdtypes.h:32
NTSTATUS NTAPI NtSetDebugFilterState(IN ULONG ComponentId, IN ULONG Level, IN BOOLEAN State)
Definition: kdmain.c:402
static BOOLEAN KdbpCmdGdtLdtIdt ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays GDT, LDT or IDTd.

Definition at line 1882 of file kdb_cli.c.

1885 {
1886  KDESCRIPTOR Reg;
1887  ULONG SegDesc[2];
1888  ULONG SegBase;
1889  ULONG SegLimit;
1890  PCHAR SegType;
1891  USHORT SegSel;
1892  UCHAR Type, Dpl;
1893  INT i;
1894  ULONG ul;
1895 
1896  if (Argv[0][0] == 'i')
1897  {
1898  /* Read IDTR */
1899  __sidt(&Reg.Limit);
1900 
1901  if (Reg.Limit < 7)
1902  {
1903  KdbpPrint("Interrupt descriptor table is empty.\n");
1904  return TRUE;
1905  }
1906 
1907  KdbpPrint("IDT Base: 0x%08x Limit: 0x%04x\n", Reg.Base, Reg.Limit);
1908  KdbpPrint(" Idx Type Seg. Sel. Offset DPL\n");
1909 
1910  for (i = 0; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8)
1911  {
1912  if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)(Reg.Base + i), sizeof(SegDesc))))
1913  {
1914  KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg.Base + i);
1915  return TRUE;
1916  }
1917 
1918  Dpl = ((SegDesc[1] >> 13) & 3);
1919  if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */
1920  SegType = "TASKGATE";
1921  else if ((SegDesc[1] & 0x1fe0) == 0x0e00) /* 32 bit Interrupt gate */
1922  SegType = "INTGATE32";
1923  else if ((SegDesc[1] & 0x1fe0) == 0x0600) /* 16 bit Interrupt gate */
1924  SegType = "INTGATE16";
1925  else if ((SegDesc[1] & 0x1fe0) == 0x0f00) /* 32 bit Trap gate */
1926  SegType = "TRAPGATE32";
1927  else if ((SegDesc[1] & 0x1fe0) == 0x0700) /* 16 bit Trap gate */
1928  SegType = "TRAPGATE16";
1929  else
1930  SegType = "UNKNOWN";
1931 
1932  if ((SegDesc[1] & (1 << 15)) == 0) /* not present */
1933  {
1934  KdbpPrint(" %03d %-10s [NP] [NP] %02d\n",
1935  i / 8, SegType, Dpl);
1936  }
1937  else if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */
1938  {
1939  SegSel = SegDesc[0] >> 16;
1940  KdbpPrint(" %03d %-10s 0x%04x %02d\n",
1941  i / 8, SegType, SegSel, Dpl);
1942  }
1943  else
1944  {
1945  SegSel = SegDesc[0] >> 16;
1946  SegBase = (SegDesc[1] & 0xffff0000) | (SegDesc[0] & 0x0000ffff);
1947  KdbpPrint(" %03d %-10s 0x%04x 0x%08x %02d\n",
1948  i / 8, SegType, SegSel, SegBase, Dpl);
1949  }
1950  }
1951  }
1952  else
1953  {
1954  ul = 0;
1955 
1956  if (Argv[0][0] == 'g')
1957  {
1958  /* Read GDTR */
1959  Ke386GetGlobalDescriptorTable(&Reg.Limit);
1960  i = 8;
1961  }
1962  else
1963  {
1964  ASSERT(Argv[0][0] == 'l');
1965 
1966  /* Read LDTR */
1967  Reg.Limit = Ke386GetLocalDescriptorTable();
1968  Reg.Base = 0;
1969  i = 0;
1970  ul = 1 << 2;
1971  }
1972 
1973  if (Reg.Limit < 7)
1974  {
1975  KdbpPrint("%s descriptor table is empty.\n",
1976  Argv[0][0] == 'g' ? "Global" : "Local");
1977  return TRUE;
1978  }
1979 
1980  KdbpPrint("%cDT Base: 0x%08x Limit: 0x%04x\n",
1981  Argv[0][0] == 'g' ? 'G' : 'L', Reg.Base, Reg.Limit);
1982  KdbpPrint(" Idx Sel. Type Base Limit DPL Attribs\n");
1983 
1984  for (; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8)
1985  {
1986  if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)(Reg.Base + i), sizeof(SegDesc))))
1987  {
1988  KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg.Base + i);
1989  return TRUE;
1990  }
1991 
1992  Dpl = ((SegDesc[1] >> 13) & 3);
1993  Type = ((SegDesc[1] >> 8) & 0xf);
1994 
1995  SegBase = SegDesc[0] >> 16;
1996  SegBase |= (SegDesc[1] & 0xff) << 16;
1997  SegBase |= SegDesc[1] & 0xff000000;
1998  SegLimit = SegDesc[0] & 0x0000ffff;
1999  SegLimit |= (SegDesc[1] >> 16) & 0xf;
2000 
2001  if ((SegDesc[1] & (1 << 23)) != 0)
2002  {
2003  SegLimit *= 4096;
2004  SegLimit += 4095;
2005  }
2006  else
2007  {
2008  SegLimit++;
2009  }
2010 
2011  if ((SegDesc[1] & (1 << 12)) == 0) /* System segment */
2012  {
2013  switch (Type)
2014  {
2015  case 1: SegType = "TSS16(Avl)"; break;
2016  case 2: SegType = "LDT"; break;
2017  case 3: SegType = "TSS16(Busy)"; break;
2018  case 4: SegType = "CALLGATE16"; break;
2019  case 5: SegType = "TASKGATE"; break;
2020  case 6: SegType = "INTGATE16"; break;
2021  case 7: SegType = "TRAPGATE16"; break;
2022  case 9: SegType = "TSS32(Avl)"; break;
2023  case 11: SegType = "TSS32(Busy)"; break;
2024  case 12: SegType = "CALLGATE32"; break;
2025  case 14: SegType = "INTGATE32"; break;
2026  case 15: SegType = "INTGATE32"; break;
2027  default: SegType = "UNKNOWN"; break;
2028  }
2029 
2030  if (!(Type >= 1 && Type <= 3) &&
2031  Type != 9 && Type != 11)
2032  {
2033  SegBase = 0;
2034  SegLimit = 0;
2035  }
2036  }
2037  else if ((SegDesc[1] & (1 << 11)) == 0) /* Data segment */
2038  {
2039  if ((SegDesc[1] & (1 << 22)) != 0)
2040  SegType = "DATA32";
2041  else
2042  SegType = "DATA16";
2043  }
2044  else /* Code segment */
2045  {
2046  if ((SegDesc[1] & (1 << 22)) != 0)
2047  SegType = "CODE32";
2048  else
2049  SegType = "CODE16";
2050  }
2051 
2052  if ((SegDesc[1] & (1 << 15)) == 0) /* not present */
2053  {
2054  KdbpPrint(" %03d 0x%04x %-11s [NP] [NP] %02d NP\n",
2055  i / 8, i | Dpl | ul, SegType, Dpl);
2056  }
2057  else
2058  {
2059  KdbpPrint(" %03d 0x%04x %-11s 0x%08x 0x%08x %02d ",
2060  i / 8, i | Dpl | ul, SegType, SegBase, SegLimit, Dpl);
2061 
2062  if ((SegDesc[1] & (1 << 12)) == 0) /* System segment */
2063  {
2064  /* FIXME: Display system segment */
2065  }
2066  else if ((SegDesc[1] & (1 << 11)) == 0) /* Data segment */
2067  {
2068  if ((SegDesc[1] & (1 << 10)) != 0) /* Expand-down */
2069  KdbpPrint(" E");
2070 
2071  KdbpPrint((SegDesc[1] & (1 << 9)) ? " R/W" : " R");
2072 
2073  if ((SegDesc[1] & (1 << 8)) != 0)
2074  KdbpPrint(" A");
2075  }
2076  else /* Code segment */
2077  {
2078  if ((SegDesc[1] & (1 << 10)) != 0) /* Conforming */
2079  KdbpPrint(" C");
2080 
2081  KdbpPrint((SegDesc[1] & (1 << 9)) ? " R/X" : " X");
2082 
2083  if ((SegDesc[1] & (1 << 8)) != 0)
2084  KdbpPrint(" A");
2085  }
2086 
2087  if ((SegDesc[1] & (1 << 20)) != 0)
2088  KdbpPrint(" AVL");
2089 
2090  KdbpPrint("\n");
2091  }
2092  }
2093  }
2094 
2095  return TRUE;
2096 }
DWORD *typedef PVOID
Definition: winlogon.h:52
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
int32_t INT
Definition: typedefs.h:57
PVOID Base
Definition: ketypes.h:486
USHORT Limit
Definition: ketypes.h:485
GLenum GLclampf GLint i
Definition: glfuncs.h:14
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:1813
unsigned char UCHAR
Definition: xmlstorage.h:181
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1761
unsigned short USHORT
Definition: pedump.c:61
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
static BOOLEAN KdbpCmdHelp ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays help screen.

Definition at line 2426 of file kdb_cli.c.

2429 {
2430  ULONG i;
2431 
2432  KdbpPrint("Kernel debugger commands:\n");
2433  for (i = 0; i < RTL_NUMBER_OF(KdbDebuggerCommands); i++)
2434  {
2435  if (!KdbDebuggerCommands[i].Syntax) /* Command group */
2436  {
2437  if (i > 0)
2438  KdbpPrint("\n");
2439 
2440  KdbpPrint("\x1b[7m* %s:\x1b[0m\n", KdbDebuggerCommands[i].Help);
2441  continue;
2442  }
2443 
2444  KdbpPrint(" %-20s - %s\n",
2445  KdbDebuggerCommands[i].Syntax,
2447  }
2448 
2449  return TRUE;
2450 }
#define TRUE
Definition: types.h:120
static const struct @1617 KdbDebuggerCommands[]
GLenum GLclampf GLint i
Definition: glfuncs.h:14
PCHAR Syntax
Definition: kdb_cli.c:133
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
PCHAR Help
Definition: kdb_cli.c:134
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
static BOOLEAN KdbpCmdMod ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists loaded modules or the one containing the specified address.

Definition at line 1818 of file kdb_cli.c.

1821 {
1822  ULONGLONG Result = 0;
1824  PLDR_DATA_TABLE_ENTRY LdrEntry;
1825  BOOLEAN DisplayOnlyOneModule = FALSE;
1826  INT i = 0;
1827 
1828  if (Argc >= 2)
1829  {
1830  /* Put the arguments back together */
1831  Argc--;
1832  while (--Argc >= 1)
1833  Argv[Argc][strlen(Argv[Argc])] = ' ';
1834 
1835  /* Evaluate the expression */
1836  if (!KdbpEvaluateExpression(Argv[1], sizeof("kdb:> ")-1 + (Argv[1]-Argv[0]), &Result))
1837  {
1838  return TRUE;
1839  }
1840 
1841  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1842  KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv[0],Result);
1843 
1844  Address = (ULONG_PTR)Result;
1845 
1846  if (!KdbpSymFindModule((PVOID)Address, NULL, -1, &LdrEntry))
1847  {
1848  KdbpPrint("No module containing address 0x%p found!\n", Address);
1849  return TRUE;
1850  }
1851 
1852  DisplayOnlyOneModule = TRUE;
1853  }
1854  else
1855  {
1856  if (!KdbpSymFindModule(NULL, NULL, 0, &LdrEntry))
1857  {
1858  ULONG_PTR ntoskrnlBase = ((ULONG_PTR)KdbpCmdMod) & 0xfff00000;
1859  KdbpPrint(" Base Size Name\n");
1860  KdbpPrint(" %08x %08x %s\n", ntoskrnlBase, 0, "ntoskrnl.exe");
1861  return TRUE;
1862  }
1863 
1864  i = 1;
1865  }
1866 
1867  KdbpPrint(" Base Size Name\n");
1868  for (;;)
1869  {
1870  KdbpPrint(" %08x %08x %wZ\n", LdrEntry->DllBase, LdrEntry->SizeOfImage, &LdrEntry->BaseDllName);
1871 
1872  if(DisplayOnlyOneModule || !KdbpSymFindModule(NULL, NULL, i++, &LdrEntry))
1873  break;
1874  }
1875 
1876  return TRUE;
1877 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static BOOLEAN KdbpEvaluateExpression(IN PCHAR Expression, IN LONG ErrOffset, OUT PULONGLONG Result)
Evaluates an expression...
Definition: kdb_cli.c:386
ULONG SizeOfImage
Definition: ldrtypes.h:141
_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
int32_t INT
Definition: typedefs.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:64
PVOID DllBase
Definition: btrfs_drv.h:1714
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static BOOLEAN KdbpCmdMod(ULONG Argc, PCHAR Argv[])
Lists loaded modules or the one containing the specified address.
Definition: kdb_cli.c:1818
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:513
unsigned char BOOLEAN
uint64_t ULONGLONG
Definition: typedefs.h:66
Definition: btrfs_drv.h:1710
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:143
#define ULONG_PTR
Definition: config.h:101
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
BOOLEAN KdbpSymFindModule(IN PVOID Address OPTIONAL, IN LPCWSTR Name OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
Find a module...
Definition: kdb_symbols.c:76
static BOOLEAN KdbpCmdPcr ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays the KPCR.

Definition at line 2101 of file kdb_cli.c.

2104 {
2105  PKIPCR Pcr = (PKIPCR)KeGetPcr();
2106 
2107  KdbpPrint("Current PCR is at 0x%08x.\n", (INT)Pcr);
2108  KdbpPrint(" Tib.ExceptionList: 0x%08x\n"
2109  " Tib.StackBase: 0x%08x\n"
2110  " Tib.StackLimit: 0x%08x\n"
2111  " Tib.SubSystemTib: 0x%08x\n"
2112  " Tib.FiberData/Version: 0x%08x\n"
2113  " Tib.ArbitraryUserPointer: 0x%08x\n"
2114  " Tib.Self: 0x%08x\n"
2115  " Self: 0x%08x\n"
2116  " PCRCB: 0x%08x\n"
2117  " Irql: 0x%02x\n"
2118  " IRR: 0x%08x\n"
2119  " IrrActive: 0x%08x\n"
2120  " IDR: 0x%08x\n"
2121  " KdVersionBlock: 0x%08x\n"
2122  " IDT: 0x%08x\n"
2123  " GDT: 0x%08x\n"
2124  " TSS: 0x%08x\n"
2125  " MajorVersion: 0x%04x\n"
2126  " MinorVersion: 0x%04x\n"
2127  " SetMember: 0x%08x\n"
2128  " StallScaleFactor: 0x%08x\n"
2129  " Number: 0x%02x\n"
2130  " L2CacheAssociativity: 0x%02x\n"
2131  " VdmAlert: 0x%08x\n"
2132  " L2CacheSize: 0x%08x\n"
2133  " InterruptMode: 0x%08x\n",
2136  Pcr->NtTib.Self, Pcr->Self, Pcr->Prcb, Pcr->Irql, Pcr->IRR, Pcr->IrrActive,
2137  Pcr->IDR, Pcr->KdVersionBlock, Pcr->IDT, Pcr->GDT, Pcr->TSS,
2138  Pcr->MajorVersion, Pcr->MinorVersion, Pcr->SetMember, Pcr->StallScaleFactor,
2140  Pcr->VdmAlert, Pcr->SecondLevelCacheSize, Pcr->InterruptMode);
2141 
2142  return TRUE;
2143 }
struct _NT_TIB * Self
Definition: compat.h:380
#define TRUE
Definition: types.h:120
ULONG IRR
Definition: ketypes.h:752
UCHAR SecondLevelCacheAssociativity
Definition: ketypes.h:872
USHORT MinorVersion
Definition: ketypes.h:877
struct _KIPCR * PKIPCR
UCHAR Number
Definition: ketypes.h:764
KIRQL Irql
Definition: ketypes.h:871
int32_t INT
Definition: typedefs.h:57
PVOID ArbitraryUserPointer
Definition: compat.h:379
#define KeGetPcr()
Definition: ke.h:25
ULONG VdmAlert
Definition: ketypes.h:767
ULONG StallScaleFactor
Definition: ketypes.h:878
ULONG SecondLevelCacheSize
Definition: ketypes.h:881
KAFFINITY SetMember
Definition: ketypes.h:761
struct _KTSS * TSS
Definition: ketypes.h:758
ULONG InterruptMode
Definition: ketypes.h:771
PVOID FiberData
Definition: compat.h:376
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: compat.h:371
PVOID SubSystemTib
Definition: compat.h:374
KPRCB Prcb
Definition: ketypes.h:889
PVOID KdVersionBlock
Definition: ketypes.h:885
PVOID StackBase
Definition: compat.h:372
PKGDTENTRY GDT
Definition: ketypes.h:757
USHORT MajorVersion
Definition: ketypes.h:876
struct _KPCR * Self
Definition: ketypes.h:863
ULONG IDR
Definition: ketypes.h:754
ULONG IrrActive
Definition: ketypes.h:753
PVOID StackLimit
Definition: compat.h:373
NT_TIB NtTib
Definition: ketypes.h:857
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
PKIDTENTRY IDT
Definition: ketypes.h:756
static BOOLEAN KdbpCmdProc ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists processes or switches to another process context.

Definition at line 1700 of file kdb_cli.c.

1703 {
1706  BOOLEAN ReferencedProcess = FALSE;
1707  PCHAR State, pend, str1, str2;
1708  ULONG ul;
1710 
1711  if (Argc >= 2 && _stricmp(Argv[1], "list") == 0)
1712  {
1713  Entry = PsActiveProcessHead.Flink;
1714  if (!Entry || Entry == &PsActiveProcessHead)
1715  {
1716  KdbpPrint("No processes in the system!\n");
1717  return TRUE;
1718  }
1719 
1720  KdbpPrint(" PID State Filename\n");
1721  do
1722  {
1723  Process = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks);
1724 
1725  if (Process == KdbCurrentProcess)
1726  {
1727  str1 = "\x1b[1m*";
1728  str2 = "\x1b[0m";
1729  }
1730  else
1731  {
1732  str1 = " ";
1733  str2 = "";
1734  }
1735 
1736  State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
1737  ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
1738 
1739  KdbpPrint(" %s0x%08x %-10s %s%s\n",
1740  str1,
1741  Process->UniqueProcessId,
1742  State,
1743  Process->ImageFileName,
1744  str2);
1745 
1746  Entry = Entry->Flink;
1747  }
1748  while(Entry != &PsActiveProcessHead);
1749  }
1750  else if (Argc >= 2 && _stricmp(Argv[1], "attach") == 0)
1751  {
1752  if (Argc < 3)
1753  {
1754  KdbpPrint("process attach: process id argument required!\n");
1755  return TRUE;
1756  }
1757 
1758  ul = strtoul(Argv[2], &pend, 0);
1759  if (Argv[2] == pend)
1760  {
1761  KdbpPrint("process attach: '%s' is not a valid process id!\n", Argv[2]);
1762  return TRUE;
1763  }
1764 
1765  if (!KdbpAttachToProcess((PVOID)ul))
1766  {
1767  return TRUE;
1768  }
1769 
1770  KdbpPrint("Attached to process 0x%08x, thread 0x%08x.\n", (ULONG)ul,
1772  }
1773  else
1774  {
1775  Process = KdbCurrentProcess;
1776 
1777  if (Argc >= 2)
1778  {
1779  ul = strtoul(Argv[1], &pend, 0);
1780  if (Argv[1] == pend)
1781  {
1782  KdbpPrint("proc: '%s' is not a valid process id!\n", Argv[1]);
1783  return TRUE;
1784  }
1785 
1786  if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID)ul, &Process)))
1787  {
1788  KdbpPrint("proc: Invalid process id!\n");
1789  return TRUE;
1790  }
1791 
1792  /* Remember our reference */
1793  ReferencedProcess = TRUE;
1794  }
1795 
1796  State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
1797  ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
1798  KdbpPrint("%s"
1799  " PID: 0x%08x\n"
1800  " State: %s (0x%x)\n"
1801  " Image Filename: %s\n",
1802  (Argc < 2) ? "Current process:\n" : "",
1803  Process->UniqueProcessId,
1804  State, Process->Pcb.State,
1805  Process->ImageFileName);
1806 
1807  /* Release our reference, if any */
1808  if (ReferencedProcess)
1809  ObDereferenceObject(Process);
1810  }
1811 
1812  return TRUE;
1813 }
DWORD *typedef PVOID
Definition: winlogon.h:52
signed char * PCHAR
Definition: retypes.h:7
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
UCHAR State
Definition: ketypes.h:1419
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
LIST_ENTRY PsActiveProcessHead
Definition: process.c:22
#define _stricmp
Definition: cat.c:22
HANDLE UniqueProcessId
Definition: pstypes.h:1199
#define FALSE
Definition: types.h:117
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
unsigned char BOOLEAN
CLIENT_ID Cid
Definition: pstypes.h:1060
HANDLE UniqueThread
Definition: compat.h:475
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
Definition: typedefs.h:118
KPROCESS Pcb
Definition: pstypes.h:1194
BOOLEAN KdbpAttachToProcess(PVOID ProcessId)
Switches to another process/thread context.
Definition: kdb.c:1200
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
enum State_ State
Definition: pofuncs.h:54
_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
CHAR ImageFileName[16]
Definition: pstypes.h:1258
unsigned int ULONG
Definition: retypes.h:1
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
static BOOLEAN KdbpCmdReboot ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Definition at line 2182 of file kdb_cli.c.

2185 {
2186  /* Reboot immediately (we do not return) */
2188  return FALSE;
2189 }
#define FALSE
Definition: types.h:117
VOID NTAPI HalReturnToFirmware(IN FIRMWARE_REENTRY Action)
Definition: reboot.c:22
static BOOLEAN KdbpCmdRegs ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays CPU registers.

Definition at line 836 of file kdb_cli.c.

839 {
841  INT i;
842  static const PCHAR EflagsBits[32] = { " CF", NULL, " PF", " BIT3", " AF", " BIT5",
843  " ZF", " SF", " TF", " IF", " DF", " OF",
844  NULL, NULL, " NT", " BIT15", " RF", " VF",
845  " AC", " VIF", " VIP", " ID", " BIT22",
846  " BIT23", " BIT24", " BIT25", " BIT26",
847  " BIT27", " BIT28", " BIT29", " BIT30",
848  " BIT31" };
849 
850  if (Argv[0][0] == 'r') /* regs */
851  {
852  KdbpPrint("CS:EIP 0x%04x:0x%08x\n"
853  "SS:ESP 0x%04x:0x%08x\n"
854  " EAX 0x%08x EBX 0x%08x\n"
855  " ECX 0x%08x EDX 0x%08x\n"
856  " ESI 0x%08x EDI 0x%08x\n"
857  " EBP 0x%08x\n",
858  Tf->SegCs & 0xFFFF, Tf->Eip,
859  Tf->HardwareSegSs, Tf->HardwareEsp,
860  Tf->Eax, Tf->Ebx,
861  Tf->Ecx, Tf->Edx,
862  Tf->Esi, Tf->Edi,
863  Tf->Ebp);
864  KdbpPrint("EFLAGS 0x%08x ", Tf->EFlags);
865 
866  for (i = 0; i < 32; i++)
867  {
868  if (i == 1)
869  {
870  if ((Tf->EFlags & (1 << 1)) == 0)
871  KdbpPrint(" !BIT1");
872  }
873  else if (i == 12)
874  {
875  KdbpPrint(" IOPL%d", (Tf->EFlags >> 12) & 3);
876  }
877  else if (i == 13)
878  {
879  }
880  else if ((Tf->EFlags & (1 << i)) != 0)
881  {
882  KdbpPrint(EflagsBits[i]);
883  }
884  }
885 
886  KdbpPrint("\n");
887  }
888  else if (Argv[0][0] == 'c') /* cregs */
889  {
890  ULONG Cr0, Cr2, Cr3, Cr4;
891  KDESCRIPTOR Gdtr = {0, 0, 0}, Idtr = {0, 0, 0};
892  USHORT Ldtr;
893  static const PCHAR Cr0Bits[32] = { " PE", " MP", " EM", " TS", " ET", " NE", NULL, NULL,
894  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
895  " WP", NULL, " AM", NULL, NULL, NULL, NULL, NULL,
896  NULL, NULL, NULL, NULL, NULL, " NW", " CD", " PG" };
897  static const PCHAR Cr4Bits[32] = { " VME", " PVI", " TSD", " DE", " PSE", " PAE", " MCE", " PGE",
898  " PCE", " OSFXSR", " OSXMMEXCPT", NULL, NULL, NULL, NULL, NULL,
899  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
900  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
901 
902  Cr0 = KdbCurrentTrapFrame->Cr0;
903  Cr2 = KdbCurrentTrapFrame->Cr2;
904  Cr3 = KdbCurrentTrapFrame->Cr3;
905  Cr4 = KdbCurrentTrapFrame->Cr4;
906 
907  /* Get descriptor table regs */
908  Ke386GetGlobalDescriptorTable(&Gdtr.Limit);
909  Ldtr = Ke386GetLocalDescriptorTable();
910  __sidt(&Idtr.Limit);
911 
912  /* Display the control registers */
913  KdbpPrint("CR0 0x%08x ", Cr0);
914 
915  for (i = 0; i < 32; i++)
916  {
917  if (!Cr0Bits[i])
918  continue;
919 
920  if ((Cr0 & (1 << i)) != 0)
921  KdbpPrint(Cr0Bits[i]);
922  }
923 
924  KdbpPrint("\nCR2 0x%08x\n", Cr2);
925  KdbpPrint("CR3 0x%08x Pagedir-Base 0x%08x %s%s\n", Cr3, (Cr3 & 0xfffff000),
926  (Cr3 & (1 << 3)) ? " PWT" : "", (Cr3 & (1 << 4)) ? " PCD" : "" );
927  KdbpPrint("CR4 0x%08x ", Cr4);
928 
929  for (i = 0; i < 32; i++)
930  {
931  if (!Cr4Bits[i])
932  continue;
933 
934  if ((Cr4 & (1 << i)) != 0)
935  KdbpPrint(Cr4Bits[i]);
936  }
937 
938  /* Display the descriptor table regs */
939  KdbpPrint("\nGDTR Base 0x%08x Size 0x%04x\n", Gdtr.Base, Gdtr.Limit);
940  KdbpPrint("LDTR 0x%04x\n", Ldtr);
941  KdbpPrint("IDTR Base 0x%08x Size 0x%04x\n", Idtr.Base, Idtr.Limit);
942  }
943  else if (Argv[0][0] == 's') /* sregs */
944  {
945  KdbpPrint("CS 0x%04x Index 0x%04x %cDT RPL%d\n",
946  Tf->SegCs & 0xffff, (Tf->SegCs & 0xffff) >> 3,
947  (Tf->SegCs & (1 << 2)) ? 'L' : 'G', Tf->SegCs & 3);
948  KdbpPrint("DS 0x%04x Index 0x%04x %cDT RPL%d\n",
949  Tf->SegDs, Tf->SegDs >> 3, (Tf->SegDs & (1 << 2)) ? 'L' : 'G', Tf->SegDs & 3);
950  KdbpPrint("ES 0x%04x Index 0x%04x %cDT RPL%d\n",
951  Tf->SegEs, Tf->SegEs >> 3, (Tf->SegEs & (1 << 2)) ? 'L' : 'G', Tf->SegEs & 3);
952  KdbpPrint("FS 0x%04x Index 0x%04x %cDT RPL%d\n",
953  Tf->SegFs, Tf->SegFs >> 3, (Tf->SegFs & (1 << 2)) ? 'L' : 'G', Tf->SegFs & 3);
954  KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
955  Tf->SegGs, Tf->SegGs >> 3, (Tf->SegGs & (1 << 2)) ? 'L' : 'G', Tf->SegGs & 3);
956  KdbpPrint("SS 0x%04x Index 0x%04x %cDT RPL%d\n",
957  Tf->HardwareSegSs, Tf->HardwareSegSs >> 3, (Tf->HardwareSegSs & (1 << 2)) ? 'L' : 'G', Tf->HardwareSegSs & 3);
958  }
959  else /* dregs */
960  {
961  ASSERT(Argv[0][0] == 'd');
962  KdbpPrint("DR0 0x%08x\n"
963  "DR1 0x%08x\n"
964  "DR2 0x%08x\n"
965  "DR3 0x%08x\n"
966  "DR6 0x%08x\n"
967  "DR7 0x%08x\n",
968  Tf->Dr0, Tf->Dr1, Tf->Dr2, Tf->Dr3,
969  Tf->Dr6, Tf->Dr7);
970  }
971 
972  return TRUE;
973 }
signed char * PCHAR
Definition: retypes.h:7
ULONG Cr3
Definition: kdb.h:18
#define TRUE
Definition: types.h:120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
ULONG Cr4
Definition: kdb.h:19
USHORT SegFs
Definition: ketypes.h:366
ULONG HardwareSegSs
Definition: ketypes.h:269
ULONG Esi
Definition: ketypes.h:261
int32_t INT
Definition: typedefs.h:57
PVOID Base
Definition: ketypes.h:486
ULONG Edi
Definition: ketypes.h:260
USHORT Limit
Definition: ketypes.h:485
GLenum GLclampf GLint i
Definition: glfuncs.h:14
UINT64 Dr2
Definition: ketypes.h:344
ULONG Eax
Definition: ketypes.h:256
USHORT SegGs
Definition: ketypes.h:367
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:1813
USHORT SegEs
Definition: ketypes.h:365
smooth NULL
Definition: ftsmooth.c:513
USHORT SegCs
Definition: ketypes.h:380
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
ULONG HardwareEsp
Definition: ketypes.h:268
UINT64 Dr6
Definition: ketypes.h:346
UINT64 Dr3
Definition: ketypes.h:345
UINT64 Dr1
Definition: ketypes.h:343
USHORT SegDs
Definition: ketypes.h:364
ULONG Ecx
Definition: ketypes.h:255
ULONG Eip
Definition: ketypes.h:265
UINT64 Dr0
Definition: ketypes.h:342
ULONG Cr0
Definition: kdb.h:15
ULONG Ebx
Definition: ketypes.h:262
unsigned short USHORT
Definition: pedump.c:61
KTRAP_FRAME Tf
Definition: kdb.h:14
unsigned int ULONG
Definition: retypes.h:1
UINT64 Dr7
Definition: ketypes.h:347
ULONG Cr2
Definition: kdb.h:17
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
ULONG EFlags
Definition: ketypes.h:384
ULONG Edx
Definition: ketypes.h:254
ULONG Ebp
Definition: ketypes.h:263
static BOOLEAN KdbpCmdSet ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Sets or displays a config variables value.

Definition at line 2247 of file kdb_cli.c.

2250 {
2251  LONG l;
2252  BOOLEAN First;
2253  PCHAR pend = 0;
2254  KDB_ENTER_CONDITION ConditionFirst = KdbDoNotEnter;
2255  KDB_ENTER_CONDITION ConditionLast = KdbDoNotEnter;
2256 
2257  static const PCHAR ExceptionNames[21] =
2258  {
2259  "ZERODEVIDE", "DEBUGTRAP", "NMI", "INT3", "OVERFLOW", "BOUND", "INVALIDOP",
2260  "NOMATHCOP", "DOUBLEFAULT", "RESERVED(9)", "INVALIDTSS", "SEGMENTNOTPRESENT",
2261  "STACKFAULT", "GPF", "PAGEFAULT", "RESERVED(15)", "MATHFAULT", "ALIGNMENTCHECK",
2262  "MACHINECHECK", "SIMDFAULT", "OTHERS"
2263  };
2264 
2265  if (Argc == 1)
2266  {
2267  KdbpPrint("Available settings:\n");
2268  KdbpPrint(" syntax [intel|at&t]\n");
2269  KdbpPrint(" condition [exception|*] [first|last] [never|always|kmode|umode]\n");
2270  KdbpPrint(" break_on_module_load [true|false]\n");
2271  }
2272  else if (strcmp(Argv[1], "syntax") == 0)
2273  {
2274  if (Argc == 2)
2275  {
2276  KdbpPrint("syntax = %s\n", KdbUseIntelSyntax ? "intel" : "at&t");
2277  }
2278  else if (Argc >= 3)
2279  {
2280  if (_stricmp(Argv[2], "intel") == 0)
2282  else if (_stricmp(Argv[2], "at&t") == 0)
2284  else
2285  KdbpPrint("Unknown syntax '%s'.\n", Argv[2]);
2286  }
2287  }
2288  else if (strcmp(Argv[1], "condition") == 0)
2289  {
2290  if (Argc == 2)
2291  {
2292  KdbpPrint("Conditions: (First) (Last)\n");
2293  for (l = 0; l < RTL_NUMBER_OF(ExceptionNames) - 1; l++)
2294  {
2295  if (!ExceptionNames[l])
2296  continue;
2297 
2298  if (!KdbpGetEnterCondition(l, TRUE, &ConditionFirst))
2299  ASSERT(0);
2300 
2301  if (!KdbpGetEnterCondition(l, FALSE, &ConditionLast))
2302  ASSERT(0);
2303 
2304  KdbpPrint(" #%02d %-20s %-8s %-8s\n", l, ExceptionNames[l],
2305  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2306  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2307  }
2308 
2309  ASSERT(l == (RTL_NUMBER_OF(ExceptionNames) - 1));
2310  KdbpPrint(" %-20s %-8s %-8s\n", ExceptionNames[l],
2311  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2312  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2313  }
2314  else
2315  {
2316  if (Argc >= 5 && strcmp(Argv[2], "*") == 0) /* Allow * only when setting condition */
2317  {
2318  l = -1;
2319  }
2320  else
2321  {
2322  l = strtoul(Argv[2], &pend, 0);
2323 
2324  if (Argv[2] == pend)
2325  {
2326  for (l = 0; l < RTL_NUMBER_OF(ExceptionNames); l++)
2327  {
2328  if (!ExceptionNames[l])
2329  continue;
2330 
2331  if (_stricmp(ExceptionNames[l], Argv[2]) == 0)
2332  break;
2333  }
2334  }
2335 
2336  if (l >= RTL_NUMBER_OF(ExceptionNames))
2337  {
2338  KdbpPrint("Unknown exception '%s'.\n", Argv[2]);
2339  return TRUE;
2340  }
2341  }
2342 
2343  if (Argc > 4)
2344  {
2345  if (_stricmp(Argv[3], "first") == 0)
2346  First = TRUE;
2347  else if (_stricmp(Argv[3], "last") == 0)
2348  First = FALSE;
2349  else
2350  {
2351  KdbpPrint("set condition: second argument must be 'first' or 'last'\n");
2352  return TRUE;
2353  }
2354 
2355  if (_stricmp(Argv[4], "never") == 0)
2356  ConditionFirst = KdbDoNotEnter;
2357  else if (_stricmp(Argv[4], "always") == 0)
2358  ConditionFirst = KdbEnterAlways;
2359  else if (_stricmp(Argv[4], "umode") == 0)
2360  ConditionFirst = KdbEnterFromUmode;
2361  else if (_stricmp(Argv[4], "kmode") == 0)
2362  ConditionFirst = KdbEnterFromKmode;
2363  else
2364  {
2365  KdbpPrint("set condition: third argument must be 'never', 'always', 'umode' or 'kmode'\n");
2366  return TRUE;
2367  }
2368 
2369  if (!KdbpSetEnterCondition(l, First, ConditionFirst))
2370  {
2371  if (l >= 0)
2372  KdbpPrint("Couldn't change condition for exception #%02d\n", l);
2373  else
2374  KdbpPrint("Couldn't change condition for all exceptions\n", l);
2375  }
2376  }
2377  else /* Argc >= 3 */
2378  {
2379  if (!KdbpGetEnterCondition(l, TRUE, &ConditionFirst))
2380  ASSERT(0);
2381 
2382  if (!KdbpGetEnterCondition(l, FALSE, &ConditionLast))
2383  ASSERT(0);
2384 
2385  if (l < (RTL_NUMBER_OF(ExceptionNames) - 1))
2386  {
2387  KdbpPrint("Condition for exception #%02d (%s): FirstChance %s LastChance %s\n",
2388  l, ExceptionNames[l],
2389  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2390  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2391  }
2392  else
2393  {
2394  KdbpPrint("Condition for all other exceptions: FirstChance %s LastChance %s\n",
2395  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2396  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2397  }
2398  }
2399  }
2400  }
2401  else if (strcmp(Argv[1], "break_on_module_load") == 0)
2402  {
2403  if (Argc == 2)
2404  KdbpPrint("break_on_module_load = %s\n", KdbBreakOnModuleLoad ? "enabled" : "disabled");
2405  else if (Argc >= 3)
2406  {
2407  if (_stricmp(Argv[2], "enable") == 0 || _stricmp(Argv[2], "enabled") == 0 || _stricmp(Argv[2], "true") == 0)
2409  else if (_stricmp(Argv[2], "disable") == 0 || _stricmp(Argv[2], "disabled") == 0 || _stricmp(Argv[2], "false") == 0)
2411  else
2412  KdbpPrint("Unknown setting '%s'.\n", Argv[2]);
2413  }
2414  }
2415  else
2416  {
2417  KdbpPrint("Unknown setting '%s'.\n", Argv[1]);
2418  }
2419 
2420  return TRUE;
2421 }
signed char * PCHAR
Definition: retypes.h:7
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
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define KDB_ENTER_CONDITION_TO_STRING(cond)
Definition: kdb_cli.c:52
#define _stricmp
Definition: cat.c:22
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
r l[0]
Definition: byte_order.h:167
unsigned char BOOLEAN
static BOOLEAN KdbBreakOnModuleLoad
Definition: kdb_cli.c:104
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:103
enum _KDB_ENTER_CONDITION KDB_ENTER_CONDITION
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static BOOLEAN First
Definition: dem.c:250
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
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.
Definition: kdb.c:1056
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
static BOOLEAN KdbpCmdStep ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Continues execution of the system/leaves KDB.

Definition at line 1200 of file kdb_cli.c.

1203 {
1204  ULONG Count = 1;
1205 
1206  if (Argc > 1)
1207  {
1208  Count = strtoul(Argv[1], NULL, 0);
1209  if (Count == 0)
1210  {
1211  KdbpPrint("%s: Integer argument required\n", Argv[0]);
1212  return TRUE;
1213  }
1214  }
1215 
1216  if (Argv[0][0] == 'n')
1218  else
1220 
1221  /* Set the number of single steps and return to the interrupted code. */
1223 
1224  return FALSE;
1225 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:513
ULONG KdbNumSingleSteps
Definition: kdb.c:43
BOOLEAN KdbSingleStepOver
Definition: kdb.c:44
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
static BOOLEAN KdbpCmdThread ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists threads or switches to another thread context.

Definition at line 1492 of file kdb_cli.c.

1495 {
1497  PETHREAD Thread = NULL;
1499  BOOLEAN ReferencedThread = FALSE, ReferencedProcess = FALSE;
1500  PULONG Esp;
1501  PULONG Ebp;
1502  ULONG Eip;
1503  ULONG ul = 0;
1504  PCHAR State, pend, str1, str2;
1505  static const PCHAR ThreadStateToString[DeferredReady+1] =
1506  {
1507  "Initialized", "Ready", "Running",
1508  "Standby", "Terminated", "Waiting",
1509  "Transition", "DeferredReady"
1510  };
1511 
1513 
1514  if (Argc >= 2 && _stricmp(Argv[1], "list") == 0)
1515  {
1516  Process = KdbCurrentProcess;
1517 
1518  if (Argc >= 3)
1519  {
1520  ul = strtoul(Argv[2], &pend, 0);
1521  if (Argv[2] == pend)
1522  {
1523  KdbpPrint("thread: '%s' is not a valid process id!\n", Argv[2]);
1524  return TRUE;
1525  }
1526 
1527  if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID)ul, &Process)))
1528  {
1529  KdbpPrint("thread: Invalid process id!\n");
1530  return TRUE;
1531  }
1532 
1533  /* Remember our reference */
1534  ReferencedProcess = TRUE;
1535  }
1536 
1537  Entry = Process->ThreadListHead.Flink;
1538  if (Entry == &Process->ThreadListHead)
1539  {
1540  if (Argc >= 3)
1541  KdbpPrint("No threads in process 0x%08x!\n", ul);
1542  else
1543  KdbpPrint("No threads in current process!\n");
1544 
1545  if (ReferencedProcess)
1546  ObDereferenceObject(Process);
1547 
1548  return TRUE;
1549  }
1550 
1551  KdbpPrint(" TID State Prior. Affinity EBP EIP\n");
1552  do
1553  {
1554  Thread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
1555 
1556  if (Thread == KdbCurrentThread)
1557  {
1558  str1 = "\x1b[1m*";
1559  str2 = "\x1b[0m";
1560  }
1561  else
1562  {
1563  str1 = " ";
1564  str2 = "";
1565  }
1566 
1567  if (!Thread->Tcb.InitialStack)
1568  {
1569  /* Thread has no kernel stack (probably terminated) */
1570  Esp = Ebp = NULL;
1571  Eip = 0;
1572  }
1573  else if (Thread->Tcb.TrapFrame)
1574  {
1575  if (Thread->Tcb.TrapFrame->PreviousPreviousMode == KernelMode)
1576  Esp = (PULONG)Thread->Tcb.TrapFrame->TempEsp;
1577  else
1578  Esp = (PULONG)Thread->Tcb.TrapFrame->HardwareEsp;
1579 
1580  Ebp = (PULONG)Thread->Tcb.TrapFrame->Ebp;
1581  Eip = Thread->Tcb.TrapFrame->Eip;
1582  }
1583  else
1584  {
1585  Esp = (PULONG)Thread->Tcb.KernelStack;
1586  Ebp = (PULONG)Esp[4];
1587  Eip = 0;
1588 
1589  if (Ebp) /* FIXME: Should we attach to the process to read Ebp[1]? */
1590  KdbpSafeReadMemory(&Eip, Ebp + 1, sizeof (Eip));
1591  }
1592 
1593  if (Thread->Tcb.State < (DeferredReady + 1))
1594  State = ThreadStateToString[Thread->Tcb.State];
1595  else
1596  State = "Unknown";
1597 
1598  KdbpPrint(" %s0x%08x %-11s %3d 0x%08x 0x%08x 0x%08x%s\n",
1599  str1,
1600  Thread->Cid.UniqueThread,
1601  State,
1602  Thread->Tcb.Priority,
1603  Thread->Tcb.Affinity,
1604  Ebp,
1605  Eip,
1606  str2);
1607 
1608  Entry = Entry->Flink;
1609  }
1610  while (Entry != &Process->ThreadListHead);
1611 
1612  /* Release our reference, if any */
1613  if (ReferencedProcess)
1614  ObDereferenceObject(Process);
1615  }
1616  else if (Argc >= 2 && _stricmp(Argv[1], "attach") == 0)
1617  {
1618  if (Argc < 3)
1619  {
1620  KdbpPrint("thread attach: thread id argument required!\n");
1621  return TRUE;
1622  }
1623 
1624  ul = strtoul(Argv[2], &pend, 0);
1625  if (Argv[2] == pend)
1626  {
1627  KdbpPrint("thread attach: '%s' is not a valid thread id!\n", Argv[2]);
1628  return TRUE;
1629  }
1630 
1631  if (!KdbpAttachToThread((PVOID)ul))
1632  {
1633  return TRUE;
1634  }
1635 
1636  KdbpPrint("Attached to thread 0x%08x.\n", ul);
1637  }
1638  else
1639  {
1640  Thread = KdbCurrentThread;
1641 
1642  if (Argc >= 2)
1643  {
1644  ul = strtoul(Argv[1], &pend, 0);
1645  if (Argv[1] == pend)
1646  {
1647  KdbpPrint("thread: '%s' is not a valid thread id!\n", Argv[1]);
1648  return TRUE;
1649  }
1650 
1651  if (!NT_SUCCESS(PsLookupThreadByThreadId((PVOID)ul, &Thread)))
1652  {
1653  KdbpPrint("thread: Invalid thread id!\n");
1654  return TRUE;
1655  }
1656 
1657  /* Remember our reference */
1658  ReferencedThread = TRUE;
1659  }
1660 
1661  if (Thread->Tcb.State < (DeferredReady + 1))
1662  State = ThreadStateToString[Thread->Tcb.State];
1663  else
1664  State = "Unknown";
1665 
1666  KdbpPrint("%s"
1667  " TID: 0x%08x\n"
1668  " State: %s (0x%x)\n"
1669  " Priority: %d\n"
1670  " Affinity: 0x%08x\n"
1671  " Initial Stack: 0x%08x\n"
1672  " Stack Limit: 0x%08x\n"
1673  " Stack Base: 0x%08x\n"
1674  " Kernel Stack: 0x%08x\n"
1675  " Trap Frame: 0x%08x\n"
1676  " NPX State: %s (0x%x)\n",
1677  (Argc < 2) ? "Current Thread:\n" : "",
1678  Thread->Cid.UniqueThread,
1679  State, Thread->Tcb.State,
1680  Thread->Tcb.Priority,
1681  Thread->Tcb.Affinity,
1682  Thread->Tcb.InitialStack,
1683  Thread->Tcb.StackLimit,
1684  Thread->Tcb.StackBase,
1685  Thread->Tcb.KernelStack,
1686  Thread->Tcb.TrapFrame,
1687  NPX_STATE_TO_STRING(Thread->Tcb.NpxState), Thread->Tcb.NpxState);
1688 
1689  /* Release our reference if we had one */
1690  if (ReferencedThread)
1691  ObDereferenceObject(Thread);
1692  }
1693 
1694  return TRUE;
1695 }
DWORD *typedef PVOID
Definition: winlogon.h:52
signed char * PCHAR
Definition: retypes.h:7
ULONG TempEsp
Definition: ketypes.h:244
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
#define NPX_STATE_TO_STRING(state)
Definition: kdb_cli.c:62
struct _Entry Entry
Definition: kefuncs.h:640
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
BOOLEAN KdbpAttachToThread(PVOID ThreadId)
Switches to another thread context.
Definition: kdb.c:1119
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
NTSTATUS NTAPI PsLookupThreadByThreadId(IN HANDLE ThreadId, OUT PETHREAD *Thread)
Definition: thread.c:643
KTHREAD Tcb
Definition: pstypes.h:1035
SCHAR Priority
Definition: ketypes.h:974
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1181
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define _stricmp
Definition: cat.c:22
ULONG_PTR StackLimit
Definition: ketypes.h:938
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:513
PVOID KernelStack
Definition: ketypes.h:939
LIST_ENTRY ThreadListHead
Definition: pstypes.h:1261
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
unsigned char BOOLEAN
CLIENT_ID Cid
Definition: pstypes.h:1060
ULONG HardwareEsp
Definition: ketypes.h:268
_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
Definition: typedefs.h:118
UCHAR NpxState
Definition: ketypes.h:998
ULONG Eip
Definition: ketypes.h:265
ULONG PreviousPreviousMode
Definition: ketypes.h:257
PVOID StackBase
Definition: ketypes.h:1282
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1761
enum State_ State
Definition: pofuncs.h:54
unsigned int * PULONG
Definition: retypes.h:1
_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
volatile UCHAR State
Definition: ketypes.h:997
GROUP_AFFINITY Affinity
Definition: ketypes.h:1233
unsigned int ULONG
Definition: retypes.h:1
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
PVOID InitialStack
Definition: ketypes.h:937
ULONG Ebp
Definition: ketypes.h:263
static BOOLEAN KdbpCmdTss ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays the TSS.

Definition at line 2148 of file kdb_cli.c.

2151 {
2152  KTSS *Tss = KeGetPcr()->TSS;
2153 
2154  KdbpPrint("Current TSS is at 0x%08x.\n", (INT)Tss);
2155  KdbpPrint(" Eip: 0x%08x\n"
2156  " Es: 0x%04x\n"
2157  " Cs: 0x%04x\n"
2158  " Ss: 0x%04x\n"
2159  " Ds: 0x%04x\n"
2160  " Fs: 0x%04x\n"
2161  " Gs: 0x%04x\n"
2162  " IoMapBase: 0x%04x\n",
2163  Tss->Eip, Tss->Es, Tss->Cs, Tss->Ds, Tss->Fs, Tss->Gs, Tss->IoMapBase);
2164 
2165  return TRUE;
2166 }
#define TRUE
Definition: types.h:120
USHORT Fs
Definition: ketypes.h:814
USHORT Cs
Definition: ketypes.h:808
USHORT Es
Definition: ketypes.h:806
int32_t INT
Definition: typedefs.h:57
#define KeGetPcr()
Definition: ke.h:25
USHORT Ds
Definition: ketypes.h:812
Definition: ketypes.h:787
ULONG Eip
Definition: ketypes.h:796
USHORT IoMapBase
Definition: ketypes.h:821
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
USHORT Gs
Definition: ketypes.h:816
static VOID KdbpCommandHistoryAppend ( IN PCHAR  Command)
static

Appends a command to the command history.

Parameters
CommandPointer to the command to append to the history.

Definition at line 3042 of file kdb_cli.c.

Referenced by KdbpCliMainLoop().

3044 {
3045  ULONG Length1 = strlen(Command) + 1;
3046  ULONG Length2 = 0;
3047  INT i;
3048  PCHAR Buffer;
3049 
3051 
3052  if (Length1 <= 1 ||
3055  {
3056  return;
3057  }
3058 
3059  /* Calculate Length1 and Length2 */
3061  KdbCommandHistoryBufferIndex += Length1;
3062  if (KdbCommandHistoryBufferIndex >= (LONG)RTL_NUMBER_OF(KdbCommandHistoryBuffer))
3063  {
3064  KdbCommandHistoryBufferIndex -= RTL_NUMBER_OF(KdbCommandHistoryBuffer);
3065  Length2 = KdbCommandHistoryBufferIndex;
3066  Length1 -= Length2;
3067  }
3068 
3069  /* Remove previous commands until there is enough space to append the new command */
3070  for (i = KdbCommandHistoryIndex; KdbCommandHistory[i];)
3071  {
3072  if ((Length2 > 0 &&
3073  (KdbCommandHistory[i] >= Buffer ||
3074  KdbCommandHistory[i] < (KdbCommandHistoryBuffer + KdbCommandHistoryBufferIndex))) ||
3075  (Length2 <= 0 &&
3076  (KdbCommandHistory[i] >= Buffer &&
3077  KdbCommandHistory[i] < (KdbCommandHistoryBuffer + KdbCommandHistoryBufferIndex))))
3078  {
3080  }
3081 
3082  i--;
3083  if (i < 0)
3085 
3086  if (i == KdbCommandHistoryIndex)
3087  break;
3088  }
3089 
3090  /* Make sure the new command history entry is free */
3091  KdbCommandHistoryIndex++;
3092  KdbCommandHistoryIndex %= RTL_NUMBER_OF(KdbCommandHistory);
3093  if (KdbCommandHistory[KdbCommandHistoryIndex])
3094  {
3096  }
3097 
3098  /* Append command */
3100  ASSERT((KdbCommandHistory[KdbCommandHistoryIndex] + Length1) <= KdbCommandHistoryBuffer + RTL_NUMBER_OF(KdbCommandHistoryBuffer));
3101  memcpy(KdbCommandHistory[KdbCommandHistoryIndex], Command, Length1);
3102  if (Length2 > 0)
3103  {
3104  memcpy(KdbCommandHistoryBuffer, Command + Length1, Length2);
3105  }
3106 }
signed char * PCHAR
Definition: retypes.h:7
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
INT Length2
Definition: FsRtlDissect.c:16
Definition: shell.h:41
int32_t INT
Definition: typedefs.h:57
INT Length1
Definition: FsRtlDissect.c:15
GLenum GLclampf GLint i
Definition: glfuncs.h:14
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:513
static LONG KdbCommandHistoryBufferIndex
Definition: kdb_cli.c:108
UINTN VOID * Buffer
Definition: acefiex.h:370
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static LONG KdbCommandHistoryIndex
Definition: kdb_cli.c:109
static PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8]
Definition: kdb_cli.c:107
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static CHAR KdbCommandHistoryBuffer[2048]
Definition: kdb_cli.c:106
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static BOOLEAN KdbpDoCommand ( IN PCHAR  Command)
static

Parses command line and executes command if found.

Parameters
CommandCommand line to parse and execute if possible.
Return values
TRUEDon't continue execution.
FALSEContinue execution (leave KDB)

Definition at line 3388 of file kdb_cli.c.

Referenced by KdbpCliInterpretInitFile(), and KdbpCliMainLoop().

3390 {
3391  ULONG i;
3392  PCHAR p;
3393  ULONG Argc;
3394  // FIXME: for what do we need a 1024 characters command line and 256 tokens?
3395  static PCH Argv[256];
3396  static CHAR OrigCommand[1024];
3397 
3398  RtlStringCbCopyA(OrigCommand, sizeof(OrigCommand), Command);
3399 
3400  Argc = 0;
3401  p = Command;
3402 
3403  for (;;)
3404  {
3405  while (*p == '\t' || *p == ' ')
3406  p++;
3407 
3408  if (*p == '\0')
3409  break;
3410 
3411  i = strcspn(p, "\t ");
3412  Argv[Argc++] = p;
3413  p += i;
3414  if (*p == '\0')
3415  break;
3416 
3417  *p = '\0';
3418  p++;
3419  }
3420 
3421  if (Argc < 1)
3422  return TRUE;
3423 
3424  for (i = 0; i < RTL_NUMBER_OF(KdbDebuggerCommands); i++)
3425  {
3426  if (!KdbDebuggerCommands[i].Name)
3427  continue;
3428 
3429  if (strcmp(KdbDebuggerCommands[i].Name, Argv[0]) == 0)
3430  {
3431  return KdbDebuggerCommands[i].Fn(Argc, Argv);
3432  }
3433  }
3434 
3435  /* Now invoke the registered callbacks */
3436  if (KdbpInvokeCliCallbacks(Command, Argc, Argv))
3437  {
3438  return TRUE;
3439  }
3440 
3441  KdbpPrint("Command '%s' is unknown.\n", OrigCommand);
3442  return TRUE;
3443 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
static const struct @1617 KdbDebuggerCommands[]
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
char CHAR
Definition: xmlstorage.h:175
Definition: shell.h:41
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:163
GLenum GLclampf GLint i
Definition: glfuncs.h:14
CHAR * PCH
Definition: ntbasedef.h:390
struct Command Command
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
static BOOLEAN KdbpInvokeCliCallbacks(IN PCHAR Command, IN ULONG Argc, IN PCH Argv[])
Invokes registered CLI callbacks until one of them handled the Command.
Definition: kdb_cli.c:3354
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
GLfloat GLfloat p
Definition: glext.h:8902
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
static BOOLEAN KdbpEvaluateExpression ( IN PCHAR  Expression,
IN LONG  ErrOffset,
OUT PULONGLONG  Result 
)
static

Evaluates an expression...

Much like KdbpRpnEvaluateExpression, but prints the error message (if any) at the given offset.

Parameters
ExpressionExpression to evaluate.
ErrOffsetOffset (in characters) to print the error message at.
ResultReceives the result on success.
Return values
TRUESuccess.
FALSEFailure.

Definition at line 386 of file kdb_cli.c.

Referenced by KdbpCmdBackTrace(), KdbpCmdBreakPoint(), KdbpCmdDisassembleX(), KdbpCmdEvalExpression(), and KdbpCmdMod().

390 {
391  static CHAR ErrMsgBuffer[130] = "^ ";
392  LONG ExpressionErrOffset = -1;
393  PCHAR ErrMsg = ErrMsgBuffer;
394  BOOLEAN Ok;
395 
397  &ExpressionErrOffset, ErrMsgBuffer + 2);
398  if (!Ok)
399  {
400  if (ExpressionErrOffset >= 0)
401  ExpressionErrOffset += ErrOffset;
402  else
403  ErrMsg += 2;
404 
405  KdbpPrint("%*s%s\n", ExpressionErrOffset, "", ErrMsg);
406  }
407 
408  return Ok;
409 }
signed char * PCHAR
Definition: retypes.h:7
PCWSTR Expression
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
long LONG
Definition: pedump.c:60
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
unsigned char BOOLEAN
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2462
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.
Definition: kdb_expr.c:1091
static BOOLEAN KdbpGetComponentId ( IN PCCH  ComponentName,
OUT PULONG  ComponentId 
)
static

Transform a component name to an integer.

Parameters
ComponentNameThe name of the component.
ComponentIdReceives the component id on success.
Return values
TRUESuccess.
FALSEFailure.

Definition at line 200 of file kdb_cli.c.

Referenced by KdbpCmdFilter().

203 {
204  ULONG i;
205 
206  static struct
207  {
208  PCCH Name;
209  ULONG Id;
210  }
211  ComponentTable[] =
212  {
213  { "DEFAULT", MAXULONG },
214  { "SYSTEM", DPFLTR_SYSTEM_ID },
215  { "SMSS", DPFLTR_SMSS_ID },
216  { "SETUP", DPFLTR_SETUP_ID },
217  { "NTFS", DPFLTR_NTFS_ID },
218  { "FSTUB", DPFLTR_FSTUB_ID },
219  { "CRASHDUMP", DPFLTR_CRASHDUMP_ID },
220  { "CDAUDIO", DPFLTR_CDAUDIO_ID },
221  { "CDROM", DPFLTR_CDROM_ID },
222  { "CLASSPNP", DPFLTR_CLASSPNP_ID },
223  { "DISK", DPFLTR_DISK_ID },
224  { "REDBOOK", DPFLTR_REDBOOK_ID },
225  { "STORPROP", DPFLTR_STORPROP_ID },
226  { "SCSIPORT", DPFLTR_SCSIPORT_ID },
227  { "SCSIMINIPORT", DPFLTR_SCSIMINIPORT_ID },
228  { "CONFIG", DPFLTR_CONFIG_ID },
229  { "I8042PRT", DPFLTR_I8042PRT_ID },
230  { "SERMOUSE", DPFLTR_SERMOUSE_ID },
231  { "LSERMOUS", DPFLTR_LSERMOUS_ID },
232  { "KBDHID", DPFLTR_KBDHID_ID },
233  { "MOUHID", DPFLTR_MOUHID_ID },
234  { "KBDCLASS", DPFLTR_KBDCLASS_ID },
235  { "MOUCLASS", DPFLTR_MOUCLASS_ID },
236  { "TWOTRACK", DPFLTR_TWOTRACK_ID },
237  { "WMILIB", DPFLTR_WMILIB_ID },
238  { "ACPI", DPFLTR_ACPI_ID },
239  { "AMLI", DPFLTR_AMLI_ID },
240  { "HALIA64", DPFLTR_HALIA64_ID },
241  { "VIDEO", DPFLTR_VIDEO_ID },
242  { "SVCHOST", DPFLTR_SVCHOST_ID },
243  { "VIDEOPRT", DPFLTR_VIDEOPRT_ID },
244  { "TCPIP", DPFLTR_TCPIP_ID },
245  { "DMSYNTH", DPFLTR_DMSYNTH_ID },
246  { "NTOSPNP", DPFLTR_NTOSPNP_ID },
247  { "FASTFAT", DPFLTR_FASTFAT_ID },
248  { "SAMSS", DPFLTR_SAMSS_ID },
249  { "PNPMGR", DPFLTR_PNPMGR_ID },
250  { "NETAPI", DPFLTR_NETAPI_ID },
251  { "SCSERVER", DPFLTR_SCSERVER_ID },
252  { "SCCLIENT", DPFLTR_SCCLIENT_ID },
253  { "SERIAL", DPFLTR_SERIAL_ID },
254  { "SERENUM", DPFLTR_SERENUM_ID },
255  { "UHCD", DPFLTR_UHCD_ID },
256  { "RPCPROXY", DPFLTR_RPCPROXY_ID },
257  { "AUTOCHK", DPFLTR_AUTOCHK_ID },
258  { "DCOMSS", DPFLTR_DCOMSS_ID },
259  { "UNIMODEM", DPFLTR_UNIMODEM_ID },
260  { "SIS", DPFLTR_SIS_ID },
261  { "FLTMGR", DPFLTR_FLTMGR_ID },
262  { "WMICORE", DPFLTR_WMICORE_ID },
263  { "BURNENG", DPFLTR_BURNENG_ID },
264  { "IMAPI", DPFLTR_IMAPI_ID },
265  { "SXS", DPFLTR_SXS_ID },
266  { "FUSION", DPFLTR_FUSION_ID },
267  { "IDLETASK", DPFLTR_IDLETASK_ID },
268  { "SOFTPCI", DPFLTR_SOFTPCI_ID },
269  { "TAPE", DPFLTR_TAPE_ID },
270  { "MCHGR", DPFLTR_MCHGR_ID },
271  { "IDEP", DPFLTR_IDEP_ID },
272  { "PCIIDE", DPFLTR_PCIIDE_ID },
273  { "FLOPPY", DPFLTR_FLOPPY_ID },
274  { "FDC", DPFLTR_FDC_ID },
275  { "TERMSRV", DPFLTR_TERMSRV_ID },
276  { "W32TIME", DPFLTR_W32TIME_ID },
277  { "PREFETCHER", DPFLTR_PREFETCHER_ID },
278  { "RSFILTER", DPFLTR_RSFILTER_ID },
279  { "FCPORT", DPFLTR_FCPORT_ID },
280  { "PCI", DPFLTR_PCI_ID },
281  { "DMIO", DPFLTR_DMIO_ID },
282  { "DMCONFIG", DPFLTR_DMCONFIG_ID },
283  { "DMADMIN", DPFLTR_DMADMIN_ID },
284  { "WSOCKTRANSPORT", DPFLTR_WSOCKTRANSPORT_ID },
285  { "VSS", DPFLTR_VSS_ID },
286  { "PNPMEM", DPFLTR_PNPMEM_ID },
287  { "PROCESSOR", DPFLTR_PROCESSOR_ID },
288  { "DMSERVER", DPFLTR_DMSERVER_ID },
289  { "SR", DPFLTR_SR_ID },
290  { "INFINIBAND", DPFLTR_INFINIBAND_ID },
291  { "IHVDRIVER", DPFLTR_IHVDRIVER_ID },
292  { "IHVVIDEO", DPFLTR_IHVVIDEO_ID },
293  { "IHVAUDIO", DPFLTR_IHVAUDIO_ID },
294  { "IHVNETWORK", DPFLTR_IHVNETWORK_ID },
295  { "IHVSTREAMING", DPFLTR_IHVSTREAMING_ID },
296  { "IHVBUS", DPFLTR_IHVBUS_ID },
297  { "HPS", DPFLTR_HPS_ID },
298  { "RTLTHREADPOOL", DPFLTR_RTLTHREADPOOL_ID },
299  { "LDR", DPFLTR_LDR_ID },
300  { "TCPIP6", DPFLTR_TCPIP6_ID },
301  { "ISAPNP", DPFLTR_ISAPNP_ID },
302  { "SHPC", DPFLTR_SHPC_ID },
303  { "STORPORT", DPFLTR_STORPORT_ID },
304  { "STORMINIPORT", DPFLTR_STORMINIPORT_ID },
305  { "PRINTSPOOLER", DPFLTR_PRINTSPOOLER_ID },
306  { "VSSDYNDISK", DPFLTR_VSSDYNDISK_ID },
307  { "VERIFIER", DPFLTR_VERIFIER_ID },
308  { "VDS", DPFLTR_VDS_ID },
309  { "VDSBAS", DPFLTR_VDSBAS_ID },
310  { "VDSDYN", DPFLTR_VDSDYN_ID },
311  { "VDSDYNDR", DPFLTR_VDSDYNDR_ID },
312  { "VDSLDR", DPFLTR_VDSLDR_ID },
313  { "VDSUTIL", DPFLTR_VDSUTIL_ID },
314  { "DFRGIFC", DPFLTR_DFRGIFC_ID },
315  { "MM", DPFLTR_MM_ID },
316  { "DFSC", DPFLTR_DFSC_ID },
317  { "WOW64", DPFLTR_WOW64_ID },
318  { "ALPC", DPFLTR_ALPC_ID },
319  { "WDI", DPFLTR_WDI_ID },
320  { "PERFLIB", DPFLTR_PERFLIB_ID },
321  { "KTM", DPFLTR_KTM_ID },
322  { "IOSTRESS", DPFLTR_IOSTRESS_ID },
323  { "HEAP", DPFLTR_HEAP_ID },
324  { "WHEA", DPFLTR_WHEA_ID },
325  { "USERGDI", DPFLTR_USERGDI_ID },
326  { "MMCSS", DPFLTR_MMCSS_ID },
327  { "TPM", DPFLTR_TPM_ID },
328  { "THREADORDER", DPFLTR_THREADORDER_ID },
329  { "ENVIRON", DPFLTR_ENVIRON_ID },
330  { "EMS", DPFLTR_EMS_ID },
331  { "WDT", DPFLTR_WDT_ID },
332  { "FVEVOL", DPFLTR_FVEVOL_ID },
333  { "NDIS", DPFLTR_NDIS_ID },
334  { "NVCTRACE", DPFLTR_NVCTRACE_ID },
335  { "LUAFV", DPFLTR_LUAFV_ID },
336  { "APPCOMPAT", DPFLTR_APPCOMPAT_ID },
337  { "USBSTOR", DPFLTR_USBSTOR_ID },
338  { "SBP2PORT", DPFLTR_SBP2PORT_ID },
339  { "COVERAGE", DPFLTR_COVERAGE_ID },
340  { "CACHEMGR", DPFLTR_CACHEMGR_ID },
341  { "MOUNTMGR", DPFLTR_MOUNTMGR_ID },
342  { "CFR", DPFLTR_CFR_ID },
343  { "TXF", DPFLTR_TXF_ID },
344  { "KSECDD", DPFLTR_KSECDD_ID },
345  { "FLTREGRESS", DPFLTR_FLTREGRESS_ID },
346  { "MPIO", DPFLTR_MPIO_ID },
347  { "MSDSM", DPFLTR_MSDSM_ID },
348  { "UDFS", DPFLTR_UDFS_ID },
349  { "PSHED", DPFLTR_PSHED_ID },
350  { "STORVSP", DPFLTR_STORVSP_ID },
351  { "LSASS", DPFLTR_LSASS_ID },
352  { "SSPICLI", DPFLTR_SSPICLI_ID },
353  { "CNG", DPFLTR_CNG_ID },
354  { "EXFAT", DPFLTR_EXFAT_ID },
355  { "FILETRACE", DPFLTR_FILETRACE_ID },
356  { "XSAVE", DPFLTR_XSAVE_ID },
357  { "SE", DPFLTR_SE_ID },
358  { "DRIVEEXTENDER", DPFLTR_DRIVEEXTENDER_ID },
359  };
360 
361  for (i = 0; i < sizeof(ComponentTable) / sizeof(ComponentTable[0]); i++)
362  {
363  if (_stricmp(ComponentName, ComponentTable[i].Name) == 0)
364  {
365  *ComponentId = ComponentTable[i].Id;
366  return TRUE;
367  }
368  }
369 
370  return FALSE;
371 }
#define TRUE
Definition: types.h:120
PCHAR Name
Definition: kdb_cli.c:132
#define _stricmp
Definition: cat.c:22
DWORD Id
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
CONST CHAR * PCCH
Definition: ntbasedef.h:391
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
#define MAXULONG
Definition: typedefs.h:251
unsigned int ULONG
Definition: retypes.h:1
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1256
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
static BOOLEAN KdbpInNmiOrDoubleFaultHandler ( ULONG_PTR  Address)
static

Definition at line 1048 of file kdb_cli.c.

Referenced by KdbpCmdBackTrace().

1050 {
1053 }
PVOID ULONG Address
Definition: oprghdlr.h:14
uint32_t ULONG_PTR
Definition: typedefs.h:64
VOID FASTCALL KiTrap03Handler(IN PKTRAP_FRAME)
Definition: traphdlr.c:608
VOID __cdecl KiTrap02(VOID)
Definition: traphdlr.c:461
VOID __cdecl KiTrap08(VOID)
VOID __cdecl KiTrap09(VOID)
#define ULONG_PTR
Definition: config.h:101
static BOOLEAN KdbpInvokeCliCallbacks ( IN PCHAR  Command,
IN ULONG  Argc,
IN PCH  Argv[] 
)
static

Invokes registered CLI callbacks until one of them handled the Command.

Parameters
Command- Command line to parse and execute if possible.
Argc- Number of arguments in Argv
Argv- Array of strings, each of them containing one argument.
Returns
TRUE, if the command was handled, FALSE if it was not handled.

Definition at line 3354 of file kdb_cli.c.

Referenced by KdbpDoCommand().

3358 {
3359  ULONG i;
3360 
3361  /* Loop all entries */
3362  for (i = 0; i < _countof(KdbCliCallbacks); i++)
3363  {
3364  /* Check if this entry is registered */
3365  if (KdbCliCallbacks[i])
3366  {
3367  /* Invoke the callback and check if it handled the command */
3368  if (KdbCliCallbacks[i](Command, Argc, Argv))
3369  {
3370  return TRUE;
3371  }
3372  }
3373  }
3374 
3375  /* None of the callbacks handled the command */
3376  return FALSE;
3377 }
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:102
#define TRUE
Definition: types.h:120
#define _countof(array)
Definition: fontsub.cpp:30
Definition: shell.h:41
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
unsigned int ULONG
Definition: retypes.h:1
VOID KdbpPager ( IN PCHAR  Buffer,
IN ULONG  BufLength 
)

Prints the given string with, page by page.

Parameters
BufferCharacters buffer to print.
BufferLenBuffer size.
Note
Doesn't correctly handle \t and terminal escape sequences when calculating the number of lines required to print a single line from the Buffer in the terminal. Maximum length of buffer is limited only by memory size.

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

Definition at line 2776 of file kdb_cli.c.

Referenced by KdbpCmdDmesg().

2779 {
2780  static CHAR InBuffer[4096];
2781  static BOOLEAN TerminalInitialized = FALSE;
2782  static BOOLEAN TerminalConnected = FALSE;
2783  static BOOLEAN TerminalReportsSize = TRUE;
2784  CHAR c = '\0';
2785  PCHAR p, p2;
2786  ULONG Length;
2787  ULONG i, j;
2788  LONG RowsPrintedByTerminal;
2789  ULONG ScanCode;
2790 
2791  if( BufLength == 0)
2792  return;
2793 
2794  /* Check if the user has aborted output of the current command */
2795  if (KdbOutputAborted)
2796  return;
2797 
2798  /* Initialize the terminal */
2799  if (!TerminalInitialized)
2800  {
2801  DbgPrint("\x1b[7h"); /* Enable linewrap */
2802 
2803  /* Query terminal type */
2804  /*DbgPrint("\x1b[Z");*/
2805  DbgPrint("\x05");
2806 
2807  TerminalInitialized = TRUE;
2808  Length = 0;
2809  KeStallExecutionProcessor(100000);
2810 
2811  for (;;)
2812  {
2813  c = KdbpTryGetCharSerial(5000);
2814  if (c == -1)
2815  break;
2816 
2817  InBuffer[Length++] = c;
2818  if (Length >= (sizeof (InBuffer) - 1))
2819  break;
2820  }
2821 
2822  InBuffer[Length] = '\0';
2823  if (Length > 0)
2824  TerminalConnected = TRUE;
2825  }
2826 
2827  /* Get number of rows and columns in terminal */
2828  if ((KdbNumberOfRowsTerminal < 0) || (KdbNumberOfColsTerminal < 0) ||
2829  (KdbNumberOfRowsPrinted) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
2830  {
2831  if ((KdbDebugState & KD_DEBUG_KDSERIAL) && TerminalConnected && TerminalReportsSize)
2832  {
2833  /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
2834  TerminalReportsSize = FALSE;
2835  KeStallExecutionProcessor(100000);
2836  DbgPrint("\x1b[18t");
2837  c = KdbpTryGetCharSerial(5000);
2838 
2839  if (c == KEY_ESC)
2840  {
2841  c = KdbpTryGetCharSerial(5000);
2842  if (c == '[')
2843  {
2844  Length = 0;
2845 
2846  for (;;)
2847  {
2848  c = KdbpTryGetCharSerial(5000);
2849  if (c == -1)
2850  break;
2851 
2852  InBuffer[Length++] = c;
2853  if (isalpha(c) || Length >= (sizeof (InBuffer) - 1))
2854  break;
2855  }
2856 
2857  InBuffer[Length] = '\0';
2858  if (InBuffer[0] == '8' && InBuffer[1] == ';')
2859  {
2860  for (i = 2; (i < Length) && (InBuffer[i] != ';'); i++);
2861 
2862  if (Buffer[i] == ';')
2863  {
2864  Buffer[i++] = '\0';
2865 
2866  /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
2867  KdbNumberOfRowsTerminal = strtoul(InBuffer + 2, NULL, 0);
2868  KdbNumberOfColsTerminal = strtoul(InBuffer + i, NULL, 0);
2869  TerminalReportsSize = TRUE;
2870  }
2871  }
2872  }
2873  /* Clear further characters */
2874  while ((c = KdbpTryGetCharSerial(5000)) != -1);
2875  }
2876  }
2877 
2878  if (KdbNumberOfRowsTerminal <= 0)
2879  {
2880  /* Set number of rows to the default. */
2882  }
2883  else if (KdbNumberOfColsTerminal <= 0)
2884  {
2885  /* Set number of cols to the default. */
2887  }
2888  }
2889 
2890  /* Get the string */
2891  p = Buffer;
2892 
2893  while (p[0] != '\0')
2894  {
2895  if ( p > Buffer+BufLength)
2896  {
2897  DbgPrint("Dmesg: error, p > Buffer+BufLength,d=%d", p - (Buffer+BufLength));
2898  return;
2899  }
2900  i = strcspn(p, "\n");
2901 
2902  // Are we out of buffer?
2903  if (p + i > Buffer + BufLength)
2904  // Leaving pager function:
2905  break;
2906 
2907  /* Calculate the number of lines which will be printed in the terminal
2908  * when outputting the current line
2909  */
2910  if (i > 0)
2911  RowsPrintedByTerminal = (i + KdbNumberOfColsPrinted - 1) / KdbNumberOfColsTerminal;
2912  else
2913  RowsPrintedByTerminal = 0;
2914 
2915  if (p[i] == '\n')
2916  RowsPrintedByTerminal++;
2917 
2918  /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
2919 
2920  /* Display a prompt if we printed one screen full of text */
2921  if (KdbNumberOfRowsTerminal > 0 &&
2922  (LONG)(KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
2923  {
2925 
2926  if (KdbNumberOfColsPrinted > 0)
2927  DbgPrint("\n");
2928 
2929  DbgPrint("--- Press q to abort, e/End,h/Home,u/PgUp, other key/PgDn ---");
2930  RowsPrintedByTerminal++;
2931 
2932  if (KdbDebugState & KD_DEBUG_KDSERIAL)
2933  c = KdbpGetCharSerial();
2934  else
2935  c = KdbpGetCharKeyboard(&ScanCode);
2936 
2937  if (c == '\r')
2938  {
2939  /* Try to read '\n' which might follow '\r' - if \n is not received here
2940  * it will be interpreted as "return" when the next command should be read.
2941  */
2942  if (KdbDebugState & KD_DEBUG_KDSERIAL)
2943  c = KdbpTryGetCharSerial(5);
2944  else
2945  c = KdbpTryGetCharKeyboard(&ScanCode, 5);
2946  }
2947 
2948  //DbgPrint("\n"); //Consize version: don't show pressed key
2949  DbgPrint(" '%c'/scan=%04x\n", c, ScanCode); // Shows pressed key
2950 
2951  if (c == 'q')
2952  {
2954  return;
2955  }
2956  if ( ScanCode == KEYSC_END || c=='e')
2957  {
2958  PCHAR pBufEnd = Buffer + BufLength;
2959  p = CountOnePageUp(Buffer, BufLength, pBufEnd);
2960  i = strcspn(p, "\n");
2961  }
2962  else if (ScanCode == KEYSC_PAGEUP || c=='u')
2963  {
2964  p = CountOnePageUp(Buffer, BufLength, p);
2965  i = strcspn(p, "\n");
2966  }
2967  else if (ScanCode == KEYSC_HOME || c=='h')
2968  {
2969  p = Buffer;
2970  i = strcspn(p, "\n");
2971  }
2972  else if (ScanCode == KEYSC_ARROWUP)
2973  {
2974  p = CountOnePageUp(Buffer, BufLength, p);
2975  i = strcspn(p, "\n");
2976  }
2977 
2980  }
2981 
2982  /* Insert a NUL after the line and print only the current line. */
2983  if (p[i] == '\n' && p[i + 1] != '\0')
2984  {
2985  c = p[i + 1];
2986  p[i + 1] = '\0';
2987  }
2988  else
2989  {
2990  c = '\0';
2991  }
2992 
2993  /* Remove escape sequences from the line if there's no terminal connected */
2994  if (!TerminalConnected)
2995  {
2996  while ((p2 = strrchr(p, '\x1b'))) /* Look for escape character */
2997  {
2998  if (p2[1] == '[')
2999  {
3000  j = 2;
3001  while (!isalpha(p2[j++]));
3002  strcpy(p2, p2 + j);
3003  }
3004  else
3005  {
3006  strcpy(p2, p2 + 1);
3007  }
3008  }
3009  }
3010 
3011  // The main printing of the current line:
3012  DbgPrint(p);
3013 
3014  // restore not null char with saved:
3015  if (c != '\0')
3016  p[i + 1] = c;
3017 
3018  /* Set p to the start of the next line and
3019  * remember the number of rows/cols printed
3020  */
3021  p += i;
3022  if (p[0] == '\n')
3023  {
3024  p++;
3026  }
3027  else
3028  {
3029  ASSERT(p[0] == '\0');
3031  }
3032 
3033  KdbNumberOfRowsPrinted += RowsPrintedByTerminal;
3034  }
3035 }
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: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 KEYSC_PAGEUP
Definition: kdb_cli.c:47
#define KEYSC_HOME
Definition: kdb_cli.c:49
#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 FALSE
Definition: types.h:117
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:513
PCHAR CountOnePageUp(PCHAR Buffer, ULONG BufLength, PCHAR pCurPos)
Calculate pointer position for N lines upper of current position.
Definition: kdb_cli.c:2724
Definition: bufpool.h:45
#define KEYSC_END
Definition: kdb_cli.c:46
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:744
#define KEYSC_ARROWUP
Definition: kdb_cli.c:50
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
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 }
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: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 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
#define FALSE
Definition: types.h:117
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:513
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: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
static VOID KdbpReadCommand ( OUT PCHAR  Buffer,
IN ULONG  Size 
)
static

Reads a line of user-input.

Parameters
BufferBuffer to store the input into. Trailing newlines are removed.
SizeSize of Buffer.
Note
Accepts only
newlines, is ignored.

Definition at line 3116 of file kdb_cli.c.

Referenced by KdbpCliMainLoop().

3119 {
3120  CHAR Key;
3121  PCHAR Orig = Buffer;
3122  ULONG ScanCode = 0;
3123  BOOLEAN EchoOn;
3124  static CHAR LastCommand[1024];
3125  static CHAR NextKey = '\0';
3126  INT CmdHistIndex = -1;
3127  INT i;
3128 
3129  EchoOn = !((KdbDebugState & KD_DEBUG_KDNOECHO) != 0);
3130 
3131  for (;;)
3132  {
3134  {
3135  Key = (NextKey == '\0') ? KdbpGetCharSerial() : NextKey;
3136  NextKey = '\0';
3137  ScanCode = 0;
3138  if (Key == KEY_ESC) /* ESC */
3139  {
3140  Key = KdbpGetCharSerial();
3141  if (Key == '[')
3142  {
3143  Key = KdbpGetCharSerial();
3144 
3145  switch (Key)
3146  {
3147  case 'A':
3148  ScanCode = KEY_SCAN_UP;
3149  break;
3150  case 'B':
3151  ScanCode = KEY_SCAN_DOWN;
3152  break;
3153  case 'C':
3154  break;
3155  case 'D':
3156  break;
3157  }
3158  }
3159  }
3160  }
3161  else
3162  {
3163  ScanCode = 0;
3164  Key = (NextKey == '\0') ? KdbpGetCharKeyboard(&ScanCode) : NextKey;
3165  NextKey = '\0';
3166  }
3167 
3168  if ((ULONG)(Buffer - Orig) >= (Size - 1))
3169  {
3170  /* Buffer is full, accept only newlines */
3171  if (Key != '\n')
3172  continue;
3173  }
3174 
3175  if (Key == '\r')
3176  {
3177  /* Read the next char - this is to throw away a \n which most clients should
3178  * send after \r.
3179  */
3180  KeStallExecutionProcessor(100000);
3181 
3182  if (KdbDebugState & KD_DEBUG_KDSERIAL)
3183  NextKey = KdbpTryGetCharSerial(5);
3184  else
3185  NextKey = KdbpTryGetCharKeyboard(&ScanCode, 5);
3186 
3187  if (NextKey == '\n' || NextKey == -1) /* \n or no response at all */
3188  NextKey = '\0';
3189 
3190  KdbpPrint("\n");
3191 
3192  /*
3193  * Repeat the last command if the user presses enter. Reduces the
3194  * risk of RSI when single-stepping.
3195  */
3196  if (Buffer != Orig)
3197  {
3199  *Buffer = '\0';
3200  RtlStringCbCopyA(LastCommand, sizeof(LastCommand), Orig);
3201  }
3202  else if (KdbRepeatLastCommand)
3203  RtlStringCbCopyA(Buffer, Size, LastCommand);
3204  else
3205  *Buffer = '\0';
3206 
3207  return;
3208  }
3209  else if (Key == KEY_BS || Key == KEY_DEL)
3210  {
3211  if (Buffer > Orig)
3212  {
3213  Buffer--;
3214  *Buffer = 0;
3215 
3216  if (EchoOn)
3217  KdbpPrint("%c %c", KEY_BS, KEY_BS);
3218  else
3219  KdbpPrint(" %c", KEY_BS);
3220  }
3221  }
3222  else if (ScanCode == KEY_SCAN_UP)
3223  {
3224  BOOLEAN Print = TRUE;
3225 
3226  if (CmdHistIndex < 0)
3227  {
3228  CmdHistIndex = KdbCommandHistoryIndex;
3229  }
3230  else
3231  {
3232  i = CmdHistIndex - 1;
3233 
3234  if (i < 0)
3235  CmdHistIndex = RTL_NUMBER_OF(KdbCommandHistory) - 1;
3236 
3238  CmdHistIndex = i;
3239  else
3240  Print = FALSE;
3241  }
3242 
3243  if (Print && KdbCommandHistory[CmdHistIndex])
3244  {
3245  while (Buffer > Orig)
3246  {
3247  Buffer--;
3248  *Buffer = 0;
3249 
3250  if (EchoOn)
3251  KdbpPrint("%c %c", KEY_BS, KEY_BS);
3252  else
3253  KdbpPrint(" %c", KEY_BS);
3254  }
3255 
3256  i = min(strlen(KdbCommandHistory[CmdHistIndex]), Size - 1);
3257  memcpy(Orig, KdbCommandHistory[CmdHistIndex], i);
3258  Orig[i] = '\0';
3259  Buffer = Orig + i;
3260  KdbpPrint("%s", Orig);
3261  }
3262  }
3263  else if (ScanCode == KEY_SCAN_DOWN)
3264  {
3265  if (CmdHistIndex > 0 && CmdHistIndex != KdbCommandHistoryIndex)
3266  {
3267  i = CmdHistIndex + 1;
3268  if (i >= (INT)RTL_NUMBER_OF(KdbCommandHistory))
3269  i = 0;
3270 
3271  if (KdbCommandHistory[i])
3272  {
3273  CmdHistIndex = i;
3274  while (Buffer > Orig)
3275  {
3276  Buffer--;
3277  *Buffer = 0;
3278 
3279  if (EchoOn)
3280  KdbpPrint("%c %c", KEY_BS, KEY_BS);
3281  else
3282  KdbpPrint(" %c", KEY_BS);
3283  }
3284 
3285  i = min(strlen(KdbCommandHistory[CmdHistIndex]), Size - 1);
3286  memcpy(Orig, KdbCommandHistory[CmdHistIndex], i);
3287  Orig[i] = '\0';
3288  Buffer = Orig + i;
3289  KdbpPrint("%s", Orig);
3290  }
3291  }
3292  }
3293  else
3294  {
3295  if (EchoOn)
3296  KdbpPrint("%c", Key);
3297 
3298  *Buffer = Key;
3299  Buffer++;
3300  }
3301  }
3302 }
signed char * PCHAR
Definition: retypes.h:7
#define KEY_ESC
Definition: kdb_cli.c:39
#define TRUE
Definition: types.h:120
ULONG ScanCode
Definition: api.c:39
ULONG KdbDebugState
Definition: kdb.c:45
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdb.h:250
char CHAR
Definition: xmlstorage.h:175
#define KdbpGetCharSerial()
Definition: kdb.h:254
int32_t INT
Definition: typedefs.h:57
CHAR KdbpTryGetCharSerial(ULONG Retry)
Definition: kdb_serial.c:19
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdb_keyboard.c:104
#define KEY_SCAN_DOWN
Definition: kdb_cli.c:43
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:797
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:163
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:114
Definition: bufpool.h:45
#define KEY_BS
Definition: kdb_cli.c:38
#define KEY_SCAN_UP
Definition: kdb_cli.c:42
UINTN Size
Definition: acefiex.h:555
unsigned char BOOLEAN
UINTN VOID * Buffer
Definition: acefiex.h:370
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static LONG KdbCommandHistoryIndex
Definition: kdb_cli.c:109
static PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8]
Definition: kdb_cli.c:107
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define min(a, b)
Definition: monoChain.cc:55
#define KEY_DEL
Definition: kdb_cli.c:40
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