ReactOS  0.4.15-dev-5640-g0dde428
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 Ke386GetGlobalDescriptorTable   __sgdt
 
#define Ke386GetLocalDescriptorTable   __sldt
 
#define KD_DEBUG_PRINT_FILTER(Name)   { #Name, DPFLTR_##Name##_ID }
 

Typedefs

typedef BOOLEAN(NTAPIPKDBG_CLI_ROUTINE) (IN PCHAR Command, IN ULONG Argc, IN PCH Argv[])
 

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 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[])
 
FORCEINLINE ULONG_PTR strtoulptr (const char *nptr, char **endptr, int base)
 
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...
 
voidmemrchr (const void *s, int c, size_t n)
 
static PCHAR CountOnePageUp (_In_ PCCH Buffer, _In_ ULONG BufLength, _In_ PCCH pCurPos)
 Calculate pointer position for N lines upper of current position. More...
 
static VOID KdpFilterEscapes (_Inout_ PSTR String)
 
VOID KdbpPagerInternal (_In_ PCHAR Buffer, _In_ ULONG BufLength, _In_ BOOLEAN DoPage)
 Prints the given string with, page by page. More...
 
VOID KdbpPager (_In_ PCHAR Buffer, _In_ ULONG BufLength)
 Prints the given string with, page by page. More...
 
VOID KdbpPrint (_In_ PSTR Format, _In_ ...)
 Prints the given string with printf-like formatting. More...
 
VOID KdbpPrintUnicodeString (_In_ PCUNICODE_STRING String)
 
static VOID KdbpCommandHistoryAppend (IN PCHAR Command)
 Appends a command to the command history. More...
 
SIZE_T KdbpReadCommand (_Out_ PCHAR Buffer, _In_ SIZE_T Size)
 Reads a line of user input from the terminal. 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 KdbpCliInterpretInitFile (VOID)
 This function is called by KdbEnterDebuggerException... More...
 
VOID KdbpCliInit (VOID)
 Called when KDB is initialized. More...
 

Variables

char __ImageBase
 
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 172 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.

◆ Ke386GetGlobalDescriptorTable

#define Ke386GetGlobalDescriptorTable   __sgdt

Definition at line 112 of file kdb_cli.c.

◆ Ke386GetLocalDescriptorTable

#define Ke386GetLocalDescriptorTable   __sldt

Definition at line 115 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.

Typedef Documentation

◆ PKDBG_CLI_ROUTINE

typedef BOOLEAN(NTAPI * PKDBG_CLI_ROUTINE) (IN PCHAR Command, IN ULONG Argc, IN PCH Argv[])

Definition at line 134 of file kdb_cli.c.

Function Documentation

◆ CountOnePageUp()

static PCHAR CountOnePageUp ( _In_ PCCH  Buffer,
_In_ ULONG  BufLength,
_In_ PCCH  pCurPos 
)
static

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

2823 {
2824  PCCH p;
2825  // p0 is initial guess of Page Start
2827  PCCH p0 = pCurPos - p0len;
2828  PCCH prev_p = p0, p1;
2829  ULONG j;
2830 
2831  if (pCurPos < Buffer)
2832  pCurPos = Buffer;
2833  ASSERT(pCurPos <= Buffer + BufLength);
2834 
2835  p = memrchr(p0, '\n', p0len);
2836  if (!p)
2837  p = p0;
2838  for (j = KdbNumberOfRowsTerminal; j--; )
2839  {
2840  int linesCnt;
2841  p1 = memrchr(p0, '\n', p-p0);
2842  prev_p = p;
2843  p = p1;
2844  if (!p)
2845  {
2846  p = prev_p;
2847  if (!p)
2848  p = p0;
2849  break;
2850  }
2851  linesCnt = (KdbNumberOfColsTerminal+prev_p-p-2) / KdbNumberOfColsTerminal;
2852  if (linesCnt > 1)
2853  j -= linesCnt-1;
2854  }
2855 
2856  ASSERT(p != NULL);
2857  ++p;
2858  return (PCHAR)p;
2859 }
signed char * PCHAR
Definition: retypes.h:7
void * memrchr(const void *s, int c, size_t n)
Definition: kdb_cli.c:2791
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
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
CONST CHAR * PCCH
Definition: ntbasedef.h:392
#define ASSERT(a)
Definition: mode.c:44
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:152
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:153
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by KdbpPagerInternal().

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

3804 {
3805  NTSTATUS Status;
3809  FILE_STANDARD_INFORMATION FileStdInfo;
3810  HANDLE hFile = NULL;
3811  INT FileSize;
3812  PCHAR FileBuffer;
3813  ULONG OldEflags;
3814 
3815  /* Initialize the object attributes */
3816  RtlInitUnicodeString(&FileName, L"\\SystemRoot\\System32\\drivers\\etc\\KDBinit");
3818  &FileName,
3820  NULL,
3821  NULL);
3822 
3823  /* Open the file */
3825  &ObjectAttributes, &Iosb, 0,
3828  if (!NT_SUCCESS(Status))
3829  {
3830  DPRINT("Could not open \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3831  return;
3832  }
3833 
3834  /* Get the size of the file */
3835  Status = ZwQueryInformationFile(hFile, &Iosb, &FileStdInfo, sizeof(FileStdInfo),
3837  if (!NT_SUCCESS(Status))
3838  {
3839  ZwClose(hFile);
3840  DPRINT("Could not query size of \\SystemRoot\\System32\\drivers\\etc\\KDBinit (Status 0x%x)", Status);
3841  return;
3842  }
3843  FileSize = FileStdInfo.EndOfFile.u.LowPart;
3844 
3845  /* Allocate memory for the file */
3846  FileBuffer = ExAllocatePool(PagedPool, FileSize + 1); /* add 1 byte for terminating '\0' */
3847  if (!FileBuffer)
3848  {
3849  ZwClose(hFile);
3850  DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize);
3851  return;
3852  }
3853 
3854  /* Load file into memory */
3855  Status = ZwReadFile(hFile, NULL, NULL, NULL, &Iosb, FileBuffer, FileSize, NULL, NULL);
3856  ZwClose(hFile);
3857 
3859  {
3860  ExFreePool(FileBuffer);
3861  DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
3862  return;
3863  }
3864 
3865  FileSize = min(FileSize, (INT)Iosb.Information);
3866  FileBuffer[FileSize] = '\0';
3867 
3868  /* Enter critical section */
3869  OldEflags = __readeflags();
3870  _disable();
3871 
3872  /* Interpret the init file... */
3873  KdbInitFileBuffer = FileBuffer;
3874  //KdbEnter(); // FIXME
3876 
3877  /* Leave critical section */
3878  __writeeflags(OldEflags);
3879 
3880  ExFreePool(FileBuffer);
3881 }
signed char * PCHAR
Definition: retypes.h:7
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
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
#define L(x)
Definition: ntvdm.h:50
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
#define FILE_READ_DATA
Definition: nt_native.h:628
Status
Definition: gdiplustypes.h:24
#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)
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1669
#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
struct _LARGE_INTEGER::@2274 u
#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 NULL
Definition: types.h:112
#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
return Iosb
Definition: create.c:4402
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
#define DPRINT
Definition: sndvol32.h:71
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:155
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by IoInitSystem().

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

3755 {
3756  PCHAR p1, p2;
3757  INT_PTR i;
3758  CHAR c;
3759 
3760  /* Execute the commands in the init file */
3761  DPRINT("KDB: Executing KDBinit file...\n");
3762  p1 = KdbInitFileBuffer;
3763  while (p1[0] != '\0')
3764  {
3765  i = strcspn(p1, "\r\n");
3766  if (i > 0)
3767  {
3768  c = p1[i];
3769  p1[i] = '\0';
3770 
3771  /* Look for "break" command and comments */
3772  p2 = p1;
3773 
3774  while (isspace(p2[0]))
3775  p2++;
3776 
3777  if (strncmp(p2, "break", sizeof("break")-1) == 0 &&
3778  (p2[sizeof("break")-1] == '\0' || isspace(p2[sizeof("break")-1])))
3779  {
3780  /* break into the debugger */
3782  }
3783  else if (p2[0] != '#' && p2[0] != '\0') /* Ignore empty lines and comments */
3784  {
3785  KdbpDoCommand(p1);
3786  }
3787 
3788  p1[i] = c;
3789  }
3790 
3791  p1 += i;
3792  while (p1[0] == '\r' || p1[0] == '\n')
3793  p1++;
3794  }
3795  DPRINT("KDB: KDBinit executed\n");
3796 }
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_PTR
Definition: typedefs.h:64
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3629
#define FALSE
Definition: types.h:117
VOID KdbpCliMainLoop(IN BOOLEAN EnteredOnSingleStep)
KDB Main Loop.
Definition: kdb_cli.c:3691
const GLubyte * c
Definition: glext.h:8905
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
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 c
Definition: ke_i.h:80
#define DPRINT
Definition: sndvol32.h:71
PCHAR KdbInitFileBuffer
Definition: kdb_cli.c:155

Referenced by KdbEnterDebuggerException().

◆ KdbpCliMainLoop()

VOID KdbpCliMainLoop ( IN BOOLEAN  EnteredOnSingleStep)

KDB Main Loop.

Parameters
EnteredOnSingleStepTRUE if KDB was entered on single step.

Definition at line 3691 of file kdb_cli.c.

3693 {
3694  static CHAR Command[1024];
3695  BOOLEAN Continue;
3696 
3697  if (EnteredOnSingleStep)
3698  {
3700  {
3702  }
3703 
3704  KdbpPrint(": ");
3706  {
3707  KdbpPrint("<INVALID>");
3708  }
3709  KdbpPrint("\n");
3710  }
3711 
3712  /* Flush the input buffer */
3714  {
3715  while (KdbpTryGetCharSerial(1) != -1);
3716  }
3717  else
3718  {
3719  ULONG ScanCode;
3720  while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
3721  }
3722 
3723  /* Main loop */
3724  do
3725  {
3726  /* Reset the number of rows/cols printed */
3728 
3729  /* Print the prompt */
3730  KdbpPrint(KdbPromptString.Buffer);
3731 
3732  /* Read a command and remember it */
3733  KdbpReadCommand(Command, sizeof(Command));
3735 
3736  /* Reset the number of rows/cols printed and output aborted state */
3739 
3740  /* Call the command */
3741  Continue = KdbpDoCommand(Command);
3743  }
3744  while (Continue);
3745 }
static VOID KdbpCommandHistoryAppend(IN PCHAR Command)
Appends a command to the command history.
Definition: kdb_cli.c:3270
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PCONTEXT Context)
Print address...
Definition: kdb_symbols.c:148
ULONG KdbDebugState
Definition: kdb.c:52
UINT ScanCode
Definition: VirtualKey.c:24
char CHAR
Definition: xmlstorage.h:175
#define KeGetContextPc(Context)
Definition: ke.h:31
SIZE_T KdbpReadCommand(_Out_ PCHAR Buffer, _In_ SIZE_T Size)
Reads a line of user input from the terminal.
Definition: kdb_cli.c:3351
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:148
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:125
static BOOLEAN KdbpDoCommand(IN PCHAR Command)
Parses command line and executes command if found.
Definition: kdb_cli.c:3629
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:149
unsigned char BOOLEAN
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:58
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:150
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:140
STRING KdbPromptString
Definition: kdb_cli.c:167
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdbpCallMainLoop(), and KdbpCliInterpretInitFile().

◆ KdbpCmdBackTrace()

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

Displays a backtrace.

Definition at line 1245 of file kdb_cli.c.

1248 {
1249  ULONG ul;
1250  ULONGLONG Result = 0;
1254 
1255  if (Argc >= 2)
1256  {
1257  /* Check for [L count] part */
1258  ul = 0;
1259  if (strcmp(Argv[Argc-2], "L") == 0)
1260  {
1261  ul = strtoul(Argv[Argc-1], NULL, 0);
1262  if (ul > 0)
1263  {
1264  Argc -= 2;
1265  }
1266  }
1267  else if (Argv[Argc-1][0] == 'L')
1268  {
1269  ul = strtoul(Argv[Argc-1] + 1, NULL, 0);
1270  if (ul > 0)
1271  {
1272  Argc--;
1273  }
1274  }
1275 
1276  /* Put the remaining arguments back together */
1277  Argc--;
1278  for (ul = 1; ul < Argc; ul++)
1279  {
1280  Argv[ul][strlen(Argv[ul])] = ' ';
1281  }
1282  Argc++;
1283  }
1284 
1285  /* Check if a Frame Address or Thread ID is given */
1286  if (Argc > 1)
1287  {
1288  if (Argv[1][0] == '*')
1289  {
1290  Argv[1]++;
1291 
1292  /* Evaluate the expression */
1293  if (!KdbpEvaluateExpression(Argv[1], KdbPromptString.Length + (Argv[1]-Argv[0]), &Result))
1294  return TRUE;
1295 
1296  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1297  KdbpPrint("Warning: Address %I64x is beeing truncated\n", Result);
1298 
1299  Frame = (ULONG_PTR)Result;
1300  }
1301  else
1302  {
1303  KdbpPrint("Thread backtrace not supported yet!\n");
1304  return TRUE;
1305  }
1306  }
1307 
1308 #ifdef _M_IX86
1309  KDESCRIPTOR Gdtr;
1310  USHORT TssSelector;
1311  PKTSS Tss;
1312 
1313  /* Retrieve the Global Descriptor Table */
1315 
1316  /* Retrieve the current (active) TSS */
1317  TssSelector = Ke386GetTr();
1318  Tss = KdbpRetrieveTss(TssSelector, NULL, &Gdtr);
1319  if (KdbpIsNestedTss(TssSelector, Tss))
1320  {
1321  /* Display the active TSS if it is nested */
1322  KdbpPrint("[Active TSS 0x%04x @ 0x%p]\n", TssSelector, Tss);
1323  }
1324 #endif
1325 
1326  /* If no Frame Address or Thread ID was given, try printing the function at EIP */
1327  if (Argc <= 1)
1328  {
1329  KdbpPrint("Eip:\n");
1331  KdbpPrint("<%p>\n", KeGetContextPc(&Context));
1332  else
1333  KdbpPrint("\n");
1334  }
1335 
1336  /* Walk through the frames */
1337  KdbpPrint("Frames:\n");
1338  for (;;)
1339  {
1340  BOOLEAN GotNextFrame;
1341 
1342  if (Frame == 0)
1343  goto CheckForParentTSS;
1344 
1345  Address = 0;
1346  if (!NT_SUCCESS(KdbpSafeReadMemory(&Address, (PVOID)(Frame + sizeof(ULONG_PTR)), sizeof(ULONG_PTR))))
1347  {
1348  KdbpPrint("Couldn't access memory at 0x%p!\n", Frame + sizeof(ULONG_PTR));
1349  goto CheckForParentTSS;
1350  }
1351 
1352  if (Address == 0)
1353  goto CheckForParentTSS;
1354 
1355  GotNextFrame = NT_SUCCESS(KdbpSafeReadMemory(&Frame, (PVOID)Frame, sizeof(ULONG_PTR)));
1356  if (GotNextFrame)
1357  {
1359  }
1360  // else
1361  // Frame = 0;
1362 
1363  /* Print the location of the call instruction (assumed 5 bytes length) */
1364  if (!KdbSymPrintAddress((PVOID)(Address - 5), &Context))
1365  KdbpPrint("<%08x>\n", Address);
1366  else
1367  KdbpPrint("\n");
1368 
1369  if (KdbOutputAborted)
1370  break;
1371 
1372  if (!GotNextFrame)
1373  {
1374  KdbpPrint("Couldn't access memory at 0x%p!\n", Frame);
1375  goto CheckForParentTSS; // break;
1376  }
1377 
1378  continue;
1379 
1380 CheckForParentTSS:
1381 #ifndef _M_IX86
1382  break;
1383 #else
1384  /*
1385  * We have ended the stack walking for the current (active) TSS.
1386  * Check whether this TSS was nested, and if so switch to its parent
1387  * and walk its stack.
1388  */
1389  if (!KdbpIsNestedTss(TssSelector, Tss))
1390  break; // The TSS is not nested, we stop there.
1391 
1392  GotNextFrame = KdbpContextFromPrevTss(&Context, &TssSelector, &Tss, &Gdtr);
1393  if (!GotNextFrame)
1394  {
1395  KdbpPrint("Couldn't access parent TSS 0x%04x\n", Tss->Backlink);
1396  break; // Cannot retrieve the parent TSS, we stop there.
1397  }
1398 
1399 
1400  Address = Context.Eip;
1401  Frame = Context.Ebp;
1402 
1403  KdbpPrint("[Parent TSS 0x%04x @ 0x%p]\n", TssSelector, Tss);
1404 
1406  KdbpPrint("<%08x>\n", Address);
1407  else
1408  KdbpPrint("\n");
1409 #endif
1410  }
1411 
1412  return TRUE;
1413 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
FORCEINLINE VOID KeSetContextFrameRegister(PCONTEXT Context, ULONG_PTR Frame)
Definition: ke.h:172
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PCONTEXT 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:441
#define TRUE
Definition: types.h:120
#define KeGetContextPc(Context)
Definition: ke.h:31
USHORT Backlink
Definition: ketypes.h:792
USHORT Limit
Definition: ketypes.h:490
uint32_t ULONG_PTR
Definition: typedefs.h:65
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define Ke386GetGlobalDescriptorTable
Definition: kdb_cli.c:112
unsigned char BOOLEAN
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:790
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:58
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:150
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
STRING KdbPromptString
Definition: kdb_cli.c:167
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1690
unsigned short USHORT
Definition: pedump.c:61
FORCEINLINE ULONG_PTR KeGetContextFrameRegister(PCONTEXT Context)
Definition: ke.h:165
#define NULL
Definition: types.h:112
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

◆ KdbpCmdBreakPoint()

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

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

Definition at line 1599 of file kdb_cli.c.

1600 {
1601  ULONGLONG Result = 0;
1604  UCHAR Size = 0;
1605  KDB_ACCESS_TYPE AccessType = 0;
1606  ULONG AddressArgIndex, i;
1607  LONG ConditionArgIndex;
1608  BOOLEAN Global = TRUE;
1609 
1610  if (Argv[0][2] == 'x') /* software breakpoint */
1611  {
1612  if (Argc < 2)
1613  {
1614  KdbpPrint("bpx: Address argument required.\n");
1615  return TRUE;
1616  }
1617 
1618  AddressArgIndex = 1;
1620  }
1621  else /* memory breakpoint */
1622  {
1623  ASSERT(Argv[0][2] == 'm');
1624 
1625  if (Argc < 2)
1626  {
1627  KdbpPrint("bpm: Access type argument required (one of r, w, rw, x)\n");
1628  return TRUE;
1629  }
1630 
1631  if (_stricmp(Argv[1], "x") == 0)
1632  AccessType = KdbAccessExec;
1633  else if (_stricmp(Argv[1], "r") == 0)
1634  AccessType = KdbAccessRead;
1635  else if (_stricmp(Argv[1], "w") == 0)
1636  AccessType = KdbAccessWrite;
1637  else if (_stricmp(Argv[1], "rw") == 0)
1638  AccessType = KdbAccessReadWrite;
1639  else
1640  {
1641  KdbpPrint("bpm: Unknown access type '%s'\n", Argv[1]);
1642  return TRUE;
1643  }
1644 
1645  if (Argc < 3)
1646  {
1647  KdbpPrint("bpm: %s argument required.\n", AccessType == KdbAccessExec ? "Address" : "Memory size");
1648  return TRUE;
1649  }
1650 
1651  AddressArgIndex = 3;
1652  if (_stricmp(Argv[2], "byte") == 0)
1653  Size = 1;
1654  else if (_stricmp(Argv[2], "word") == 0)
1655  Size = 2;
1656  else if (_stricmp(Argv[2], "dword") == 0)
1657  Size = 4;
1658  else if (AccessType == KdbAccessExec)
1659  {
1660  Size = 1;
1661  AddressArgIndex--;
1662  }
1663  else
1664  {
1665  KdbpPrint("bpm: Unknown memory size '%s'\n", Argv[2]);
1666  return TRUE;
1667  }
1668 
1669  if (Argc <= AddressArgIndex)
1670  {
1671  KdbpPrint("bpm: Address argument required.\n");
1672  return TRUE;
1673  }
1674 
1676  }
1677 
1678  /* Put the arguments back together */
1679  ConditionArgIndex = -1;
1680  for (i = AddressArgIndex; i < (Argc-1); i++)
1681  {
1682  if (strcmp(Argv[i+1], "IF") == 0) /* IF found */
1683  {
1684  ConditionArgIndex = i + 2;
1685  if ((ULONG)ConditionArgIndex >= Argc)
1686  {
1687  KdbpPrint("%s: IF requires condition expression.\n", Argv[0]);
1688  return TRUE;
1689  }
1690 
1691  for (i = ConditionArgIndex; i < (Argc-1); i++)
1692  Argv[i][strlen(Argv[i])] = ' ';
1693 
1694  break;
1695  }
1696 
1697  Argv[i][strlen(Argv[i])] = ' ';
1698  }
1699 
1700  /* Evaluate the address expression */
1701  if (!KdbpEvaluateExpression(Argv[AddressArgIndex],
1702  KdbPromptString.Length + (Argv[AddressArgIndex]-Argv[0]),
1703  &Result))
1704  {
1705  return TRUE;
1706  }
1707 
1708  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
1709  KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv[0],Result);
1710 
1712 
1713  KdbpInsertBreakPoint(Address, Type, Size, AccessType,
1714  (ConditionArgIndex < 0) ? NULL : Argv[ConditionArgIndex],
1715  Global, NULL);
1716 
1717  return TRUE;
1718 }
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:441
#define TRUE
Definition: types.h:120
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
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:480
#define _stricmp
Definition: cat.c:22
UNICODE_STRING Global
Definition: symlink.c:37
uint32_t ULONG_PTR
Definition: typedefs.h:65
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
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
#define ASSERT(a)
Definition: mode.c:44
uint64_t ULONGLONG
Definition: typedefs.h:67
Type
Definition: Type.h:6
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE
unsigned char UCHAR
Definition: xmlstorage.h:181
STRING KdbPromptString
Definition: kdb_cli.c:167
enum _KDB_BREAKPOINT_TYPE KDB_BREAKPOINT_TYPE
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 NULL
Definition: types.h:112
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 1461 of file kdb_cli.c.

1464 {
1465  LONG l;
1466  ULONG_PTR Address = 0;
1468  KDB_ACCESS_TYPE AccessType = 0;
1469  UCHAR Size = 0;
1470  UCHAR DebugReg = 0;
1471  BOOLEAN Enabled = FALSE;
1472  BOOLEAN Global = FALSE;
1474  PCHAR str1, str2, ConditionExpr, GlobalOrLocal;
1475  CHAR Buffer[20];
1476 
1478  if (l < 0)
1479  {
1480  KdbpPrint("No breakpoints.\n");
1481  return TRUE;
1482  }
1483 
1484  KdbpPrint("Breakpoints:\n");
1485  do
1486  {
1487  if (!KdbpGetBreakPointInfo(l, &Address, &Type, &Size, &AccessType, &DebugReg,
1488  &Enabled, &Global, &Process, &ConditionExpr))
1489  {
1490  continue;
1491  }
1492 
1493  if (l == KdbLastBreakPointNr)
1494  {
1495  str1 = "\x1b[1m*";
1496  str2 = "\x1b[0m";
1497  }
1498  else
1499  {
1500  str1 = " ";
1501  str2 = "";
1502  }
1503 
1504  if (Global)
1505  {
1506  GlobalOrLocal = " global";
1507  }
1508  else
1509  {
1510  GlobalOrLocal = Buffer;
1511  sprintf(Buffer, " PID 0x%Ix",
1512  (ULONG_PTR)(Process ? Process->UniqueProcessId : INVALID_HANDLE_VALUE));
1513  }
1514 
1516  {
1517  KdbpPrint(" %s%03d BPX 0x%08x%s%s%s%s%s\n",
1518  str1, l, Address,
1519  Enabled ? "" : " disabled",
1520  GlobalOrLocal,
1521  ConditionExpr ? " IF " : "",
1522  ConditionExpr ? ConditionExpr : "",
1523  str2);
1524  }
1525  else if (Type == KdbBreakPointHardware)
1526  {
1527  if (!Enabled)
1528  {
1529  KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s disabled%s%s%s%s\n", str1, l, Address,
1530  KDB_ACCESS_TYPE_TO_STRING(AccessType),
1531  Size == 1 ? "byte" : (Size == 2 ? "word" : "dword"),
1532  GlobalOrLocal,
1533  ConditionExpr ? " IF " : "",
1534  ConditionExpr ? ConditionExpr : "",
1535  str2);
1536  }
1537  else
1538  {
1539  KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s DR%d%s%s%s%s\n", str1, l, Address,
1540  KDB_ACCESS_TYPE_TO_STRING(AccessType),
1541  Size == 1 ? "byte" : (Size == 2 ? "word" : "dword"),
1542  DebugReg,
1543  GlobalOrLocal,
1544  ConditionExpr ? " IF " : "",
1545  ConditionExpr ? ConditionExpr : "",
1546  str2);
1547  }
1548  }
1549  }
1550  while ((l = KdbpGetNextBreakPointNr(l+1)) >= 0);
1551 
1552  return TRUE;
1553 }
signed char * PCHAR
Definition: retypes.h:7
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TRUE
Definition: types.h:120
#define KDB_ACCESS_TYPE_TO_STRING(type)
Definition: kdb_cli.c:57
char CHAR
Definition: xmlstorage.h:175
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
UNICODE_STRING Global
Definition: symlink.c:37
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define sprintf(buf, format,...)
Definition: sprintf.c:55
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
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:384
Type
Definition: Type.h:6
enum _KDB_ACCESS_TYPE KDB_ACCESS_TYPE
unsigned char UCHAR
Definition: xmlstorage.h:181
enum _KDB_BREAKPOINT_TYPE KDB_BREAKPOINT_TYPE
BOOLEAN KdbpGetBreakPointInfo(IN ULONG BreakPointNr, OUT ULONG_PTR *Address OPTIONAL, OUT KDB_BREAKPOINT_TYPE *Type OPTIONAL, OUT UCHAR *Size OPTIONAL, OUT KDB_ACCESS_TYPE *AccessType OPTIONAL, OUT UCHAR *DebugReg OPTIONAL, OUT BOOLEAN *Enabled OPTIONAL, OUT BOOLEAN *Global OPTIONAL, OUT PEPROCESS *Process OPTIONAL, OUT PCHAR *ConditionExpression OPTIONAL)
Returns information of the specified breakpoint.
Definition: kdb.c:411
LONG KdbLastBreakPointNr
Definition: kdb.c:49
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

◆ KdbpCmdBugCheck()

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

Bugchecks the system.

Definition at line 2510 of file kdb_cli.c.

2513 {
2514  /* Set the flag and quit looping */
2516  return FALSE;
2517 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN KdbpBugCheckRequested
Definition: kdb_cli.c:156

◆ KdbpCmdContinue()

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

Continues execution of the system/leaves KDB.

Definition at line 1420 of file kdb_cli.c.

1423 {
1424  /* Exit the main loop */
1425  return FALSE;
1426 }
#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 820 of file kdb_cli.c.

823 {
824  ULONG Count;
825  ULONG ul;
826  INT i;
827  ULONGLONG Result = 0;
829  LONG InstLen;
830 
831  if (Argv[0][0] == 'x') /* display memory */
832  Count = 16;
833  else /* disassemble */
834  Count = 10;
835 
836  if (Argc >= 2)
837  {
838  /* Check for [L count] part */
839  ul = 0;
840  if (strcmp(Argv[Argc-2], "L") == 0)
841  {
842  ul = strtoul(Argv[Argc-1], NULL, 0);
843  if (ul > 0)
844  {
845  Count = ul;
846  Argc -= 2;
847  }
848  }
849  else if (Argv[Argc-1][0] == 'L')
850  {
851  ul = strtoul(Argv[Argc-1] + 1, NULL, 0);
852  if (ul > 0)
853  {
854  Count = ul;
855  Argc--;
856  }
857  }
858 
859  /* Put the remaining arguments back together */
860  Argc--;
861  for (ul = 1; ul < Argc; ul++)
862  {
863  Argv[ul][strlen(Argv[ul])] = ' ';
864  }
865  Argc++;
866  }
867 
868  /* Evaluate the expression */
869  if (Argc > 1)
870  {
871  if (!KdbpEvaluateExpression(Argv[1], KdbPromptString.Length + (Argv[1]-Argv[0]), &Result))
872  return TRUE;
873 
874  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
875  KdbpPrint("Warning: Address %I64x is beeing truncated\n",Result);
876 
878  }
879  else if (Argv[0][0] == 'x')
880  {
881  KdbpPrint("x: Address argument required.\n");
882  return TRUE;
883  }
884 
885  if (Argv[0][0] == 'x')
886  {
887  /* Display dwords */
888  ul = 0;
889 
890  while (Count > 0)
891  {
893  KdbpPrint("<%p>:", (PVOID)Address);
894  else
895  KdbpPrint(":");
896 
897  i = min(4, Count);
898  Count -= i;
899 
900  while (--i >= 0)
901  {
902  if (!NT_SUCCESS(KdbpSafeReadMemory(&ul, (PVOID)Address, sizeof(ul))))
903  KdbpPrint(" ????????");
904  else
905  KdbpPrint(" %08x", ul);
906 
907  Address += sizeof(ul);
908  }
909 
910  KdbpPrint("\n");
911  }
912  }
913  else
914  {
915  /* Disassemble */
916  while (Count-- > 0)
917  {
919  KdbpPrint("<%08x>: ", Address);
920  else
921  KdbpPrint(": ");
922 
924  if (InstLen < 0)
925  {
926  KdbpPrint("<INVALID>\n");
927  return TRUE;
928  }
929 
930  KdbpPrint("\n");
931  Address += InstLen;
932  }
933  }
934 
935  return TRUE;
936 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PCONTEXT 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:441
#define TRUE
Definition: types.h:120
#define KeGetContextPc(Context)
Definition: ke.h:31
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
LONG KdbpDisassemble(IN ULONG_PTR Address, IN ULONG IntelSyntax)
Definition: i386-dis.c:125
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
long LONG
Definition: pedump.c:60
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:58
int Count
Definition: noreturn.cpp:7
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:140
STRING KdbPromptString
Definition: kdb_cli.c:167
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1690
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 min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
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

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

2538 {
2539  ULONG beg, end;
2540 
2541  KdbpIsInDmesgMode = TRUE; /* Toggle logging flag */
2542  if (!KdpDmesgBuffer)
2543  {
2544  KdbpPrint("Dmesg: error, buffer is not allocated! /DEBUGPORT=SCREEN kernel param required for dmesg.\n");
2545  return TRUE;
2546  }
2547 
2548  KdbpPrint("*** Dmesg *** TotalWritten=%lu, BufferSize=%lu, CurrentPosition=%lu\n",
2550 
2551  /* Pass data to the pager */
2554 
2555  /* No roll-overs, and overwritten=lost bytes */
2557  {
2558  /* Show buffer (KdpDmesgBuffer + beg, num) */
2560  }
2561  else
2562  {
2563  /* Show 2 buffers: (KdpDmesgBuffer + beg, KdpDmesgBufferSize - beg)
2564  * and: (KdpDmesgBuffer, end) */
2566  KdbpPrint("*** Dmesg: buffer rollup ***\n");
2568  }
2569  KdbpPrint("*** Dmesg: end of output ***\n");
2570 
2571  KdbpIsInDmesgMode = FALSE; /* Toggle logging flag */
2572 
2573  return TRUE;
2574 }
PCHAR KdpDmesgBuffer
Definition: kdio.c:41
volatile BOOLEAN KdbpIsInDmesgMode
Definition: kdio.c:45
VOID KdbpPager(_In_ PCHAR Buffer, _In_ ULONG BufLength)
Prints the given string with, page by page.
Definition: kdb_cli.c:3206
#define TRUE
Definition: types.h:120
const ULONG KdpDmesgBufferSize
Definition: kdio.c:40
volatile ULONG KdbDmesgTotalWritten
Definition: kdio.c:44
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
volatile ULONG KdpDmesgCurrentPosition
Definition: kdio.c:42
GLuint GLuint end
Definition: gl.h:1545
unsigned int ULONG
Definition: retypes.h:1
volatile ULONG KdpDmesgFreeBytes
Definition: kdio.c:43

◆ KdbpCmdEnableDisableClearBreakPoint()

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

Enables, disables or clears a breakpoint.

Definition at line 1558 of file kdb_cli.c.

1561 {
1562  PCHAR pend;
1563  ULONG BreakPointNr;
1564 
1565  if (Argc < 2)
1566  {
1567  KdbpPrint("%s: argument required\n", Argv[0]);
1568  return TRUE;
1569  }
1570 
1571  pend = Argv[1];
1572  BreakPointNr = strtoul(Argv[1], &pend, 0);
1573  if (pend == Argv[1] || *pend != '\0')
1574  {
1575  KdbpPrint("%s: integer argument required\n", Argv[0]);
1576  return TRUE;
1577  }
1578 
1579  if (Argv[0][1] == 'e') /* enable */
1580  {
1581  KdbpEnableBreakPoint(BreakPointNr, NULL);
1582  }
1583  else if (Argv [0][1] == 'd') /* disable */
1584  {
1585  KdbpDisableBreakPoint(BreakPointNr, NULL);
1586  }
1587  else /* clear */
1588  {
1589  ASSERT(Argv[0][1] == 'c');
1590  KdbpDeleteBreakPoint(BreakPointNr, NULL);
1591  }
1592 
1593  return TRUE;
1594 }
BOOLEAN KdbpDeleteBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Deletes a breakpoint.
Definition: kdb.c:601
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
BOOLEAN KdbpDisableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Disables a breakpoint.
Definition: kdb.c:871
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
BOOLEAN KdbpEnableBreakPoint(IN LONG BreakPointNr OPTIONAL, IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL)
Enables a breakpoint.
Definition: kdb.c:704
#define ASSERT(a)
Definition: mode.c:44
#define NULL
Definition: types.h:112
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 487 of file kdb_cli.c.

490 {
491  ULONG i;
492  SIZE_T len;
493  ULONGLONG Result = 0;
494  ULONG ul;
495  LONG l = 0;
496  BOOLEAN Ok;
497 
498  if (Argc < 2)
499  {
500  KdbpPrint("?: Argument required\n");
501  return TRUE;
502  }
503 
504  /* Put the arguments back together */
505  Argc--;
506  for (i = 1; i < Argc; i++)
507  {
508  len = strlen(Argv[i]);
509  Argv[i][len] = ' ';
510  }
511 
512  /* Evaluate the expression */
513  Ok = KdbpEvaluateExpression(Argv[1], KdbPromptString.Length + (Argv[1]-Argv[0]), &Result);
514  if (Ok)
515  {
516  if (Result > 0x00000000ffffffffLL)
517  {
518  if (Result & 0x8000000000000000LL)
519  KdbpPrint("0x%016I64x %20I64u %20I64d\n", Result, Result, Result);
520  else
521  KdbpPrint("0x%016I64x %20I64u\n", Result, Result);
522  }
523  else
524  {
525  ul = (ULONG)Result;
526 
527  if (ul <= 0xff && ul >= 0x80)
528  l = (LONG)((CHAR)ul);
529  else if (ul <= 0xffff && ul >= 0x8000)
530  l = (LONG)((SHORT)ul);
531  else
532  l = (LONG)ul;
533 
534  if (l < 0)
535  KdbpPrint("0x%08lx %10lu %10ld\n", ul, ul, l);
536  else
537  KdbpPrint("0x%08lx %10lu\n", ul, ul);
538  }
539  }
540 
541  return TRUE;
542 }
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:441
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
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:167
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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
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 716 of file kdb_cli.c.

719 {
721  ULONG set = DPFLTR_MASK, clear = DPFLTR_MASK;
722  PCHAR pend;
723  PCSTR opt, p;
724 
725  static struct
726  {
727  PCSTR Name;
728  ULONG Level;
729  }
730  debug_classes[] =
731  {
732  { "error", 1 << DPFLTR_ERROR_LEVEL },
733  { "warning", 1 << DPFLTR_WARNING_LEVEL },
734  { "trace", 1 << DPFLTR_TRACE_LEVEL },
735  { "info", 1 << DPFLTR_INFO_LEVEL },
736  };
737 
738  if (Argc <= 1)
739  {
740  /* Display the list of available debug filter components */
741  KdbpPrint("REMARKS:\n"
742  "- The 'WIN2000' system-wide debug filter component is used for DbgPrint()\n"
743  " messages without Component ID and Level.\n"
744  "- The 'DEFAULT' debug filter component is used for DbgPrint() messages with\n"
745  " an unknown Component ID.\n\n");
746  KdbpPrint("The list of debug filter components currently available on your system is:\n\n");
747  KdbpPrint(" Component Name Component ID\n"
748  " ================== ================\n");
749  for (i = 0; i < RTL_NUMBER_OF(ComponentTable); i++)
750  {
751  KdbpPrint("%20s 0x%08lx\n", ComponentTable[i].Name, ComponentTable[i].Id);
752  }
753  return TRUE;
754  }
755 
756  for (i = 1; i < Argc; i++)
757  {
758  opt = Argv[i];
759  p = opt + strcspn(opt, "+-");
760  if (!p[0]) p = opt; /* Assume it's a debug channel name */
761 
762  if (p > opt)
763  {
764  for (j = 0; j < RTL_NUMBER_OF(debug_classes); j++)
765  {
767  if (len != (p - opt))
768  continue;
769  if (_strnicmp(opt, debug_classes[j].Name, len) == 0) /* Found it */
770  {
771  if (*p == '+')
772  set |= debug_classes[j].Level;
773  else
774  clear |= debug_classes[j].Level;
775  break;
776  }
777  }
778  if (j == RTL_NUMBER_OF(debug_classes))
779  {
780  Level = strtoul(opt, &pend, 0);
781  if (pend != p)
782  {
783  KdbpPrint("filter: bad class name '%.*s'\n", p - opt, opt);
784  continue;
785  }
786  if (*p == '+')
787  set |= Level;
788  else
789  clear |= Level;
790  }
791  }
792  else
793  {
794  if (*p == '-')
795  clear = MAXULONG;
796  else
797  set = MAXULONG;
798  }
799  if (*p == '+' || *p == '-')
800  p++;
801 
803  {
804  KdbpPrint("filter: '%s' is not a valid component name!\n", p);
805  return TRUE;
806  }
807 
808  /* Get current mask value */
811  }
812 
813  return TRUE;
814 }
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:2406
#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
PCSTR Name
Definition: kdb_cli.c:177
#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:178
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:1278
#define DPFLTR_WARNING_LEVEL
Definition: kdtypes.h:31
static struct @1794 ComponentTable[]
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#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
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 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:695
Definition: _set.h:46
#define DPFLTR_TRACE_LEVEL
Definition: kdtypes.h:32

◆ KdbpCmdGdtLdtIdt()

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

Displays GDT, LDT or IDT.

Definition at line 2116 of file kdb_cli.c.

2119 {
2120  KDESCRIPTOR Reg;
2121  ULONG SegDesc[2];
2122  ULONG SegBase;
2123  ULONG SegLimit;
2124  PCHAR SegType;
2125  USHORT SegSel;
2126  UCHAR Type, Dpl;
2127  INT i;
2128  ULONG ul;
2129 
2130  if (Argv[0][0] == 'i')
2131  {
2132  /* Read IDTR */
2133  __sidt(&Reg.Limit);
2134 
2135  if (Reg.Limit < 7)
2136  {
2137  KdbpPrint("Interrupt descriptor table is empty.\n");
2138  return TRUE;
2139  }
2140 
2141  KdbpPrint("IDT Base: 0x%08x Limit: 0x%04x\n", Reg.Base, Reg.Limit);
2142  KdbpPrint(" Idx Type Seg. Sel. Offset DPL\n");
2143 
2144  for (i = 0; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8)
2145  {
2146  if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)((ULONG_PTR)Reg.Base + i), sizeof(SegDesc))))
2147  {
2148  KdbpPrint("Couldn't access memory at 0x%p!\n", (PVOID)((ULONG_PTR)Reg.Base + i));
2149  return TRUE;
2150  }
2151 
2152  Dpl = ((SegDesc[1] >> 13) & 3);
2153  if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */
2154  SegType = "TASKGATE";
2155  else if ((SegDesc[1] & 0x1fe0) == 0x0e00) /* 32 bit Interrupt gate */
2156  SegType = "INTGATE32";
2157  else if ((SegDesc[1] & 0x1fe0) == 0x0600) /* 16 bit Interrupt gate */
2158  SegType = "INTGATE16";
2159  else if ((SegDesc[1] & 0x1fe0) == 0x0f00) /* 32 bit Trap gate */
2160  SegType = "TRAPGATE32";
2161  else if ((SegDesc[1] & 0x1fe0) == 0x0700) /* 16 bit Trap gate */
2162  SegType = "TRAPGATE16";
2163  else
2164  SegType = "UNKNOWN";
2165 
2166  if ((SegDesc[1] & (1 << 15)) == 0) /* not present */
2167  {
2168  KdbpPrint(" %03d %-10s [NP] [NP] %02d\n",
2169  i / 8, SegType, Dpl);
2170  }
2171  else if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */
2172  {
2173  SegSel = SegDesc[0] >> 16;
2174  KdbpPrint(" %03d %-10s 0x%04x %02d\n",
2175  i / 8, SegType, SegSel, Dpl);
2176  }
2177  else
2178  {
2179  SegSel = SegDesc[0] >> 16;
2180  SegBase = (SegDesc[1] & 0xffff0000) | (SegDesc[0] & 0x0000ffff);
2181  KdbpPrint(" %03d %-10s 0x%04x 0x%08x %02d\n",
2182  i / 8, SegType, SegSel, SegBase, Dpl);
2183  }
2184  }
2185  }
2186  else
2187  {
2188  ul = 0;
2189 
2190  if (Argv[0][0] == 'g')
2191  {
2192  /* Read GDTR */
2194  i = 8;
2195  }
2196  else
2197  {
2198  ASSERT(Argv[0][0] == 'l');
2199 
2200  /* Read LDTR */
2202  Reg.Base = 0;
2203  i = 0;
2204  ul = 1 << 2;
2205  }
2206 
2207  if (Reg.Limit < 7)
2208  {
2209  KdbpPrint("%s descriptor table is empty.\n",
2210  Argv[0][0] == 'g' ? "Global" : "Local");
2211  return TRUE;
2212  }
2213 
2214  KdbpPrint("%cDT Base: 0x%08x Limit: 0x%04x\n",
2215  Argv[0][0] == 'g' ? 'G' : 'L', Reg.Base, Reg.Limit);
2216  KdbpPrint(" Idx Sel. Type Base Limit DPL Attribs\n");
2217 
2218  for (; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8)
2219  {
2220  if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)((ULONG_PTR)Reg.Base + i), sizeof(SegDesc))))
2221  {
2222  KdbpPrint("Couldn't access memory at 0x%p!\n", (ULONG_PTR)Reg.Base + i);
2223  return TRUE;
2224  }
2225 
2226  Dpl = ((SegDesc[1] >> 13) & 3);
2227  Type = ((SegDesc[1] >> 8) & 0xf);
2228 
2229  SegBase = SegDesc[0] >> 16;
2230  SegBase |= (SegDesc[1] & 0xff) << 16;
2231  SegBase |= SegDesc[1] & 0xff000000;
2232  SegLimit = SegDesc[0] & 0x0000ffff;
2233  SegLimit |= (SegDesc[1] >> 16) & 0xf;
2234 
2235  if ((SegDesc[1] & (1 << 23)) != 0)
2236  {
2237  SegLimit *= 4096;
2238  SegLimit += 4095;
2239  }
2240  else
2241  {
2242  SegLimit++;
2243  }
2244 
2245  if ((SegDesc[1] & (1 << 12)) == 0) /* System segment */
2246  {
2247  switch (Type)
2248  {
2249  case 1: SegType = "TSS16(Avl)"; break;
2250  case 2: SegType = "LDT"; break;
2251  case 3: SegType = "TSS16(Busy)"; break;
2252  case 4: SegType = "CALLGATE16"; break;
2253  case 5: SegType = "TASKGATE"; break;
2254  case 6: SegType = "INTGATE16"; break;
2255  case 7: SegType = "TRAPGATE16"; break;
2256  case 9: SegType = "TSS32(Avl)"; break;
2257  case 11: SegType = "TSS32(Busy)"; break;
2258  case 12: SegType = "CALLGATE32"; break;
2259  case 14: SegType = "INTGATE32"; break;
2260  case 15: SegType = "TRAPGATE32"; break;
2261  default: SegType = "UNKNOWN"; break;
2262  }
2263 
2264  if (!(Type >= 1 && Type <= 3) &&
2265  Type != 9 && Type != 11)
2266  {
2267  SegBase = 0;
2268  SegLimit = 0;
2269  }
2270  }
2271  else if ((SegDesc[1] & (1 << 11)) == 0) /* Data segment */
2272  {
2273  if ((SegDesc[1] & (1 << 22)) != 0)
2274  SegType = "DATA32";
2275  else
2276  SegType = "DATA16";
2277  }
2278  else /* Code segment */
2279  {
2280  if ((SegDesc[1] & (1 << 22)) != 0)
2281  SegType = "CODE32";
2282  else
2283  SegType = "CODE16";
2284  }
2285 
2286  if ((SegDesc[1] & (1 << 15)) == 0) /* Not present */
2287  {
2288  KdbpPrint(" %03d 0x%04x %-11s [NP] [NP] %02d NP\n",
2289  i / 8, i | Dpl | ul, SegType, Dpl);
2290  }
2291  else
2292  {
2293  KdbpPrint(" %03d 0x%04x %-11s 0x%08x 0x%08x %02d ",
2294  i / 8, i | Dpl | ul, SegType, SegBase, SegLimit, Dpl);
2295 
2296  if ((SegDesc[1] & (1 << 12)) == 0) /* System segment */
2297  {
2298  /* FIXME: Display system segment */
2299  }
2300  else if ((SegDesc[1] & (1 << 11)) == 0) /* Data segment */
2301  {
2302  if ((SegDesc[1] & (1 << 10)) != 0) /* Expand-down */
2303  KdbpPrint(" E");
2304 
2305  KdbpPrint((SegDesc[1] & (1 << 9)) ? " R/W" : " R");
2306 
2307  if ((SegDesc[1] & (1 << 8)) != 0)
2308  KdbpPrint(" A");
2309  }
2310  else /* Code segment */
2311  {
2312  if ((SegDesc[1] & (1 << 10)) != 0) /* Conforming */
2313  KdbpPrint(" C");
2314 
2315  KdbpPrint((SegDesc[1] & (1 << 9)) ? " R/X" : " X");
2316 
2317  if ((SegDesc[1] & (1 << 8)) != 0)
2318  KdbpPrint(" A");
2319  }
2320 
2321  if ((SegDesc[1] & (1 << 20)) != 0)
2322  KdbpPrint(" AVL");
2323 
2324  KdbpPrint("\n");
2325  }
2326  }
2327  }
2328 
2329  return TRUE;
2330 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
#define Ke386GetLocalDescriptorTable
Definition: kdb_cli.c:115
int32_t INT
Definition: typedefs.h:58
PVOID Base
Definition: ketypes.h:491
USHORT Limit
Definition: ketypes.h:490
uint32_t ULONG_PTR
Definition: typedefs.h:65
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:2023
#define Ke386GetGlobalDescriptorTable
Definition: kdb_cli.c:112
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Type
Definition: Type.h:6
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1690
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
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 2758 of file kdb_cli.c.

2761 {
2762  ULONG i;
2763 
2764  KdbpPrint("Kernel debugger commands:\n");
2765  for (i = 0; i < RTL_NUMBER_OF(KdbDebuggerCommands); i++)
2766  {
2767  if (!KdbDebuggerCommands[i].Syntax) /* Command group */
2768  {
2769  if (i > 0)
2770  KdbpPrint("\n");
2771 
2772  KdbpPrint("\x1b[7m* %s:\x1b[0m\n", KdbDebuggerCommands[i].Help);
2773  continue;
2774  }
2775 
2776  KdbpPrint(" %-20s - %s\n",
2779  }
2780 
2781  return TRUE;
2782 }
#define TRUE
Definition: types.h:120
static const struct @1795 KdbDebuggerCommands[]
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
PCHAR Syntax
Definition: kdb_cli.c:362
PCHAR Help
Definition: kdb_cli.c:363
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 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 2050 of file kdb_cli.c.

2053 {
2054  ULONGLONG Result = 0;
2056  PLDR_DATA_TABLE_ENTRY LdrEntry;
2057  BOOLEAN DisplayOnlyOneModule = FALSE;
2058  INT i = 0;
2059 
2060  if (Argc >= 2)
2061  {
2062  /* Put the arguments back together */
2063  Argc--;
2064  while (--Argc >= 1)
2065  Argv[Argc][strlen(Argv[Argc])] = ' ';
2066 
2067  /* Evaluate the expression */
2068  if (!KdbpEvaluateExpression(Argv[1], KdbPromptString.Length + (Argv[1]-Argv[0]), &Result))
2069  {
2070  return TRUE;
2071  }
2072 
2073  if (Result > (ULONGLONG)(~((ULONG_PTR)0)))
2074  KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv[0],Result);
2075 
2077 
2078  if (!KdbpSymFindModule((PVOID)Address, -1, &LdrEntry))
2079  {
2080  KdbpPrint("No module containing address 0x%p found!\n", Address);
2081  return TRUE;
2082  }
2083 
2084  DisplayOnlyOneModule = TRUE;
2085  }
2086  else
2087  {
2088  if (!KdbpSymFindModule(NULL, 0, &LdrEntry))
2089  {
2090  ULONG_PTR ntoskrnlBase = (ULONG_PTR)__ImageBase;
2091  KdbpPrint(" Base Size Name\n");
2092  KdbpPrint(" %p %08x %s\n", (PVOID)ntoskrnlBase, 0, "ntoskrnl.exe");
2093  return TRUE;
2094  }
2095 
2096  i = 1;
2097  }
2098 
2099  KdbpPrint(" Base Size Name\n");
2100  for (;;)
2101  {
2102  KdbpPrint(" %p %08x ", LdrEntry->DllBase, LdrEntry->SizeOfImage);
2103  KdbpPrintUnicodeString(&LdrEntry->BaseDllName);
2104  KdbpPrint("\n");
2105 
2106  if(DisplayOnlyOneModule || !KdbpSymFindModule(NULL, i++, &LdrEntry))
2107  break;
2108  }
2109 
2110  return TRUE;
2111 }
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:441
#define TRUE
Definition: types.h:120
ULONG SizeOfImage
Definition: ldrtypes.h:143
int32_t INT
Definition: typedefs.h:58
VOID KdbpPrintUnicodeString(_In_ PCUNICODE_STRING String)
Definition: kdb_cli.c:3247
uint32_t ULONG_PTR
Definition: typedefs.h:65
PVOID DllBase
Definition: btrfs_drv.h:1880
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
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
BOOLEAN KdbpSymFindModule(IN PVOID Address OPTIONAL, IN INT Index OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *pLdrEntry)
Find a module...
Definition: kdb_symbols.c:75
Definition: btrfs_drv.h:1876
char __ImageBase
Definition: mstscax.cpp:17
STRING KdbPromptString
Definition: kdb_cli.c:167
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
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101

◆ KdbpCmdPcr()

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

Displays the KPCR.

Definition at line 2335 of file kdb_cli.c.

2338 {
2339  PKIPCR Pcr = (PKIPCR)KeGetPcr();
2340 
2341  KdbpPrint("Current PCR is at 0x%p.\n", Pcr);
2342 #ifdef _M_IX86
2343  KdbpPrint(" Tib.ExceptionList: 0x%08x\n"
2344  " Tib.StackBase: 0x%08x\n"
2345  " Tib.StackLimit: 0x%08x\n"
2346  " Tib.SubSystemTib: 0x%08x\n"
2347  " Tib.FiberData/Version: 0x%08x\n"
2348  " Tib.ArbitraryUserPointer: 0x%08x\n"
2349  " Tib.Self: 0x%08x\n"
2350  " SelfPcr: 0x%08x\n"
2351  " PCRCB: 0x%08x\n"
2352  " Irql: 0x%02x\n"
2353  " IRR: 0x%08x\n"
2354  " IrrActive: 0x%08x\n"
2355  " IDR: 0x%08x\n"
2356  " KdVersionBlock: 0x%08x\n"
2357  " IDT: 0x%08x\n"
2358  " GDT: 0x%08x\n"
2359  " TSS: 0x%08x\n"
2360  " MajorVersion: 0x%04x\n"
2361  " MinorVersion: 0x%04x\n"
2362  " SetMember: 0x%08x\n"
2363  " StallScaleFactor: 0x%08x\n"
2364  " Number: 0x%02x\n"
2365  " L2CacheAssociativity: 0x%02x\n"
2366  " VdmAlert: 0x%08x\n"
2367  " L2CacheSize: 0x%08x\n"
2368  " InterruptMode: 0x%08x\n"
2369  , Pcr->NtTib.ExceptionList, Pcr->NtTib.StackBase, Pcr->NtTib.StackLimit,
2371  Pcr->NtTib.Self
2372  , Pcr->SelfPcr
2373  , Pcr->Prcb, Pcr->Irql
2374  , Pcr->IRR, Pcr->IrrActive , Pcr->IDR
2375  , Pcr->KdVersionBlock
2376  , Pcr->IDT, Pcr->GDT, Pcr->TSS
2377  , Pcr->MajorVersion, Pcr->MinorVersion
2378  , Pcr->SetMember
2379  , Pcr->StallScaleFactor
2380  , Pcr->Number
2382  , Pcr->VdmAlert
2383  , Pcr->SecondLevelCacheSize
2384  , Pcr->InterruptMode);
2385 #else
2386  KdbpPrint(" GdtBase: 0x%p\n", Pcr->GdtBase);
2387  KdbpPrint(" TssBase: 0x%p\n", Pcr->TssBase);
2388  KdbpPrint(" UserRsp: 0x%p\n", (PVOID)Pcr->UserRsp);
2389  KdbpPrint(" Self: 0x%p\n", Pcr->Self);
2390  KdbpPrint(" CurrentPrcb: 0x%p\n", Pcr->CurrentPrcb);
2391  KdbpPrint(" LockArray: 0x%p\n", Pcr->LockArray);
2392  KdbpPrint(" Used_Self: 0x%p\n", Pcr->Used_Self);
2393  KdbpPrint(" IdtBase: 0x%p\n", Pcr->IdtBase);
2394  KdbpPrint(" Irql: %u\n", Pcr->Irql);
2395  KdbpPrint(" SecondLevelCacheAssociativity: 0x%u\n", Pcr->SecondLevelCacheAssociativity);
2396  KdbpPrint(" ObsoleteNumber: %u\n", Pcr->ObsoleteNumber);
2397  KdbpPrint(" MajorVersion: 0x%x\n", Pcr->MajorVersion);
2398  KdbpPrint(" MinorVersion: 0x%x\n", Pcr->MinorVersion);
2399  KdbpPrint(" StallScaleFactor: 0x%lx\n", Pcr->StallScaleFactor);
2400  KdbpPrint(" SecondLevelCacheSize: 0x%lx\n", Pcr->SecondLevelCacheSize);
2401  KdbpPrint(" KdVersionBlock: 0x%p\n", Pcr->KdVersionBlock);
2402 #endif
2403 
2404  return TRUE;
2405 }
struct _NT_TIB * Self
Definition: compat.h:720
union _KGDTENTRY64 * GdtBase
Definition: ketypes.h:865
ULONG IRR
Definition: ketypes.h:755
#define TRUE
Definition: types.h:120
UCHAR ObsoleteNumber
Definition: ketypes.h:878
UCHAR SecondLevelCacheAssociativity
Definition: ketypes.h:877
USHORT MinorVersion
Definition: ketypes.h:882
struct _KIPCR * PKIPCR
UCHAR Number
Definition: ketypes.h:767
KIRQL Irql
Definition: ketypes.h:876
ULONG64 UserRsp
Definition: ketypes.h:867
PVOID ArbitraryUserPointer
Definition: compat.h:719
#define KeGetPcr()
Definition: ke.h:26
PVOID Used_Self
Definition: ketypes.h:871
struct _KTSS64 * TssBase
Definition: ketypes.h:866
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
ULONG VdmAlert
Definition: ketypes.h:770
ULONG StallScaleFactor
Definition: ketypes.h:883
struct _KPRCB * CurrentPrcb
Definition: ketypes.h:869
ULONG SecondLevelCacheSize
Definition: ketypes.h:886
KAFFINITY SetMember
Definition: ketypes.h:764
struct _KTSS * TSS
Definition: ketypes.h:761
ULONG InterruptMode
Definition: ketypes.h:774
PVOID FiberData
Definition: compat.h:716
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: compat.h:711
PVOID SubSystemTib
Definition: compat.h:714
KPRCB Prcb
Definition: ketypes.h:894
struct _KPCR * Self
Definition: ketypes.h:868
union _KIDTENTRY64 * IdtBase
Definition: ketypes.h:874
PVOID KdVersionBlock
Definition: ketypes.h:890
PVOID StackBase
Definition: compat.h:712
PKGDTENTRY GDT
Definition: ketypes.h:760
USHORT MajorVersion
Definition: ketypes.h:881
ULONG IDR
Definition: ketypes.h:757
ULONG IrrActive
Definition: ketypes.h:756
PVOID StackLimit
Definition: compat.h:713
NT_TIB NtTib
Definition: ketypes.h:862
PKIDTENTRY IDT
Definition: ketypes.h:759
PKSPIN_LOCK_QUEUE LockArray
Definition: ketypes.h:870
struct _KPCR * SelfPcr
Definition: ketypes.h:752

◆ KdbpCmdProc()

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

Lists processes or switches to another process context.

Definition at line 1932 of file kdb_cli.c.

1935 {
1938  BOOLEAN ReferencedProcess = FALSE;
1939  PCHAR State, pend, str1, str2;
1940  ULONG_PTR ul;
1942 
1943  if (Argc >= 2 && _stricmp(Argv[1], "list") == 0)
1944  {
1946  if (!Entry || Entry == &PsActiveProcessHead)
1947  {
1948  KdbpPrint("No processes in the system!\n");
1949  return TRUE;
1950  }
1951 
1952  KdbpPrint(" PID State Filename\n");
1953  do
1954  {
1955  Process = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks);
1956 
1957  if (Process == KdbCurrentProcess)
1958  {
1959  str1 = "\x1b[1m*";
1960  str2 = "\x1b[0m";
1961  }
1962  else
1963  {
1964  str1 = " ";
1965  str2 = "";
1966  }
1967 
1968  State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
1969  ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
1970 
1971  KdbpPrint(" %s0x%08x %-10s %s%s\n",
1972  str1,
1973  Process->UniqueProcessId,
1974  State,
1975  Process->ImageFileName,
1976  str2);
1977 
1978  Entry = Entry->Flink;
1979  }
1980  while(Entry != &PsActiveProcessHead);
1981  }
1982  else if (Argc >= 2 && _stricmp(Argv[1], "attach") == 0)
1983  {
1984  if (Argc < 3)
1985  {
1986  KdbpPrint("process attach: process id argument required!\n");
1987  return TRUE;
1988  }
1989 
1990  ul = strtoulptr(Argv[2], &pend, 0);
1991  if (Argv[2] == pend)
1992  {
1993  KdbpPrint("process attach: '%s' is not a valid process id!\n", Argv[2]);
1994  return TRUE;
1995  }
1996 
1997  if (!KdbpAttachToProcess((PVOID)ul))
1998  {
1999  return TRUE;
2000  }
2001 
2002  KdbpPrint("Attached to process 0x%p, thread 0x%p.\n", (PVOID)ul,
2004  }
2005  else
2006  {
2008 
2009  if (Argc >= 2)
2010  {
2011  ul = strtoulptr(Argv[1], &pend, 0);
2012  if (Argv[1] == pend)
2013  {
2014  KdbpPrint("proc: '%s' is not a valid process id!\n", Argv[1]);
2015  return TRUE;
2016  }
2017 
2019  {
2020  KdbpPrint("proc: Invalid process id!\n");
2021  return TRUE;
2022  }
2023 
2024  /* Remember our reference */
2025  ReferencedProcess = TRUE;
2026  }
2027 
2028  State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
2029  ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
2030  KdbpPrint("%s"
2031  " PID: 0x%08x\n"
2032  " State: %s (0x%x)\n"
2033  " Image Filename: %s\n",
2034  (Argc < 2) ? "Current process:\n" : "",
2035  Process->UniqueProcessId,
2036  State, Process->Pcb.State,
2037  Process->ImageFileName);
2038 
2039  /* Release our reference, if any */
2040  if (ReferencedProcess)
2042  }
2043 
2044  return TRUE;
2045 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
PEPROCESS KdbCurrentProcess
Definition: kdb.c:54
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
LIST_ENTRY PsActiveProcessHead
Definition: process.c:22
#define _stricmp
Definition: cat.c:22
uint32_t ULONG_PTR
Definition: typedefs.h:65
Entry
Definition: section.c:4943
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
FORCEINLINE ULONG_PTR strtoulptr(const char *nptr, char **endptr, int base)
Definition: kdb_cli.c:121
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:1128
#define ObDereferenceObject
Definition: obfuncs.h:203
HANDLE UniqueThread
Definition: compat.h:826
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:1120
_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:56
base of all file and directory entries
Definition: entries.h:82

◆ KdbpCmdReboot()

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

Definition at line 2520 of file kdb_cli.c.

2523 {
2524  /* Reboot immediately (we do not return) */
2526  return FALSE;
2527 }
#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 941 of file kdb_cli.c.

944 {
946  INT i;
947  static const PCHAR EflagsBits[32] = { " CF", NULL, " PF", " BIT3", " AF", " BIT5",
948  " ZF", " SF", " TF", " IF", " DF", " OF",
949  NULL, NULL, " NT", " BIT15", " RF", " VF",
950  " AC", " VIF", " VIP", " ID", " BIT22",
951  " BIT23", " BIT24", " BIT25", " BIT26",
952  " BIT27", " BIT28", " BIT29", " BIT30",
953  " BIT31" };
954 
955  if (Argv[0][0] == 'r') /* regs */
956  {
957 #ifdef _M_IX86
958  KdbpPrint("CS:EIP 0x%04x:0x%08x\n"
959  "SS:ESP 0x%04x:0x%08x\n"
960  " EAX 0x%08x EBX 0x%08x\n"
961  " ECX 0x%08x EDX 0x%08x\n"
962  " ESI 0x%08x EDI 0x%08x\n"
963  " EBP 0x%08x\n",
964  Context->SegCs & 0xFFFF, Context->Eip,
965  Context->SegSs, Context->Esp,
966  Context->Eax, Context->Ebx,
967  Context->Ecx, Context->Edx,
968  Context->Esi, Context->Edi,
969  Context->Ebp);
970 #else
971  KdbpPrint("CS:RIP 0x%04x:0x%p\n"
972  "SS:RSP 0x%04x:0x%p\n"
973  " RAX 0x%p RBX 0x%p\n"
974  " RCX 0x%p RDX 0x%p\n"
975  " RSI 0x%p RDI 0x%p\n"
976  " RBP 0x%p\n",
977  Context->SegCs & 0xFFFF, Context->Rip,
978  Context->SegSs, Context->Rsp,
979  Context->Rax, Context->Rbx,
980  Context->Rcx, Context->Rdx,
981  Context->Rsi, Context->Rdi,
982  Context->Rbp);
983 #endif
984  /* Display the EFlags */
985  KdbpPrint("EFLAGS 0x%08x ", Context->EFlags);
986  for (i = 0; i < 32; i++)
987  {
988  if (i == 1)
989  {
990  if ((Context->EFlags & (1 << 1)) == 0)
991  KdbpPrint(" !BIT1");
992  }
993  else if (i == 12)
994  {
995  KdbpPrint(" IOPL%d", (Context->EFlags >> 12) & 3);
996  }
997  else if (i == 13)
998  {
999  }
1000  else if ((Context->EFlags & (1 << i)) != 0)
1001  {
1002  KdbpPrint(EflagsBits[i]);
1003  }
1004  }
1005  KdbpPrint("\n");
1006  }
1007  else if (Argv[0][0] == 's') /* sregs */
1008  {
1009  KdbpPrint("CS 0x%04x Index 0x%04x %cDT RPL%d\n",
1010  Context->SegCs & 0xffff, (Context->SegCs & 0xffff) >> 3,
1011  (Context->SegCs & (1 << 2)) ? 'L' : 'G', Context->SegCs & 3);
1012  KdbpPrint("DS 0x%04x Index 0x%04x %cDT RPL%d\n",
1013  Context->SegDs, Context->SegDs >> 3, (Context->SegDs & (1 << 2)) ? 'L' : 'G', Context->SegDs & 3);
1014  KdbpPrint("ES 0x%04x Index 0x%04x %cDT RPL%d\n",
1015  Context->SegEs, Context->SegEs >> 3, (Context->SegEs & (1 << 2)) ? 'L' : 'G', Context->SegEs & 3);
1016  KdbpPrint("FS 0x%04x Index 0x%04x %cDT RPL%d\n",
1017  Context->SegFs, Context->SegFs >> 3, (Context->SegFs & (1 << 2)) ? 'L' : 'G', Context->SegFs & 3);
1018  KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
1019  Context->SegGs, Context->SegGs >> 3, (Context->SegGs & (1 << 2)) ? 'L' : 'G', Context->SegGs & 3);
1020  KdbpPrint("SS 0x%04x Index 0x%04x %cDT RPL%d\n",
1021  Context->SegSs, Context->SegSs >> 3, (Context->SegSs & (1 << 2)) ? 'L' : 'G', Context->SegSs & 3);
1022  }
1023  else /* dregs */
1024  {
1025  ASSERT(Argv[0][0] == 'd');
1026  KdbpPrint("DR0 0x%08x\n"
1027  "DR1 0x%08x\n"
1028  "DR2 0x%08x\n"
1029  "DR3 0x%08x\n"
1030  "DR6 0x%08x\n"
1031  "DR7 0x%08x\n",
1032  Context->Dr0, Context->Dr1, Context->Dr2, Context->Dr3,
1033  Context->Dr6, Context->Dr7);
1034  }
1035 
1036  return TRUE;
1037 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
int32_t INT
Definition: typedefs.h:58
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
PKDB_KTRAP_FRAME KdbCurrentTrapFrame
Definition: kdb.c:58
#define ASSERT(a)
Definition: mode.c:44
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 NULL
Definition: types.h:112

◆ KdbpCmdSet()

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

Sets or displays a config variables value.

Definition at line 2579 of file kdb_cli.c.

2582 {
2583  LONG l;
2584  BOOLEAN First;
2585  PCHAR pend = 0;
2586  KDB_ENTER_CONDITION ConditionFirst = KdbDoNotEnter;
2587  KDB_ENTER_CONDITION ConditionLast = KdbDoNotEnter;
2588 
2589  static const PCHAR ExceptionNames[21] =
2590  {
2591  "ZERODEVIDE", "DEBUGTRAP", "NMI", "INT3", "OVERFLOW", "BOUND", "INVALIDOP",
2592  "NOMATHCOP", "DOUBLEFAULT", "RESERVED(9)", "INVALIDTSS", "SEGMENTNOTPRESENT",
2593  "STACKFAULT", "GPF", "PAGEFAULT", "RESERVED(15)", "MATHFAULT", "ALIGNMENTCHECK",
2594  "MACHINECHECK", "SIMDFAULT", "OTHERS"
2595  };
2596 
2597  if (Argc == 1)
2598  {
2599  KdbpPrint("Available settings:\n");
2600  KdbpPrint(" syntax [intel|at&t]\n");
2601  KdbpPrint(" condition [exception|*] [first|last] [never|always|kmode|umode]\n");
2602  KdbpPrint(" break_on_module_load [true|false]\n");
2603  }
2604  else if (strcmp(Argv[1], "syntax") == 0)
2605  {
2606  if (Argc == 2)
2607  {
2608  KdbpPrint("syntax = %s\n", KdbUseIntelSyntax ? "intel" : "at&t");
2609  }
2610  else if (Argc >= 3)
2611  {
2612  if (_stricmp(Argv[2], "intel") == 0)
2614  else if (_stricmp(Argv[2], "at&t") == 0)
2616  else
2617  KdbpPrint("Unknown syntax '%s'.\n", Argv[2]);
2618  }
2619  }
2620  else if (strcmp(Argv[1], "condition") == 0)
2621  {
2622  if (Argc == 2)
2623  {
2624  KdbpPrint("Conditions: (First) (Last)\n");
2625  for (l = 0; l < RTL_NUMBER_OF(ExceptionNames) - 1; l++)
2626  {
2627  if (!ExceptionNames[l])
2628  continue;
2629 
2630  if (!KdbpGetEnterCondition(l, TRUE, &ConditionFirst))
2631  ASSERT(FALSE);
2632 
2633  if (!KdbpGetEnterCondition(l, FALSE, &ConditionLast))
2634  ASSERT(FALSE);
2635 
2636  KdbpPrint(" #%02d %-20s %-8s %-8s\n", l, ExceptionNames[l],
2637  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2638  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2639  }
2640 
2641  ASSERT(l == (RTL_NUMBER_OF(ExceptionNames) - 1));
2642  KdbpPrint(" %-20s %-8s %-8s\n", ExceptionNames[l],
2643  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2644  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2645  }
2646  else
2647  {
2648  if (Argc >= 5 && strcmp(Argv[2], "*") == 0) /* Allow * only when setting condition */
2649  {
2650  l = -1;
2651  }
2652  else
2653  {
2654  l = strtoul(Argv[2], &pend, 0);
2655 
2656  if (Argv[2] == pend)
2657  {
2658  for (l = 0; l < RTL_NUMBER_OF(ExceptionNames); l++)
2659  {
2660  if (!ExceptionNames[l])
2661  continue;
2662 
2663  if (_stricmp(ExceptionNames[l], Argv[2]) == 0)
2664  break;
2665  }
2666  }
2667 
2668  if (l >= RTL_NUMBER_OF(ExceptionNames))
2669  {
2670  KdbpPrint("Unknown exception '%s'.\n", Argv[2]);
2671  return TRUE;
2672  }
2673  }
2674 
2675  if (Argc > 4)
2676  {
2677  if (_stricmp(Argv[3], "first") == 0)
2678  First = TRUE;
2679  else if (_stricmp(Argv[3], "last") == 0)
2680  First = FALSE;
2681  else
2682  {
2683  KdbpPrint("set condition: second argument must be 'first' or 'last'\n");
2684  return TRUE;
2685  }
2686 
2687  if (_stricmp(Argv[4], "never") == 0)
2688  ConditionFirst = KdbDoNotEnter;
2689  else if (_stricmp(Argv[4], "always") == 0)
2690  ConditionFirst = KdbEnterAlways;
2691  else if (_stricmp(Argv[4], "umode") == 0)
2692  ConditionFirst = KdbEnterFromUmode;
2693  else if (_stricmp(Argv[4], "kmode") == 0)
2694  ConditionFirst = KdbEnterFromKmode;
2695  else
2696  {
2697  KdbpPrint("set condition: third argument must be 'never', 'always', 'umode' or 'kmode'\n");
2698  return TRUE;
2699  }
2700 
2701  if (!KdbpSetEnterCondition(l, First, ConditionFirst))
2702  {
2703  if (l >= 0)
2704  KdbpPrint("Couldn't change condition for exception #%02d\n", l);
2705  else
2706  KdbpPrint("Couldn't change condition for all exceptions\n", l);
2707  }
2708  }
2709  else /* Argc >= 3 */
2710  {
2711  if (!KdbpGetEnterCondition(l, TRUE, &ConditionFirst))
2712  ASSERT(FALSE);
2713 
2714  if (!KdbpGetEnterCondition(l, FALSE, &ConditionLast))
2715  ASSERT(FALSE);
2716 
2717  if (l < (RTL_NUMBER_OF(ExceptionNames) - 1))
2718  {
2719  KdbpPrint("Condition for exception #%02d (%s): FirstChance %s LastChance %s\n",
2720  l, ExceptionNames[l],
2721  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2722  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2723  }
2724  else
2725  {
2726  KdbpPrint("Condition for all other exceptions: FirstChance %s LastChance %s\n",
2727  KDB_ENTER_CONDITION_TO_STRING(ConditionFirst),
2728  KDB_ENTER_CONDITION_TO_STRING(ConditionLast));
2729  }
2730  }
2731  }
2732  }
2733  else if (strcmp(Argv[1], "break_on_module_load") == 0)
2734  {
2735  if (Argc == 2)
2736  KdbpPrint("break_on_module_load = %s\n", KdbBreakOnModuleLoad ? "enabled" : "disabled");
2737  else if (Argc >= 3)
2738  {
2739  if (_stricmp(Argv[2], "enable") == 0 || _stricmp(Argv[2], "enabled") == 0 || _stricmp(Argv[2], "true") == 0)
2741  else if (_stricmp(Argv[2], "disable") == 0 || _stricmp(Argv[2], "disabled") == 0 || _stricmp(Argv[2], "false") == 0)
2743  else
2744  KdbpPrint("Unknown setting '%s'.\n", Argv[2]);
2745  }
2746  }
2747  else
2748  {
2749  KdbpPrint("Unknown setting '%s'.\n", Argv[1]);
2750  }
2751 
2752  return TRUE;
2753 }
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:998
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
#define KDB_ENTER_CONDITION_TO_STRING(cond)
Definition: kdb_cli.c:52
#define _stricmp
Definition: cat.c:22
WCHAR First[]
Definition: FormatMessage.c:11
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
r l[0]
Definition: byte_order.h:167
#define ASSERT(a)
Definition: mode.c:44
static BOOLEAN KdbBreakOnModuleLoad
Definition: kdb_cli.c:141
static BOOLEAN KdbUseIntelSyntax
Definition: kdb_cli.c:140
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:976

◆ KdbpCmdStep()

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

Continues execution of the system/leaves KDB.

Definition at line 1431 of file kdb_cli.c.

1434 {
1435  ULONG Count = 1;
1436 
1437  if (Argc > 1)
1438  {
1439  Count = strtoul(Argv[1], NULL, 0);
1440  if (Count == 0)
1441  {
1442  KdbpPrint("%s: Integer argument required\n", Argv[0]);
1443  return TRUE;
1444  }
1445  }
1446 
1447  if (Argv[0][0] == 'n')
1449  else
1451 
1452  /* Set the number of single steps and return to the interrupted code. */
1454 
1455  return FALSE;
1456 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
int Count
Definition: noreturn.cpp:7
ULONG KdbNumSingleSteps
Definition: kdb.c:50
BOOLEAN KdbSingleStepOver
Definition: kdb.c:51
#define NULL
Definition: types.h:112
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 1723 of file kdb_cli.c.

1726 {
1728  PETHREAD Thread = NULL;
1730  BOOLEAN ReferencedThread = FALSE, ReferencedProcess = FALSE;
1731  PULONG_PTR Stack;
1732  PULONG_PTR Frame;
1733  ULONG_PTR Pc;
1734  ULONG_PTR ul = 0;
1735  PCHAR State, pend, str1, str2;
1736  static const PCHAR ThreadStateToString[DeferredReady+1] =
1737  {
1738  "Initialized", "Ready", "Running",
1739  "Standby", "Terminated", "Waiting",
1740  "Transition", "DeferredReady"
1741  };
1742 
1744 
1745  if (Argc >= 2 && _stricmp(Argv[1], "list") == 0)
1746  {
1748 
1749  if (Argc >= 3)
1750  {
1751  ul = strtoulptr(Argv[2], &pend, 0);
1752  if (Argv[2] == pend)
1753  {
1754  KdbpPrint("thread: '%s' is not a valid process id!\n", Argv[2]);
1755  return TRUE;
1756  }
1757 
1759  {
1760  KdbpPrint("thread: Invalid process id!\n");
1761  return TRUE;
1762  }
1763 
1764  /* Remember our reference */
1765  ReferencedProcess = TRUE;
1766  }
1767 
1768  Entry = Process->ThreadListHead.Flink;
1769  if (Entry == &Process->ThreadListHead)
1770  {
1771  if (Argc >= 3)
1772  KdbpPrint("No threads in process 0x%px!\n", (PVOID)ul);
1773  else
1774  KdbpPrint("No threads in current process!\n");
1775 
1776  if (ReferencedProcess)
1778 
1779  return TRUE;
1780  }
1781 
1782  KdbpPrint(" TID State Prior. Affinity EBP EIP\n");
1783  do
1784  {
1785  Thread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
1786 
1787  if (Thread == KdbCurrentThread)
1788  {
1789  str1 = "\x1b[1m*";
1790  str2 = "\x1b[0m";
1791  }
1792  else
1793  {
1794  str1 = " ";
1795  str2 = "";
1796  }
1797 
1798  if (!Thread->Tcb.InitialStack)
1799  {
1800  /* Thread has no kernel stack (probably terminated) */
1801  Stack = Frame = NULL;
1802  Pc = 0;
1803  }
1804  else if (Thread->Tcb.TrapFrame)
1805  {
1809  }
1810  else
1811  {
1813  Frame = (PULONG_PTR)Stack[4];
1814  Pc = 0;
1815 
1816  if (Frame) /* FIXME: Should we attach to the process to read Ebp[1]? */
1817  KdbpSafeReadMemory(&Pc, Frame + 1, sizeof(Pc));
1818  }
1819 
1820  if (Thread->Tcb.State < (DeferredReady + 1))
1821  State = ThreadStateToString[Thread->Tcb.State];
1822  else
1823  State = "Unknown";
1824 
1825  KdbpPrint(" %s0x%08x %-11s %3d 0x%08x 0x%08x 0x%08x%s\n",
1826  str1,
1828  State,
1829  Thread->Tcb.Priority,
1830  Thread->Tcb.Affinity,
1831  Frame,
1832  Pc,
1833  str2);
1834 
1835  Entry = Entry->Flink;
1836  }
1837  while (Entry != &Process->ThreadListHead);
1838 
1839  /* Release our reference, if any */
1840  if (ReferencedProcess)
1842  }
1843  else if (Argc >= 2 && _stricmp(Argv[1], "attach") == 0)
1844  {
1845  if (Argc < 3)
1846  {
1847  KdbpPrint("thread attach: thread id argument required!\n");
1848  return TRUE;
1849  }
1850 
1851  ul = strtoulptr(Argv[2], &pend, 0);
1852  if (Argv[2] == pend)
1853  {
1854  KdbpPrint("thread attach: '%s' is not a valid thread id!\n", Argv[2]);
1855  return TRUE;
1856  }
1857 
1858  if (!KdbpAttachToThread((PVOID)ul))
1859  {
1860  return TRUE;
1861  }
1862 
1863  KdbpPrint("Attached to thread 0x%08x.\n", ul);
1864  }
1865  else
1866  {
1868 
1869  if (Argc >= 2)
1870  {
1871  ul = strtoulptr(Argv[1], &pend, 0);
1872  if (Argv[1] == pend)
1873  {
1874  KdbpPrint("thread: '%s' is not a valid thread id!\n", Argv[1]);
1875  return TRUE;
1876  }
1877 
1879  {
1880  KdbpPrint("thread: Invalid thread id!\n");
1881  return TRUE;
1882  }
1883 
1884  /* Remember our reference */
1885  ReferencedThread = TRUE;
1886  }
1887 
1888  if (Thread->Tcb.State < (DeferredReady + 1))
1889  State = ThreadStateToString[Thread->Tcb.State];
1890  else
1891  State = "Unknown";
1892 
1893  KdbpPrint("%s"
1894  " TID: 0x%08x\n"
1895  " State: %s (0x%x)\n"
1896  " Priority: %d\n"
1897  " Affinity: 0x%08x\n"
1898  " Initial Stack: 0x%08x\n"
1899  " Stack Limit: 0x%08x\n"
1900  " Stack Base: 0x%08x\n"
1901  " Kernel Stack: 0x%08x\n"
1902  " Trap Frame: 0x%08x\n"
1903 #ifndef _M_AMD64
1904  " NPX State: %s (0x%x)\n"
1905 #endif
1906  , (Argc < 2) ? "Current Thread:\n" : ""
1908  , State, Thread->Tcb.State
1909  , Thread->Tcb.Priority
1910  , Thread->Tcb.Affinity
1912  , Thread->Tcb.StackLimit
1913  , Thread->Tcb.StackBase
1915  , Thread->Tcb.TrapFrame
1916 #ifndef _M_AMD64
1918 #endif
1919  );
1920 
1921  /* Release our reference if we had one */
1922  if (ReferencedThread)
1924  }
1925 
1926  return TRUE;
1927 }
signed char * PCHAR
Definition: retypes.h:7
#define KeGetTrapFramePc(TrapFrame)
Definition: ke.h:37
#define NPX_STATE_TO_STRING(state)
Definition: kdb_cli.c:62
#define TRUE
Definition: types.h:120
BOOLEAN KdbpAttachToThread(PVOID ThreadId)
Switches to another thread context.
Definition: kdb.c:1039
PEPROCESS KdbCurrentProcess
Definition: kdb.c:54
NTSTATUS NTAPI PsLookupThreadByThreadId(IN HANDLE ThreadId, OUT PETHREAD *Thread)
Definition: thread.c:643
KTHREAD Tcb
Definition: pstypes.h:1103
SCHAR Priority
Definition: ketypes.h:1722
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1714
#define _stricmp
Definition: cat.c:22
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
Entry
Definition: section.c:4943
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
#define FALSE
Definition: types.h:117
FORCEINLINE ULONG_PTR strtoulptr(const char *nptr, char **endptr, int base)
Definition: kdb_cli.c:121
unsigned char BOOLEAN
PVOID KernelStack
Definition: ketypes.h:1615
FORCEINLINE ULONG_PTR KeGetTrapFrameStackRegister(PKTRAP_FRAME TrapFrame)
Definition: ke.h:193
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:2008
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID Cid
Definition: pstypes.h:1128
#define ObDereferenceObject
Definition: obfuncs.h:203
volatile VOID * StackLimit
Definition: ketypes.h:1605
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
HANDLE UniqueThread
Definition: compat.h:826
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
Definition: typedefs.h:119
PVOID StackBase
Definition: ketypes.h:1606
NTSTATUS KdbpSafeReadMemory(OUT PVOID Dest, IN PVOID Src, IN ULONG Bytes)
Definition: kdb.c:1690
#define NULL
Definition: types.h:112
_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:56
volatile UCHAR State
Definition: ketypes.h:1729
GROUP_AFFINITY Affinity
Definition: ketypes.h:1878
FORCEINLINE ULONG_PTR KeGetTrapFrameFrameRegister(PKTRAP_FRAME TrapFrame)
Definition: ke.h:200
uint32_t * PULONG_PTR
Definition: typedefs.h:65
PVOID InitialStack
Definition: ketypes.h:1604
base of all file and directory entries
Definition: entries.h:82

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

3272 {
3273  SIZE_T Length1 = strlen(Command) + 1;
3274  SIZE_T Length2 = 0;
3275  INT i;
3276  PCHAR Buffer;
3277 
3279 
3280  if (Length1 <= 1 ||
3283  {
3284  return;
3285  }
3286 
3287  /* Calculate Length1 and Length2 */
3291  {
3294  Length1 -= Length2;
3295  }
3296 
3297  /* Remove previous commands until there is enough space to append the new command */
3299  {
3300  if ((Length2 > 0 &&
3301  (KdbCommandHistory[i] >= Buffer ||
3303  (Length2 <= 0 &&
3304  (KdbCommandHistory[i] >= Buffer &&
3306  {
3308  }
3309 
3310  i--;
3311  if (i < 0)
3313 
3314  if (i == KdbCommandHistoryIndex)
3315  break;
3316  }
3317 
3318  /* Make sure the new command history entry is free */
3322  {
3324  }
3325 
3326  /* Append command */
3330  if (Length2 > 0)
3331  {
3333  }
3334 }
signed char * PCHAR
Definition: retypes.h:7
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
INT Length2
Definition: FsRtlDissect.c:16
Definition: shell.h:41
int32_t INT
Definition: typedefs.h:58
INT Length1
Definition: FsRtlDissect.c:15
long LONG
Definition: pedump.c:60
Definition: bufpool.h:45
#define ASSERT(a)
Definition: mode.c:44
static LONG KdbCommandHistoryBufferIndex
Definition: kdb_cli.c:145
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static LONG KdbCommandHistoryIndex
Definition: kdb_cli.c:146
ULONG_PTR SIZE_T
Definition: typedefs.h:80
static PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8]
Definition: kdb_cli.c:144
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 RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define NULL
Definition: types.h:112
static CHAR KdbCommandHistoryBuffer[2048]
Definition: kdb_cli.c:143
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

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

3631 {
3632  SIZE_T i;
3633  PCHAR p;
3634  ULONG Argc;
3635  // FIXME: for what do we need a 1024 characters command line and 256 tokens?
3636  static PCHAR Argv[256];
3637  static CHAR OrigCommand[1024];
3638 
3639  RtlStringCbCopyA(OrigCommand, sizeof(OrigCommand), Command);
3640 
3641  Argc = 0;
3642  p = Command;
3643 
3644  for (;;)
3645  {
3646  while (*p == '\t' || *p == ' ')
3647  p++;
3648 
3649  if (*p == '\0')
3650  break;
3651 
3652  i = strcspn(p, "\t ");
3653  Argv[Argc++] = p;
3654  p += i;
3655  if (*p == '\0')
3656  break;
3657 
3658  *p = '\0';
3659  p++;
3660  }
3661 
3662  if (Argc < 1)
3663  return TRUE;
3664 
3665  for (i = 0; i < RTL_NUMBER_OF(KdbDebuggerCommands); i++)
3666  {
3667  if (!KdbDebuggerCommands[i].Name)
3668  continue;
3669 
3670  if (strcmp(KdbDebuggerCommands[i].Name, Argv[0]) == 0)
3671  {
3672  return KdbDebuggerCommands[i].Fn(Argc, Argv);
3673  }
3674  }
3675 
3676  /* Now invoke the registered callbacks */
3677  if (KdbpInvokeCliCallbacks(Command, Argc, Argv))
3678  {
3679  return TRUE;
3680  }
3681 
3682  KdbpPrint("Command '%s' is unknown.\n", OrigCommand);
3683  return TRUE;
3684 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
char CHAR
Definition: xmlstorage.h:175
Definition: shell.h:41
static const struct @1795 KdbDebuggerCommands[]
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
struct Command Command
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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 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:3595

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

445 {
446  static CHAR ErrMsgBuffer[130] = "^ ";
447  LONG ExpressionErrOffset = -1;
448  PCHAR ErrMsg = ErrMsgBuffer;
449  BOOLEAN Ok;
450 
452  &ExpressionErrOffset, ErrMsgBuffer + 2);
453  if (!Ok)
454  {
455  if (ExpressionErrOffset >= 0)
456  ExpressionErrOffset += ErrOffset;
457  else
458  ErrMsg += 2;
459 
460  KdbpPrint("%*s%s\n", ExpressionErrOffset, "", ErrMsg);
461  }
462 
463  return Ok;
464 }
signed char * PCHAR
Definition: retypes.h:7
PCWSTR Expression
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
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:58
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:1102

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

698 {
699  ULONG i;
700 
701  for (i = 0; i < RTL_NUMBER_OF(ComponentTable); i++)
702  {
703  if (_stricmp(ComponentName, ComponentTable[i].Name) == 0)
704  {
706  return TRUE;
707  }
708  }
709 
710  return FALSE;
711 }
#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:1278
#define _stricmp
Definition: cat.c:22
static struct @1794 ComponentTable[]
#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 i
Definition: glfuncs.h:248
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdbpCmdFilter().

◆ KdbpGetHexNumber()

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

Definition at line 468 of file kdb_cli.c.

471 {
472  char *endptr;
473 
474  /* Skip optional '0x' prefix */
475  if ((pszNum[0] == '0') && ((pszNum[1] == 'x') || (pszNum[1] == 'X')))
476  pszNum += 2;
477 
478  /* Make a number from the string (hex) */
479  *pulValue = strtoul(pszNum, &endptr, 16);
480 
481  return (*endptr == '\0');
482 }
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 3595 of file kdb_cli.c.

3599 {
3600  ULONG i;
3601 
3602  /* Loop all entries */
3603  for (i = 0; i < _countof(KdbCliCallbacks); i++)
3604  {
3605  /* Check if this entry is registered */
3606  if (KdbCliCallbacks[i])
3607  {
3608  /* Invoke the callback and check if it handled the command */
3609  if (KdbCliCallbacks[i](Command, Argc, Argv))
3610  {
3611  return TRUE;
3612  }
3613  }
3614  }
3615 
3616  /* None of the callbacks handled the command */
3617  return FALSE;
3618 }
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:139
#define TRUE
Definition: types.h:120
Definition: shell.h:41
#define FALSE
Definition: types.h:117
#define _countof(array)
Definition: sndvol32.h:68
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
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdbpDoCommand().

◆ 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. Uses KdpDprintf internally (NOT DbgPrint!). Callers must already hold the debugger lock.

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

Definition at line 3206 of file kdb_cli.c.

3209 {
3210  /* Call the internal function */
3211  KdbpPagerInternal(Buffer, BufLength, TRUE);
3212 }
#define TRUE
Definition: types.h:120
Definition: bufpool.h:45
VOID KdbpPagerInternal(_In_ PCHAR Buffer, _In_ ULONG BufLength, _In_ BOOLEAN DoPage)
Prints the given string with, page by page.
Definition: kdb_cli.c:2898

Referenced by KdbpCmdDmesg().

◆ KdbpPagerInternal()

VOID KdbpPagerInternal ( _In_ PCHAR  Buffer,
_In_ ULONG  BufLength,
_In_ BOOLEAN  DoPage 
)

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. Uses KdpDprintf internally (NOT DbgPrint!). Callers must already hold the debugger lock.

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

Definition at line 2898 of file kdb_cli.c.

2902 {
2903  static CHAR InBuffer[128];
2904  static BOOLEAN TerminalInitialized = FALSE;
2905  static BOOLEAN TerminalConnected = FALSE;
2906  static BOOLEAN TerminalReportsSize = TRUE;
2907  CHAR c;
2908  ULONG ScanCode;
2909  PCHAR p;
2910  ULONG Length;
2911  SIZE_T i;
2912  LONG RowsPrintedByTerminal;
2913 
2914  if (BufLength == 0)
2915  return;
2916 
2917  /* Check if the user has aborted output of the current command */
2918  if (KdbOutputAborted)
2919  return;
2920 
2921  /* Initialize the terminal */
2922  if (!TerminalInitialized)
2923  {
2924  TerminalInitialized = TRUE;
2925 
2926  /* Enable line-wrap */
2927  KdpDprintf("\x1b[?7h");
2928 
2929  /*
2930  * Query terminal type.
2931  * Historically it was done with CTRL-E ('\x05'), however nowadays
2932  * terminals respond to it with an empty (or a user-configurable)
2933  * string. Instead, use the VT52-compatible 'ESC Z' sequence or the
2934  * VT100-compatible 'ESC[c' one.
2935  */
2936  KdpDprintf("\x1b[c");
2937  KeStallExecutionProcessor(100000);
2938 
2939  Length = 0;
2940  for (;;)
2941  {
2942  /* Verify we get an answer, but don't care about it */
2943  c = KdbpTryGetCharSerial(5000);
2944  if (c == -1)
2945  break;
2946  ++Length;
2947  }
2948  if (Length > 0)
2949  TerminalConnected = TRUE;
2950  }
2951 
2952  /* Get number of rows and columns in terminal */
2953  if ((KdbNumberOfRowsTerminal < 0) || (KdbNumberOfColsTerminal < 0) ||
2954  /* Refresh terminal size each time when number of rows printed is 0 */
2955  (KdbNumberOfRowsPrinted) == 0)
2956  {
2957  /* Retrieve the size of the serial terminal only when it is the
2958  * controlling terminal: serial output is enabled *and* KDSERIAL
2959  * is set (i.e. user input through serial). */
2960  BOOLEAN SerialTerminal =
2961 #if 0
2962  // Old logic where KDSERIAL also enables serial output.
2964  (KdpDebugMode.Serial && !KdpDebugMode.Screen);
2965 #else
2966  // New logic where KDSERIAL does not necessarily enable serial output.
2967  KdpDebugMode.Serial &&
2968  ((KdbDebugState & KD_DEBUG_KDSERIAL) || !KdpDebugMode.Screen);
2969 #endif
2970 
2971  if (SerialTerminal && TerminalConnected && TerminalReportsSize)
2972  {
2973  /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
2974  TerminalReportsSize = FALSE;
2975  KdpDprintf("\x1b[18t");
2976  KeStallExecutionProcessor(100000);
2977 
2978  c = KdbpTryGetCharSerial(5000);
2979  if (c == KEY_ESC)
2980  {
2981  c = KdbpTryGetCharSerial(5000);
2982  if (c == '[')
2983  {
2984  Length = 0;
2985  for (;;)
2986  {
2987  c = KdbpTryGetCharSerial(5000);
2988  if (c == -1)
2989  break;
2990 
2991  InBuffer[Length++] = c;
2992  if (isalpha(c) || Length >= (sizeof(InBuffer) - 1))
2993  break;
2994  }
2995  InBuffer[Length] = '\0';
2996 
2997  if (InBuffer[0] == '8' && InBuffer[1] == ';')
2998  {
2999  for (i = 2; (i < Length) && (InBuffer[i] != ';'); i++);
3000 
3001  if (InBuffer[i] == ';')
3002  {
3003  InBuffer[i++] = '\0';
3004 
3005  /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
3006  KdbNumberOfRowsTerminal = strtoul(InBuffer + 2, NULL, 0);
3007  KdbNumberOfColsTerminal = strtoul(InBuffer + i, NULL, 0);
3008  TerminalReportsSize = TRUE;
3009  }
3010  }
3011  }
3012  /* Clear further characters */
3013  while ((c = KdbpTryGetCharSerial(5000)) != -1);
3014  }
3015  }
3016 
3017  if (KdbNumberOfRowsTerminal <= 0)
3018  {
3019  /* Set number of rows to the default */
3020  if (KdpDebugMode.Screen && !SerialTerminal)
3021  KdbNumberOfRowsTerminal = (SCREEN_HEIGHT / (13 /*BOOTCHAR_HEIGHT*/ + 1));
3022  else
3024  }
3025  if (KdbNumberOfColsTerminal <= 0)
3026  {
3027  /* Set number of cols to the default */
3028  if (KdpDebugMode.Screen && !SerialTerminal)
3029  KdbNumberOfColsTerminal = (SCREEN_WIDTH / 8 /*BOOTCHAR_WIDTH*/);
3030  else
3032  }
3033 
3034  // KdpDprintf("Cols/Rows: %dx%d\n",
3035  // KdbNumberOfColsTerminal, KdbNumberOfRowsTerminal);
3036  }
3037 
3038  /* Loop through the strings */
3039  p = Buffer;
3040  while (p[0] != '\0')
3041  {
3042  if (DoPage)
3043  {
3044  if (p > Buffer + BufLength)
3045  {
3046  KdpDprintf("Dmesg: error, p > Buffer+BufLength,d=%d", p - (Buffer + BufLength));
3047  return;
3048  }
3049  }
3050  i = strcspn(p, "\n");
3051 
3052  if (DoPage)
3053  {
3054  /* Are we out of buffer? */
3055  if (p + i > Buffer + BufLength)
3056  break; // Leaving pager function
3057  }
3058 
3059  /* Calculate the number of lines which will be printed in
3060  * the terminal when outputting the current line. */
3061  if (i > 0)
3062  RowsPrintedByTerminal = (i + KdbNumberOfColsPrinted - 1) / KdbNumberOfColsTerminal;
3063  else
3064  RowsPrintedByTerminal = 0;
3065 
3066  if (p[i] == '\n')
3067  RowsPrintedByTerminal++;
3068 
3069  //KdpDprintf("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);
3070 
3071  /* Display a prompt if we printed one screen full of text */
3072  if (KdbNumberOfRowsTerminal > 0 &&
3073  (LONG)(KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
3074  {
3076 
3077  if (KdbNumberOfColsPrinted > 0)
3078  KdpDprintf("\n");
3079 
3080  if (DoPage)
3081  {
3082  KdpDprintf("--- Press q to abort, e/End,h/Home,u/PgUp, other key/PgDn ---");
3083  }
3084  else
3085  {
3086  KdpDprintf("--- Press q to abort, any other key to continue ---");
3087  }
3088  RowsPrintedByTerminal++;
3089 
3091  c = KdbpGetCharSerial();
3092  else
3094 
3095  if (c == '\r')
3096  {
3097  /* Try to read '\n' which might follow '\r' - if \n is not received here
3098  * it will be interpreted as "return" when the next command should be read.
3099  */
3101  c = KdbpTryGetCharSerial(5);
3102  else
3104  }
3105 
3106  if (DoPage)
3107  {
3108  //KdpDprintf("\n"); // Concise version: don't show pressed key
3109  KdpDprintf(" '%c'/scan=%04x\n", c, ScanCode); // Shows pressed key
3110  }
3111  else
3112  {
3113  KdpDprintf("\n");
3114  }
3115 
3116  if (c == 'q')
3117  {
3119  return;
3120  }
3121 
3122  if (DoPage)
3123  {
3124  if (ScanCode == KEYSC_END || c == 'e')
3125  {
3126  PCHAR pBufEnd = Buffer + BufLength;
3127  p = CountOnePageUp(Buffer, BufLength, pBufEnd);
3128  i = strcspn(p, "\n");
3129  }
3130  else if (ScanCode == KEYSC_PAGEUP || c == 'u')
3131  {
3132  p = CountOnePageUp(Buffer, BufLength, p);
3133  i = strcspn(p, "\n");
3134  }
3135  else if (ScanCode == KEYSC_HOME || c == 'h')
3136  {
3137  p = Buffer;
3138  i = strcspn(p, "\n");
3139  }
3140  else if (ScanCode == KEYSC_ARROWUP)
3141  {
3142  p = CountOnePageUp(Buffer, BufLength, p);
3143  i = strcspn(p, "\n");
3144  }
3145  }
3146 
3149  }
3150 
3151  /* Insert a NUL after the line and print only the current line */
3152  if (p[i] == '\n' && p[i + 1] != '\0')
3153  {
3154  c = p[i + 1];
3155  p[i + 1] = '\0';
3156  }
3157  else
3158  {
3159  c = '\0';
3160  }
3161 
3162  /* Remove escape sequences from the line if there is no terminal connected */
3163  // FIXME: Dangerous operation since we modify the source string!!
3164  if (!TerminalConnected)
3166 
3167  /* Print the current line */
3168  // KdpDprintf(p);
3169  KdpDprintf("%s", p);
3170 
3171  /* Restore not null char with saved */
3172  if (c != '\0')
3173  p[i + 1] = c;
3174 
3175  /* Set p to the start of the next line and
3176  * remember the number of rows/cols printed */
3177  p += i;
3178  if (p[0] == '\n')
3179  {
3180  p++;
3182  }
3183  else
3184  {
3185  ASSERT(p[0] == '\0');
3187  }
3188 
3189  KdbNumberOfRowsPrinted += RowsPrintedByTerminal;
3190  }
3191 }
signed char * PCHAR
Definition: retypes.h:7
#define KEY_ESC
Definition: kdb_cli.c:39
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ULONG KdbDebugState
Definition: kdb.c:52
UINT ScanCode
Definition: VirtualKey.c:24
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdb.h:267
#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 SCREEN_WIDTH
Definition: pc98video.c:27
#define KEYSC_HOME
Definition: kdb_cli.c:49
#define isalpha(c)
Definition: acclib.h:74
#define KdbpGetCharSerial()
Definition: kdb.h:271
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:148
KDP_DEBUG_MODE KdpDebugMode
Definition: kdio.c:48
#define FALSE
Definition: types.h:117
static ULONG KdbNumberOfColsPrinted
Definition: kdb_cli.c:149
static VOID KdpFilterEscapes(_Inout_ PSTR String)
Definition: kdb_cli.c:2862
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:151
Definition: bufpool.h:45
#define KEYSC_END
Definition: kdb_cli.c:46
#define SCREEN_HEIGHT
Definition: pc98video.c:28
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:150
#define ASSERT(a)
Definition: mode.c:44
const GLubyte * c
Definition: glext.h:8905
static LONG KdbNumberOfRowsTerminal
Definition: kdb_cli.c:152
static LONG KdbNumberOfColsTerminal
Definition: kdb_cli.c:153
static PCHAR CountOnePageUp(_In_ PCCH Buffer, _In_ ULONG BufLength, _In_ PCCH pCurPos)
Calculate pointer position for N lines upper of current position.
Definition: kdb_cli.c:2819
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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 KEYSC_ARROWUP
Definition: kdb_cli.c:50
#define NULL
Definition: types.h:112
#define c
Definition: ke_i.h:80
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:81
#define KdpDprintf(...)
Definition: mmdbg.c:19

Referenced by KdbpPager(), and KdbpPrint().

◆ KdbpPrint()

VOID KdbpPrint ( _In_ PSTR  Format,
_In_ ...   
)

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

3227 {
3228  static CHAR Buffer[4096];
3229  ULONG Length;
3230  va_list ap;
3231 
3232  /* Check if the user has aborted output of the current command */
3233  if (KdbOutputAborted)
3234  return;
3235 
3236  /* Build the string */
3237  va_start(ap, Format);
3238  Length = _vsnprintf(Buffer, sizeof(Buffer) - 1, Format, ap);
3239  Buffer[Length] = '\0';
3240  va_end(ap);
3241 
3242  /* Actually print it */
3244 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
char CHAR
Definition: xmlstorage.h:175
#define va_end(ap)
Definition: acmsvcex.h:90
#define FALSE
Definition: types.h:117
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
static BOOLEAN KdbOutputAborted
Definition: kdb_cli.c:150
VOID KdbpPagerInternal(_In_ PCHAR Buffer, _In_ ULONG BufLength, _In_ BOOLEAN DoPage)
Prints the given string with, page by page.
Definition: kdb_cli.c:2898
va_start(ap, x)
#define _vsnprintf
Definition: xmlstorage.h:202
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
unsigned int ULONG
Definition: retypes.h:1

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

◆ KdbpPrintUnicodeString()

VOID KdbpPrintUnicodeString ( _In_ PCUNICODE_STRING  String)

Definition at line 3247 of file kdb_cli.c.

3249 {
3250  ULONG i;
3251 
3252  if ((String == NULL) || (String->Buffer == NULL))
3253  {
3254  KdbpPrint("<NULL>");
3255  return;
3256  }
3257 
3258  for (i = 0; i < String->Length / sizeof(WCHAR); i++)
3259  {
3260  KdbpPrint("%c", (CHAR)String->Buffer[i]);
3261  }
3262 }
char CHAR
Definition: xmlstorage.h:175
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
Definition: kdb_cli.c:3224
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
__wchar_t WCHAR
Definition: xmlstorage.h:180
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 NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdbpCmdMod().

◆ KdbpReadCommand()

SIZE_T KdbpReadCommand ( _Out_ PCHAR  Buffer,
_In_ SIZE_T  Size 
)

Reads a line of user input from the terminal.

Parameters
[out]BufferBuffer where to store the input. Trailing newlines are removed.
[in]SizeSize of Buffer.
Returns
Returns the number of characters stored, not counting the NULL terminator.
Note
Accepts only
newlines, \r is ignored.

Definition at line 3351 of file kdb_cli.c.

3354 {
3355  PCHAR Orig = Buffer;
3356  ULONG ScanCode = 0;
3357  CHAR Key;
3358  BOOLEAN EchoOn;
3359  static CHAR LastCommand[1024];
3360  static CHAR NextKey = '\0';
3361  INT CmdHistIndex = -1;
3362  INT_PTR i;
3363 
3364  /* Bail out if the buffer is zero-sized */
3365  if (Size == 0)
3366  return 0;
3367 
3368  EchoOn = ((KdbDebugState & KD_DEBUG_KDNOECHO) == 0);
3369 
3370  for (;;)
3371  {
3373  {
3374  Key = (NextKey == '\0') ? KdbpGetCharSerial() : NextKey;
3375  NextKey = '\0';
3376  ScanCode = 0;
3377  if (Key == KEY_ESC) /* ESC */
3378  {
3379  Key = KdbpGetCharSerial();
3380  if (Key == '[')
3381  {
3382  Key = KdbpGetCharSerial();
3383 
3384  switch (Key)
3385  {
3386  case 'A':
3388  break;
3389  case 'B':
3391  break;
3392  case 'C':
3393  break;
3394  case 'D':
3395  break;
3396  }
3397  }
3398  }
3399  }
3400  else
3401  {
3402  ScanCode = 0;
3403  Key = (NextKey == '\0') ? KdbpGetCharKeyboard(&ScanCode) : NextKey;
3404  NextKey = '\0';
3405  }
3406 
3407  /* Check for return or newline */
3408  if ((Key == '\r') || (Key == '\n'))
3409  {
3410  if (Key == '\r')
3411  {
3412  /*
3413  * We might need to discard the next '\n' which most clients
3414  * should send after \r. Wait a bit to make sure we receive it.
3415  */
3416  KeStallExecutionProcessor(100000);
3417 
3419  NextKey = KdbpTryGetCharSerial(5);
3420  else
3421  NextKey = KdbpTryGetCharKeyboard(&ScanCode, 5);
3422 
3423  if (NextKey == '\n' || NextKey == -1) /* \n or no response at all */
3424  NextKey = '\0';
3425  }
3426 
3427  KdpDprintf("\n");
3428 
3429  /*
3430  * Repeat the last command if the user presses enter. Reduces the
3431  * risk of RSI when single-stepping.
3432  */
3433  if (Buffer != Orig)
3434  {
3436  *Buffer = '\0';
3437  RtlStringCbCopyA(LastCommand, sizeof(LastCommand), Orig);
3438  }
3439  else if (KdbRepeatLastCommand)
3440  RtlStringCbCopyA(Buffer, Size, LastCommand);
3441  else
3442  *Buffer = '\0';
3443 
3444  return (SIZE_T)(Buffer - Orig);
3445  }
3446  else if (Key == KEY_BS || Key == KEY_DEL)
3447  {
3448  if (Buffer > Orig)
3449  {
3450  Buffer--;
3451  *Buffer = '\0';
3452 
3453  if (EchoOn)
3454  KdpDprintf("%c %c", KEY_BS, KEY_BS);
3455  else
3456  KdpDprintf(" %c", KEY_BS);
3457  }
3458  }
3459  else if (ScanCode == KEY_SCAN_UP)
3460  {
3461  BOOLEAN Print = TRUE;
3462 
3463  if (CmdHistIndex < 0)
3464  {
3465  CmdHistIndex = KdbCommandHistoryIndex;
3466  }
3467  else
3468  {
3469  i = CmdHistIndex - 1;
3470 
3471  if (i < 0)
3472  CmdHistIndex = RTL_NUMBER_OF(KdbCommandHistory) - 1;
3473 
3475  CmdHistIndex = i;
3476  else
3477  Print = FALSE;
3478  }
3479 
3480  if (Print && KdbCommandHistory[CmdHistIndex])
3481  {
3482  while (Buffer > Orig)
3483  {
3484  Buffer--;
3485  *Buffer = '\0';
3486 
3487  if (EchoOn)
3488  KdpDprintf("%c %c", KEY_BS, KEY_BS);
3489  else
3490  KdpDprintf(" %c", KEY_BS);
3491  }
3492 
3493  i = min(strlen(KdbCommandHistory[CmdHistIndex]), Size - 1);
3494  memcpy(Orig, KdbCommandHistory[CmdHistIndex], i);
3495  Orig[i] = '\0';
3496  Buffer = Orig + i;
3497  KdpDprintf("%s", Orig);
3498  }
3499  }
3500  else if (ScanCode == KEY_SCAN_DOWN)
3501  {
3502  if (CmdHistIndex > 0 && CmdHistIndex != KdbCommandHistoryIndex)
3503  {
3504  i = CmdHistIndex + 1;
3506  i = 0;
3507 
3508  if (KdbCommandHistory[i])
3509  {
3510  CmdHistIndex = i;
3511  while (Buffer > Orig)
3512  {
3513  Buffer--;
3514  *Buffer = '\0';
3515 
3516  if (EchoOn)
3517  KdpDprintf("%c %c", KEY_BS, KEY_BS);
3518  else
3519  KdpDprintf(" %c", KEY_BS);
3520  }
3521 
3522  i = min(strlen(KdbCommandHistory[CmdHistIndex]), Size - 1);
3523  memcpy(Orig, KdbCommandHistory[CmdHistIndex], i);
3524  Orig[i] = '\0';
3525  Buffer = Orig + i;
3526  KdpDprintf("%s", Orig);
3527  }
3528  }
3529  }
3530  else
3531  {
3532  /* Don't accept any key if the buffer is full */
3533  if ((SIZE_T)(Buffer - Orig) >= (Size - 1))
3534  continue;
3535 
3536  if (EchoOn)
3537  KdpDprintf("%c", Key);
3538 
3539  *Buffer = Key;
3540  Buffer++;
3541  }
3542  }
3543 }
signed char * PCHAR
Definition: retypes.h:7
#define KEY_ESC
Definition: kdb_cli.c:39
ULONG KdbDebugState
Definition: kdb.c:52
UINT ScanCode
Definition: VirtualKey.c:24
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdb.h:267
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define KdbpGetCharSerial()
Definition: kdb.h:271
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
CHAR KdbpTryGetCharSerial(ULONG Retry)
Definition: kdb_serial.c:19
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdb_keyboard.c:104
#define KEY_SCAN_DOWN
Definition: kdb_cli.c:43
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:776
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
static BOOLEAN KdbRepeatLastCommand
Definition: kdb_cli.c:151
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFKEY * Key
Definition: wdfdevice.h:2654
Definition: bufpool.h:45
#define KEY_BS
Definition: kdb_cli.c:38
#define KEY_SCAN_UP
Definition: kdb_cli.c:42
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static LONG KdbCommandHistoryIndex
Definition: kdb_cli.c:146
ULONG_PTR SIZE_T
Definition: typedefs.h:80
static PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8]
Definition: kdb_cli.c:144
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 RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define min(a, b)
Definition: monoChain.cc:55
#define KEY_DEL
Definition: kdb_cli.c:40
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:81
#define KdpDprintf(...)
Definition: mmdbg.c:19

Referenced by KdbpCliMainLoop(), and KdReceivePacket().

◆ KdbRegisterCliCallback()

BOOLEAN NTAPI KdbRegisterCliCallback ( PVOID  Callback,
BOOLEAN  Deregister 
)

Definition at line 3548 of file kdb_cli.c.

3551 {
3552  ULONG i;
3553 
3554  /* Loop all entries */
3555  for (i = 0; i < _countof(KdbCliCallbacks); i++)
3556  {
3557  /* Check if deregistering was requested */
3558  if (Deregister)
3559  {
3560  /* Check if this entry is the one that was registered */
3561  if (KdbCliCallbacks[i] == Callback)
3562  {
3563  /* Delete it and report success */
3564  KdbCliCallbacks[i] = NULL;
3565  return TRUE;
3566  }
3567  }
3568  else
3569  {
3570  /* Check if this entry is free */
3571  if (KdbCliCallbacks[i] == NULL)
3572  {
3573  /* Set it and and report success */
3575  return TRUE;
3576  }
3577  }
3578  }
3579 
3580  /* Unsuccessful */
3581  return FALSE;
3582 }
static PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
Definition: kdb_cli.c:139
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define _countof(array)
Definition: sndvol32.h:68
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
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 NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdSystemDebugControl().

◆ KdpFilterEscapes()

static VOID KdpFilterEscapes ( _Inout_ PSTR  String)
static

Definition at line 2862 of file kdb_cli.c.

2864 {
2865  PCHAR p;
2866  SIZE_T i;
2867  size_t len;
2868 
2869  while ((p = strrchr(String, '\x1b'))) /* Look for escape character */
2870  {
2871  len = strlen(p);
2872  if (p[1] == '[')
2873  {
2874  i = 2;
2875  while (!isalpha(p[i++]));
2876  memmove(p, p + i, len + 1 - i);
2877  }
2878  else
2879  {
2880  memmove(p, p + 1, len);
2881  }
2882  }
2883 }
signed char * PCHAR
Definition: retypes.h:7
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define isalpha(c)
Definition: acclib.h:74
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
GLenum GLsizei len
Definition: glext.h:6722
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by KdbpPagerInternal().

◆ memrchr()

void* memrchr ( const void s,
int  c,
size_t  n 
)

Definition at line 2791 of file kdb_cli.c.

2792 {
2793  const unsigned char *cp;
2794 
2795  if (n != 0)
2796  {
2797  cp = (unsigned char *)s + n;
2798  do
2799  {
2800  if (*(--cp) == (unsigned char)c)
2801  return (void *)cp;
2802  } while (--n != 0);
2803  }
2804  return NULL;
2805 }
GLdouble n
Definition: glext.h:7729
unsigned char
Definition: typeof.h:29
const GLubyte * c
Definition: glext.h:8905
GLdouble s
Definition: gl.h:2039
#define NULL
Definition: types.h:112
POINT cp
Definition: magnifier.c:59

Referenced by CountOnePageUp().

◆ strtoulptr()

FORCEINLINE ULONG_PTR strtoulptr ( const char nptr,
char **  endptr,
int  base 
)

Definition at line 121 of file kdb_cli.c.

122 {
123 #ifdef _M_IX86
124  return strtoul(nptr, endptr, base);
125 #else
126  return strtoull(nptr, endptr, base);
127 #endif
128 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define strtoull
Definition: stabs.c:58

Referenced by KdbpCmdProc(), and KdbpCmdThread().

Variable Documentation

◆ __ImageBase

char __ImageBase

Definition at line 17 of file mstscax.cpp.

Referenced by KdbpCmdMod().

◆ ComponentTable

struct { ... } ComponentTable[]

◆ Fn

BOOLEAN(* Fn) (ULONG Argc, PCHAR Argv[])

Definition at line 364 of file kdb_cli.c.

Referenced by UhciGet32BitFrameNumber().

◆ Help

int Help

Definition at line 363 of file kdb_cli.c.

Referenced by COMMAND_PROTOTYPE(), create_system_dirid(), FindCommand(), and KdbpCmdHelp().

◆ Id

ULONG Id

Definition at line 178 of file kdb_cli.c.

Referenced by KdbpCmdFilter().

◆ KdbBreakOnModuleLoad

BOOLEAN KdbBreakOnModuleLoad = FALSE
static

Definition at line 141 of file kdb_cli.c.

Referenced by KdbpCmdSet().

◆ KdbCliCallbacks

PKDBG_CLI_ROUTINE KdbCliCallbacks[10]
static

Definition at line 139 of file kdb_cli.c.

Referenced by KdbpInvokeCliCallbacks(), and KdbRegisterCliCallback().

◆ KdbCommandHistory

PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer)/8] = { NULL }
static

Definition at line 144 of file kdb_cli.c.

Referenced by KdbpCommandHistoryAppend(), and KdbpReadCommand().

◆ KdbCommandHistoryBuffer

CHAR KdbCommandHistoryBuffer[2048]
static

Definition at line 143 of file kdb_cli.c.

Referenced by KdbpCommandHistoryAppend().

◆ KdbCommandHistoryBufferIndex

LONG KdbCommandHistoryBufferIndex = 0
static

Definition at line 145 of file kdb_cli.c.

Referenced by KdbpCommandHistoryAppend().

◆