ReactOS  0.4.10-dev-244-gb941574
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[])
 
BOOLEAN ExpKdbgExtPoolUsed (ULONG Argc, PCHAR Argv[])
 
BOOLEAN ExpKdbgExtFileCache (ULONG Argc, PCHAR Argv[])
 
BOOLEAN ExpKdbgExtDefWrites (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_reads_bytes_(InStringLength) PCHAR UnsafeInString, _In_ USHORT InStringLength, _Out_writes_bytes_(OutStringLength) PCHAR UnsafeOutString, _In_ USHORT OutStringLength, _In_ KPROCESSOR_MODE PreviousMode)
 

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

Referenced by KdbpPager().

2731 {
2732  PCHAR p;
2733  // p0 is initial guess of Page Start
2735  PCHAR p0 = pCurPos - p0len;
2736  PCHAR prev_p = p0, p1;
2737  ULONG j;
2738 
2739  if (pCurPos < Buffer)
2740  pCurPos = Buffer;
2741  ASSERT(pCurPos <= Buffer + BufLength);
2742 
2743  p = memrchr(p0, '\n', p0len);
2744  if (NULL == p)
2745  p = p0;
2746  for (j = KdbNumberOfRowsTerminal; j--; )
2747  {
2748  int linesCnt;
2749  p1 = memrchr(p0, '\n', p-p0);
2750  prev_p = p;
2751  p = p1;
2752  if (NULL == p)
2753  {
2754  p = prev_p;
2755  if (NULL == p)
2756  p = p0;
2757  break;
2758  }
2759  linesCnt = (KdbNumberOfColsTerminal+prev_p-p-2) / KdbNumberOfColsTerminal;
2760  if (linesCnt > 1)
2761  j -= linesCnt-1;
2762  }
2763 
2764  ASSERT(p != 0);
2765  ++p;
2766  return p;
2767 }
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:2702
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
smooth NULL
Definition: ftsmooth.c:416
const GLfloat * p0
Definition: s_aatritemp.h:42
Definition: bufpool.h:45
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:118
UINTN VOID * Buffer
Definition: acefiex.h:370
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:119
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
const GLfloat * p1
Definition: s_aatritemp.h:43
BOOLEAN ExpKdbgExtDefWrites ( ULONG  Argc,
PCHAR  Argv[] 
)
BOOLEAN ExpKdbgExtFileCache ( ULONG  Argc,
PCHAR  Argv[] 
)
BOOLEAN ExpKdbgExtPool ( ULONG  Argc,
PCHAR  Argv[] 
)
BOOLEAN ExpKdbgExtPoolUsed ( 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 3583 of file kdb_cli.c.

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

This function is called by KdbEnterDebuggerException...

Used to interpret the init file in a context with a trapframe setup (KdbpCliInit call KdbEnter which will call KdbEnterDebuggerException which will call this function if KdbInitFileBuffer is not NULL.

Definition at line 3534 of file kdb_cli.c.

Referenced by KdbEnterDebuggerException().

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

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3456 of file kdb_cli.c.

Referenced by KdbpCallMainLoop(), and KdbpCliInterpretInitFile().

3458 {
3459  static CHAR Command[1024];
3460  BOOLEAN Continue;
3461 
3462  if (EnteredOnSingleStep)
3463  {
3465  {
3466  KdbpPrint("<%x>", KdbCurrentTrapFrame->Tf.Eip);
3467  }
3468 
3469  KdbpPrint(": ");
3471  {
3472  KdbpPrint("<INVALID>");
3473  }
3474  KdbpPrint("\n");
3475  }
3476 
3477  /* Flush the input buffer */
3479  {
3480  while (KdbpTryGetCharSerial(1) != -1);
3481  }
3482  else
3483  {
3484  ULONG ScanCode;
3485  while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
3486  }
3487 
3488  /* Main loop */
3489  do
3490  {
3491  /* Reset the number of rows/cols printed */
3493 
3494  /* Print the prompt */
3495  KdbpPrint("kdb:> ");
3496 
3497  /* Read a command and remember it */
3498  KdbpReadCommand(Command, sizeof (Command));
3499  KdbpCommandHistoryAppend(Command);
3500 
3501  /* Reset the number of rows/cols printed and output aborted state */
3504 
3505  /* Call the command */
3506  Continue = KdbpDoCommand(Command);
3508  }
3509  while (Continue);
3510 }
DWORD *typedef PVOID
Definition: winlogon.h:52
static VOID KdbpReadCommand(OUT PCHAR Buffer, IN ULONG Size)
Reads a line of user-input.
Definition: kdb_cli.c:3122
static VOID KdbpCommandHistoryAppend(IN PCHAR Command)
Appends a command to the command history.
Definition: kdb_cli.c:3048
ULONG ScanCode
Definition: api.c:39
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PKTRAP_FRAME Context)
Print address...
Definition: kdb_symbols.c:148
ULONG KdbDebugState
Definition: kdb.c:45
char CHAR
Definition: xmlstorage.h:175
Definition: shell.h:41
CHAR KdbpTryGetCharSerial(ULONG Retry)
Definition: kdb_serial.c:19
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdb_keyboard.c:104
static ULONG KdbNumberOfRowsPrinted
Definition: kdb_cli.c:114
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3394
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:115
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
unsigned char BOOLEAN
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:116
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:106
volatile int Continue
Definition: gdblib.c:102
ULONG Eip
Definition: ketypes.h:265
KTRAP_FRAME Tf
Definition: kdb.h:14
unsigned int ULONG
Definition: retypes.h:1
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2468
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:123
VOID KdbpCliModuleLoaded ( IN PUNICODE_STRING  Name)

Called when a module is loaded.

Parameters
NameFilename of the module which was loaded.

Definition at line 3517 of file kdb_cli.c.

3519 {
3520  if (!KdbBreakOnModuleLoad)
3521  return;
3522 
3523  KdbpPrint("Module %wZ loaded.\n", Name);
3525 }
static BOOLEAN KdbBreakOnModuleLoad
Definition: kdb_cli.c:107
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2468
static BOOLEAN KdbpCmdBackTrace ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays a backtrace.

Definition at line 1064 of file kdb_cli.c.

1067 {
1068  ULONG ul;
1069  ULONGLONG Result = 0;
1072  KTRAP_FRAME TrapFrame;
1073 
1074  if (Argc >= 2)
1075  {
1076  /* Check for [L count] part */
1077  ul = 0;
1078 
1079  if (strcmp(Argv[Argc-2], "L") == 0)
1080  {
1081  ul = strtoul(Argv[Argc-1], NULL, 0);
1082  if (ul > 0)
1083  {
1084  Argc -= 2;
1085  }
1086  }
1087  else if (Argv[Argc-1][0] == 'L')
1088  {
1089  ul = strtoul(Argv[Argc-1] + 1, NULL, 0);
1090  if (ul > 0)
1091  {
1092  Argc--;
1093  }
1094  }
1095 
1096  /* Put the remaining arguments back together */
1097  Argc--;
1098  for (ul = 1; ul < Argc; ul++)
1099  {
1100  Argv[ul][strlen(Argv[ul])] = ' ';
1101  }
1102  Argc++;
1103  }
1104 
1105  /* Check if frame addr or thread id is given. */
1106  if (Argc > 1)
1107  {
1108  if (Argv[1][0] == '*')
1109  {
1110  Argv[1]++;
1111 
1112  /* Evaluate the expression */
1113  if (!KdbpEvaluateExpression(Argv[1], sizeof("kdb:> ")-1 + (Argv[1]-Argv[0]), &Result))
1114  return TRUE;
1115 
1116  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1117  KdbpPrint("Warning: Address %I64x is beeing truncated\n",Result);
1118 
1119  Frame = (ULONG_PTR)Result;
1120  }
1121  else
1122  {
1123  KdbpPrint("Thread backtrace not supported yet!\n");
1124  return TRUE;
1125  }
1126  }
1127  else
1128  {
1129  KdbpPrint("Eip:\n");
1130 
1131  /* Try printing the function at EIP */
1133  KdbpPrint("<%08x>\n", KdbCurrentTrapFrame->Tf.Eip);
1134  else
1135  KdbpPrint("\n");
1136  }
1137 
1138  TrapFrame = KdbCurrentTrapFrame->Tf;
1139  KdbpPrint("Frames:\n");
1140 
1141  for (;;)
1142  {
1143  BOOLEAN GotNextFrame;
1144 
1145  if (Frame == 0)
1146  break;
1147 
1148  if (!NT_SUCCESS(KdbpSafeReadMemory(&Address, (PVOID)(Frame + sizeof(ULONG_PTR)), sizeof (ULONG_PTR))))
1149  {
1150  KdbpPrint("Couldn't access memory at 0x%p!\n", Frame + sizeof(ULONG_PTR));
1151  break;
1152  }
1153 
1154  if ((GotNextFrame = NT_SUCCESS(KdbpSafeReadMemory(&Frame, (PVOID)Frame, sizeof (ULONG_PTR)))))
1155  TrapFrame.Ebp = Frame;
1156 
1157  /* Print the location of the call instruction */
1158  if (!KdbSymPrintAddress((PVOID)(Address - 5), &TrapFrame))
1159  KdbpPrint("<%08x>\n", Address);
1160  else
1161  KdbpPrint("\n");
1162 
1163  if (KdbOutputAborted) break;
1164 
1165  if (Address == 0)
1166  break;
1167 
1168  if (KdbpInNmiOrDoubleFaultHandler(Address))
1169  {
1170  if ((GotNextFrame = KdbpTrapFrameFromPrevTss(&TrapFrame)))
1171  {
1172  Address = TrapFrame.Eip;
1173  Frame = TrapFrame.Ebp;
1174 
1175  if (!KdbSymPrintAddress((PVOID)Address, &TrapFrame))
1176  KdbpPrint("<%08x>\n", Address);
1177  else
1178  KdbpPrint("\n");
1179  }
1180  }
1181 
1182  if (!GotNextFrame)
1183  {
1184  KdbpPrint("Couldn't access memory at 0x%p!\n", Frame);
1185  break;
1186  }
1187  }
1188 
1189  return TRUE;
1190 }
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:392
_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:63
smooth NULL
Definition: ftsmooth.c:416
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
unsigned char BOOLEAN
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:116
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
uint64_t ULONGLONG
Definition: typedefs.h:65
static BOOLEAN KdbpInNmiOrDoubleFaultHandler(ULONG_PTR Address)
Definition: kdb_cli.c:1054
ULONG Eip
Definition: ketypes.h:265
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1734
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:2468
static BOOLEAN KdbpTrapFrameFromPrevTss(PKTRAP_FRAME TrapFrame)
Definition: kdb_cli.c:982
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 1374 of file kdb_cli.c.

1375 {
1376  ULONGLONG Result = 0;
1379  UCHAR Size = 0;
1380  KDB_ACCESS_TYPE AccessType = 0;
1381  ULONG AddressArgIndex, i;
1382  LONG ConditionArgIndex;
1383  BOOLEAN Global = TRUE;
1384 
1385  if (Argv[0][2] == 'x') /* software breakpoint */
1386  {
1387  if (Argc < 2)
1388  {
1389  KdbpPrint("bpx: Address argument required.\n");
1390  return TRUE;
1391  }
1392 
1393  AddressArgIndex = 1;
1394  Type = KdbBreakPointSoftware;
1395  }
1396  else /* memory breakpoint */
1397  {
1398  ASSERT(Argv[0][2] == 'm');
1399 
1400  if (Argc < 2)
1401  {
1402  KdbpPrint("bpm: Access type argument required (one of r, w, rw, x)\n");
1403  return TRUE;
1404  }
1405 
1406  if (_stricmp(Argv[1], "x") == 0)
1407  AccessType = KdbAccessExec;
1408  else if (_stricmp(Argv[1], "r") == 0)
1409  AccessType = KdbAccessRead;
1410  else if (_stricmp(Argv[1], "w") == 0)
1411  AccessType = KdbAccessWrite;
1412  else if (_stricmp(Argv[1], "rw") == 0)
1413  AccessType = KdbAccessReadWrite;
1414  else
1415  {
1416  KdbpPrint("bpm: Unknown access type '%s'\n", Argv[1]);
1417  return TRUE;
1418  }
1419 
1420  if (Argc < 3)
1421  {
1422  KdbpPrint("bpm: %s argument required.\n", AccessType == KdbAccessExec ? "Address" : "Memory size");
1423  return TRUE;
1424  }
1425 
1426  AddressArgIndex = 3;
1427  if (_stricmp(Argv[2], "byte") == 0)
1428  Size = 1;
1429  else if (_stricmp(Argv[2], "word") == 0)
1430  Size = 2;
1431  else if (_stricmp(Argv[2], "dword") == 0)
1432  Size = 4;
1433  else if (AccessType == KdbAccessExec)
1434  {
1435  Size = 1;
1436  AddressArgIndex--;
1437  }
1438  else
1439  {
1440  KdbpPrint("bpm: Unknown memory size '%s'\n", Argv[2]);
1441  return TRUE;
1442  }
1443 
1444  if (Argc <= AddressArgIndex)
1445  {
1446  KdbpPrint("bpm: Address argument required.\n");
1447  return TRUE;
1448  }
1449 
1450  Type = KdbBreakPointHardware;
1451  }
1452 
1453  /* Put the arguments back together */
1454  ConditionArgIndex = -1;
1455  for (i = AddressArgIndex; i < (Argc-1); i++)
1456  {
1457  if (strcmp(Argv[i+1], "IF") == 0) /* IF found */
1458  {
1459  ConditionArgIndex = i + 2;
1460  if ((ULONG)ConditionArgIndex >= Argc)
1461  {
1462  KdbpPrint("%s: IF requires condition expression.\n", Argv[0]);
1463  return TRUE;
1464  }
1465 
1466  for (i = ConditionArgIndex; i < (Argc-1); i++)
1467  Argv[i][strlen(Argv[i])] = ' ';
1468 
1469  break;
1470  }
1471 
1472  Argv[i][strlen(Argv[i])] = ' ';
1473  }
1474 
1475  /* Evaluate the address expression */
1476  if (!KdbpEvaluateExpression(Argv[AddressArgIndex],
1477  sizeof("kdb:> ")-1 + (Argv[AddressArgIndex]-Argv[0]),
1478  &Result))
1479  {
1480  return TRUE;
1481  }
1482 
1483  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1484  KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv[0],Result);
1485 
1486  Address = (ULONG_PTR)Result;
1487 
1488  KdbpInsertBreakPoint(Address, Type, Size, AccessType,
1489  (ConditionArgIndex < 0) ? NULL : Argv[ConditionArgIndex],
1490  Global, NULL);
1491 
1492  return TRUE;
1493 }
#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:392
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:533
#define _stricmp
Definition: cat.c:22
UNICODE_STRING Global
Definition: symlink.c:37
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLenum GLclampf GLint i
Definition: glfuncs.h:14
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
UINTN Size
Definition: acefiex.h:555
unsigned char BOOLEAN
uint64_t ULONGLONG
Definition: typedefs.h:65
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:2468
static BOOLEAN KdbpCmdBreakPointList ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists breakpoints.

Definition at line 1236 of file kdb_cli.c.

1239 {
1240  LONG l;
1241  ULONG_PTR Address = 0;
1243  KDB_ACCESS_TYPE AccessType = 0;
1244  UCHAR Size = 0;
1245  UCHAR DebugReg = 0;
1246  BOOLEAN Enabled = FALSE;
1247  BOOLEAN Global = FALSE;
1249  PCHAR str1, str2, ConditionExpr, GlobalOrLocal;
1250  CHAR Buffer[20];
1251 
1252  l = KdbpGetNextBreakPointNr(0);
1253  if (l < 0)
1254  {
1255  KdbpPrint("No breakpoints.\n");
1256  return TRUE;
1257  }
1258 
1259  KdbpPrint("Breakpoints:\n");
1260  do
1261  {
1262  if (!KdbpGetBreakPointInfo(l, &Address, &Type, &Size, &AccessType, &DebugReg,
1263  &Enabled, &Global, &Process, &ConditionExpr))
1264  {
1265  continue;
1266  }
1267 
1268  if (l == KdbLastBreakPointNr)
1269  {
1270  str1 = "\x1b[1m*";
1271  str2 = "\x1b[0m";
1272  }
1273  else
1274  {
1275  str1 = " ";
1276  str2 = "";
1277  }
1278 
1279  if (Global)
1280  {
1281  GlobalOrLocal = " global";
1282  }
1283  else
1284  {
1285  GlobalOrLocal = Buffer;
1286  sprintf(Buffer, " PID 0x%08lx",
1287  (ULONG)(Process ? Process->UniqueProcessId : INVALID_HANDLE_VALUE));
1288  }
1289 
1290  if (Type == KdbBreakPointSoftware || Type == KdbBreakPointTemporary)
1291  {
1292  KdbpPrint(" %s%03d BPX 0x%08x%s%s%s%s%s\n",
1293  str1, l, Address,
1294  Enabled ? "" : " disabled",
1295  GlobalOrLocal,
1296  ConditionExpr ? " IF " : "",
1297  ConditionExpr ? ConditionExpr : "",
1298  str2);
1299  }
1300  else if (Type == KdbBreakPointHardware)
1301  {
1302  if (!Enabled)
1303  {
1304  KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s disabled%s%s%s%s\n", str1, l, Address,
1305  KDB_ACCESS_TYPE_TO_STRING(AccessType),
1306  Size == 1 ? "byte" : (Size == 2 ? "word" : "dword"),
1307  GlobalOrLocal,
1308  ConditionExpr ? " IF " : "",
1309  ConditionExpr ? ConditionExpr : "",
1310  str2);
1311  }
1312  else
1313  {
1314  KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s DR%d%s%s%s%s\n", str1, l, Address,
1315  KDB_ACCESS_TYPE_TO_STRING(AccessType),
1316  Size == 1 ? "byte" : (Size == 2 ? "word" : "dword"),
1317  DebugReg,
1318  GlobalOrLocal,
1319  ConditionExpr ? " IF " : "",
1320  ConditionExpr ? ConditionExpr : "",
1321  str2);
1322  }
1323  }
1324  }
1325  while ((l = KdbpGetNextBreakPointNr(l+1)) >= 0);
1326 
1327  return TRUE;
1328 }
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:1198
uint32_t ULONG_PTR
Definition: typedefs.h:63
#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:416
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:437
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:464
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:2468
static BOOLEAN KdbpCmdBugCheck ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Bugchecks the system.

Definition at line 2177 of file kdb_cli.c.

2180 {
2181  /* Set the flag and quit looping */
2183 
2184  return FALSE;
2185 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN KdbpBugCheckRequested
Definition: kdb_cli.c:122
static BOOLEAN KdbpCmdContinue ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Continues execution of the system/leaves KDB.

Definition at line 1195 of file kdb_cli.c.

1198 {
1199  /* Exit the main loop */
1200  return FALSE;
1201 }
#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 721 of file kdb_cli.c.

724 {
725  ULONG Count;
726  ULONG ul;
727  INT i;
728  ULONGLONG Result = 0;
730  LONG InstLen;
731 
732  if (Argv[0][0] == 'x') /* display memory */
733  Count = 16;
734  else /* disassemble */
735  Count = 10;
736 
737  if (Argc >= 2)
738  {
739  /* Check for [L count] part */
740  ul = 0;
741  if (strcmp(Argv[Argc-2], "L") == 0)
742  {
743  ul = strtoul(Argv[Argc-1], NULL, 0);
744  if (ul > 0)
745  {
746  Count = ul;
747  Argc -= 2;
748  }
749  }
750  else if (Argv[Argc-1][0] == 'L')
751  {
752  ul = strtoul(Argv[Argc-1] + 1, NULL, 0);
753  if (ul > 0)
754  {
755  Count = ul;
756  Argc--;
757  }
758  }
759 
760  /* Put the remaining arguments back together */
761  Argc--;
762  for (ul = 1; ul < Argc; ul++)
763  {
764  Argv[ul][strlen(Argv[ul])] = ' ';
765  }
766  Argc++;
767  }
768 
769  /* Evaluate the expression */
770  if (Argc > 1)
771  {
772  if (!KdbpEvaluateExpression(Argv[1], sizeof("kdb:> ")-1 + (Argv[1]-Argv[0]), &Result))
773  return TRUE;
774 
775  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
776  KdbpPrint("Warning: Address %I64x is beeing truncated\n",Result);
777 
778  Address = (ULONG_PTR)Result;
779  }
780  else if (Argv[0][0] == 'x')
781  {
782  KdbpPrint("x: Address argument required.\n");
783  return TRUE;
784  }
785 
786  if (Argv[0][0] == 'x')
787  {
788  /* Display dwords */
789  ul = 0;
790 
791  while (Count > 0)
792  {
793  if (!KdbSymPrintAddress((PVOID)Address, NULL))
794  KdbpPrint("<%x>:", Address);
795  else
796  KdbpPrint(":");
797 
798  i = min(4, Count);
799  Count -= i;
800 
801  while (--i >= 0)
802  {
803  if (!NT_SUCCESS(KdbpSafeReadMemory(&ul, (PVOID)Address, sizeof(ul))))
804  KdbpPrint(" ????????");
805  else
806  KdbpPrint(" %08x", ul);
807 
808  Address += sizeof(ul);
809  }
810 
811  KdbpPrint("\n");
812  }
813  }
814  else
815  {
816  /* Disassemble */
817  while (Count-- > 0)
818  {
819  if (!KdbSymPrintAddress((PVOID)Address, NULL))
820  KdbpPrint("<%08x>: ", Address);
821  else
822  KdbpPrint(": ");
823 
824  InstLen = KdbpDisassemble(Address, KdbUseIntelSyntax);
825  if (InstLen < 0)
826  {
827  KdbpPrint("<INVALID>\n");
828  return TRUE;
829  }
830 
831  KdbpPrint("\n");
832  Address += InstLen;
833  }
834  }
835 
836  return TRUE;
837 }
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:392
_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:56
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLenum GLclampf GLint i
Definition: glfuncs.h:14
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
uint64_t ULONGLONG
Definition: typedefs.h:65
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:106
ULONG Eip
Definition: ketypes.h:265
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1734
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:2468
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 2209 of file kdb_cli.c.

2212 {
2213  ULONG beg, end;
2214 
2215  KdbpIsInDmesgMode = TRUE; /* Toggle logging flag */
2216  if (!KdpDmesgBuffer)
2217  {
2218  KdbpPrint("Dmesg: error, buffer is not allocated! /DEBUGPORT=SCREEN kernel param required for dmesg.\n");
2219  return TRUE;
2220  }
2221 
2222  KdbpPrint("*** Dmesg *** TotalWritten=%lu, BufferSize=%lu, CurrentPosition=%lu\n",
2224 
2225  // Pass data to the pager:
2227  beg = (end + KdpDmesgFreeBytes) % KdpDmesgBufferSize;
2228 
2229  // no roll-overs, and overwritten=lost bytes
2231  {
2232  // show buffer (KdpDmesgBuffer + beg, num)
2234  }
2235  else
2236  {
2237  // show 2 buffers: (KdpDmesgBuffer + beg, KdpDmesgBufferSize - beg)
2238  // and: (KdpDmesgBuffer, end)
2240  KdbpPrint("*** Dmesg: buffer rollup ***\n");
2241  KdbpPager(KdpDmesgBuffer, end);
2242  }
2243  KdbpPrint("*** Dmesg: end of output ***\n");
2244 
2245  KdbpIsInDmesgMode = FALSE; /* Toggle logging flag */
2246 
2247  return TRUE;
2248 }
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:2782
unsigned int ULONG
Definition: retypes.h:1
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2468
volatile ULONG KdpDmesgFreeBytes
Definition: kdio.c:43
static BOOLEAN KdbpCmdEnableDisableClearBreakPoint ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Enables, disables or clears a breakpoint.

Definition at line 1333 of file kdb_cli.c.

1336 {
1337  PCHAR pend;
1338  ULONG BreakPointNr;
1339 
1340  if (Argc < 2)
1341  {
1342  KdbpPrint("%s: argument required\n", Argv[0]);
1343  return TRUE;
1344  }
1345 
1346  pend = Argv[1];
1347  BreakPointNr = strtoul(Argv[1], &pend, 0);
1348  if (pend == Argv[1] || *pend != '\0')
1349  {
1350  KdbpPrint("%s: integer argument required\n", Argv[0]);
1351  return TRUE;
1352  }
1353 
1354  if (Argv[0][1] == 'e') /* enable */
1355  {
1356  KdbpEnableBreakPoint(BreakPointNr, NULL);
1357  }
1358  else if (Argv [0][1] == 'd') /* disable */
1359  {
1360  KdbpDisableBreakPoint(BreakPointNr, NULL);
1361  }
1362  else /* clear */
1363  {
1364  ASSERT(Argv[0][1] == 'c');
1365  KdbpDeleteBreakPoint(BreakPointNr, NULL);
1366  }
1367 
1368  return TRUE;
1369 }
BOOLEAN KdbpDeleteBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Deletes a breakpoint.
Definition: kdb.c:654
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:924
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN KdbpEnableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Enables a breakpoint.
Definition: kdb.c:757
unsigned int ULONG
Definition: retypes.h:1
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2468
static BOOLEAN KdbpCmdEvalExpression ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Evaluates an expression and displays the result.

Definition at line 438 of file kdb_cli.c.

441 {
442  ULONG i, len;
443  ULONGLONG Result = 0;
444  ULONG ul;
445  LONG l = 0;
446  BOOLEAN Ok;
447 
448  if (Argc < 2)
449  {
450  KdbpPrint("?: Argument required\n");
451  return TRUE;
452  }
453 
454  /* Put the arguments back together */
455  Argc--;
456  for (i = 1; i < Argc; i++)
457  {
458  len = strlen(Argv[i]);
459  Argv[i][len] = ' ';
460  }
461 
462  /* Evaluate the expression */
463  Ok = KdbpEvaluateExpression(Argv[1], sizeof("kdb:> ")-1 + (Argv[1]-Argv[0]), &Result);
464  if (Ok)
465  {
466  if (Result > 0x00000000ffffffffLL)
467  {
468  if (Result & 0x8000000000000000LL)
469  KdbpPrint("0x%016I64x %20I64u %20I64d\n", Result, Result, Result);
470  else
471  KdbpPrint("0x%016I64x %20I64u\n", Result, Result);
472  }
473  else
474  {
475  ul = (ULONG)Result;
476 
477  if (ul <= 0xff && ul >= 0x80)
478  l = (LONG)((CHAR)ul);
479  else if (ul <= 0xffff && ul >= 0x8000)
480  l = (LONG)((SHORT)ul);
481  else
482  l = (LONG)ul;
483 
484  if (l < 0)
485  KdbpPrint("0x%08lx %10lu %10ld\n", ul, ul, l);
486  else
487  KdbpPrint("0x%08lx %10lu\n", ul, ul);
488  }
489  }
490 
491  return TRUE;
492 }
#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:392
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:65
#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:2468
static BOOLEAN KdbpCmdFilter ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Display list of active debug channels.

Definition at line 635 of file kdb_cli.c.

638 {
640  ULONG set = DPFLTR_MASK, clear = DPFLTR_MASK;
641  PCHAR pend;
642  LPCSTR opt, p;
643 
644  static struct
645  {
646  LPCSTR Name;
647  ULONG Level;
648  }
649  debug_classes[] =
650  {
651  { "error", 1 << DPFLTR_ERROR_LEVEL },
652  { "warning", 1 << DPFLTR_WARNING_LEVEL },
653  { "trace", 1 << DPFLTR_TRACE_LEVEL },
654  { "info", 1 << DPFLTR_INFO_LEVEL },
655  };
656 
657  for (i = 1; i < Argc; i++)
658  {
659  opt = Argv[i];
660  p = opt + strcspn(opt, "+-");
661  if (!p[0]) p = opt; /* assume it's a debug channel name */
662 
663  if (p > opt)
664  {
665  for (j = 0; j < sizeof(debug_classes) / sizeof(debug_classes[0]); j++)
666  {
668  if (len != (p - opt))
669  continue;
670  if (_strnicmp(opt, debug_classes[j].Name, len) == 0) /* found it */
671  {
672  if (*p == '+')
673  set |= debug_classes[j].Level;
674  else
675  clear |= debug_classes[j].Level;
676  break;
677  }
678  }
679  if (j == sizeof(debug_classes) / sizeof(debug_classes[0]))
680  {
681  Level = strtoul(opt, &pend, 0);
682  if (pend != p)
683  {
684  KdbpPrint("filter: bad class name '%.*s'\n", p - opt, opt);
685  continue;
686  }
687  if (*p == '+')
688  set |= Level;
689  else
690  clear |= Level;
691  }
692  }
693  else
694  {
695  if (*p == '-')
696  clear = MAXULONG;
697  else
698  set = MAXULONG;
699  }
700  if (*p == '+' || *p == '-')
701  p++;
702 
703  if (!KdbpGetComponentId(p, &ComponentId))
704  {
705  KdbpPrint("filter: '%s' is not a valid component name!\n", p);
706  return TRUE;
707  }
708 
709  /* Get current mask value */
710  NtSetDebugFilterState(ComponentId, set, TRUE);
711  NtSetDebugFilterState(ComponentId, clear, FALSE);
712  }
713 
714  return TRUE;
715 }
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:135
#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:206
_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
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
GLenum GLsizei len
Definition: glext.h:6722
#define MAXULONG
Definition: typedefs.h:250
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define DPFLTR_ERROR_LEVEL
Definition: main.cpp:32
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:2468
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:432
static BOOLEAN KdbpCmdGdtLdtIdt ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays GDT, LDT or IDTd.

Definition at line 1888 of file kdb_cli.c.

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

Displays help screen.

Definition at line 2432 of file kdb_cli.c.

2435 {
2436  ULONG i;
2437 
2438  KdbpPrint("Kernel debugger commands:\n");
2439  for (i = 0; i < RTL_NUMBER_OF(KdbDebuggerCommands); i++)
2440  {
2441  if (!KdbDebuggerCommands[i].Syntax) /* Command group */
2442  {
2443  if (i > 0)
2444  KdbpPrint("\n");
2445 
2446  KdbpPrint("\x1b[7m* %s:\x1b[0m\n", KdbDebuggerCommands[i].Help);
2447  continue;
2448  }
2449 
2450  KdbpPrint(" %-20s - %s\n",
2451  KdbDebuggerCommands[i].Syntax,
2453  }
2454 
2455  return TRUE;
2456 }
#define TRUE
Definition: types.h:120
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static const struct @1680 KdbDebuggerCommands[]
PCHAR Syntax
Definition: kdb_cli.c:136
PCHAR Help
Definition: kdb_cli.c:137
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
unsigned int ULONG
Definition: retypes.h:1
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2468
static BOOLEAN KdbpCmdMod ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists loaded modules or the one containing the specified address.

Definition at line 1824 of file kdb_cli.c.

1827 {
1828  ULONGLONG Result = 0;
1830  PLDR_DATA_TABLE_ENTRY LdrEntry;
1831  BOOLEAN DisplayOnlyOneModule = FALSE;
1832  INT i = 0;
1833 
1834  if (Argc >= 2)
1835  {
1836  /* Put the arguments back together */
1837  Argc--;
1838  while (--Argc >= 1)
1839  Argv[Argc][strlen(Argv[Argc])] = ' ';
1840 
1841  /* Evaluate the expression */
1842  if (!KdbpEvaluateExpression(Argv[1], sizeof("kdb:> ")-1 + (Argv[1]-Argv[0]), &Result))
1843  {
1844  return TRUE;
1845  }
1846 
1847  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1848  KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv[0],Result);
1849 
1850  Address = (ULONG_PTR)Result;
1851 
1852  if (!KdbpSymFindModule((PVOID)Address, NULL, -1, &LdrEntry))
1853  {
1854  KdbpPrint("No module containing address 0x%p found!\n", Address);
1855  return TRUE;
1856  }
1857 
1858  DisplayOnlyOneModule = TRUE;
1859  }
1860  else
1861  {
1862  if (!KdbpSymFindModule(NULL, NULL, 0, &LdrEntry))
1863  {
1864  ULONG_PTR ntoskrnlBase = ((ULONG_PTR)KdbpCmdMod) & 0xfff00000;
1865  KdbpPrint(" Base Size Name\n");
1866  KdbpPrint(" %08x %08x %s\n", ntoskrnlBase, 0, "ntoskrnl.exe");
1867  return TRUE;
1868  }
1869 
1870  i = 1;
1871  }
1872 
1873  KdbpPrint(" Base Size Name\n");
1874  for (;;)
1875  {
1876  KdbpPrint(" %08x %08x %wZ\n", LdrEntry->DllBase, LdrEntry->SizeOfImage, &LdrEntry->BaseDllName);
1877 
1878  if(DisplayOnlyOneModule || !KdbpSymFindModule(NULL, NULL, i++, &LdrEntry))
1879  break;
1880  }
1881 
1882  return TRUE;
1883 }
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:392
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:56
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID DllBase
Definition: btrfs_drv.h:1766
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:1824
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
unsigned char BOOLEAN
uint64_t ULONGLONG
Definition: typedefs.h:65
Definition: btrfs_drv.h:1762
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:2468
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 2107 of file kdb_cli.c.

2110 {
2111  PKIPCR Pcr = (PKIPCR)KeGetPcr();
2112 
2113  KdbpPrint("Current PCR is at 0x%08x.\n", (INT)Pcr);
2114  KdbpPrint(" Tib.ExceptionList: 0x%08x\n"
2115  " Tib.StackBase: 0x%08x\n"
2116  " Tib.StackLimit: 0x%08x\n"
2117  " Tib.SubSystemTib: 0x%08x\n"
2118  " Tib.FiberData/Version: 0x%08x\n"
2119  " Tib.ArbitraryUserPointer: 0x%08x\n"
2120  " Tib.Self: 0x%08x\n"
2121  " SelfPcr: 0x%08x\n"
2122  " PCRCB: 0x%08x\n"
2123  " Irql: 0x%02x\n"
2124  " IRR: 0x%08x\n"
2125  " IrrActive: 0x%08x\n"
2126  " IDR: 0x%08x\n"
2127  " KdVersionBlock: 0x%08x\n"
2128  " IDT: 0x%08x\n"
2129  " GDT: 0x%08x\n"
2130  " TSS: 0x%08x\n"
2131  " MajorVersion: 0x%04x\n"
2132  " MinorVersion: 0x%04x\n"
2133  " SetMember: 0x%08x\n"
2134  " StallScaleFactor: 0x%08x\n"
2135  " Number: 0x%02x\n"
2136  " L2CacheAssociativity: 0x%02x\n"
2137  " VdmAlert: 0x%08x\n"
2138  " L2CacheSize: 0x%08x\n"
2139  " InterruptMode: 0x%08x\n",
2142  Pcr->NtTib.Self, Pcr->SelfPcr, Pcr->Prcb, Pcr->Irql, Pcr->IRR, Pcr->IrrActive,
2143  Pcr->IDR, Pcr->KdVersionBlock, Pcr->IDT, Pcr->GDT, Pcr->TSS,
2144  Pcr->MajorVersion, Pcr->MinorVersion, Pcr->SetMember, Pcr->StallScaleFactor,
2146  Pcr->VdmAlert, Pcr->SecondLevelCacheSize, Pcr->InterruptMode);
2147 
2148  return TRUE;
2149 }
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:56
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
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:2468
PKIDTENTRY IDT
Definition: ketypes.h:756
struct _KPCR * SelfPcr
Definition: ketypes.h:749
static BOOLEAN KdbpCmdProc ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists processes or switches to another process context.

Definition at line 1706 of file kdb_cli.c.

1709 {
1712  BOOLEAN ReferencedProcess = FALSE;
1713  PCHAR State, pend, str1, str2;
1714  ULONG ul;
1716 
1717  if (Argc >= 2 && _stricmp(Argv[1], "list") == 0)
1718  {
1719  Entry = PsActiveProcessHead.Flink;
1720  if (!Entry || Entry == &PsActiveProcessHead)
1721  {
1722  KdbpPrint("No processes in the system!\n");
1723  return TRUE;
1724  }
1725 
1726  KdbpPrint(" PID State Filename\n");
1727  do
1728  {
1729  Process = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks);
1730 
1731  if (Process == KdbCurrentProcess)
1732  {
1733  str1 = "\x1b[1m*";
1734  str2 = "\x1b[0m";
1735  }
1736  else
1737  {
1738  str1 = " ";
1739  str2 = "";
1740  }
1741 
1742  State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
1743  ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
1744 
1745  KdbpPrint(" %s0x%08x %-10s %s%s\n",
1746  str1,
1747  Process->UniqueProcessId,
1748  State,
1749  Process->ImageFileName,
1750  str2);
1751 
1752  Entry = Entry->Flink;
1753  }
1754  while(Entry != &PsActiveProcessHead);
1755  }
1756  else if (Argc >= 2 && _stricmp(Argv[1], "attach") == 0)
1757  {
1758  if (Argc < 3)
1759  {
1760  KdbpPrint("process attach: process id argument required!\n");
1761  return TRUE;
1762  }
1763 
1764  ul = strtoul(Argv[2], &pend, 0);
1765  if (Argv[2] == pend)
1766  {
1767  KdbpPrint("process attach: '%s' is not a valid process id!\n", Argv[2]);
1768  return TRUE;
1769  }
1770 
1771  if (!KdbpAttachToProcess((PVOID)ul))
1772  {
1773  return TRUE;
1774  }
1775 
1776  KdbpPrint("Attached to process 0x%08x, thread 0x%08x.\n", (ULONG)ul,
1778  }
1779  else
1780  {
1781  Process = KdbCurrentProcess;
1782 
1783  if (Argc >= 2)
1784  {
1785  ul = strtoul(Argv[1], &pend, 0);
1786  if (Argv[1] == pend)
1787  {
1788  KdbpPrint("proc: '%s' is not a valid process id!\n", Argv[1]);
1789  return TRUE;
1790  }
1791 
1792  if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID)ul, &Process)))
1793  {
1794  KdbpPrint("proc: Invalid process id!\n");
1795  return TRUE;
1796  }
1797 
1798  /* Remember our reference */
1799  ReferencedProcess = TRUE;
1800  }
1801 
1802  State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
1803  ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
1804  KdbpPrint("%s"
1805  " PID: 0x%08x\n"
1806  " State: %s (0x%x)\n"
1807  " Image Filename: %s\n",
1808  (Argc < 2) ? "Current process:\n" : "",
1809  Process->UniqueProcessId,
1810  State, Process->Pcb.State,
1811  Process->ImageFileName);
1812 
1813  /* Release our reference, if any */
1814  if (ReferencedProcess)
1815  ObDereferenceObject(Process);
1816  }
1817 
1818  return TRUE;
1819 }
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:2013
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
LIST_ENTRY PsActiveProcessHead
Definition: process.c:22
#define _stricmp
Definition: cat.c:22
HANDLE UniqueProcessId
Definition: pstypes.h:1198
#define FALSE
Definition: types.h:117
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
unsigned char BOOLEAN
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
CLIENT_ID Cid
Definition: pstypes.h:1059
HANDLE UniqueThread
Definition: compat.h:475
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
Definition: typedefs.h:117
KPROCESS Pcb
Definition: pstypes.h:1193
BOOLEAN KdbpAttachToProcess(PVOID ProcessId)
Switches to another process/thread context.
Definition: kdb.c:1173
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:1257
unsigned int ULONG
Definition: retypes.h:1
VOID KdbpPrint(IN PCHAR Format, IN...OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2468
static BOOLEAN KdbpCmdReboot ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Definition at line 2188 of file kdb_cli.c.

2191 {
2192  /* Reboot immediately (we do not return) */
2194  return FALSE;
2195 }
#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 842 of file kdb_cli.c.

845 {
847  INT i;
848  static const PCHAR EflagsBits[32] = { " CF", NULL, " PF", " BIT3", " AF", " BIT5",
849  " ZF", " SF", " TF", " IF", " DF", " OF",
850  NULL, NULL, " NT", " BIT15", " RF", " VF",
851  " AC", " VIF", " VIP", " ID", " BIT22",
852  " BIT23", " BIT24", " BIT25", " BIT26",
853  " BIT27", " BIT28", " BIT29", " BIT30",
854  " BIT31" };
855 
856  if (Argv[0][0] == 'r') /* regs */
857  {
858  KdbpPrint("CS:EIP 0x%04x:0x%08x\n"
859  "SS:ESP 0x%04x:0x%08x\n"
860  " EAX 0x%08x EBX 0x%08x\n"
861  " ECX 0x%08x EDX 0x%08x\n"
862  " ESI 0x%08x EDI 0x%08x\n"
863  " EBP 0x%08x\n",
864  Tf->SegCs & 0xFFFF, Tf->Eip,
865  Tf->HardwareSegSs, Tf->HardwareEsp,
866  Tf->Eax, Tf->Ebx,
867  Tf->Ecx, Tf->Edx,
868  Tf->Esi, Tf->Edi,
869  Tf->Ebp);
870  KdbpPrint("EFLAGS 0x%08x ", Tf->EFlags);
871 
872  for (i = 0; i < 32; i++)
873  {
874  if (i == 1)
875  {
876  if ((Tf->EFlags & (1 << 1)) == 0)
877  KdbpPrint(" !BIT1");
878  }
879  else if (i == 12)
880  {
881  KdbpPrint(" IOPL%d", (Tf->EFlags >> 12) & 3);
882  }
883  else if (i == 13)
884  {
885  }
886  else if ((Tf->EFlags & (1 << i)) != 0)
887  {
888  KdbpPrint(EflagsBits[i]);
889  }
890  }
891 
892  KdbpPrint("\n");
893  }
894  else if (Argv[0][0] == 'c') /* cregs */
895  {
896  ULONG Cr0, Cr2, Cr3, Cr4;
897  KDESCRIPTOR Gdtr = {0, 0, 0}, Idtr = {0, 0, 0};
898  USHORT Ldtr;
899  static const PCHAR Cr0Bits[32] = { " PE", " MP", " EM", " TS", " ET", " NE", NULL, NULL,
900  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
901  " WP", NULL, " AM", NULL, NULL, NULL, NULL, NULL,
902  NULL, NULL, NULL, NULL, NULL, " NW", " CD", " PG" };
903  static const PCHAR Cr4Bits[32] = { " VME", " PVI", " TSD", " DE", " PSE", " PAE", " MCE", " PGE",
904  " PCE", " OSFXSR", " OSXMMEXCPT", NULL, NULL, NULL, NULL, NULL,
905  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
906  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
907 
908  Cr0 = KdbCurrentTrapFrame->Cr0;
909  Cr2 = KdbCurrentTrapFrame->Cr2;
910  Cr3 = KdbCurrentTrapFrame->Cr3;
911  Cr4 = KdbCurrentTrapFrame->Cr4;
912 
913  /* Get descriptor table regs */
914  Ke386GetGlobalDescriptorTable(&Gdtr.Limit);
915  Ldtr = Ke386GetLocalDescriptorTable();
916  __sidt(&Idtr.Limit);
917 
918  /* Display the control registers */
919  KdbpPrint("CR0 0x%08x ", Cr0);
920 
921  for (i = 0; i < 32; i++)
922  {
923  if (!Cr0Bits[i])
924  continue;
925 
926  if ((Cr0 & (1 << i)) != 0)
927  KdbpPrint(Cr0Bits[i]);
928  }
929 
930  KdbpPrint("\nCR2 0x%08x\n", Cr2);
931  KdbpPrint("CR3 0x%08x Pagedir-Base 0x%08x %s%s\n", Cr3, (Cr3 & 0xfffff000),
932  (Cr3 & (1 << 3)) ? " PWT" : "", (Cr3 & (1 << 4)) ? " PCD" : "" );
933  KdbpPrint("CR4 0x%08x ", Cr4);
934 
935  for (i = 0; i < 32; i++)
936  {
937  if (!Cr4Bits[i])
938  continue;
939 
940  if ((Cr4 & (1 << i)) != 0)
941  KdbpPrint(Cr4Bits[i]);
942  }
943 
944  /* Display the descriptor table regs */
945  KdbpPrint("\nGDTR Base 0x%08x Size 0x%04x\n", Gdtr.Base, Gdtr.Limit);
946  KdbpPrint("LDTR 0x%04x\n", Ldtr);
947  KdbpPrint("IDTR Base 0x%08x Size 0x%04x\n", Idtr.Base, Idtr.Limit);
948  }
949  else if (Argv[0][0] == 's') /* sregs */
950  {
951  KdbpPrint("CS 0x%04x Index 0x%04x %cDT RPL%d\n",
952  Tf->SegCs & 0xffff, (Tf->SegCs & 0xffff) >> 3,
953  (Tf->SegCs & (1 << 2)) ? 'L' : 'G', Tf->SegCs & 3);
954  KdbpPrint("DS 0x%04x Index 0x%04x %cDT RPL%d\n",
955  Tf->SegDs, Tf->SegDs >> 3, (Tf->SegDs & (1 << 2)) ? 'L' : 'G', Tf->SegDs & 3);
956  KdbpPrint("ES 0x%04x Index 0x%04x %cDT RPL%d\n",
957  Tf->SegEs, Tf->SegEs >> 3, (Tf->SegEs & (1 << 2)) ? 'L' : 'G', Tf->SegEs & 3);
958  KdbpPrint("FS 0x%04x Index 0x%04x %cDT RPL%d\n",
959  Tf->SegFs, Tf->SegFs >> 3, (Tf->SegFs & (1 << 2)) ? 'L' : 'G', Tf->SegFs & 3);
960  KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
961  Tf->SegGs, Tf->SegGs >> 3, (Tf->SegGs & (1 << 2)) ? 'L' : 'G', Tf->SegGs & 3);
962  KdbpPrint("SS 0x%04x Index 0x%04x %cDT RPL%d\n",
963  Tf->HardwareSegSs, Tf->HardwareSegSs >> 3, (Tf->HardwareSegSs & (1 << 2)) ? 'L' : 'G', Tf->HardwareSegSs & 3);
964  }
965  else /* dregs */
966  {
967  ASSERT(Argv[0][0] == 'd');
968  KdbpPrint("DR0 0x%08x\n"
969  "DR1 0x%08x\n"
970  "DR2 0x%08x\n"
971  "DR3 0x%08x\n"
972  "DR6 0x%08x\n"
973  "DR7 0x%08x\n",
974  Tf->Dr0, Tf->Dr1, Tf->Dr2, Tf->Dr3,
975  Tf->Dr6, Tf->Dr7);
976  }
977 
978  return TRUE;
979 }
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:56
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:1925
USHORT SegEs
Definition: ketypes.h:365
smooth NULL
Definition: ftsmooth.c:416
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:2468
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 2253 of file kdb_cli.c.

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

Continues execution of the system/leaves KDB.

Definition at line 1206 of file kdb_cli.c.

1209 {
1210  ULONG Count = 1;
1211 
1212  if (Argc > 1)
1213  {
1214  Count = strtoul(Argv[1], NULL, 0);
1215  if (Count == 0)
1216  {
1217  KdbpPrint("%s: Integer argument required\n", Argv[0]);
1218  return TRUE;
1219  }
1220  }
1221 
1222  if (Argv[0][0] == 'n')
1224  else
1226 
1227  /* Set the number of single steps and return to the interrupted code. */
1229 
1230  return FALSE;
1231 }
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:416
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:2468
static BOOLEAN KdbpCmdThread ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists threads or switches to another thread context.

Definition at line 1498 of file kdb_cli.c.

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

Displays the TSS.

Definition at line 2154 of file kdb_cli.c.

2157 {
2158  KTSS *Tss = KeGetPcr()->TSS;
2159 
2160  KdbpPrint("Current TSS is at 0x%08x.\n", (INT)Tss);
2161  KdbpPrint(" Eip: 0x%08x\n"
2162  " Es: 0x%04x\n"
2163  " Cs: 0x%04x\n"
2164  " Ss: 0x%04x\n"
2165  " Ds: 0x%04x\n"
2166  " Fs: 0x%04x\n"
2167  " Gs: 0x%04x\n"
2168  " IoMapBase: 0x%04x\n",
2169  Tss->Eip, Tss->Es, Tss->Cs, Tss->Ds, Tss->Fs, Tss->Gs, Tss->IoMapBase);
2170 
2171  return TRUE;
2172 }
#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:56
#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:2468
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 3048 of file kdb_cli.c.

Referenced by KdbpCliMainLoop().

3050 {
3051  ULONG Length1 = strlen(Command) + 1;
3052  ULONG Length2 = 0;
3053  INT i;
3054  PCHAR Buffer;
3055 
3057 
3058  if (Length1 <= 1 ||
3061  {
3062  return;
3063  }
3064 
3065  /* Calculate Length1 and Length2 */
3067  KdbCommandHistoryBufferIndex += Length1;
3068  if (KdbCommandHistoryBufferIndex >= (LONG)RTL_NUMBER_OF(KdbCommandHistoryBuffer))
3069  {
3070  KdbCommandHistoryBufferIndex -= RTL_NUMBER_OF(KdbCommandHistoryBuffer);
3071  Length2 = KdbCommandHistoryBufferIndex;
3072  Length1 -= Length2;
3073  }
3074 
3075  /* Remove previous commands until there is enough space to append the new command */
3076  for (i = KdbCommandHistoryIndex; KdbCommandHistory[i];)
3077  {
3078  if ((Length2 > 0 &&
3079  (KdbCommandHistory[i] >= Buffer ||
3080  KdbCommandHistory[i] < (KdbCommandHistoryBuffer + KdbCommandHistoryBufferIndex))) ||
3081  (Length2 <= 0 &&
3082  (KdbCommandHistory[i] >= Buffer &&
3083  KdbCommandHistory[i] < (KdbCommandHistoryBuffer + KdbCommandHistoryBufferIndex))))
3084  {
3086  }
3087 
3088  i--;
3089  if (i < 0)
3091 
3092  if (i == KdbCommandHistoryIndex)
3093  break;
3094  }
3095 
3096  /* Make sure the new command history entry is free */
3097  KdbCommandHistoryIndex++;
3098  KdbCommandHistoryIndex %= RTL_NUMBER_OF(KdbCommandHistory);
3099  if (KdbCommandHistory[KdbCommandHistoryIndex])
3100  {
3102  }
3103 
3104  /* Append command */
3106  ASSERT((KdbCommandHistory[KdbCommandHistoryIndex] + Length1) <= KdbCommandHistoryBuffer + RTL_NUMBER_OF(KdbCommandHistoryBuffer));
3107  memcpy(KdbCommandHistory[KdbCommandHistoryIndex], Command, Length1);
3108  if (Length2 > 0)
3109  {
3110  memcpy(KdbCommandHistoryBuffer, Command + Length1, Length2);
3111  }
3112 }
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:56
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:416
static LONG KdbCommandHistoryBufferIndex
Definition: kdb_cli.c:111
UINTN VOID * Buffer
Definition: acefiex.h:370
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static LONG KdbCommandHistoryIndex
Definition: kdb_cli.c:112
static PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8]
Definition: kdb_cli.c:110
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static CHAR KdbCommandHistoryBuffer[2048]
Definition: kdb_cli.c:109
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 3394 of file kdb_cli.c.

Referenced by KdbpCliInterpretInitFile(), and KdbpCliMainLoop().

3396 {
3397  ULONG i;
3398  PCHAR p;
3399  ULONG Argc;
3400  // FIXME: for what do we need a 1024 characters command line and 256 tokens?
3401  static PCH Argv[256];
3402  static CHAR OrigCommand[1024];
3403 
3404  RtlStringCbCopyA(OrigCommand, sizeof(OrigCommand), Command);
3405 
3406  Argc = 0;
3407  p = Command;
3408 
3409  for (;;)
3410  {
3411  while (*p == '\t' || *p == ' ')
3412  p++;
3413 
3414  if (*p == '\0')
3415  break;
3416 
3417  i = strcspn(p, "\t ");
3418  Argv[Argc++] = p;
3419  p += i;
3420  if (*p == '\0')
3421  break;
3422 
3423  *p = '\0';
3424  p++;
3425  }
3426 
3427  if (Argc < 1)
3428  return TRUE;
3429 
3430  for (i = 0; i < RTL_NUMBER_OF(KdbDebuggerCommands); i++)
3431  {
3432  if (!KdbDebuggerCommands[i].Name)
3433  continue;
3434 
3435  if (strcmp(KdbDebuggerCommands[i].Name, Argv[0]) == 0)
3436  {
3437  return KdbDebuggerCommands[i].Fn(Argc, Argv);
3438  }
3439  }
3440 
3441  /* Now invoke the registered callbacks */
3442  if (KdbpInvokeCliCallbacks(Command, Argc, Argv))
3443  {
3444  return TRUE;
3445  }
3446 
3447  KdbpPrint("Command '%s' is unknown.\n", OrigCommand);
3448  return TRUE;
3449 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
_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:398
static const struct @1680 KdbDebuggerCommands[]
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:3360
#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:2468
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 392 of file kdb_cli.c.

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

396 {
397  static CHAR ErrMsgBuffer[130] = "^ ";
398  LONG ExpressionErrOffset = -1;
399  PCHAR ErrMsg = ErrMsgBuffer;
400  BOOLEAN Ok;
401 
403  &ExpressionErrOffset, ErrMsgBuffer + 2);
404  if (!Ok)
405  {
406  if (ExpressionErrOffset >= 0)
407  ExpressionErrOffset += ErrOffset;
408  else
409  ErrMsg += 2;
410 
411  KdbpPrint("%*s%s\n", ExpressionErrOffset, "", ErrMsg);
412  }
413 
414  return Ok;
415 }
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:2468
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 206 of file kdb_cli.c.

Referenced by KdbpCmdFilter().

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

422 {
423  char *endptr;
424 
425  /* Skip optional '0x' prefix */
426  if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
427  pszNum += 2;
428 
429  /* Make a number from the string (hex) */
430  *pulValue = strtoul(pszNum, &endptr, 16);
431 
432  return (*endptr == '\0');
433 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
static BOOLEAN KdbpInNmiOrDoubleFaultHandler ( ULONG_PTR  Address)
static

Definition at line 1054 of file kdb_cli.c.

Referenced by KdbpCmdBackTrace().

1056 {
1059 }
PVOID ULONG Address
Definition: oprghdlr.h:14
uint32_t ULONG_PTR
Definition: typedefs.h:63
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 3360 of file kdb_cli.c.

Referenced by KdbpDoCommand().

3364 {
3365  ULONG i;
3366 
3367  /* Loop all entries */
3368  for (i = 0; i < _countof(KdbCliCallbacks); i++)
3369  {
3370  /* Check if this entry is registered */
3371  if (KdbCliCallbacks[i])
3372  {
3373  /* Invoke the callback and check if it handled the command */
3374  if (KdbCliCallbacks[i](Command, Argc, Argv))
3375  {
3376  return TRUE;
3377  }
3378  }
3379  }
3380 
3381  /* None of the callbacks handled the command */
3382  return FALSE;
3383 }
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:105
#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 2782 of file kdb_cli.c.

Referenced by KdbpCmdDmesg().

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

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

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

Referenced by KdbpCliMainLoop().

3125 {
3126  CHAR Key;
3127  PCHAR Orig = Buffer;
3128  ULONG ScanCode = 0;
3129  BOOLEAN EchoOn;
3130  static CHAR LastCommand[1024];
3131  static CHAR NextKey = '\0';
3132  INT CmdHistIndex = -1;
3133  INT i;
3134 
3135  EchoOn = !((KdbDebugState & KD_DEBUG_KDNOECHO) != 0);
3136 
3137  for (;;)
3138  {
3140  {
3141  Key = (NextKey == '\0') ? KdbpGetCharSerial() : NextKey;
3142  NextKey = '\0';
3143  ScanCode = 0;
3144  if (Key == KEY_ESC) /* ESC */
3145  {
3146  Key = KdbpGetCharSerial();
3147  if (Key == '[')
3148  {
3149  Key = KdbpGetCharSerial();
3150 
3151  switch (Key)
3152  {
3153  case 'A':
3154  ScanCode = KEY_SCAN_UP;
3155  break;
3156  case 'B':
3157  ScanCode = KEY_SCAN_DOWN;
3158  break;
3159  case 'C':
3160  break;
3161  case 'D':
3162  break;
3163  }
3164  }
3165  }
3166  }
3167  else
3168  {
3169  ScanCode = 0;
3170  Key = (NextKey == '\0') ? KdbpGetCharKeyboard(&ScanCode) : NextKey;
3171  NextKey = '\0';
3172  }
3173 
3174  if ((ULONG)(Buffer - Orig) >= (Size - 1))
3175  {
3176  /* Buffer is full, accept only newlines */
3177  if (Key != '\n')
3178  continue;
3179  }
3180 
3181  if (Key == '\r')
3182  {
3183  /* Read the next char - this is to throw away a \n which most clients should
3184  * send after \r.
3185  */
3186  KeStallExecutionProcessor(100000);
3187 
3188  if (KdbDebugState & KD_DEBUG_KDSERIAL)
3189  NextKey = KdbpTryGetCharSerial(5);
3190  else
3191  NextKey = KdbpTryGetCharKeyboard(&ScanCode, 5);
3192 
3193  if (NextKey == '\n' || NextKey == -1) /* \n or no response at all */
3194  NextKey = '\0';
3195 
3196  KdbpPrint("\n");
3197 
3198  /*
3199  * Repeat the last command if the user presses enter. Reduces the
3200  * risk of RSI when single-stepping.
3201  */
3202  if (Buffer != Orig)
3203  {
3205  *Buffer = '\0';
3206  RtlStringCbCopyA(LastCommand, sizeof(LastCommand), Orig);
3207  }
3208  else if (KdbRepeatLastCommand)
3209  RtlStringCbCopyA(Buffer, Size, LastCommand);
3210  else
3211  *Buffer = '\0';
3212 
3213  return;
3214  }
3215  else if (Key == KEY_BS || Key == KEY_DEL)
3216  {
3217  if (Buffer > Orig)
3218  {
3219  Buffer--;
3220  *Buffer = 0;
3221 
3222  if (EchoOn)
3223  KdbpPrint("%c %c", KEY_BS, KEY_BS);
3224  else
3225  KdbpPrint(" %c", KEY_BS);
3226  }
3227  }
3228  else if (ScanCode == KEY_SCAN_UP)
3229  {
3230  BOOLEAN Print = TRUE;
3231 
3232  if (CmdHistIndex < 0)
3233  {
3234  CmdHistIndex = KdbCommandHistoryIndex;
3235  }
3236  else
3237  {
3238  i = CmdHistIndex - 1;
3239 
3240  if (i < 0)
3241  CmdHistIndex = RTL_NUMBER_OF(KdbCommandHistory) - 1;
3242 
3244  CmdHistIndex = i;
3245  else
3246  Print = FALSE;
3247  }
3248 
3249  if (Print && KdbCommandHistory[CmdHistIndex])
3250  {
3251  while (Buffer > Orig)
3252  {
3253  Buffer--;
3254  *Buffer = 0;
3255 
3256  if (EchoOn)
3257  KdbpPrint("%c %c", KEY_BS, KEY_BS);
3258  else
3259  KdbpPrint(" %c", KEY_BS);
3260  }
3261 
3262  i = min(strlen(KdbCommandHistory[CmdHistIndex]), Size - 1);
3263  memcpy(Orig, KdbCommandHistory[CmdHistIndex], i);
3264  Orig[i] = '\0';
3265  Buffer = Orig + i;
3266  KdbpPrint("%s", Orig);
3267  }
3268  }
3269  else if (ScanCode == KEY_SCAN_DOWN)
3270  {
3271  if (CmdHistIndex > 0 && CmdHistIndex != KdbCommandHistoryIndex)
3272  {
3273  i = CmdHistIndex + 1;
3274  if (i >= (INT)RTL_NUMBER_OF(KdbCommandHistory))
3275  i = 0;
3276 
3277  if (KdbCommandHistory[i])
3278  {
3279  CmdHistIndex = i;
3280  while (Buffer > Orig)
3281  {
3282  Buffer--;
3283  *Buffer = 0;
3284 
3285  if (EchoOn)
3286  KdbpPrint("%c %c", KEY_BS, KEY_BS);
3287  else
3288  KdbpPrint(" %c", KEY_BS);
3289  }
3290 
3291  i = min(strlen(KdbCommandHistory[CmdHistIndex]), Size - 1);
3292  memcpy(Orig, KdbCommandHistory[CmdHistIndex], i);
3293  Orig[i] = '\0';
3294  Buffer = Orig + i;
3295  KdbpPrint("%s", Orig);
3296  }
3297  }
3298  }
3299  else
3300  {
3301  if (EchoOn)
3302  KdbpPrint("%c", Key);
3303 
3304  *Buffer = Key;
3305  Buffer++;
3306  }
3307  }
3308 }
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:56
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: