ReactOS  0.4.15-dev-1184-g23e04ae
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)
 
#define KD_DEBUG_PRINT_FILTER(Name)   { #Name, DPFLTR_##Name##_ID }
 

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 IDT. 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[])
 Displays the list of active debug channels, or enable/disable 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 ExpKdbgExtPoolFind (ULONG Argc, PCHAR Argv[])
 
BOOLEAN ExpKdbgExtFileCache (ULONG Argc, PCHAR Argv[])
 
BOOLEAN ExpKdbgExtDefWrites (ULONG Argc, PCHAR Argv[])
 
BOOLEAN ExpKdbgExtIrpFind (ULONG Argc, PCHAR Argv[])
 
BOOLEAN ExpKdbgExtHandle (ULONG Argc, PCHAR Argv[])
 
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 KdbpGetComponentId (IN PCSTR ComponentName, OUT PULONG ComponentId)
 Retrieves the component ID corresponding to a given component name. More...
 
static PKTSS KdbpRetrieveTss (IN USHORT TssSelector, OUT PULONG pType OPTIONAL, IN PKDESCRIPTOR pGdtr OPTIONAL)
 
FORCEINLINE BOOLEAN KdbpIsNestedTss (IN USHORT TssSelector, IN PKTSS Tss)
 
static BOOLEAN KdbpTrapFrameFromPrevTss (IN OUT PKTRAP_FRAME TrapFrame, OUT PUSHORT TssSelector, IN OUT PKTSS *pTss, IN PKDESCRIPTOR pGdtr)
 
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 PCHAR 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...
 

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
 
STRING KdbPromptString = RTL_CONSTANT_STRING("kdb:> ")
 
struct {
   PCSTR   Name
 
   ULONG   Id
 
ComponentTable []
 
struct {
   PCHAR   Name
 
   PCHAR   Syntax
 
   PCHAR   Help
 
   BOOLEAN(*   Fn )(ULONG Argc, PCHAR Argv[])
 
KdbDebuggerCommands []
 

Macro Definition Documentation

◆ KD_DEBUG_PRINT_FILTER

#define KD_DEBUG_PRINT_FILTER (   Name)    { #Name, DPFLTR_##Name##_ID }

Definition at line 141 of file kdb_cli.c.

◆ KDB_ACCESS_TYPE_TO_STRING

#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.

◆ KDB_ENTER_CONDITION_TO_STRING

#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.

◆ KEY_BS

#define KEY_BS   8

Definition at line 38 of file kdb_cli.c.

◆ KEY_DEL

#define KEY_DEL   127

Definition at line 40 of file kdb_cli.c.

◆ KEY_ESC

#define KEY_ESC   27

Definition at line 39 of file kdb_cli.c.

◆ KEY_SCAN_DOWN

#define KEY_SCAN_DOWN   80

Definition at line 43 of file kdb_cli.c.

◆ KEY_SCAN_UP

#define KEY_SCAN_UP   72

Definition at line 42 of file kdb_cli.c.

◆ KEYSC_ARROWUP

#define KEYSC_ARROWUP   0x0048

Definition at line 50 of file kdb_cli.c.

◆ KEYSC_END

#define KEYSC_END   0x004f

Definition at line 46 of file kdb_cli.c.

◆ KEYSC_HOME

#define KEYSC_HOME   0x0047

Definition at line 49 of file kdb_cli.c.

◆ KEYSC_PAGEDOWN

#define KEYSC_PAGEDOWN   0x0051

Definition at line 48 of file kdb_cli.c.

◆ KEYSC_PAGEUP

#define KEYSC_PAGEUP   0x0049

Definition at line 47 of file kdb_cli.c.

◆ NDEBUG

#define NDEBUG

Definition at line 33 of file kdb_cli.c.

◆ NPX_STATE_TO_STRING

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

Definition at line 62 of file kdb_cli.c.

Function Documentation

◆ CountOnePageUp()

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

2934 {
2935  PCHAR p;
2936  // p0 is initial guess of Page Start
2938  PCHAR p0 = pCurPos - p0len;
2939  PCHAR prev_p = p0, p1;
2940  ULONG j;
2941 
2942  if (pCurPos < Buffer)
2943  pCurPos = Buffer;
2944  ASSERT(pCurPos <= Buffer + BufLength);
2945 
2946  p = memrchr(p0, '\n', p0len);
2947  if (NULL == p)
2948  p = p0;
2949  for (j = KdbNumberOfRowsTerminal; j--; )
2950  {
2951  int linesCnt;
2952  p1 = memrchr(p0, '\n', p-p0);
2953  prev_p = p;
2954  p = p1;
2955  if (NULL == p)
2956  {
2957  p = prev_p;
2958  if (NULL == p)
2959  p = p0;
2960  break;
2961  }
2962  linesCnt = (KdbNumberOfColsTerminal+prev_p-p-2) / KdbNumberOfColsTerminal;
2963  if (linesCnt > 1)
2964  j -= linesCnt-1;
2965  }
2966 
2967  ASSERT(p != 0);
2968  ++p;
2969  return p;
2970 }
signed char * PCHAR
Definition: retypes.h:7
void * memrchr(const void *s, int c, size_t n)
Definition: kdb_cli.c:2905
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:121
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:122
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by KdbpPager().

◆ ExpKdbgExtDefWrites()

BOOLEAN ExpKdbgExtDefWrites ( ULONG  Argc,
PCHAR  Argv[] 
)

◆ ExpKdbgExtFileCache()

BOOLEAN ExpKdbgExtFileCache ( ULONG  Argc,
PCHAR  Argv[] 
)

◆ ExpKdbgExtHandle()

BOOLEAN ExpKdbgExtHandle ( ULONG  Argc,
PCHAR  Argv[] 
)

◆ ExpKdbgExtIrpFind()

BOOLEAN ExpKdbgExtIrpFind ( ULONG  Argc,
PCHAR  Argv[] 
)

◆ ExpKdbgExtPool()

BOOLEAN ExpKdbgExtPool ( ULONG  Argc,
PCHAR  Argv[] 
)

◆ ExpKdbgExtPoolFind()

BOOLEAN ExpKdbgExtPoolFind ( ULONG  Argc,
PCHAR  Argv[] 
)

◆ ExpKdbgExtPoolUsed()

BOOLEAN ExpKdbgExtPoolUsed ( ULONG  Argc,
PCHAR  Argv[] 
)

◆ KdbpCliInit()

VOID KdbpCliInit ( VOID  )

Called when KDB is initialized.

Reads the KDBinit file from the SystemRoot\System32\drivers\etc directory and executes it.

Definition at line 3787 of file kdb_cli.c.

3788 {
3789  NTSTATUS Status;
3793  FILE_STANDARD_INFORMATION FileStdInfo;
3794  HANDLE hFile = NULL;
3795  INT FileSize;
3796  PCHAR FileBuffer;
3797  ULONG OldEflags;
3798 
3799  /* Initialize the object attributes */
3800  RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3802 
3803  /* Open the file */
3805  &ObjectAttributes, &Iosb, 0,
3808  if (!NT_SUCCESS(Status))
3809  {
3810  DPRINT("Could not open \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3811  return;
3812  }
3813 
3814  /* Get the size of the file */
3815  Status = ZwQueryInformationFile(hFile, &Iosb, &FileStdInfo, sizeof(FileStdInfo),
3817  if (!NT_SUCCESS(Status))
3818  {
3819  ZwClose(hFile);
3820  DPRINT("Could not query size of \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3821  return;
3822  }
3823  FileSize = FileStdInfo.EndOfFile.u.LowPart;
3824 
3825  /* Allocate memory for the file */
3826  FileBuffer = ExAllocatePool(PagedPool, FileSize + 1); /* add 1 byte for terminating '\0' */
3827  if (!FileBuffer)
3828  {
3829  ZwClose(hFile);
3830  DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize);
3831  return;
3832  }
3833 
3834  /* Load file into memory */
3835  Status = ZwReadFile(hFile, NULL, NULL, NULL, &Iosb, FileBuffer, FileSize, NULL, NULL);
3836  ZwClose(hFile);
3837 
3839  {
3840  ExFreePool(FileBuffer);
3841  DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3842  return;
3843  }
3844 
3845  FileSize = min(FileSize, (INT)Iosb.Information);
3846  FileBuffer[FileSize] = '\0';
3847 
3848  /* Enter critical section */
3849  OldEflags = __readeflags();
3850  _disable();
3851 
3852  /* Interpret the init file... */
3853  KdbInitFileBuffer = FileBuffer;
3854  KdbEnter();
3856 
3857  /* Leave critical section */
3858  __writeeflags(OldEflags);
3859 
3860  ExFreePool(FileBuffer);
3861 }
signed char * PCHAR
Definition: retypes.h:7
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
VOID KdbEnter(VOID)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
int32_t INT
Definition: typedefs.h:58
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1569
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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)
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1564
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define SYNCHRONIZE
Definition: nt_native.h:61
_In_ HANDLE hFile
Definition: mswsock.h:90
struct _FileName FileName
Definition: fatprocs.h:893
#define min(a, b)
Definition: monoChain.cc:55
#define FileStandardInformation
Definition: propsheet.cpp:61
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
struct _LARGE_INTEGER::@2267 u
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:124
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ KdbpCliInterpretInitFile()

VOID KdbpCliInterpretInitFile ( VOID  )

This function is called by KdbEnterDebuggerException...

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

Definition at line 3738 of file kdb_cli.c.

3739 {
3740  PCHAR p1, p2;
3741  INT i;
3742  CHAR c;
3743 
3744  /* Execute the commands in the init file */
3745  DPRINT("KDB: Executing KDBinit file...\n");
3746  p1 = KdbInitFileBuffer;
3747  while (p1[0] != '\0')
3748  {
3749  i = strcspn(p1, "\r\n");
3750  if (i > 0)
3751  {
3752  c = p1[i];
3753  p1[i] = '\0';
3754 
3755  /* Look for "break" command and comments */
3756  p2 = p1;
3757 
3758  while (isspace(p2[0]))
3759  p2++;
3760 
3761  if (strncmp(p2, "break", sizeof("break")-1) == 0 &&
3762  (p2[sizeof("break")-1] == '\0' || isspace(p2[sizeof("break")-1])))
3763  {
3764  /* break into the debugger */
3766  }
3767  else if (p2[0] != '#' && p2[0] != '\0') /* Ignore empty lines and comments */
3768  {
3769  KdbpDoCommand(p1);
3770  }
3771 
3772  p1[i] = c;
3773  }
3774 
3775  p1 += i;
3776  while (p1[0] == '\r' || p1[0] == '\n')
3777  p1++;
3778  }
3779  DPRINT("KDB: KDBinit executed\n");
3780 }
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:58
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3598
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
VOID KdbpCliMainLoop(IN BOOLEAN EnteredOnSingleStep)
KDB Main Loop.
Definition: kdb_cli.c:3660
const GLubyte * c
Definition: glext.h:8905
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define c
Definition: ke_i.h:80
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:124

Referenced by KdbEnterDebuggerException().

◆ KdbpCliMainLoop()

VOID KdbpCliMainLoop ( IN BOOLEAN  EnteredOnSingleStep)

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3660 of file kdb_cli.c.

3662 {
3663  static CHAR Command[1024];
3664  BOOLEAN Continue;
3665 
3666  if (EnteredOnSingleStep)
3667  {
3669  {
3670  KdbpPrint("<%08x>", KdbCurrentTrapFrame->Tf.Eip);
3671  }
3672 
3673  KdbpPrint(": ");
3675  {
3676  KdbpPrint("<INVALID>");
3677  }
3678  KdbpPrint("\n");
3679  }
3680 
3681  /* Flush the input buffer */
3683  {
3684  while (KdbpTryGetCharSerial(1) != -1);
3685  }
3686  else
3687  {
3688  ULONG ScanCode;
3689  while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
3690  }
3691 
3692  /* Main loop */
3693  do
3694  {
3695  /* Reset the number of rows/cols printed */
3697 
3698  /* Print the prompt */
3699  KdbpPrint(KdbPromptString.Buffer);
3700 
3701  /* Read a command and remember it */
3702  KdbpReadCommand(Command, sizeof(Command));
3704 
3705  /* Reset the number of rows/cols printed and output aborted state */
3708 
3709  /* Call the command */
3712  }
3713  while (Continue);
3714 }
static VOID KdbpReadCommand(OUT PCHAR Buffer, IN ULONG Size)
Reads a line of user-input.
Definition: kdb_cli.c:3326
static VOID KdbpCommandHistoryAppend(IN PCHAR Command)
Appends a command to the command history.
Definition: kdb_cli.c:3252
ULONG ScanCode
Definition: api.c:39
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PKTRAP_FRAME Context)
Print address...
Definition: kdb_symbols.c:148
ULONG KdbDebugState
Definition: kdb.c:45
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
Definition: shell.h:41
CHAR KdbpTryGetCharSerial(ULONG Retry)
Definition: kdb_serial.c:19
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdb_keyboard.c:104
static ULONG KdbNumberOfRowsPrinted
Definition: kdb_cli.c:117
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3598
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:118
unsigned char BOOLEAN
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:119
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:109
volatile int Continue
Definition: gdblib.c:102
STRING KdbPromptString
Definition: kdb_cli.c:136
ULONG Eip
Definition: ketypes.h:267
KTRAP_FRAME Tf
Definition: kdb.h:15
unsigned int ULONG
Definition: retypes.h:1
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:123

Referenced by KdbpCallMainLoop(), and KdbpCliInterpretInitFile().

◆ KdbpCliModuleLoaded()

VOID KdbpCliModuleLoaded ( IN PUNICODE_STRING  Name)

Called when a module is loaded.

Parameters
NameFilename of the module which was loaded.

Definition at line 3721 of file kdb_cli.c.

3723 {
3724  if (!KdbBreakOnModuleLoad)
3725  return;
3726 
3727  KdbpPrint("Module %wZ loaded.\n", Name);
3729 }
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
static BOOLEAN KdbBreakOnModuleLoad
Definition: kdb_cli.c:110
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)

◆ KdbpCmdBackTrace()

static BOOLEAN KdbpCmdBackTrace ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays a backtrace.

Definition at line 1161 of file kdb_cli.c.

1164 {
1165  ULONG ul;
1166  ULONGLONG Result = 0;
1167  KTRAP_FRAME TrapFrame = KdbCurrentTrapFrame->Tf;
1168  ULONG_PTR Frame = TrapFrame.Ebp;
1170  KDESCRIPTOR Gdtr;
1171  USHORT TssSelector;
1172  PKTSS Tss;
1173 
1174  if (Argc >= 2)
1175  {
1176  /* Check for [L count] part */
1177  ul = 0;
1178  if (strcmp(Argv[Argc-2], "L") == 0)
1179  {
1180  ul = strtoul(Argv[Argc-1], NULL, 0);
1181  if (ul > 0)
1182  {
1183  Argc -= 2;
1184  }
1185  }
1186  else if (Argv[Argc-1][0] == 'L')
1187  {
1188  ul = strtoul(Argv[Argc-1] + 1, NULL, 0);
1189  if (ul > 0)
1190  {
1191  Argc--;
1192  }
1193  }
1194 
1195  /* Put the remaining arguments back together */
1196  Argc--;
1197  for (ul = 1; ul < Argc; ul++)
1198  {
1199  Argv[ul][strlen(Argv[ul])] = ' ';
1200  }
1201  Argc++;
1202  }
1203 
1204  /* Check if a Frame Address or Thread ID is given */
1205  if (Argc > 1)
1206  {
1207  if (Argv[1][0] == '*')
1208  {
1209  Argv[1]++;
1210 
1211  /* Evaluate the expression */
1212  if (!KdbpEvaluateExpression(Argv[1], KdbPromptString.Length + (Argv[1]-Argv[0]), &Result))
1213  return TRUE;
1214 
1215  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1216  KdbpPrint("Warning: Address %I64x is beeing truncated\n", Result);
1217 
1218  Frame = (ULONG_PTR)Result;
1219  }
1220  else
1221  {
1222  KdbpPrint("Thread backtrace not supported yet!\n");
1223  return TRUE;
1224  }
1225  }
1226 
1227  /* Retrieve the Global Descriptor Table */
1228  Ke386GetGlobalDescriptorTable(&Gdtr.Limit);
1229 
1230  /* Retrieve the current (active) TSS */
1231  TssSelector = Ke386GetTr();
1232  Tss = KdbpRetrieveTss(TssSelector, NULL, &Gdtr);
1233  if (KdbpIsNestedTss(TssSelector, Tss))
1234  {
1235  /* Display the active TSS if it is nested */
1236  KdbpPrint("[Active TSS 0x%04x @ 0x%p]\n", TssSelector, Tss);
1237  }
1238 
1239  /* If no Frame Address or Thread ID was given, try printing the function at EIP */
1240  if (Argc <= 1)
1241  {
1242  KdbpPrint("Eip:\n");
1243  if (!KdbSymPrintAddress((PVOID)TrapFrame.Eip, &TrapFrame))
1244  KdbpPrint("<%08x>\n", TrapFrame.Eip);
1245  else
1246  KdbpPrint("\n");
1247  }
1248 
1249  /* Walk through the frames */
1250  KdbpPrint("Frames:\n");
1251  for (;;)
1252  {
1253  BOOLEAN GotNextFrame;
1254 
1255  if (Frame == 0)
1256  goto CheckForParentTSS;
1257 
1258  Address = 0;
1259  if (!NT_SUCCESS(KdbpSafeReadMemory(&Address, (PVOID)(Frame + sizeof(ULONG_PTR)), sizeof(ULONG_PTR))))
1260  {
1261  KdbpPrint("Couldn't access memory at 0x%p!\n", Frame + sizeof(ULONG_PTR));
1262  goto CheckForParentTSS;
1263  }
1264 
1265  if (Address == 0)
1266  goto CheckForParentTSS;
1267 
1268  GotNextFrame = NT_SUCCESS(KdbpSafeReadMemory(&Frame, (PVOID)Frame, sizeof(ULONG_PTR)));
1269  if (GotNextFrame)
1270  TrapFrame.Ebp = Frame;
1271  // else
1272  // Frame = 0;
1273 
1274  /* Print the location of the call instruction (assumed 5 bytes length) */
1275  if (!KdbSymPrintAddress((PVOID)(Address - 5), &TrapFrame))
1276  KdbpPrint("<%08x>\n", Address);
1277  else
1278  KdbpPrint("\n");
1279 
1280  if (KdbOutputAborted)
1281  break;
1282 
1283  if (!GotNextFrame)
1284  {
1285  KdbpPrint("Couldn't access memory at 0x%p!\n", Frame);
1286  goto CheckForParentTSS; // break;
1287  }
1288 
1289  continue;
1290 
1291 CheckForParentTSS:
1292  /*
1293  * We have ended the stack walking for the current (active) TSS.
1294  * Check whether this TSS was nested, and if so switch to its parent
1295  * and walk its stack.
1296  */
1297  if (!KdbpIsNestedTss(TssSelector, Tss))
1298  break; // The TSS is not nested, we stop there.
1299 
1300  GotNextFrame = KdbpTrapFrameFromPrevTss(&TrapFrame, &TssSelector, &Tss, &Gdtr);
1301  if (!GotNextFrame)
1302  {
1303  KdbpPrint("Couldn't access parent TSS 0x%04x\n", Tss->Backlink);
1304  break; // Cannot retrieve the parent TSS, we stop there.
1305  }
1306  Address = TrapFrame.Eip;
1307  Frame = TrapFrame.Ebp;
1308 
1309  KdbpPrint("[Parent TSS 0x%04x @ 0x%p]\n", TssSelector, Tss);
1310 
1311  if (!KdbSymPrintAddress((PVOID)Address, &TrapFrame))
1312  KdbpPrint("<%08x>\n", Address);
1313  else
1314  KdbpPrint("\n");
1315  }
1316 
1317  return TRUE;
1318 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
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:408
#define TRUE
Definition: types.h:120
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
USHORT Backlink
Definition: ketypes.h:791
USHORT Limit
Definition: ketypes.h:485
static PKTSS KdbpRetrieveTss(IN USHORT TssSelector, OUT PULONG pType OPTIONAL, IN PKDESCRIPTOR pGdtr OPTIONAL)
Definition: kdb_cli.c:1046
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
_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
Definition: ketypes.h:789
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
static BOOLEAN KdbpTrapFrameFromPrevTss(IN OUT PKTRAP_FRAME TrapFrame, OUT PUSHORT TssSelector, IN OUT PKTSS *pTss, IN PKDESCRIPTOR pGdtr)
Definition: kdb_cli.c:1113
STRING KdbPromptString
Definition: kdb_cli.c:136
ULONG Eip
Definition: ketypes.h:267
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1726
unsigned short USHORT
Definition: pedump.c:61
KTRAP_FRAME Tf
Definition: kdb.h:15
FORCEINLINE BOOLEAN KdbpIsNestedTss(IN USHORT TssSelector, IN PKTSS Tss)
Definition: kdb_cli.c:1092
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
ULONG Ebp
Definition: ketypes.h:265

◆ KdbpCmdBreakPoint()

static BOOLEAN KdbpCmdBreakPoint ( ULONG  Argc,
PCHAR  Argv[] 
)
static

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

Definition at line 1502 of file kdb_cli.c.

1503 {
1504  ULONGLONG Result = 0;
1507  UCHAR Size = 0;
1508  KDB_ACCESS_TYPE AccessType = 0;
1509  ULONG AddressArgIndex, i;
1510  LONG ConditionArgIndex;
1511  BOOLEAN Global = TRUE;
1512 
1513  if (Argv[0][2] == 'x') /* software breakpoint */
1514  {
1515  if (Argc < 2)
1516  {
1517  KdbpPrint("bpx: Address argument required.\n");
1518  return TRUE;
1519  }
1520 
1521  AddressArgIndex = 1;
1523  }
1524  else /* memory breakpoint */
1525  {
1526  ASSERT(Argv[0][2] == 'm');
1527 
1528  if (Argc < 2)
1529  {
1530  KdbpPrint("bpm: Access type argument required (one of r, w, rw, x)\n");
1531  return TRUE;
1532  }
1533 
1534  if (_stricmp(Argv[1], "x") == 0)
1535  AccessType = KdbAccessExec;
1536  else if (_stricmp(Argv[1], "r") == 0)
1537  AccessType = KdbAccessRead;
1538  else if (_stricmp(Argv[1], "w") == 0)
1539  AccessType = KdbAccessWrite;
1540  else if (_stricmp(Argv[1], "rw") == 0)
1541  AccessType = KdbAccessReadWrite;
1542  else
1543  {
1544  KdbpPrint("bpm: Unknown access type '%s'\n", Argv[1]);
1545  return TRUE;
1546  }
1547 
1548  if (Argc < 3)
1549  {
1550  KdbpPrint("bpm: %s argument required.\n", AccessType == KdbAccessExec ? "Address" : "Memory size");
1551  return TRUE;
1552  }
1553 
1554  AddressArgIndex = 3;
1555  if (_stricmp(Argv[2], "byte") == 0)
1556  Size = 1;
1557  else if (_stricmp(Argv[2], "word") == 0)
1558  Size = 2;
1559  else if (_stricmp(Argv[2], "dword") == 0)
1560  Size = 4;
1561  else if (AccessType == KdbAccessExec)
1562  {
1563  Size = 1;
1564  AddressArgIndex--;
1565  }
1566  else
1567  {
1568  KdbpPrint("bpm: Unknown memory size '%s'\n", Argv[2]);
1569  return TRUE;
1570  }
1571 
1572  if (Argc <= AddressArgIndex)
1573  {
1574  KdbpPrint("bpm: Address argument required.\n");
1575  return TRUE;
1576  }
1577 
1579  }
1580 
1581  /* Put the arguments back together */
1582  ConditionArgIndex = -1;
1583  for (i = AddressArgIndex; i < (Argc-1); i++)
1584  {
1585  if (strcmp(Argv[i+1], "IF") == 0) /* IF found */
1586  {
1587  ConditionArgIndex = i + 2;
1588  if ((ULONG)ConditionArgIndex >= Argc)
1589  {
1590  KdbpPrint("%s: IF requires condition expression.\n", Argv[0]);
1591  return TRUE;
1592  }
1593 
1594  for (i = ConditionArgIndex; i < (Argc-1); i++)
1595  Argv[i][strlen(Argv[i])] = ' ';
1596 
1597  break;
1598  }
1599 
1600  Argv[i][strlen(Argv[i])] = ' ';
1601  }
1602 
1603  /* Evaluate the address expression */
1604  if (!KdbpEvaluateExpression(Argv[AddressArgIndex],
1605  KdbPromptString.Length + (Argv[AddressArgIndex]-Argv[0]),
1606  &Result))
1607  {
1608  return TRUE;
1609  }
1610 
1611  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1612  KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv[0],Result);
1613 
1615 
1616  KdbpInsertBreakPoint(Address, Type, Size, AccessType,
1617  (ConditionArgIndex < 0) ? NULL : Argv[ConditionArgIndex],
1618  Global, NULL);
1619 
1620  return TRUE;
1621 }
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:408
#define TRUE
Definition: types.h:120
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
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:65
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
_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
uint64_t ULONGLONG
Definition: typedefs.h:67
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE
unsigned char UCHAR
Definition: xmlstorage.h:181
STRING KdbPromptString
Definition: kdb_cli.c:136
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
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

◆ KdbpCmdBreakPointList()

static BOOLEAN KdbpCmdBreakPointList ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists breakpoints.

Definition at line 1364 of file kdb_cli.c.

1367 {
1368  LONG l;
1369  ULONG_PTR Address = 0;
1371  KDB_ACCESS_TYPE AccessType = 0;
1372  UCHAR Size = 0;
1373  UCHAR DebugReg = 0;
1374  BOOLEAN Enabled = FALSE;
1375  BOOLEAN Global = FALSE;
1377  PCHAR str1, str2, ConditionExpr, GlobalOrLocal;
1378  CHAR Buffer[20];
1379 
1381  if (l < 0)
1382  {
1383  KdbpPrint("No breakpoints.\n");
1384  return TRUE;
1385  }
1386 
1387  KdbpPrint("Breakpoints:\n");
1388  do
1389  {
1390  if (!KdbpGetBreakPointInfo(l, &Address, &Type, &Size, &AccessType, &DebugReg,
1391  &Enabled, &Global, &Process, &ConditionExpr))
1392  {
1393  continue;
1394  }
1395 
1396  if (l == KdbLastBreakPointNr)
1397  {
1398  str1 = "\x1b[1m*";
1399  str2 = "\x1b[0m";
1400  }
1401  else
1402  {
1403  str1 = " ";
1404  str2 = "";
1405  }
1406 
1407  if (Global)
1408  {
1409  GlobalOrLocal = " global";
1410  }
1411  else
1412  {
1413  GlobalOrLocal = Buffer;
1414  sprintf(Buffer, " PID 0x%08lx",
1415  (ULONG)(Process ? Process->UniqueProcessId : INVALID_HANDLE_VALUE));
1416  }
1417 
1419  {
1420  KdbpPrint(" %s%03d BPX 0x%08x%s%s%s%s%s\n",
1421  str1, l, Address,
1422  Enabled ? "" : " disabled",
1423  GlobalOrLocal,
1424  ConditionExpr ? " IF " : "",
1425  ConditionExpr ? ConditionExpr : "",
1426  str2);
1427  }
1428  else if (Type == KdbBreakPointHardware)
1429  {
1430  if (!Enabled)
1431  {
1432  KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s disabled%s%s%s%s\n", str1, l, Address,
1433  KDB_ACCESS_TYPE_TO_STRING(AccessType),
1434  Size == 1 ? "byte" : (Size == 2 ? "word" : "dword"),
1435  GlobalOrLocal,
1436  ConditionExpr ? " IF " : "",
1437  ConditionExpr ? ConditionExpr : "",
1438  str2);
1439  }
1440  else
1441  {
1442  KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s DR%d%s%s%s%s\n", str1, l, Address,
1443  KDB_ACCESS_TYPE_TO_STRING(AccessType),
1444  Size == 1 ? "byte" : (Size == 2 ? "word" : "dword"),
1445  DebugReg,
1446  GlobalOrLocal,
1447  ConditionExpr ? " IF " : "",
1448  ConditionExpr ? ConditionExpr : "",
1449  str2);
1450  }
1451  }
1452  }
1453  while ((l = KdbpGetNextBreakPointNr(l+1)) >= 0);
1454 
1455  return TRUE;
1456 }
signed char * PCHAR
Definition: retypes.h:7
Type
Definition: Type.h:6
#define TRUE
Definition: types.h:120
#define KDB_ACCESS_TYPE_TO_STRING(type)
Definition: kdb_cli.c:57
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
UNICODE_STRING Global
Definition: symlink.c:37
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
Definition: bufpool.h:45
r l[0]
Definition: byte_order.h:167
LONG KdbpGetNextBreakPointNr(IN ULONG Start OPTIONAL)
Gets the number of the next breakpoint >= Start.
Definition: kdb.c:437
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE
unsigned char UCHAR
Definition: xmlstorage.h:181
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ KdbpCmdBugCheck()

static BOOLEAN KdbpCmdBugCheck ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Bugchecks the system.

Definition at line 2380 of file kdb_cli.c.

2383 {
2384  /* Set the flag and quit looping */
2386  return FALSE;
2387 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN KdbpBugCheckRequested
Definition: kdb_cli.c:125

◆ KdbpCmdContinue()

static BOOLEAN KdbpCmdContinue ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Continues execution of the system/leaves KDB.

Definition at line 1323 of file kdb_cli.c.

1326 {
1327  /* Exit the main loop */
1328  return FALSE;
1329 }
#define FALSE
Definition: types.h:117

◆ KdbpCmdDisassembleX()

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

785 {
786  ULONG Count;
787  ULONG ul;
788  INT i;
789  ULONGLONG Result = 0;
791  LONG InstLen;
792 
793  if (Argv[0][0] == 'x') /* display memory */
794  Count = 16;
795  else /* disassemble */
796  Count = 10;
797 
798  if (Argc >= 2)
799  {
800  /* Check for [L count] part */
801  ul = 0;
802  if (strcmp(Argv[Argc-2], "L") == 0)
803  {
804  ul = strtoul(Argv[Argc-1], NULL, 0);
805  if (ul > 0)
806  {
807  Count = ul;
808  Argc -= 2;
809  }
810  }
811  else if (Argv[Argc-1][0] == 'L')
812  {
813  ul = strtoul(Argv[Argc-1] + 1, NULL, 0);
814  if (ul > 0)
815  {
816  Count = ul;
817  Argc--;
818  }
819  }
820 
821  /* Put the remaining arguments back together */
822  Argc--;
823  for (ul = 1; ul < Argc; ul++)
824  {
825  Argv[ul][strlen(Argv[ul])] = ' ';
826  }
827  Argc++;
828  }
829 
830  /* Evaluate the expression */
831  if (Argc > 1)
832  {
833  if (!KdbpEvaluateExpression(Argv[1], KdbPromptString.Length + (Argv[1]-Argv[0]), &Result))
834  return TRUE;
835 
836  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
837  KdbpPrint("Warning: Address %I64x is beeing truncated\n",Result);
838 
840  }
841  else if (Argv[0][0] == 'x')
842  {
843  KdbpPrint("x: Address argument required.\n");
844  return TRUE;
845  }
846 
847  if (Argv[0][0] == 'x')
848  {
849  /* Display dwords */
850  ul = 0;
851 
852  while (Count > 0)
853  {
855  KdbpPrint("<%08x>:", Address);
856  else
857  KdbpPrint(":");
858 
859  i = min(4, Count);
860  Count -= i;
861 
862  while (--i >= 0)
863  {
864  if (!NT_SUCCESS(KdbpSafeReadMemory(&ul, (PVOID)Address, sizeof(ul))))
865  KdbpPrint(" ????????");
866  else
867  KdbpPrint(" %08x", ul);
868 
869  Address += sizeof(ul);
870  }
871 
872  KdbpPrint("\n");
873  }
874  }
875  else
876  {
877  /* Disassemble */
878  while (Count-- > 0)
879  {
881  KdbpPrint("<%08x>: ", Address);
882  else
883  KdbpPrint(": ");
884 
886  if (InstLen < 0)
887  {
888  KdbpPrint("<INVALID>\n");
889  return TRUE;
890  }
891 
892  KdbpPrint("\n");
893  Address += InstLen;
894  }
895  }
896 
897  return TRUE;
898 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
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:408
#define TRUE
Definition: types.h:120
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1223
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
_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
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:109
STRING KdbPromptString
Definition: kdb_cli.c:136
ULONG Eip
Definition: ketypes.h:267
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1726
KTRAP_FRAME Tf
Definition: kdb.h:15
#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
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:123

◆ KdbpCmdDmesg()

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

2414 {
2415  ULONG beg, end;
2416 
2417  KdbpIsInDmesgMode = TRUE; /* Toggle logging flag */
2418  if (!KdpDmesgBuffer)
2419  {
2420  KdbpPrint("Dmesg: error, buffer is not allocated! /DEBUGPORT=SCREEN kernel param required for dmesg.\n");
2421  return TRUE;
2422  }
2423 
2424  KdbpPrint("*** Dmesg *** TotalWritten=%lu, BufferSize=%lu, CurrentPosition=%lu\n",
2426 
2427  /* Pass data to the pager */
2430 
2431  /* No roll-overs, and overwritten=lost bytes */
2433  {
2434  /* Show buffer (KdpDmesgBuffer + beg, num) */
2436  }
2437  else
2438  {
2439  /* Show 2 buffers: (KdpDmesgBuffer + beg, KdpDmesgBufferSize - beg)
2440  * and: (KdpDmesgBuffer, end) */
2442  KdbpPrint("*** Dmesg: buffer rollup ***\n");
2444  }
2445  KdbpPrint("*** Dmesg: end of output ***\n");
2446 
2447  KdbpIsInDmesgMode = FALSE; /* Toggle logging flag */
2448 
2449  return TRUE;
2450 }
PCHAR KdpDmesgBuffer
Definition: kdio.c:42
volatile BOOLEAN KdbpIsInDmesgMode
Definition: kdio.c:46
#define TRUE
Definition: types.h:120
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
const ULONG KdpDmesgBufferSize
Definition: kdio.c:41
GLuint GLuint end
Definition: gl.h:1545
volatile ULONG KdbDmesgTotalWritten
Definition: kdio.c:45
#define FALSE
Definition: types.h:117
volatile ULONG KdpDmesgCurrentPosition
Definition: kdio.c:43
VOID KdbpPager(IN PCHAR Buffer, IN ULONG BufLength)
Prints the given string with, page by page.
Definition: kdb_cli.c:2985
unsigned int ULONG
Definition: retypes.h:1
volatile ULONG KdpDmesgFreeBytes
Definition: kdio.c:44

◆ KdbpCmdEnableDisableClearBreakPoint()

static BOOLEAN KdbpCmdEnableDisableClearBreakPoint ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Enables, disables or clears a breakpoint.

Definition at line 1461 of file kdb_cli.c.

1464 {
1465  PCHAR pend;
1466  ULONG BreakPointNr;
1467 
1468  if (Argc < 2)
1469  {
1470  KdbpPrint("%s: argument required\n", Argv[0]);
1471  return TRUE;
1472  }
1473 
1474  pend = Argv[1];
1475  BreakPointNr = strtoul(Argv[1], &pend, 0);
1476  if (pend == Argv[1] || *pend != '\0')
1477  {
1478  KdbpPrint("%s: integer argument required\n", Argv[0]);
1479  return TRUE;
1480  }
1481 
1482  if (Argv[0][1] == 'e') /* enable */
1483  {
1484  KdbpEnableBreakPoint(BreakPointNr, NULL);
1485  }
1486  else if (Argv [0][1] == 'd') /* disable */
1487  {
1488  KdbpDisableBreakPoint(BreakPointNr, NULL);
1489  }
1490  else /* clear */
1491  {
1492  ASSERT(Argv[0][1] == 'c');
1493  KdbpDeleteBreakPoint(BreakPointNr, NULL);
1494  }
1495 
1496  return TRUE;
1497 }
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
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1

◆ KdbpCmdEvalExpression()

static BOOLEAN KdbpCmdEvalExpression ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Evaluates an expression and displays the result.

Definition at line 454 of file kdb_cli.c.

457 {
458  ULONG i, len;
459  ULONGLONG Result = 0;
460  ULONG ul;
461  LONG l = 0;
462  BOOLEAN Ok;
463 
464  if (Argc < 2)
465  {
466  KdbpPrint("?: Argument required\n");
467  return TRUE;
468  }
469 
470  /* Put the arguments back together */
471  Argc--;
472  for (i = 1; i < Argc; i++)
473  {
474  len = strlen(Argv[i]);
475  Argv[i][len] = ' ';
476  }
477 
478  /* Evaluate the expression */
479  Ok = KdbpEvaluateExpression(Argv[1], KdbPromptString.Length + (Argv[1]-Argv[0]), &Result);
480  if (Ok)
481  {
482  if (Result > 0x00000000ffffffffLL)
483  {
484  if (Result & 0x8000000000000000LL)
485  KdbpPrint("0x%016I64x %20I64u %20I64d\n", Result, Result, Result);
486  else
487  KdbpPrint("0x%016I64x %20I64u\n", Result, Result);
488  }
489  else
490  {
491  ul = (ULONG)Result;
492 
493  if (ul <= 0xff && ul >= 0x80)
494  l = (LONG)((CHAR)ul);
495  else if (ul <= 0xffff && ul >= 0x8000)
496  l = (LONG)((SHORT)ul);
497  else
498  l = (LONG)ul;
499 
500  if (l < 0)
501  KdbpPrint("0x%08lx %10lu %10ld\n", ul, ul, l);
502  else
503  KdbpPrint("0x%08lx %10lu\n", ul, ul);
504  }
505  }
506 
507  return TRUE;
508 }
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:408
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
short SHORT
Definition: pedump.c:59
unsigned char BOOLEAN
_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
r l[0]
Definition: byte_order.h:167
uint64_t ULONGLONG
Definition: typedefs.h:67
GLenum GLsizei len
Definition: glext.h:6722
STRING KdbPromptString
Definition: kdb_cli.c:136
unsigned int ULONG
Definition: retypes.h:1

◆ KdbpCmdFilter()

static BOOLEAN KdbpCmdFilter ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays the list of active debug channels, or enable/disable debug channels.

Definition at line 678 of file kdb_cli.c.

681 {
683  ULONG set = DPFLTR_MASK, clear = DPFLTR_MASK;
684  PCHAR pend;
685  PCSTR opt, p;
686 
687  static struct
688  {
689  PCSTR Name;
690  ULONG Level;
691  }
692  debug_classes[] =
693  {
694  { "error", 1 << DPFLTR_ERROR_LEVEL },
695  { "warning", 1 << DPFLTR_WARNING_LEVEL },
696  { "trace", 1 << DPFLTR_TRACE_LEVEL },
697  { "info", 1 << DPFLTR_INFO_LEVEL },
698  };
699 
700  if (Argc <= 1)
701  {
702  /* Display the list of available debug filter components */
703  KdbpPrint("REMARKS:\n"
704  "- The 'WIN2000' system-wide debug filter component is used for DbgPrint()\n"
705  " messages without Component ID and Level.\n"
706  "- The 'DEFAULT' debug filter component is used for DbgPrint() messages with\n"
707  " an unknown Component ID.\n\n");
708  KdbpPrint("The list of debug filter components currently available on your system is:\n\n");
709  KdbpPrint(" Component Name Component ID\n"
710  " ================== ================\n");
711  for (i = 0; i < RTL_NUMBER_OF(ComponentTable); i++)
712  {
713  KdbpPrint("%20s 0x%08lx\n", ComponentTable[i].Name, ComponentTable[i].Id);
714  }
715  return TRUE;
716  }
717 
718  for (i = 1; i < Argc; i++)
719  {
720  opt = Argv[i];
721  p = opt + strcspn(opt, "+-");
722  if (!p[0]) p = opt; /* Assume it's a debug channel name */
723 
724  if (p > opt)
725  {
726  for (j = 0; j < RTL_NUMBER_OF(debug_classes); j++)
727  {
729  if (len != (p - opt))
730  continue;
731  if (_strnicmp(opt, debug_classes[j].Name, len) == 0) /* Found it */
732  {
733  if (*p == '+')
734  set |= debug_classes[j].Level;
735  else
736  clear |= debug_classes[j].Level;
737  break;
738  }
739  }
740  if (j == RTL_NUMBER_OF(debug_classes))
741  {
742  Level = strtoul(opt, &pend, 0);
743  if (pend != p)
744  {
745  KdbpPrint("filter: bad class name '%.*s'\n", p - opt, opt);
746  continue;
747  }
748  if (*p == '+')
749  set |= Level;
750  else
751  clear |= Level;
752  }
753  }
754  else
755  {
756  if (*p == '-')
757  clear = MAXULONG;
758  else
759  set = MAXULONG;
760  }
761  if (*p == '+' || *p == '-')
762  p++;
763 
765  {
766  KdbpPrint("filter: '%s' is not a valid component name!\n", p);
767  return TRUE;
768  }
769 
770  /* Get current mask value */
773  }
774 
775  return TRUE;
776 }
signed char * PCHAR
Definition: retypes.h:7
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
NTSTATUS NTAPI NtSetDebugFilterState(_In_ ULONG ComponentId, _In_ ULONG Level, _In_ BOOLEAN State)
Definition: kdapi.c:2388
#define TRUE
Definition: types.h:120
_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
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
PCSTR Name
Definition: kdb_cli.c:146
#define DPFLTR_MASK
Definition: kdtypes.h:34
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
ULONG Id
Definition: kdb_cli.c:147
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 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1274
#define DPFLTR_WARNING_LEVEL
Definition: kdtypes.h:31
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static const char *const debug_classes[]
Definition: debug.c:51
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
GLenum GLsizei len
Definition: glext.h:6722
#define MAXULONG
Definition: typedefs.h:251
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define DPFLTR_ERROR_LEVEL
Definition: main.cpp:32
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
unsigned int ULONG
Definition: retypes.h:1
const char * PCSTR
Definition: typedefs.h:52
GLfloat GLfloat p
Definition: glext.h:8902
static BOOLEAN KdbpGetComponentId(IN PCSTR ComponentName, OUT PULONG ComponentId)
Retrieves the component ID corresponding to a given component name.
Definition: kdb_cli.c:657
Definition: _set.h:46
#define DPFLTR_TRACE_LEVEL
Definition: kdtypes.h:32
static struct @1791 ComponentTable[]

◆ KdbpCmdGdtLdtIdt()

static BOOLEAN KdbpCmdGdtLdtIdt ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays GDT, LDT or IDT.

Definition at line 2016 of file kdb_cli.c.

2019 {
2020  KDESCRIPTOR Reg;
2021  ULONG SegDesc[2];
2022  ULONG SegBase;
2023  ULONG SegLimit;
2024  PCHAR SegType;
2025  USHORT SegSel;
2026  UCHAR Type, Dpl;
2027  INT i;
2028  ULONG ul;
2029 
2030  if (Argv[0][0] == 'i')
2031  {
2032  /* Read IDTR */
2033  __sidt(&Reg.Limit);
2034 
2035  if (Reg.Limit < 7)
2036  {
2037  KdbpPrint("Interrupt descriptor table is empty.\n");
2038  return TRUE;
2039  }
2040 
2041  KdbpPrint("IDT Base: 0x%08x Limit: 0x%04x\n", Reg.Base, Reg.Limit);
2042  KdbpPrint(" Idx Type Seg. Sel. Offset DPL\n");
2043 
2044  for (i = 0; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8)
2045  {
2046  if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)(Reg.Base + i), sizeof(SegDesc))))
2047  {
2048  KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg.Base + i);
2049  return TRUE;
2050  }
2051 
2052  Dpl = ((SegDesc[1] >> 13) & 3);
2053  if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */
2054  SegType = "TASKGATE";
2055  else if ((SegDesc[1] & 0x1fe0) == 0x0e00) /* 32 bit Interrupt gate */
2056  SegType = "INTGATE32";
2057  else if ((SegDesc[1] & 0x1fe0) == 0x0600) /* 16 bit Interrupt gate */
2058  SegType = "INTGATE16";
2059  else if ((SegDesc[1] & 0x1fe0) == 0x0f00) /* 32 bit Trap gate */
2060  SegType = "TRAPGATE32";
2061  else if ((SegDesc[1] & 0x1fe0) == 0x0700) /* 16 bit Trap gate */
2062  SegType = "TRAPGATE16";
2063  else
2064  SegType = "UNKNOWN";
2065 
2066  if ((SegDesc[1] & (1 << 15)) == 0) /* not present */
2067  {
2068  KdbpPrint(" %03d %-10s [NP] [NP] %02d\n",
2069  i / 8, SegType, Dpl);
2070  }
2071  else if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */
2072  {
2073  SegSel = SegDesc[0] >> 16;
2074  KdbpPrint(" %03d %-10s 0x%04x %02d\n",
2075  i / 8, SegType, SegSel, Dpl);
2076  }
2077  else
2078  {
2079  SegSel = SegDesc[0] >> 16;
2080  SegBase = (SegDesc[1] & 0xffff0000) | (SegDesc[0] & 0x0000ffff);
2081  KdbpPrint(" %03d %-10s 0x%04x 0x%08x %02d\n",
2082  i / 8, SegType, SegSel, SegBase, Dpl);
2083  }
2084  }
2085  }
2086  else
2087  {
2088  ul = 0;
2089 
2090  if (Argv[0][0] == 'g')
2091  {
2092  /* Read GDTR */
2093  Ke386GetGlobalDescriptorTable(&Reg.Limit);
2094  i = 8;
2095  }
2096  else
2097  {
2098  ASSERT(Argv[0][0] == 'l');
2099 
2100  /* Read LDTR */
2101  Reg.Limit = Ke386GetLocalDescriptorTable();
2102  Reg.Base = 0;
2103  i = 0;
2104  ul = 1 << 2;
2105  }
2106 
2107  if (Reg.Limit < 7)
2108  {
2109  KdbpPrint("%s descriptor table is empty.\n",
2110  Argv[0][0] == 'g' ? "Global" : "Local");
2111  return TRUE;
2112  }
2113 
2114  KdbpPrint("%cDT Base: 0x%08x Limit: 0x%04x\n",
2115  Argv[0][0] == 'g' ? 'G' : 'L', Reg.Base, Reg.Limit);
2116  KdbpPrint(" Idx Sel. Type Base Limit DPL Attribs\n");
2117 
2118  for (; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8)
2119  {
2120  if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)(Reg.Base + i), sizeof(SegDesc))))
2121  {
2122  KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg.Base + i);
2123  return TRUE;
2124  }
2125 
2126  Dpl = ((SegDesc[1] >> 13) & 3);
2127  Type = ((SegDesc[1] >> 8) & 0xf);
2128 
2129  SegBase = SegDesc[0] >> 16;
2130  SegBase |= (SegDesc[1] & 0xff) << 16;
2131  SegBase |= SegDesc[1] & 0xff000000;
2132  SegLimit = SegDesc[0] & 0x0000ffff;
2133  SegLimit |= (SegDesc[1] >> 16) & 0xf;
2134 
2135  if ((SegDesc[1] & (1 << 23)) != 0)
2136  {
2137  SegLimit *= 4096;
2138  SegLimit += 4095;
2139  }
2140  else
2141  {
2142  SegLimit++;
2143  }
2144 
2145  if ((SegDesc[1] & (1 << 12)) == 0) /* System segment */
2146  {
2147  switch (Type)
2148  {
2149  case 1: SegType = "TSS16(Avl)"; break;
2150  case 2: SegType = "LDT"; break;
2151  case 3: SegType = "TSS16(Busy)"; break;
2152  case 4: SegType = "CALLGATE16"; break;
2153  case 5: SegType = "TASKGATE"; break;
2154  case 6: SegType = "INTGATE16"; break;
2155  case 7: SegType = "TRAPGATE16"; break;
2156  case 9: SegType = "TSS32(Avl)"; break;
2157  case 11: SegType = "TSS32(Busy)"; break;
2158  case 12: SegType = "CALLGATE32"; break;
2159  case 14: SegType = "INTGATE32"; break;
2160  case 15: SegType = "TRAPGATE32"; break;
2161  default: SegType = "UNKNOWN"; break;
2162  }
2163 
2164  if (!(Type >= 1 && Type <= 3) &&
2165  Type != 9 && Type != 11)
2166  {
2167  SegBase = 0;
2168  SegLimit = 0;
2169  }
2170  }
2171  else if ((SegDesc[1] & (1 << 11)) == 0) /* Data segment */
2172  {
2173  if ((SegDesc[1] & (1 << 22)) != 0)
2174  SegType = "DATA32";
2175  else
2176  SegType = "DATA16";
2177  }
2178  else /* Code segment */
2179  {
2180  if ((SegDesc[1] & (1 << 22)) != 0)
2181  SegType = "CODE32";
2182  else
2183  SegType = "CODE16";
2184  }
2185 
2186  if ((SegDesc[1] & (1 << 15)) == 0) /* Not present */
2187  {
2188  KdbpPrint(" %03d 0x%04x %-11s [NP] [NP] %02d NP\n",
2189  i / 8, i | Dpl | ul, SegType, Dpl);
2190  }
2191  else
2192  {
2193  KdbpPrint(" %03d 0x%04x %-11s 0x%08x 0x%08x %02d ",
2194  i / 8, i | Dpl | ul, SegType, SegBase, SegLimit, Dpl);
2195 
2196  if ((SegDesc[1] & (1 << 12)) == 0) /* System segment */
2197  {
2198  /* FIXME: Display system segment */
2199  }
2200  else if ((SegDesc[1] & (1 << 11)) == 0) /* Data segment */
2201  {
2202  if ((SegDesc[1] & (1 << 10)) != 0) /* Expand-down */
2203  KdbpPrint(" E");
2204 
2205  KdbpPrint((SegDesc[1] & (1 << 9)) ? " R/W" : " R");
2206 
2207  if ((SegDesc[1] & (1 << 8)) != 0)
2208  KdbpPrint(" A");
2209  }
2210  else /* Code segment */
2211  {
2212  if ((SegDesc[1] & (1 << 10)) != 0) /* Conforming */
2213  KdbpPrint(" C");
2214 
2215  KdbpPrint((SegDesc[1] & (1 << 9)) ? " R/X" : " X");
2216 
2217  if ((SegDesc[1] & (1 << 8)) != 0)
2218  KdbpPrint(" A");
2219  }
2220 
2221  if ((SegDesc[1] & (1 << 20)) != 0)
2222  KdbpPrint(" AVL");
2223 
2224  KdbpPrint("\n");
2225  }
2226  }
2227  }
2228 
2229  return TRUE;
2230 }
signed char * PCHAR
Definition: retypes.h:7
Type
Definition: Type.h:6
#define TRUE
Definition: types.h:120
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
int32_t INT
Definition: typedefs.h:58
PVOID Base
Definition: ketypes.h:486
USHORT Limit
Definition: ketypes.h:485
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:1934
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1726
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1

◆ KdbpCmdHelp()

static BOOLEAN KdbpCmdHelp ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays help screen.

Definition at line 2634 of file kdb_cli.c.

2637 {
2638  ULONG i;
2639 
2640  KdbpPrint("Kernel debugger commands:\n");
2641  for (i = 0; i < RTL_NUMBER_OF(KdbDebuggerCommands); i++)
2642  {
2643  if (!KdbDebuggerCommands[i].Syntax) /* Command group */
2644  {
2645  if (i > 0)
2646  KdbpPrint("\n");
2647 
2648  KdbpPrint("\x1b[7m* %s:\x1b[0m\n", KdbDebuggerCommands[i].Help);
2649  continue;
2650  }
2651 
2652  KdbpPrint(" %-20s - %s\n",
2655  }
2656 
2657  return TRUE;
2658 }
#define TRUE
Definition: types.h:120
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
static const struct @1792 KdbDebuggerCommands[]
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PCHAR Syntax
Definition: kdb_cli.c:331
PCHAR Help
Definition: kdb_cli.c:332
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
unsigned int ULONG
Definition: retypes.h:1

◆ KdbpCmdMod()

static BOOLEAN KdbpCmdMod ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists loaded modules or the one containing the specified address.

Definition at line 1952 of file kdb_cli.c.

1955 {
1956  ULONGLONG Result = 0;
1958  PLDR_DATA_TABLE_ENTRY LdrEntry;
1959  BOOLEAN DisplayOnlyOneModule = FALSE;
1960  INT i = 0;
1961 
1962  if (Argc >= 2)
1963  {
1964  /* Put the arguments back together */
1965  Argc--;
1966  while (--Argc >= 1)
1967  Argv[Argc][strlen(Argv[Argc])] = ' ';
1968 
1969  /* Evaluate the expression */
1970  if (!KdbpEvaluateExpression(Argv[1], KdbPromptString.Length + (Argv[1]-Argv[0]), &Result))
1971  {
1972  return TRUE;
1973  }
1974 
1975  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1976  KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv[0],Result);
1977 
1979 
1980  if (!KdbpSymFindModule((PVOID)Address, NULL, -1, &LdrEntry))
1981  {
1982  KdbpPrint("No module containing address 0x%p found!\n", Address);
1983  return TRUE;
1984  }
1985 
1986  DisplayOnlyOneModule = TRUE;
1987  }
1988  else
1989  {
1990  if (!KdbpSymFindModule(NULL, NULL, 0, &LdrEntry))
1991  {
1992  ULONG_PTR ntoskrnlBase = ((ULONG_PTR)KdbpCmdMod) & 0xfff00000;
1993  KdbpPrint(" Base Size Name\n");
1994  KdbpPrint(" %08x %08x %s\n", ntoskrnlBase, 0, "ntoskrnl.exe");
1995  return TRUE;
1996  }
1997 
1998  i = 1;
1999  }
2000 
2001  KdbpPrint(" Base Size Name\n");
2002  for (;;)
2003  {
2004  KdbpPrint(" %08x %08x %wZ\n", LdrEntry->DllBase, LdrEntry->SizeOfImage, &LdrEntry->BaseDllName);
2005 
2006  if(DisplayOnlyOneModule || !KdbpSymFindModule(NULL, NULL, i++, &LdrEntry))
2007  break;
2008  }
2009 
2010  return TRUE;
2011 }
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:408
#define TRUE
Definition: types.h:120
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
ULONG SizeOfImage
Definition: ldrtypes.h:143
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
PVOID DllBase
Definition: btrfs_drv.h:1926
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static BOOLEAN KdbpCmdMod(ULONG Argc, PCHAR Argv[])
Lists loaded modules or the one containing the specified address.
Definition: kdb_cli.c:1952
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
_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
uint64_t ULONGLONG
Definition: typedefs.h:67
Definition: btrfs_drv.h:1922
STRING KdbPromptString
Definition: kdb_cli.c:136
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
#define ULONG_PTR
Definition: config.h:101
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

◆ KdbpCmdPcr()

static BOOLEAN KdbpCmdPcr ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays the KPCR.

Definition at line 2235 of file kdb_cli.c.

2238 {
2239  PKIPCR Pcr = (PKIPCR)KeGetPcr();
2240 
2241  KdbpPrint("Current PCR is at 0x%p.\n", Pcr);
2242  KdbpPrint(" Tib.ExceptionList: 0x%08x\n"
2243  " Tib.StackBase: 0x%08x\n"
2244  " Tib.StackLimit: 0x%08x\n"
2245  " Tib.SubSystemTib: 0x%08x\n"
2246  " Tib.FiberData/Version: 0x%08x\n"
2247  " Tib.ArbitraryUserPointer: 0x%08x\n"
2248  " Tib.Self: 0x%08x\n"
2249  " SelfPcr: 0x%08x\n"
2250  " PCRCB: 0x%08x\n"
2251  " Irql: 0x%02x\n"
2252  " IRR: 0x%08x\n"
2253  " IrrActive: 0x%08x\n"
2254  " IDR: 0x%08x\n"
2255  " KdVersionBlock: 0x%08x\n"
2256  " IDT: 0x%08x\n"
2257  " GDT: 0x%08x\n"
2258  " TSS: 0x%08x\n"
2259  " MajorVersion: 0x%04x\n"
2260  " MinorVersion: 0x%04x\n"
2261  " SetMember: 0x%08x\n"
2262  " StallScaleFactor: 0x%08x\n"
2263  " Number: 0x%02x\n"
2264  " L2CacheAssociativity: 0x%02x\n"
2265  " VdmAlert: 0x%08x\n"
2266  " L2CacheSize: 0x%08x\n"
2267  " InterruptMode: 0x%08x\n",
2270  Pcr->NtTib.Self, Pcr->SelfPcr, Pcr->Prcb, Pcr->Irql, Pcr->IRR, Pcr->IrrActive,
2271  Pcr->IDR, Pcr->KdVersionBlock, Pcr->IDT, Pcr->GDT, Pcr->TSS,
2272  Pcr->MajorVersion, Pcr->MinorVersion, Pcr->SetMember, Pcr->StallScaleFactor,
2274  Pcr->VdmAlert, Pcr->SecondLevelCacheSize, Pcr->InterruptMode);
2275 
2276  return TRUE;
2277 }
struct _NT_TIB * Self
Definition: compat.h:468
ULONG IRR
Definition: ketypes.h:754
#define TRUE
Definition: types.h:120
UCHAR SecondLevelCacheAssociativity
Definition: ketypes.h:872
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
USHORT MinorVersion
Definition: ketypes.h:877
struct _KIPCR * PKIPCR
UCHAR Number
Definition: ketypes.h:766
KIRQL Irql
Definition: ketypes.h:871
PVOID ArbitraryUserPointer
Definition: compat.h:467
#define KeGetPcr()
Definition: ke.h:25
ULONG VdmAlert
Definition: ketypes.h:769
ULONG StallScaleFactor
Definition: ketypes.h:878
ULONG SecondLevelCacheSize
Definition: ketypes.h:881
KAFFINITY SetMember
Definition: ketypes.h:763
struct _KTSS * TSS
Definition: ketypes.h:760
ULONG InterruptMode
Definition: ketypes.h:773
PVOID FiberData
Definition: compat.h:464
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: compat.h:459
PVOID SubSystemTib
Definition: compat.h:462
KPRCB Prcb
Definition: ketypes.h:889
PVOID KdVersionBlock
Definition: ketypes.h:885
PVOID StackBase
Definition: compat.h:460
PKGDTENTRY GDT
Definition: ketypes.h:759
USHORT MajorVersion
Definition: ketypes.h:876
ULONG IDR
Definition: ketypes.h:756
ULONG IrrActive
Definition: ketypes.h:755
PVOID StackLimit
Definition: compat.h:461
NT_TIB NtTib
Definition: ketypes.h:857
PKIDTENTRY IDT
Definition: ketypes.h:758
struct _KPCR * SelfPcr
Definition: ketypes.h:751

◆ KdbpCmdProc()

static BOOLEAN KdbpCmdProc ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists processes or switches to another process context.

Definition at line 1834 of file kdb_cli.c.

1837 {
1840  BOOLEAN ReferencedProcess = FALSE;
1841  PCHAR State, pend, str1, str2;
1842  ULONG ul;
1844 
1845  if (Argc >= 2 && _stricmp(Argv[1], "list") == 0)
1846  {
1848  if (!Entry || Entry == &PsActiveProcessHead)
1849  {
1850  KdbpPrint("No processes in the system!\n");
1851  return TRUE;
1852  }
1853 
1854  KdbpPrint(" PID State Filename\n");
1855  do
1856  {
1857  Process = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks);
1858 
1859  if (Process == KdbCurrentProcess)
1860  {
1861  str1 = "\x1b[1m*";
1862  str2 = "\x1b[0m";
1863  }
1864  else
1865  {
1866  str1 = " ";
1867  str2 = "";
1868  }
1869 
1870  State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
1871  ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
1872 
1873  KdbpPrint(" %s0x%08x %-10s %s%s\n",
1874  str1,
1875  Process->UniqueProcessId,
1876  State,
1877  Process->ImageFileName,
1878  str2);
1879 
1880  Entry = Entry->Flink;
1881  }
1882  while(Entry != &PsActiveProcessHead);
1883  }
1884  else if (Argc >= 2 && _stricmp(Argv[1], "attach") == 0)
1885  {
1886  if (Argc < 3)
1887  {
1888  KdbpPrint("process attach: process id argument required!\n");
1889  return TRUE;
1890  }
1891 
1892  ul = strtoul(Argv[2], &pend, 0);
1893  if (Argv[2] == pend)
1894  {
1895  KdbpPrint("process attach: '%s' is not a valid process id!\n", Argv[2]);
1896  return TRUE;
1897  }
1898 
1899  if (!KdbpAttachToProcess((PVOID)ul))
1900  {
1901  return TRUE;
1902  }
1903 
1904  KdbpPrint("Attached to process 0x%08x, thread 0x%08x.\n", (ULONG)ul,
1906  }
1907  else
1908  {
1910 
1911  if (Argc >= 2)
1912  {
1913  ul = strtoul(Argv[1], &pend, 0);
1914  if (Argv[1] == pend)
1915  {
1916  KdbpPrint("proc: '%s' is not a valid process id!\n", Argv[1]);
1917  return TRUE;
1918  }
1919 
1921  {
1922  KdbpPrint("proc: Invalid process id!\n");
1923  return TRUE;
1924  }
1925 
1926  /* Remember our reference */
1927  ReferencedProcess = TRUE;
1928  }
1929 
1930  State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
1931  ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
1932  KdbpPrint("%s"
1933  " PID: 0x%08x\n"
1934  " State: %s (0x%x)\n"
1935  " Image Filename: %s\n",
1936  (Argc < 2) ? "Current process:\n" : "",
1937  Process->UniqueProcessId,
1938  State, Process->Pcb.State,
1939  Process->ImageFileName);
1940 
1941  /* Release our reference, if any */
1942  if (ReferencedProcess)
1944  }
1945 
1946  return TRUE;
1947 }
signed char * PCHAR
Definition: retypes.h:7
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
PEPROCESS KdbCurrentProcess
Definition: kdb.c:47
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
LIST_ENTRY PsActiveProcessHead
Definition: process.c:22
#define _stricmp
Definition: cat.c:22
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
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:121
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID Cid
Definition: pstypes.h:1070
HANDLE UniqueThread
Definition: compat.h:574
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
Definition: typedefs.h:119
BOOLEAN KdbpAttachToProcess(PVOID ProcessId)
Switches to another process/thread context.
Definition: kdb.c:1173
_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
unsigned int ULONG
Definition: retypes.h:1
base of all file and directory entries
Definition: entries.h:82

◆ KdbpCmdReboot()

static BOOLEAN KdbpCmdReboot ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Definition at line 2390 of file kdb_cli.c.

2393 {
2394  /* Reboot immediately (we do not return) */
2396  return FALSE;
2397 }
#define FALSE
Definition: types.h:117
VOID NTAPI HalReturnToFirmware(IN FIRMWARE_REENTRY Action)
Definition: reboot.c:22

◆ KdbpCmdRegs()

static BOOLEAN KdbpCmdRegs ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays CPU registers.

Definition at line 903 of file kdb_cli.c.

906 {
908  INT i;
909  static const PCHAR EflagsBits[32] = { " CF", NULL, " PF", " BIT3", " AF", " BIT5",
910  " ZF", " SF", " TF", " IF", " DF", " OF",
911  NULL, NULL, " NT", " BIT15", " RF", " VF",
912  " AC", " VIF", " VIP", " ID", " BIT22",
913  " BIT23", " BIT24", " BIT25", " BIT26",
914  " BIT27", " BIT28", " BIT29", " BIT30",
915  " BIT31" };
916 
917  if (Argv[0][0] == 'r') /* regs */
918  {
919  KdbpPrint("CS:EIP 0x%04x:0x%08x\n"
920  "SS:ESP 0x%04x:0x%08x\n"
921  " EAX 0x%08x EBX 0x%08x\n"
922  " ECX 0x%08x EDX 0x%08x\n"
923  " ESI 0x%08x EDI 0x%08x\n"
924  " EBP 0x%08x\n",
925  Tf->SegCs & 0xFFFF, Tf->Eip,
926  Tf->HardwareSegSs, Tf->HardwareEsp,
927  Tf->Eax, Tf->Ebx,
928  Tf->Ecx, Tf->Edx,
929  Tf->Esi, Tf->Edi,
930  Tf->Ebp);
931 
932  /* Display the EFlags */
933  KdbpPrint("EFLAGS 0x%08x ", Tf->EFlags);
934  for (i = 0; i < 32; i++)
935  {
936  if (i == 1)
937  {
938  if ((Tf->EFlags & (1 << 1)) == 0)
939  KdbpPrint(" !BIT1");
940  }
941  else if (i == 12)
942  {
943  KdbpPrint(" IOPL%d", (Tf->EFlags >> 12) & 3);
944  }
945  else if (i == 13)
946  {
947  }
948  else if ((Tf->EFlags & (1 << i)) != 0)
949  {
950  KdbpPrint(EflagsBits[i]);
951  }
952  }
953  KdbpPrint("\n");
954  }
955  else if (Argv[0][0] == 'c') /* cregs */
956  {
957  ULONG Cr0, Cr2, Cr3, Cr4;
958  KDESCRIPTOR Gdtr = {0, 0, 0}, Idtr = {0, 0, 0};
959  USHORT Ldtr, Tr;
960  static const PCHAR Cr0Bits[32] = { " PE", " MP", " EM", " TS", " ET", " NE", NULL, NULL,
961  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
962  " WP", NULL, " AM", NULL, NULL, NULL, NULL, NULL,
963  NULL, NULL, NULL, NULL, NULL, " NW", " CD", " PG" };
964  static const PCHAR Cr4Bits[32] = { " VME", " PVI", " TSD", " DE", " PSE", " PAE", " MCE", " PGE",
965  " PCE", " OSFXSR", " OSXMMEXCPT", NULL, NULL, NULL, NULL, NULL,
966  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
967  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
968 
969  /* Retrieve the control registers */
970  Cr0 = KdbCurrentTrapFrame->Cr0;
971  Cr2 = KdbCurrentTrapFrame->Cr2;
972  Cr3 = KdbCurrentTrapFrame->Cr3;
973  Cr4 = KdbCurrentTrapFrame->Cr4;
974 
975  /* Retrieve the descriptor table and task segment registers */
976  Ke386GetGlobalDescriptorTable(&Gdtr.Limit);
977  Ldtr = Ke386GetLocalDescriptorTable();
978  __sidt(&Idtr.Limit);
979  Tr = Ke386GetTr();
980 
981  /* Display the control registers */
982  KdbpPrint("CR0 0x%08x ", Cr0);
983  for (i = 0; i < 32; i++)
984  {
985  if (!Cr0Bits[i])
986  continue;
987 
988  if ((Cr0 & (1 << i)) != 0)
989  KdbpPrint(Cr0Bits[i]);
990  }
991  KdbpPrint("\n");
992 
993  KdbpPrint("CR2 0x%08x\n", Cr2);
994  KdbpPrint("CR3 0x%08x Pagedir-Base 0x%08x %s%s\n", Cr3, (Cr3 & 0xfffff000),
995  (Cr3 & (1 << 3)) ? " PWT" : "", (Cr3 & (1 << 4)) ? " PCD" : "" );
996  KdbpPrint("CR4 0x%08x ", Cr4);
997  for (i = 0; i < 32; i++)
998  {
999  if (!Cr4Bits[i])
1000  continue;
1001 
1002  if ((Cr4 & (1 << i)) != 0)
1003  KdbpPrint(Cr4Bits[i]);
1004  }
1005  KdbpPrint("\n");
1006 
1007  /* Display the descriptor table and task segment registers */
1008  KdbpPrint("GDTR Base 0x%08x Size 0x%04x\n", Gdtr.Base, Gdtr.Limit);
1009  KdbpPrint("LDTR 0x%04x\n", Ldtr);
1010  KdbpPrint("IDTR Base 0x%08x Size 0x%04x\n", Idtr.Base, Idtr.Limit);
1011  KdbpPrint("TR 0x%04x\n", Tr);
1012  }
1013  else if (Argv[0][0] == 's') /* sregs */
1014  {
1015  KdbpPrint("CS 0x%04x Index 0x%04x %cDT RPL%d\n",
1016  Tf->SegCs & 0xffff, (Tf->SegCs & 0xffff) >> 3,
1017  (Tf->SegCs & (1 << 2)) ? 'L' : 'G', Tf->SegCs & 3);
1018  KdbpPrint("DS 0x%04x Index 0x%04x %cDT RPL%d\n",
1019  Tf->SegDs, Tf->SegDs >> 3, (Tf->SegDs & (1 << 2)) ? 'L' : 'G', Tf->SegDs & 3);
1020  KdbpPrint("ES 0x%04x Index 0x%04x %cDT RPL%d\n",
1021  Tf->SegEs, Tf->SegEs >> 3, (Tf->SegEs & (1 << 2)) ? 'L' : 'G', Tf->SegEs & 3);
1022  KdbpPrint("FS 0x%04x Index 0x%04x %cDT RPL%d\n",
1023  Tf->SegFs, Tf->SegFs >> 3, (Tf->SegFs & (1 << 2)) ? 'L' : 'G', Tf->SegFs & 3);
1024  KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
1025  Tf->SegGs, Tf->SegGs >> 3, (Tf->SegGs & (1 << 2)) ? 'L' : 'G', Tf->SegGs & 3);
1026  KdbpPrint("SS 0x%04x Index 0x%04x %cDT RPL%d\n",
1027  Tf->HardwareSegSs, Tf->HardwareSegSs >> 3, (Tf->HardwareSegSs & (1 << 2)) ? 'L' : 'G', Tf->HardwareSegSs & 3);
1028  }
1029  else /* dregs */
1030  {
1031  ASSERT(Argv[0][0] == 'd');
1032  KdbpPrint("DR0 0x%08x\n"
1033  "DR1 0x%08x\n"
1034  "DR2 0x%08x\n"
1035  "DR3 0x%08x\n"
1036  "DR6 0x%08x\n"
1037  "DR7 0x%08x\n",
1038  Tf->Dr0, Tf->Dr1, Tf->Dr2, Tf->Dr3,
1039  Tf->Dr6, Tf->Dr7);
1040  }
1041 
1042  return TRUE;
1043 }
signed char * PCHAR
Definition: retypes.h:7
ULONG Cr3
Definition: kdb.h:19
#define TRUE
Definition: types.h:120
ULONG Cr4
Definition: kdb.h:20
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
USHORT SegFs
Definition: ketypes.h:366
ULONG HardwareSegSs
Definition: ketypes.h:271
ULONG Esi
Definition: ketypes.h:263
int32_t INT
Definition: typedefs.h:58
PVOID Base
Definition: ketypes.h:486
ULONG Edi
Definition: ketypes.h:262
USHORT Limit
Definition: ketypes.h:485
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
UINT64 Dr2
Definition: ketypes.h:344
ULONG Eax
Definition: ketypes.h:258
USHORT SegGs
Definition: ketypes.h:367
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:1934
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:270
UINT64 Dr6
Definition: ketypes.h:346
UINT64 Dr3
Definition: ketypes.h:345
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
UINT64 Dr1
Definition: ketypes.h:343
USHORT SegDs
Definition: ketypes.h:364
ULONG Ecx
Definition: ketypes.h:257
ULONG Eip
Definition: ketypes.h:267
UINT64 Dr0
Definition: ketypes.h:342
ULONG Cr0
Definition: kdb.h:16
ULONG Ebx
Definition: ketypes.h:264
unsigned short USHORT
Definition: pedump.c:61
KTRAP_FRAME Tf
Definition: kdb.h:15
unsigned int ULONG
Definition: retypes.h:1
UINT64 Dr7
Definition: ketypes.h:347
ULONG Cr2
Definition: kdb.h:18
ULONG EFlags
Definition: ketypes.h:384
ULONG Edx
Definition: ketypes.h:256
ULONG Ebp
Definition: ketypes.h:265

◆ KdbpCmdSet()

static BOOLEAN KdbpCmdSet ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Sets or displays a config variables value.

Definition at line 2455 of file kdb_cli.c.

2458 {
2459  LONG l;
2460  BOOLEAN First;
2461  PCHAR pend = 0;
2462  KDB_ENTER_CONDITION ConditionFirst = KdbDoNotEnter;
2463  KDB_ENTER_CONDITION ConditionLast = KdbDoNotEnter;
2464 
2465  static const PCHAR ExceptionNames[21] =
2466  {
2467  "ZERODEVIDE", "DEBUGTRAP", "NMI", "INT3", "OVERFLOW", "BOUND", "INVALIDOP",
2468  "NOMATHCOP", "DOUBLEFAULT", "RESERVED(9)", "INVALIDTSS", "SEGMENTNOTPRESENT",
2469  "STACKFAULT", "GPF", "PAGEFAULT", "RESERVED(15)", "MATHFAULT", "ALIGNMENTCHECK",
2470  "MACHINECHECK", "SIMDFAULT", "OTHERS"
2471  };
2472 
2473  if (Argc == 1)
2474  {
2475  KdbpPrint("Available settings:\n");
2476  KdbpPrint(" syntax [intel|at&t]\n");
2477  KdbpPrint(" condition [exception|*] [first|last] [never|always|kmode|umode]\n");
2478  KdbpPrint(" break_on_module_load [true|false]\n");
2479  }
2480  else if (strcmp(Argv[1], "syntax") == 0)
2481  {
2482  if (Argc == 2)
2483  {
2484  KdbpPrint("syntax = %s\n", KdbUseIntelSyntax ? "intel" : "at&t");
2485  }
2486  else if (Argc >= 3)
2487  {
2488  if (_stricmp(Argv[2], "intel") == 0)
2490  else if (_stricmp(Argv[2], "at&t") == 0)
2492  else
2493  KdbpPrint("Unknown syntax '%s'.\n", Argv[2]);
2494  }
2495  }
2496  else if (strcmp(Argv[1], "condition") == 0)
2497  {
2498  if (Argc == 2)
2499  {
2500  KdbpPrint("Conditions: (First) (Last)\n");
2501  for (l = 0; l < RTL_NUMBER_OF(ExceptionNames) - 1; l++)
2502  {
2503  if (!ExceptionNames[l])
2504  continue;
2505 
2506  if (!KdbpGetEnterCondition(l, TRUE, &ConditionFirst))
2507  ASSERT(FALSE);
2508 
2509  if (!KdbpGetEnterCondition(l, FALSE, &ConditionLast))
2510  ASSERT(FALSE);
2511 
2512  KdbpPrint(" #%02d %-20s %-8s %-8s\n", l, ExceptionNames[l],
2513  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2514  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2515  }
2516 
2517  ASSERT(l == (RTL_NUMBER_OF(ExceptionNames) - 1));
2518  KdbpPrint(" %-20s %-8s %-8s\n", ExceptionNames[l],
2519  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2520  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2521  }
2522  else
2523  {
2524  if (Argc >= 5 && strcmp(Argv[2], "*") == 0) /* Allow * only when setting condition */
2525  {
2526  l = -1;
2527  }
2528  else
2529  {
2530  l = strtoul(Argv[2], &pend, 0);
2531 
2532  if (Argv[2] == pend)
2533  {
2534  for (l = 0; l < RTL_NUMBER_OF(ExceptionNames); l++)
2535  {
2536  if (!ExceptionNames[l])
2537  continue;
2538 
2539  if (_stricmp(ExceptionNames[l], Argv[2]) == 0)
2540  break;
2541  }
2542  }
2543 
2544  if (l >= RTL_NUMBER_OF(ExceptionNames))
2545  {
2546  KdbpPrint("Unknown exception '%s'.\n", Argv[2]);
2547  return TRUE;
2548  }
2549  }
2550 
2551  if (Argc > 4)
2552  {
2553  if (_stricmp(Argv[3], "first") == 0)
2554  First = TRUE;
2555  else if (_stricmp(Argv[3], "last") == 0)
2556  First = FALSE;
2557  else
2558  {
2559  KdbpPrint("set condition: second argument must be 'first' or 'last'\n");
2560  return TRUE;
2561  }
2562 
2563  if (_stricmp(Argv[4], "never") == 0)
2564  ConditionFirst = KdbDoNotEnter;
2565  else if (_stricmp(Argv[4], "always") == 0)
2566  ConditionFirst = KdbEnterAlways;
2567  else if (_stricmp(Argv[4], "umode") == 0)
2568  ConditionFirst = KdbEnterFromUmode;
2569  else if (_stricmp(Argv[4], "kmode") == 0)
2570  ConditionFirst = KdbEnterFromKmode;
2571  else
2572  {
2573  KdbpPrint("set condition: third argument must be 'never', 'always', 'umode' or 'kmode'\n");
2574  return TRUE;
2575  }
2576 
2577  if (!KdbpSetEnterCondition(l, First, ConditionFirst))
2578  {
2579  if (l >= 0)
2580  KdbpPrint("Couldn't change condition for exception #%02d\n", l);
2581  else
2582  KdbpPrint("Couldn't change condition for all exceptions\n", l);
2583  }
2584  }
2585  else /* Argc >= 3 */
2586  {
2587  if (!KdbpGetEnterCondition(l, TRUE, &ConditionFirst))
2588  ASSERT(FALSE);
2589 
2590  if (!KdbpGetEnterCondition(l, FALSE, &ConditionLast))
2591  ASSERT(FALSE);
2592 
2593  if (l < (RTL_NUMBER_OF(ExceptionNames) - 1))
2594  {
2595  KdbpPrint("Condition for exception #%02d (%s): FirstChance %s LastChance %s\n",
2596  l, ExceptionNames[l],
2597  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2598  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2599  }
2600  else
2601  {
2602  KdbpPrint("Condition for all other exceptions: FirstChance %s LastChance %s\n",
2603  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2604  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2605  }
2606  }
2607  }
2608  }
2609  else if (strcmp(Argv[1], "break_on_module_load") == 0)
2610  {
2611  if (Argc == 2)
2612  KdbpPrint("break_on_module_load = %s\n", KdbBreakOnModuleLoad ? "enabled" : "disabled");
2613  else if (Argc >= 3)
2614  {
2615  if (_stricmp(Argv[2], "enable") == 0 || _stricmp(Argv[2], "enabled") == 0 || _stricmp(Argv[2], "true") == 0)
2617  else if (_stricmp(Argv[2], "disable") == 0 || _stricmp(Argv[2], "disabled") == 0 || _stricmp(Argv[2], "false") == 0)
2619  else
2620  KdbpPrint("Unknown setting '%s'.\n", Argv[2]);
2621  }
2622  }
2623  else
2624  {
2625  KdbpPrint("Unknown setting '%s'.\n", Argv[1]);
2626  }
2627 
2628  return TRUE;
2629 }
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
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
#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
unsigned char BOOLEAN
r l[0]
Definition: byte_order.h:167
static BOOLEAN KdbBreakOnModuleLoad
Definition: kdb_cli.c:110
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:109
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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

◆ KdbpCmdStep()

static BOOLEAN KdbpCmdStep ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Continues execution of the system/leaves KDB.

Definition at line 1334 of file kdb_cli.c.

1337 {
1338  ULONG Count = 1;
1339 
1340  if (Argc > 1)
1341  {
1342  Count = strtoul(Argv[1], NULL, 0);
1343  if (Count == 0)
1344  {
1345  KdbpPrint("%s: Integer argument required\n", Argv[0]);
1346  return TRUE;
1347  }
1348  }
1349 
1350  if (Argv[0][0] == 'n')
1352  else
1354 
1355  /* Set the number of single steps and return to the interrupted code. */
1357 
1358  return FALSE;
1359 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1223
#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

◆ KdbpCmdThread()

static BOOLEAN KdbpCmdThread ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Lists threads or switches to another thread context.

Definition at line 1626 of file kdb_cli.c.

1629 {
1631  PETHREAD Thread = NULL;
1633  BOOLEAN ReferencedThread = FALSE, ReferencedProcess = FALSE;
1634  PULONG Esp;
1635  PULONG Ebp;
1636  ULONG Eip;
1637  ULONG ul = 0;
1638  PCHAR State, pend, str1, str2;
1639  static const PCHAR ThreadStateToString[DeferredReady+1] =
1640  {
1641  "Initialized", "Ready", "Running",
1642  "Standby", "Terminated", "Waiting",
1643  "Transition", "DeferredReady"
1644  };
1645 
1647 
1648  if (Argc >= 2 && _stricmp(Argv[1], "list") == 0)
1649  {
1651 
1652  if (Argc >= 3)
1653  {
1654  ul = strtoul(Argv[2], &pend, 0);
1655  if (Argv[2] == pend)
1656  {
1657  KdbpPrint("thread: '%s' is not a valid process id!\n", Argv[2]);
1658  return TRUE;
1659  }
1660 
1662  {
1663  KdbpPrint("thread: Invalid process id!\n");
1664  return TRUE;
1665  }
1666 
1667  /* Remember our reference */
1668  ReferencedProcess = TRUE;
1669  }
1670 
1671  Entry = Process->ThreadListHead.Flink;
1672  if (Entry == &Process->ThreadListHead)
1673  {
1674  if (Argc >= 3)
1675  KdbpPrint("No threads in process 0x%08x!\n", ul);
1676  else
1677  KdbpPrint("No threads in current process!\n");
1678 
1679  if (ReferencedProcess)
1681 
1682  return TRUE;
1683  }
1684 
1685  KdbpPrint(" TID State Prior. Affinity EBP EIP\n");
1686  do
1687  {
1688  Thread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
1689 
1690  if (Thread == KdbCurrentThread)
1691  {
1692  str1 = "\x1b[1m*";
1693  str2 = "\x1b[0m";
1694  }
1695  else
1696  {
1697  str1 = " ";
1698  str2 = "";
1699  }
1700 
1701  if (!Thread->Tcb.InitialStack)
1702  {
1703  /* Thread has no kernel stack (probably terminated) */
1704  Esp = Ebp = NULL;
1705  Eip = 0;
1706  }
1707  else if (Thread->Tcb.TrapFrame)
1708  {
1710  Esp = (PULONG)Thread->Tcb.TrapFrame->TempEsp;
1711  else
1713 
1714  Ebp = (PULONG)Thread->Tcb.TrapFrame->Ebp;
1715  Eip = Thread->Tcb.TrapFrame->Eip;
1716  }
1717  else
1718  {
1719  Esp = (PULONG)Thread->Tcb.KernelStack;
1720  Ebp = (PULONG)Esp[4];
1721  Eip = 0;
1722 
1723  if (Ebp) /* FIXME: Should we attach to the process to read Ebp[1]? */
1724  KdbpSafeReadMemory(&Eip, Ebp + 1, sizeof(Eip));
1725  }
1726 
1727  if (Thread->Tcb.State < (DeferredReady + 1))
1728  State = ThreadStateToString[Thread->Tcb.State];
1729  else
1730  State = "Unknown";
1731 
1732  KdbpPrint(" %s0x%08x %-11s %3d 0x%08x 0x%08x 0x%08x%s\n",
1733  str1,
1735  State,
1736  Thread->Tcb.Priority,
1737  Thread->Tcb.Affinity,
1738  Ebp,
1739  Eip,
1740  str2);
1741 
1742  Entry = Entry->Flink;
1743  }
1744  while (Entry != &Process->ThreadListHead);
1745 
1746  /* Release our reference, if any */
1747  if (ReferencedProcess)
1749  }
1750  else if (Argc >= 2 && _stricmp(Argv[1], "attach") == 0)
1751  {
1752  if (Argc < 3)
1753  {
1754  KdbpPrint("thread attach: thread id argument required!\n");
1755  return TRUE;
1756  }
1757 
1758  ul = strtoul(Argv[2], &pend, 0);
1759  if (Argv[2] == pend)
1760  {
1761  KdbpPrint("thread attach: '%s' is not a valid thread id!\n", Argv[2]);
1762  return TRUE;
1763  }
1764 
1765  if (!KdbpAttachToThread((PVOID)ul))
1766  {
1767  return TRUE;
1768  }
1769 
1770  KdbpPrint("Attached to thread 0x%08x.\n", ul);
1771  }
1772  else
1773  {
1775 
1776  if (Argc >= 2)
1777  {
1778  ul = strtoul(Argv[1], &pend, 0);
1779  if (Argv[1] == pend)
1780  {
1781  KdbpPrint("thread: '%s' is not a valid thread id!\n", Argv[1]);
1782  return TRUE;
1783  }
1784 
1786  {
1787  KdbpPrint("thread: Invalid thread id!\n");
1788  return TRUE;
1789  }
1790 
1791  /* Remember our reference */
1792  ReferencedThread = TRUE;
1793  }
1794 
1795  if (Thread->Tcb.State < (DeferredReady + 1))
1796  State = ThreadStateToString[Thread->Tcb.State];
1797  else
1798  State = "Unknown";
1799 
1800  KdbpPrint("%s"
1801  " TID: 0x%08x\n"
1802  " State: %s (0x%x)\n"
1803  " Priority: %d\n"
1804  " Affinity: 0x%08x\n"
1805  " Initial Stack: 0x%08x\n"
1806  " Stack Limit: 0x%08x\n"
1807  " Stack Base: 0x%08x\n"
1808  " Kernel Stack: 0x%08x\n"
1809  " Trap Frame: 0x%08x\n"
1810  " NPX State: %s (0x%x)\n",
1811  (Argc < 2) ? "Current Thread:\n" : "",
1813  State, Thread->Tcb.State,
1814  Thread->Tcb.Priority,
1815  Thread->Tcb.Affinity,
1818  Thread->Tcb.StackBase,
1820  Thread->Tcb.TrapFrame,
1822 
1823  /* Release our reference if we had one */
1824  if (ReferencedThread)
1826  }
1827 
1828  return TRUE;
1829 }
signed char * PCHAR
Definition: retypes.h:7
ULONG TempEsp
Definition: ketypes.h:246
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define NPX_STATE_TO_STRING(state)
Definition: kdb_cli.c:62
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
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
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
KTHREAD Tcb
Definition: pstypes.h:1045
SCHAR Priority
Definition: ketypes.h:1672
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
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
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
PVOID KernelStack
Definition: ketypes.h:1565
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID Cid
Definition: pstypes.h:1070
ULONG HardwareEsp
Definition: ketypes.h:270
volatile VOID * StackLimit
Definition: ketypes.h:1555
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
HANDLE UniqueThread
Definition: compat.h:574
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
Definition: typedefs.h:119
ULONG Eip
Definition: ketypes.h:267
ULONG PreviousPreviousMode
Definition: ketypes.h:259
PVOID StackBase
Definition: ketypes.h:1556
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1726
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
PVOID InitialStack
Definition: ketypes.h:1554
base of all file and directory entries
Definition: entries.h:82
ULONG Ebp
Definition: ketypes.h:265

◆ KdbpCmdTss()

static BOOLEAN KdbpCmdTss ( ULONG  Argc,
PCHAR  Argv[] 
)
static

Displays the TSS.

Definition at line 2282 of file kdb_cli.c.

2285 {
2286  USHORT TssSelector;
2287  PKTSS Tss = NULL;
2288 
2289  if (Argc >= 2)
2290  {
2291  /*
2292  * Specified TSS via its selector [selector] or descriptor address [*descaddr].
2293  * Note that we ignore any other argument values.
2294  */
2295  PCHAR Param, pszNext;
2296  ULONG ulValue;
2297 
2298  Param = Argv[1];
2299  if (Argv[1][0] == '*')
2300  ++Param;
2301 
2302  ulValue = strtoul(Param, &pszNext, 0);
2303  if (pszNext && *pszNext)
2304  {
2305  KdbpPrint("Invalid TSS specification.\n");
2306  return TRUE;
2307  }
2308 
2309  if (Argv[1][0] == '*')
2310  {
2311  /* Descriptor specified */
2312  TssSelector = 0; // Unknown selector!
2313  // TODO: Room for improvement: Find the TSS descriptor
2314  // in the GDT so as to validate it.
2315  Tss = (PKTSS)(ULONG_PTR)ulValue;
2316  if (!Tss)
2317  {
2318  KdbpPrint("Invalid 32-bit TSS descriptor.\n");
2319  return TRUE;
2320  }
2321  }
2322  else
2323  {
2324  /* Selector specified, retrive the corresponding TSS */
2325  TssSelector = (USHORT)ulValue;
2326  Tss = KdbpRetrieveTss(TssSelector, NULL, NULL);
2327  if (!Tss)
2328  {
2329  KdbpPrint("Invalid 32-bit TSS selector.\n");
2330  return TRUE;
2331  }
2332  }
2333  }
2334 
2335  if (!Tss)
2336  {
2337  /* If no TSS was specified, use the current TSS descriptor */
2338  TssSelector = Ke386GetTr();
2339  Tss = KeGetPcr()->TSS;
2340  // NOTE: If everything works OK, Tss is the current TSS corresponding to the TR selector.
2341  }
2342 
2343  KdbpPrint("%s TSS 0x%04x is at 0x%p.\n",
2344  (Tss == KeGetPcr()->TSS) ? "Current" : "Specified", TssSelector, Tss);
2345  KdbpPrint(" Backlink: 0x%04x\n"
2346  " Ss0:Esp0: 0x%04x:0x%08x\n"
2347  // NOTE: Ss1:Esp1 and Ss2:Esp2: are in the NotUsed1 field.
2348  " CR3: 0x%08x\n"
2349  " EFlags: 0x%08x\n"
2350  " Eax: 0x%08x\n"
2351  " Ebx: 0x%08x\n"
2352  " Ecx: 0x%08x\n"
2353  " Edx: 0x%08x\n"
2354  " Esi: 0x%08x\n"
2355  " Edi: 0x%08x\n"
2356  " Eip: 0x%08x\n"
2357  " Esp: 0x%08x\n"
2358  " Ebp: 0x%08x\n"
2359  " Cs: 0x%04x\n"
2360  " Ss: 0x%04x\n"
2361  " Ds: 0x%04x\n"
2362  " Es: 0x%04x\n"
2363  " Fs: 0x%04x\n"
2364  " Gs: 0x%04x\n"
2365  " LDT: 0x%04x\n"
2366  " Flags: 0x%04x\n"
2367  " IoMapBase: 0x%04x\n",
2368  Tss->Backlink, Tss->Ss0, Tss->Esp0, Tss->CR3, Tss->EFlags,
2369  Tss->Eax, Tss->Ebx, Tss->Ecx, Tss->Edx, Tss->Esi, Tss->Edi,
2370  Tss->Eip, Tss->Esp, Tss->Ebp,
2371  Tss->Cs, Tss->Ss, Tss->Ds, Tss->Es, Tss->Fs, Tss->Gs,
2372  Tss->LDT, Tss->Flags, Tss->IoMapBase);
2373 
2374  return TRUE;
2375 }
signed char * PCHAR
Definition: retypes.h:7
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
USHORT Fs
Definition: ketypes.h:816
#define TRUE
Definition: types.h:120
ULONG CR3
Definition: ketypes.h:797
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
USHORT Cs
Definition: ketypes.h:810
USHORT Es
Definition: ketypes.h:808
USHORT Backlink
Definition: ketypes.h:791
#define KeGetPcr()
Definition: ke.h:25
USHORT LDT
Definition: ketypes.h:820
static PKTSS KdbpRetrieveTss(IN USHORT TssSelector, OUT PULONG pType OPTIONAL, IN PKDESCRIPTOR pGdtr OPTIONAL)
Definition: kdb_cli.c:1046
uint32_t ULONG_PTR
Definition: typedefs.h:65
USHORT Ds
Definition: ketypes.h:814
ULONG Edx
Definition: ketypes.h:802
smooth NULL
Definition: ftsmooth.c:416
Definition: ketypes.h:789
ULONG Ebx
Definition: ketypes.h:803
USHORT Ss0
Definition: ketypes.h:794
ULONG Eip
Definition: ketypes.h:798
ULONG Ecx
Definition: ketypes.h:801
USHORT IoMapBase
Definition: ketypes.h:823
ULONG EFlags
Definition: ketypes.h:799
#define PKTSS
Definition: ketypes.h:921
ULONG Eax
Definition: ketypes.h:800
USHORT Ss
Definition: ketypes.h:812
ULONG Esp
Definition: ketypes.h:804
USHORT Flags
Definition: ketypes.h:822
ULONG Esp0
Definition: ketypes.h:793
unsigned short USHORT
Definition: pedump.c:61
ULONG Edi
Definition: ketypes.h:807
ULONG Ebp
Definition: ketypes.h:805
ULONG Esi
Definition: ketypes.h:806
unsigned int ULONG
Definition: retypes.h:1
USHORT Gs
Definition: ketypes.h:818

◆ KdbpCommandHistoryAppend()

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

3254 {
3255  ULONG Length1 = strlen(Command) + 1;
3256  ULONG Length2 = 0;
3257  INT i;
3258  PCHAR Buffer;
3259 
3261 
3262  if (Length1 <= 1 ||
3265  {
3266  return;
3267  }
3268 
3269  /* Calculate Length1 and Length2 */
3273  {
3276  Length1 -= Length2;
3277  }
3278 
3279  /* Remove previous commands until there is enough space to append the new command */
3281  {
3282  if ((Length2 > 0 &&
3283  (KdbCommandHistory[i] >= Buffer ||
3285  (Length2 <= 0 &&
3286  (KdbCommandHistory[i] >= Buffer &&
3288  {
3290  }
3291 
3292  i--;
3293  if (i < 0)
3295 
3296  if (i == KdbCommandHistoryIndex)
3297  break;
3298  }
3299 
3300  /* Make sure the new command history entry is free */
3304  {
3306  }
3307 
3308  /* Append command */
3312  if (Length2 > 0)
3313  {
3315  }
3316 }
signed char * PCHAR
Definition: retypes.h:7
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
INT Length2
Definition: FsRtlDissect.c:16
Definition: shell.h:41
int32_t INT
Definition: typedefs.h:58
INT Length1
Definition: FsRtlDissect.c:15
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static LONG KdbCommandHistoryBufferIndex
Definition: kdb_cli.c:114
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static LONG KdbCommandHistoryIndex
Definition: kdb_cli.c:115
static PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8]
Definition: kdb_cli.c:113
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static CHAR KdbCommandHistoryBuffer[2048]
Definition: kdb_cli.c:112
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by KdbpCliMainLoop().

◆ KdbpDoCommand()

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

3600 {
3601  ULONG i;
3602  PCHAR p;
3603  ULONG Argc;
3604  // FIXME: for what do we need a 1024 characters command line and 256 tokens?
3605  static PCHAR Argv[256];
3606  static CHAR OrigCommand[1024];
3607 
3608  RtlStringCbCopyA(OrigCommand, sizeof(OrigCommand), Command);
3609 
3610  Argc = 0;
3611  p = Command;
3612 
3613  for (;;)
3614  {
3615  while (*p == '\t' || *p == ' ')
3616  p++;
3617 
3618  if (*p == '\0')
3619  break;
3620 
3621  i = strcspn(p, "\t ");
3622  Argv[Argc++] = p;
3623  p += i;
3624  if (*p == '\0')
3625  break;
3626 
3627  *p = '\0';
3628  p++;
3629  }
3630 
3631  if (Argc < 1)
3632  return TRUE;
3633 
3634  for (i = 0; i < RTL_NUMBER_OF(KdbDebuggerCommands); i++)
3635  {
3636  if (!KdbDebuggerCommands[i].Name)
3637  continue;
3638 
3639  if (strcmp(KdbDebuggerCommands[i].Name, Argv[0]) == 0)
3640  {
3641  return KdbDebuggerCommands[i].Fn(Argc, Argv);
3642  }
3643  }
3644 
3645  /* Now invoke the registered callbacks */
3646  if (KdbpInvokeCliCallbacks(Command, Argc, Argv))
3647  {
3648  return TRUE;
3649  }
3650 
3651  KdbpPrint("Command '%s' is unknown.\n", OrigCommand);
3652  return TRUE;
3653 }
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
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
static const struct @1792 KdbDebuggerCommands[]
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:156
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct Command Command
#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
static BOOLEAN KdbpInvokeCliCallbacks(IN PCHAR Command, IN ULONG Argc, IN PCHAR Argv[])
Invokes registered CLI callbacks until one of them handled the Command.
Definition: kdb_cli.c:3564

Referenced by KdbpCliInterpretInitFile(), and KdbpCliMainLoop().

◆ KdbpEvaluateExpression()

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

412 {
413  static CHAR ErrMsgBuffer[130] = "^ ";
414  LONG ExpressionErrOffset = -1;
415  PCHAR ErrMsg = ErrMsgBuffer;
416  BOOLEAN Ok;
417 
419  &ExpressionErrOffset, ErrMsgBuffer + 2);
420  if (!Ok)
421  {
422  if (ExpressionErrOffset >= 0)
423  ExpressionErrOffset += ErrOffset;
424  else
425  ErrMsg += 2;
426 
427  KdbpPrint("%*s%s\n", ExpressionErrOffset, "", ErrMsg);
428  }
429 
430  return Ok;
431 }
signed char * PCHAR
Definition: retypes.h:7
PCWSTR Expression
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(IN PCHAR Format, IN ... OPTIONAL)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:2670
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
_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
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:51
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

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

◆ KdbpGetComponentId()

static BOOLEAN KdbpGetComponentId ( IN PCSTR  ComponentName,
OUT PULONG  ComponentId 
)
static

Retrieves the component ID corresponding to a given component name.

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

Definition at line 657 of file kdb_cli.c.

660 {
661  ULONG i;
662 
663  for (i = 0; i < RTL_NUMBER_OF(ComponentTable); i++)
664  {
665  if (_stricmp(ComponentName, ComponentTable[i].Name) == 0)
666  {
668  return TRUE;
669  }
670  }
671 
672  return FALSE;
673 }
#define TRUE
Definition: types.h:120
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 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1274
#define _stricmp
Definition: cat.c:22
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
unsigned int ULONG
Definition: retypes.h:1
static struct @1791 ComponentTable[]

Referenced by KdbpCmdFilter().

◆ KdbpGetHexNumber()

BOOLEAN NTAPI KdbpGetHexNumber ( IN PCHAR  pszNum,
OUT ULONG_PTR pulValue 
)

Definition at line 435 of file kdb_cli.c.

438 {
439  char *endptr;
440 
441  /* Skip optional '0x' prefix */
442  if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
443  pszNum += 2;
444 
445  /* Make a number from the string (hex) */
446  *pulValue = strtoul(pszNum, &endptr, 16);
447 
448  return (*endptr == '\0');
449 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696

◆ KdbpInvokeCliCallbacks()

static BOOLEAN KdbpInvokeCliCallbacks ( IN PCHAR  Command,
IN ULONG  Argc,
IN PCHAR  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 3564 of file kdb_cli.c.

3568 {
3569  ULONG i;
3570 
3571  /* Loop all entries */
3572  for (i = 0; i < _countof(KdbCliCallbacks); i++)
3573  {
3574  /* Check if this entry is registered */
3575  if (KdbCliCallbacks[i])
3576  {
3577  /* Invoke the callback and check if it handled the command */
3578  if (KdbCliCallbacks[i](Command, Argc, Argv))
3579  {
3580  return TRUE;
3581  }
3582  }
3583  }
3584 
3585  /* None of the callbacks handled the command */
3586  return FALSE;
3587 }
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:108
#define TRUE
Definition: types.h:120
Definition: shell.h:41
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
#define _countof(array)
Definition: sndvol32.h:68
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdbpDoCommand().

◆ KdbpIsNestedTss()

FORCEINLINE BOOLEAN KdbpIsNestedTss ( IN USHORT  TssSelector,
IN PKTSS  Tss 
)

Definition at line 1092 of file kdb_cli.c.

1095 {
1096  USHORT Backlink;
1097 
1098  if (!Tss)
1099  return FALSE;
1100 
1101  /* Retrieve the TSS Backlink */
1102  if (!NT_SUCCESS(KdbpSafeReadMemory(&Backlink,
1103  (PVOID)&Tss->Backlink,
1104  sizeof(USHORT))))
1105  {
1106  return FALSE;
1107  }
1108 
1109  return (Backlink != 0 && Backlink != TssSelector);
1110 }
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1726
unsigned short USHORT
Definition: pedump.c:61

Referenced by KdbpCmdBackTrace().

◆ KdbpPager()

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

2988 {
2989  static CHAR InBuffer[4096];
2990  static BOOLEAN TerminalInitialized = FALSE;
2991  static BOOLEAN TerminalConnected = FALSE;
2992  static BOOLEAN TerminalReportsSize = TRUE;
2993  CHAR c = '\0';
2994  PCHAR p, p2;
2995  ULONG Length;
2996  ULONG i, j;
2997  LONG RowsPrintedByTerminal;
2998  ULONG ScanCode;
2999 
3000  if( BufLength == 0)
3001  return;
3002 
3003  /* Check if the user has aborted output of the current command */
3004  if (KdbOutputAborted)
3005  return;
3006 
3007  /* Initialize the terminal */
3008  if (!TerminalInitialized)
3009  {
3010  DbgPrint("\x1b[7h"); /* Enable linewrap */
3011 
3012  /* Query terminal type */
3013  /*DbgPrint("\x1b[Z");*/
3014  DbgPrint("\x05");
3015 
3016  TerminalInitialized = TRUE;
3017  Length = 0;
3018  KeStallExecutionProcessor(100000);
3019 
3020  for (;;)
3021  {
3022  c = KdbpTryGetCharSerial(5000);
3023  if (c == -1)
3024  break;
3025 
3026  InBuffer[Length++] = c;
3027  if (Length >= (sizeof(InBuffer) - 1))
3028  break;
3029  }
3030 
3031  InBuffer[Length] = '\0';
3032  if (Length > 0)
3033  TerminalConnected = TRUE;
3034  }
3035 
3036  /* Get number of rows and columns in terminal */
3037  if ((KdbNumberOfRowsTerminal < 0) || (KdbNumberOfColsTerminal < 0) ||
3038  (KdbNumberOfRowsPrinted) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
3039  {
3040  if ((KdbDebugState & KD_DEBUG_KDSERIAL) && TerminalConnected && TerminalReportsSize)
3041  {
3042  /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
3043  TerminalReportsSize = FALSE;
3044  KeStallExecutionProcessor(100000);
3045  DbgPrint("\x1b[18t");
3046  c = KdbpTryGetCharSerial(5000);
3047 
3048  if (c == KEY_ESC)
3049  {
3050  c = KdbpTryGetCharSerial(5000);
3051  if (c == '[')
3052  {
3053  Length = 0;
3054 
3055  for (;;)
3056  {
3057  c = KdbpTryGetCharSerial(5000);
3058  if (c == -1)
3059  break;
3060 
3061  InBuffer[Length++] = c;
3062  if (isalpha(c) || Length >= (sizeof(InBuffer) - 1))
3063  break;
3064  }
3065 
3066  InBuffer[Length] = '\0';
3067  if (InBuffer[0] == '8' && InBuffer[1] == ';')
3068  {
3069  for (i = 2; (i < Length) && (InBuffer[i] != ';'); i++);
3070 
3071  if (Buffer[i] == ';')
3072  {
3073  Buffer[i++] = '\0';
3074 
3075  /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
3076  KdbNumberOfRowsTerminal = strtoul(InBuffer + 2, NULL, 0);
3077  KdbNumberOfColsTerminal = strtoul(InBuffer + i, NULL, 0);
3078  TerminalReportsSize = TRUE;
3079  }
3080  }
3081  }
3082  /* Clear further characters */
3083  while ((c = KdbpTryGetCharSerial(5000)) != -1);
3084  }
3085  }
3086 
3087  if (KdbNumberOfRowsTerminal <= 0)
3088  {
3089  /* Set number of rows to the default. */
3091  }
3092  else if (KdbNumberOfColsTerminal <= 0)
3093  {
3094  /* Set number of cols to the default. */
3096  }
3097  }
3098 
3099  /* Get the string */
3100  p = Buffer;
3101 
3102  while (p[0] != '\0')
3103  {
3104  if ( p > Buffer+BufLength)
3105  {
3106  DbgPrint("Dmesg: error, p > Buffer+BufLength,d=%d", p - (Buffer+BufLength));
3107  return;
3108  }
3109  i = strcspn(p, "\n");
3110 
3111  // Are we out of buffer?
3112  if (p + i > Buffer + BufLength)
3113  // Leaving pager function:
3114  break;
3115 
3116  /* Calculate the number of lines which will be printed in the terminal
3117  * when outputting the current line.
3118  */
3119  if (i > 0)
3120  RowsPrintedByTerminal = (i + KdbNumberOfColsPrinted - 1) / KdbNumberOfColsTerminal;
3121  else
3122  RowsPrintedByTerminal = 0;
3123 
3124  if (p[i] == '\n')
3125  RowsPrintedByTerminal++;
3126 
3127  /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
3128 
3129  /* Display a prompt if we printed one screen full of text */
3130  if (KdbNumberOfRowsTerminal > 0 &&
3131  (LONG)(KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
3132  {
3134 
3135  if (KdbNumberOfColsPrinted > 0)
3136  DbgPrint("\n");
3137 
3138  DbgPrint("--- Press q to abort, e/End,h/Home,u/PgUp, other key/PgDn ---");
3139  RowsPrintedByTerminal++;
3140 
3142  c = KdbpGetCharSerial();
3143  else
3145 
3146  if (c == '\r')
3147  {
3148  /* Try to read '\n' which might follow '\r' - if \n is not received here
3149  * it will be interpreted as "return" when the next command should be read.
3150  */
3152  c = KdbpTryGetCharSerial(5);
3153  else
3155  }
3156 
3157  //DbgPrint("\n"); //Consize version: don't show pressed key
3158  DbgPrint(" '%c'/scan=%04x\n", c, ScanCode); // Shows pressed key
3159 
3160  if (c == 'q')
3161  {
3163  return;
3164  }
3165  if ( ScanCode == KEYSC_END || c=='e')
3166  {
3167  PCHAR pBufEnd = Buffer + BufLength;
3168  p = CountOnePageUp(Buffer, BufLength, pBufEnd);
3169  i = strcspn(p, "\n");
3170  }
3171  else if (ScanCode == KEYSC_PAGEUP || c=='u')
3172  {
3173  p = CountOnePageUp(Buffer, BufLength, p);
3174  i = strcspn(p, "\n");
3175  }
3176  else if (ScanCode == KEYSC_HOME || c=='h')
3177  {
3178  p = Buffer;
3179  i = strcspn(p, "\n");
3180  }
3181  else if (ScanCode == KEYSC_ARROWUP)
3182  {
3183  p = CountOnePageUp(Buffer, BufLength, p);
3184  i = strcspn(p, "\n");
3185  }
3186 
3189  }
3190 
3191  /* Insert a NUL after the line and print only the current line. */
3192  if (p[i] == '\n' && p[i + 1] != '\0')
3193  {
3194  c = p[i + 1];
3195  p[i + 1] = '\0';
3196  }
3197  else
3198  {
3199  c = '\0';
3200  }
3201 
3202  /* Remove escape sequences from the line if there's no terminal connected */
3203  if (!TerminalConnected)
3204  {
3205  while ((p2 = strrchr(p, '\x1b'))) /* Look for escape character */
3206  {
3207  size_t len = strlen(p2);
3208  if (p2[1] == '[')
3209  {
3210  j = 2;
3211  while (!isalpha(p2[j++]));
3212  memmove(p2, p2 + j, len + 1 - j);
3213  }
3214  else
3215  {
3216  memmove(p2, p2 + 1, len);
3217  }
3218  }
3219  }
3220 
3221  // The main printing of the current line:
3222  DbgPrint(p);
3223 
3224  // restore not null char with saved:
3225  if (c != '\0')
3226  p[i + 1] = c;
3227 
3228  /* Set p to the start of the next line and
3229  * remember the number of rows/cols printed
3230  */
3231  p += i;
3232  if (p[0] == '\n')
3233  {
3234  p++;
3236  }
3237  else
3238  {
3239  ASSERT(p[0] == '\0');
3241  }
3242 
3243  KdbNumberOfRowsPrinted += RowsPrintedByTerminal;
3244  }
3245 }
signed char * PCHAR
Definition: retypes.h:7
#define KEY_ESC
Definition: kdb_cli.c:39
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
ULONG ScanCode
Definition: api.c:39
ULONG KdbDebugState
Definition: kdb.c:45
#define DbgPrint
Definition: loader.c:25
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdb.h:251
#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
#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:255
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
CHAR KdbpTryGetCharSerial(ULONG Retry)
Definition: kdb_serial.c:19
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdb_keyboard.c:104
static ULONG KdbNumberOfRowsPrinted
Definition: kdb_cli.c:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:118
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:120
smooth NULL
Definition: ftsmooth.c:416
PCHAR CountOnePageUp(PCHAR Buffer, ULONG BufLength, PCHAR pCurPos)
Calculate pointer position for N lines upper of current position.
Definition: kdb_cli.c:2933
Definition: bufpool.h:45
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define KEYSC_END
Definition: kdb_cli.c:46
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:119
const GLubyte * c
Definition: glext.h:8905
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:121
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:122
GLenum GLsizei len
Definition: glext.h:6722
#define KEYSC_ARROWUP
Definition: kdb_cli.c:50
#define c
Definition: ke_i.h:80
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:95

Referenced by KdbpCmdDmesg().

◆ KdbpPrint()

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

Prints the given string with printf-like formatting.

Parameters
FormatFormat of the string/arguments.
...Variable number of arguments matching the format specified in Format.
Note
Doesn't correctly handle \t and terminal escape sequences when calculating the number of lines required to print a single line from the Buffer in the terminal. Prints maximum 4096 chars, because of its buffer size.

Definition at line 2670 of file kdb_cli.c.

2673 {
2674  static CHAR Buffer[4096];
2675  static BOOLEAN TerminalInitialized = FALSE;
2676  static BOOLEAN TerminalConnected = FALSE;
2677  static BOOLEAN TerminalReportsSize = TRUE;
2678  CHAR c = '\0';
2679  PCHAR p, p2;
2680  ULONG Length;
2681  ULONG i, j;
2682  LONG RowsPrintedByTerminal;
2683  ULONG ScanCode;
2684  va_list ap;
2685 
2686  /* Check if the user has aborted output of the current command */
2687  if (KdbOutputAborted)
2688  return;
2689 
2690  /* Initialize the terminal */
2691  if (!TerminalInitialized)
2692  {
2693  DbgPrint("\x1b[7h"); /* Enable linewrap */
2694 
2695  /* Query terminal type */
2696  /*DbgPrint("\x1b[Z");*/
2697  DbgPrint("\x05");
2698 
2699  TerminalInitialized = TRUE;
2700  Length = 0;
2701  KeStallExecutionProcessor(100000);
2702 
2703  for (;;)
2704  {
2705  c = KdbpTryGetCharSerial(5000);
2706  if (c == -1)
2707  break;
2708 
2709  Buffer[Length++] = c;
2710  if (Length >= (sizeof(Buffer) - 1))
2711  break;
2712  }
2713 
2714  Buffer[Length] = '\0';
2715  if (Length > 0)
2716  TerminalConnected = TRUE;
2717  }
2718 
2719  /* Get number of rows and columns in terminal */
2720  if ((KdbNumberOfRowsTerminal < 0) || (KdbNumberOfColsTerminal < 0) ||
2721  (KdbNumberOfRowsPrinted) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
2722  {
2723  if ((KdbDebugState & KD_DEBUG_KDSERIAL) && TerminalConnected && TerminalReportsSize)
2724  {
2725  /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
2726  TerminalReportsSize = FALSE;
2727  KeStallExecutionProcessor(100000);
2728  DbgPrint("\x1b[18t");
2729  c = KdbpTryGetCharSerial(5000);
2730 
2731  if (c == KEY_ESC)
2732  {
2733  c = KdbpTryGetCharSerial(5000);
2734  if (c == '[')
2735  {
2736  Length = 0;
2737 
2738  for (;;)
2739  {
2740  c = KdbpTryGetCharSerial(5000);
2741  if (c == -1)
2742  break;
2743 
2744  Buffer[Length++] = c;
2745  if (isalpha(c) || Length >= (sizeof(Buffer) - 1))
2746  break;
2747  }
2748 
2749  Buffer[Length] = '\0';
2750  if (Buffer[0] == '8' && Buffer[1] == ';')
2751  {
2752  for (i = 2; (i < Length) && (Buffer[i] != ';'); i++);
2753 
2754  if (Buffer[i] == ';')
2755  {
2756  Buffer[i++] = '\0';
2757 
2758  /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
2761  TerminalReportsSize = TRUE;
2762  }
2763  }
2764  }
2765  /* Clear further characters */
2766  while ((c = KdbpTryGetCharSerial(5000)) != -1);
2767  }
2768  }
2769 
2770  if (KdbNumberOfRowsTerminal <= 0)
2771  {
2772  /* Set number of rows to the default. */
2773  KdbNumberOfRowsTerminal = 23; //24; //Mna.: 23 for SCREEN debugport
2774  }
2775  else if (KdbNumberOfColsTerminal <= 0)
2776  {
2777  /* Set number of cols to the default. */
2778  KdbNumberOfColsTerminal = 75; //80; //Mna.: 75 for SCREEN debugport
2779  }
2780  }
2781 
2782  /* Get the string */
2783  va_start(ap, Format);
2784  Length = _vsnprintf(Buffer, sizeof(Buffer) - 1, Format, ap);
2785  Buffer[Length] = '\0';
2786  va_end(ap);
2787 
2788  p = Buffer;
2789  while (p[0] != '\0')
2790  {
2791  i = strcspn(p, "\n");
2792 
2793  /* Calculate the number of lines which will be printed in the terminal
2794  * when outputting the current line
2795  */
2796  if (i > 0)
2797  RowsPrintedByTerminal = (i + KdbNumberOfColsPrinted - 1) / KdbNumberOfColsTerminal;
2798  else
2799  RowsPrintedByTerminal = 0;
2800 
2801  if (p[i] == '\n')
2802  RowsPrintedByTerminal++;
2803 
2804  /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
2805 
2806  /* Display a prompt if we printed one screen full of text */
2807  if (KdbNumberOfRowsTerminal > 0 &&
2808  (LONG)(KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
2809  {
2811 
2812  if (KdbNumberOfColsPrinted > 0)
2813  DbgPrint("\n");
2814 
2815  DbgPrint("--- Press q to abort, any other key to continue ---");
2816  RowsPrintedByTerminal++; /* added by Mna. */
2817 
2819  c = KdbpGetCharSerial();
2820  else
2822 
2823  if (c == '\r')
2824  {
2825  /* Try to read '\n' which might follow '\r' - if \n is not received here
2826  * it will be interpreted as "return" when the next command should be read.
2827  */
2829  c = KdbpTryGetCharSerial(5);
2830  else
2832  }
2833 
2834  DbgPrint("\n");
2835  if (c == 'q')
2836  {
2838  return;
2839  }
2840 
2843  }
2844 
2845  /* Insert a NUL after the line and print only the current line. */
2846  if (p[i] == '\n' && p[i + 1] != '\0')
2847  {
2848  c = p[i + 1];
2849  p[i + 1] = '\0';
2850  }
2851  else
2852  {
2853  c = '\0';
2854  }
2855 
2856  /* Remove escape sequences from the line if there's no terminal connected */
2857  if (!TerminalConnected)
2858  {
2859  while ((p2 = strrchr(p, '\x1b'))) /* Look for escape character */
2860  {
2861  size_t len = strlen(p2);
2862  if (p2[1] == '[')
2863  {
2864  j = 2;
2865  while (!isalpha(p2[j++]));
2866  memmove(p2, p2 + j, len + 1 - j);
2867  }
2868  else
2869  {
2870  memmove(p2, p2 + 1, len);
2871  }
2872  }
2873  }
2874 
2875  DbgPrint("%s", p);
2876 
2877  if (c != '\0')
2878  p[i + 1] = c;
2879 
2880  /* Set p to the start of the next line and
2881  * remember the number of rows/cols printed
2882  */
2883  p += i;
2884  if (p[0] == '\n')
2885  {
2886  p++;
2888  }
2889  else
2890  {
2891  ASSERT(p[0] == '\0');
2893  }
2894 
2895  KdbNumberOfRowsPrinted += RowsPrintedByTerminal;
2896  }
2897 }
signed char * PCHAR
Definition: retypes.h:7
#define KEY_ESC
Definition: kdb_cli.c:39
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
ULONG ScanCode
Definition: api.c:39
ULONG KdbDebugState
Definition: kdb.c:45
#define DbgPrint
Definition: loader.c:25
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdb.h:251
#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
#define isalpha(c)
Definition: acclib.h:74
#define KdbpGetCharSerial()
Definition: kdb.h:255
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
CHAR KdbpTryGetCharSerial(ULONG Retry)
Definition: kdb_serial.c:19
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdb_keyboard.c:104
static ULONG KdbNumberOfRowsPrinted
Definition: kdb_cli.c:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define va_end(ap)
Definition: acmsvcex.h:90
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:118
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:120
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:119
const GLubyte * c
Definition: glext.h:8905
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:121
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:122
GLenum GLsizei len
Definition: glext.h:6722
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define _vsnprintf
Definition: xmlstorage.h:202
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
#define c
Definition: ke_i.h:80
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:95

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

◆ KdbpReadCommand()

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, \r is ignored.

Definition at line 3326 of file kdb_cli.c.

3329 {
3330  CHAR Key;
3331  PCHAR Orig = Buffer;
3332  ULONG ScanCode = 0;
3333  BOOLEAN EchoOn;
3334  static CHAR LastCommand[1024];
3335  static CHAR NextKey = '\0';
3336  INT CmdHistIndex = -1;
3337  INT i;
3338 
3339  EchoOn = !((KdbDebugState & KD_DEBUG_KDNOECHO) != 0);
3340 
3341  for (;;)
3342  {
3344  {
3345  Key = (NextKey == '\0') ? KdbpGetCharSerial() : NextKey;
3346  NextKey = '\0';
3347  ScanCode = 0;
3348  if (Key == KEY_ESC) /* ESC */
3349  {
3350  Key = KdbpGetCharSerial();
3351  if (Key == '[')
3352  {
3353  Key = KdbpGetCharSerial();
3354 
3355  switch (Key)
3356  {
3357  case 'A':
3359  break;
3360  case 'B':
3362  break;
3363  case 'C':
3364  break;
3365  case 'D':
3366  break;
3367  }