/* DEFINES *******************************************************************/
-/* FIXME: NDK headers */
-#define TempEsp TempEip
-#define TempSegSs TempCs
-
#define KEY_BS 8
#define KEY_ESC 27
#define KEY_DEL 127
/* GLOBALS *******************************************************************/
STATIC BOOLEAN KdbUseIntelSyntax = FALSE; /* Set to TRUE for intel syntax */
+STATIC BOOLEAN KdbBreakOnModuleLoad = FALSE; /* Set to TRUE to break into KDB when a module is loaded */
STATIC CHAR KdbCommandHistoryBuffer[2048]; /* Command history string ringbuffer */
STATIC PCHAR KdbCommandHistory[sizeof(KdbCommandHistoryBuffer) / 8] = { NULL }; /* Command history ringbuffer */
STATIC BOOLEAN
KdbpCmdEvalExpression(ULONG Argc, PCHAR Argv[])
{
- INT i, len;
+ UINT i, len;
ULONGLONG Result = 0;
ULONG ul;
LONG l = 0;
" ECX 0x%08x EDX 0x%08x\n"
" ESI 0x%08x EDI 0x%08x\n"
" EBP 0x%08x\n",
- Tf->Cs & 0xFFFF, Tf->Eip,
- Tf->Ss, Tf->Esp,
+ Tf->SegCs & 0xFFFF, Tf->Eip,
+ Tf->HardwareSegSs, Tf->HardwareEsp,
Tf->Eax, Tf->Ebx,
Tf->Ecx, Tf->Edx,
Tf->Esi, Tf->Edi,
Tf->Ebp);
- KdbpPrint("EFLAGS 0x%08x ", Tf->Eflags);
+ KdbpPrint("EFLAGS 0x%08x ", Tf->EFlags);
for (i = 0; i < 32; i++)
{
if (i == 1)
{
- if ((Tf->Eflags & (1 << 1)) == 0)
+ if ((Tf->EFlags & (1 << 1)) == 0)
KdbpPrint(" !BIT1");
}
else if (i == 12)
{
- KdbpPrint(" IOPL%d", (Tf->Eflags >> 12) & 3);
+ KdbpPrint(" IOPL%d", (Tf->EFlags >> 12) & 3);
}
else if (i == 13)
{
}
- else if ((Tf->Eflags & (1 << i)) != 0)
+ else if ((Tf->EFlags & (1 << i)) != 0)
KdbpPrint(EflagsBits[i]);
}
KdbpPrint("\n");
else if (Argv[0][0] == 'c') /* cregs */
{
ULONG Cr0, Cr2, Cr3, Cr4;
- struct __attribute__((packed)) {
- USHORT Limit;
- ULONG Base;
- } Gdtr, Ldtr, Idtr;
+ KDESCRIPTOR Gdtr, Ldtr, Idtr;
ULONG Tr;
STATIC CONST PCHAR Cr0Bits[32] = { " PE", " MP", " EM", " TS", " ET", " NE", NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
Cr4 = KdbCurrentTrapFrame->Cr4;
/* Get descriptor table regs */
- asm volatile("sgdt %0" : : "m"(Gdtr));
- asm volatile("sldt %0" : : "m"(Ldtr));
- asm volatile("sidt %0" : : "m"(Idtr));
+ asm volatile("sgdt %0" : : "m"(Gdtr.Limit));
+ asm volatile("sldt %0" : : "m"(Ldtr.Limit));
+ asm volatile("sidt %0" : : "m"(Idtr.Limit));
/* Get the task register */
asm volatile("str %0" : "=g"(Tr));
else if (Argv[0][0] == 's') /* sregs */
{
KdbpPrint("CS 0x%04x Index 0x%04x %cDT RPL%d\n",
- Tf->Cs & 0xffff, (Tf->Cs & 0xffff) >> 3,
- (Tf->Cs & (1 << 2)) ? 'L' : 'G', Tf->Cs & 3);
+ Tf->SegCs & 0xffff, (Tf->SegCs & 0xffff) >> 3,
+ (Tf->SegCs & (1 << 2)) ? 'L' : 'G', Tf->SegCs & 3);
KdbpPrint("DS 0x%04x Index 0x%04x %cDT RPL%d\n",
- Tf->Ds, Tf->Ds >> 3, (Tf->Ds & (1 << 2)) ? 'L' : 'G', Tf->Ds & 3);
+ Tf->SegDs, Tf->SegDs >> 3, (Tf->SegDs & (1 << 2)) ? 'L' : 'G', Tf->SegDs & 3);
KdbpPrint("ES 0x%04x Index 0x%04x %cDT RPL%d\n",
- Tf->Es, Tf->Es >> 3, (Tf->Es & (1 << 2)) ? 'L' : 'G', Tf->Es & 3);
+ Tf->SegEs, Tf->SegEs >> 3, (Tf->SegEs & (1 << 2)) ? 'L' : 'G', Tf->SegEs & 3);
KdbpPrint("FS 0x%04x Index 0x%04x %cDT RPL%d\n",
- Tf->Fs, Tf->Fs >> 3, (Tf->Fs & (1 << 2)) ? 'L' : 'G', Tf->Fs & 3);
+ Tf->SegFs, Tf->SegFs >> 3, (Tf->SegFs & (1 << 2)) ? 'L' : 'G', Tf->SegFs & 3);
KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
- Tf->Gs, Tf->Gs >> 3, (Tf->Gs & (1 << 2)) ? 'L' : 'G', Tf->Gs & 3);
+ Tf->SegGs, Tf->SegGs >> 3, (Tf->SegGs & (1 << 2)) ? 'L' : 'G', Tf->SegGs & 3);
KdbpPrint("SS 0x%04x Index 0x%04x %cDT RPL%d\n",
- Tf->Ss, Tf->Ss >> 3, (Tf->Ss & (1 << 2)) ? 'L' : 'G', Tf->Ss & 3);
+ Tf->HardwareSegSs, Tf->HardwareSegSs >> 3, (Tf->HardwareSegSs & (1 << 2)) ? 'L' : 'G', Tf->HardwareSegSs & 3);
}
else /* dregs */
{
KDB_BREAKPOINT_TYPE Type;
UCHAR Size = 0;
KDB_ACCESS_TYPE AccessType = 0;
- INT AddressArgIndex, ConditionArgIndex, i;
+ UINT AddressArgIndex, ConditionArgIndex, i;
BOOLEAN Global = TRUE;
if (Argv[0][2] == 'x') /* software breakpoint */
if (Thread->Tcb.TrapFrame != NULL)
{
- if (Thread->Tcb.TrapFrame->PreviousMode == KernelMode)
+ if (Thread->Tcb.TrapFrame->PreviousPreviousMode == KernelMode)
Esp = (PULONG)Thread->Tcb.TrapFrame->TempEsp;
else
- Esp = (PULONG)Thread->Tcb.TrapFrame->Esp;
+ Esp = (PULONG)Thread->Tcb.TrapFrame->HardwareEsp;
Ebp = (PULONG)Thread->Tcb.TrapFrame->Ebp;
Eip = Thread->Tcb.TrapFrame->Eip;
}
str2 = "";
}
- State = ((Process->Pcb.State == PROCESS_STATE_TERMINATED) ? "Terminated" :
- ((Process->Pcb.State == PROCESS_STATE_ACTIVE) ? "Active" : "Unknown"));
+ State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
+ ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
KdbpPrint(" %s0x%08x %-10s %s%s\n",
str1,
}
}
- State = ((Process->Pcb.State == PROCESS_STATE_TERMINATED) ? "Terminated" :
- ((Process->Pcb.State == PROCESS_STATE_ACTIVE) ? "Active" : "Unknown"));
+ State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
+ ((Process->Pcb.State == ProcessOutOfMemory) ? "Out of Memory" : "In Transition"));
KdbpPrint("%s"
" PID: 0x%08x\n"
" State: %s (0x%x)\n"
" VdmAlert: 0x%08x\n"
" L2CacheSize: 0x%08x\n"
" InterruptMode: 0x%08x\n",
- Pcr->Tib.ExceptionList, Pcr->Tib.StackBase, Pcr->Tib.StackLimit,
- Pcr->Tib.SubSystemTib, Pcr->Tib.FiberData, Pcr->Tib.ArbitraryUserPointer,
- Pcr->Tib.Self, Pcr->Self, Pcr->Prcb, Pcr->Irql, Pcr->IRR, Pcr->IrrActive,
+ Pcr->NtTib.ExceptionList, Pcr->NtTib.StackBase, Pcr->NtTib.StackLimit,
+ Pcr->NtTib.SubSystemTib, Pcr->NtTib.FiberData, Pcr->NtTib.ArbitraryUserPointer,
+ Pcr->NtTib.Self, Pcr->Self, Pcr->Prcb, Pcr->Irql, Pcr->IRR, Pcr->IrrActive,
Pcr->IDR, Pcr->KdVersionBlock, Pcr->IDT, Pcr->GDT, Pcr->TSS,
Pcr->MajorVersion, Pcr->MinorVersion, Pcr->SetMember, Pcr->StallScaleFactor,
Pcr->Number, Pcr->L2CacheAssociativity,
KTSS *Tss = KeGetCurrentKPCR()->TSS;
KdbpPrint("Current TSS is at 0x%08x.\n", (INT)Tss);
- KdbpPrint(" PreviousTask: 0x%08x\n"
- " Ss0:Esp0: 0x%04x:0x%08x\n"
- " Ss1:Esp1: 0x%04x:0x%08x\n"
- " Ss2:Esp2: 0x%04x:0x%08x\n"
- " Cr3: 0x%08x\n"
- " Eip: 0x%08x\n"
- " Eflags: 0x%08x\n"
- " Eax: 0x%08x\n"
- " Ecx: 0x%08x\n"
- " Edx: 0x%08x\n"
- " Ebx: 0x%08x\n"
- " Esp: 0x%08x\n"
- " Ebp: 0x%08x\n"
- " Esi: 0x%08x\n"
- " Edi: 0x%08x\n"
+ KdbpPrint(" Eip: 0x%08x\n"
" Es: 0x%04x\n"
" Cs: 0x%04x\n"
" Ss: 0x%04x\n"
" Ds: 0x%04x\n"
" Fs: 0x%04x\n"
" Gs: 0x%04x\n"
- " Ldt: 0x%04x\n"
- " Trap: 0x%04x\n"
" IoMapBase: 0x%04x\n",
- Tss->PreviousTask, Tss->Ss0, Tss->Esp0, Tss->Ss1, Tss->Esp1,
- Tss->Ss2, Tss->Esp2, Tss->Cr3, Tss->Eip, Tss->Eflags, Tss->Eax,
- Tss->Ecx, Tss->Edx, Tss->Ebx, Tss->Esp, Tss->Ebp, Tss->Esi,
- Tss->Edi, Tss->Es, Tss->Cs, Tss->Ss, Tss->Ds, Tss->Fs, Tss->Gs,
- Tss->Ldt, Tss->Trap, Tss->IoMapBase);
+ Tss->Eip, Tss->Es, Tss->Cs, Tss->Ds, Tss->Fs, Tss->Gs, Tss->IoMapBase);
return TRUE;
}
STATIC BOOLEAN
KdbpCmdSet(ULONG Argc, PCHAR Argv[])
{
- LONG l;
+ ULONG l;
BOOLEAN First;
PCHAR pend = 0;
KDB_ENTER_CONDITION ConditionFirst = KdbDoNotEnter;
KdbpPrint("Available settings:\n");
KdbpPrint(" syntax [intel|at&t]\n");
KdbpPrint(" condition [exception|*] [first|last] [never|always|kmode|umode]\n");
+ KdbpPrint(" break_on_module_load [true|false]\n");
}
else if (strcmp(Argv[1], "syntax") == 0)
{
l = -1;
else
{
- l = (LONG)strtoul(Argv[2], &pend, 0);
+ l = strtoul(Argv[2], &pend, 0);
if (Argv[2] == pend)
{
for (l = 0; l < RTL_NUMBER_OF(ExceptionNames); l++)
}
}
}
+ else if (strcmp(Argv[1], "break_on_module_load") == 0)
+ {
+ if (Argc == 2)
+ KdbpPrint("break_on_module_load = %s\n", KdbBreakOnModuleLoad ? "enabled" : "disabled");
+ else if (Argc >= 3)
+ {
+ if (_stricmp(Argv[2], "enable") == 0 || _stricmp(Argv[2], "enabled") == 0 ||
+ _stricmp(Argv[2], "true") == 0)
+ KdbBreakOnModuleLoad = TRUE;
+ else if (_stricmp(Argv[2], "disable") == 0 || _stricmp(Argv[2], "disabled") == 0 ||
+ _stricmp(Argv[2], "false") == 0)
+ KdbBreakOnModuleLoad = FALSE;
+ else
+ KdbpPrint("Unknown setting '%s'.\n", Argv[2]);
+ }
+ }
else
KdbpPrint("Unknown setting '%s'.\n", Argv[1]);
STATIC BOOLEAN TerminalReportsSize = TRUE;
CHAR c = '\0';
PCHAR p, p2;
- INT Length;
- INT i, j;
+ UINT Length;
+ UINT i, j;
INT RowsPrintedByTerminal;
ULONG ScanCode;
va_list ap;
if ((KdbNumberOfRowsTerminal < 0) || (KdbNumberOfColsTerminal < 0) ||
(KdbNumberOfRowsPrinted) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
{
- if ((KdbDebugState & KD_DEBUG_KDSERIAL) && TerminalReportsSize)
+ if ((KdbDebugState & KD_DEBUG_KDSERIAL) && TerminalConnected && TerminalReportsSize)
{
/* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
TerminalReportsSize = FALSE;
/*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
/* Display a prompt if we printed one screen full of text */
- if ((KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
+ if (KdbNumberOfRowsTerminal > 0 &&
+ (LONG)(KdbNumberOfRowsPrinted + RowsPrintedByTerminal) >= KdbNumberOfRowsTerminal)
{
if (KdbNumberOfColsPrinted > 0)
DbgPrint("\n");
KdbpCommandHistoryAppend(
IN PCHAR Command)
{
- LONG Length1 = strlen(Command) + 1;
- LONG Length2 = 0;
+ ULONG Length1 = strlen(Command) + 1;
+ ULONG Length2 = 0;
INT i;
PCHAR Buffer;
/* Calculate Length1 and Length2 */
Buffer = KdbCommandHistoryBuffer + KdbCommandHistoryBufferIndex;
KdbCommandHistoryBufferIndex += Length1;
- if (KdbCommandHistoryBufferIndex >= RTL_NUMBER_OF(KdbCommandHistoryBuffer))
+ if (KdbCommandHistoryBufferIndex >= (LONG)RTL_NUMBER_OF(KdbCommandHistoryBuffer))
{
KdbCommandHistoryBufferIndex -= RTL_NUMBER_OF(KdbCommandHistoryBuffer);
Length2 = KdbCommandHistoryBufferIndex;
NextKey = '\0';
}
- if ((Buffer - Orig) >= (Size - 1))
+ if ((ULONG)(Buffer - Orig) >= (Size - 1))
{
/* Buffer is full, accept only newlines */
if (Key != '\n')
if (CmdHistIndex > 0 && CmdHistIndex != KdbCommandHistoryIndex)
{
i = CmdHistIndex + 1;
- if (i >= RTL_NUMBER_OF(KdbCommandHistory))
+ if (i >= (INT)RTL_NUMBER_OF(KdbCommandHistory))
i = 0;
if (KdbCommandHistory[i] != NULL)
{
VOID
KdbpCliModuleLoaded(IN PUNICODE_STRING Name)
{
- return;
+ if (!KdbBreakOnModuleLoad)
+ return;
DbgPrint("Module %wZ loaded.\n", Name);
DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status);
return;
}
- FileSize = min(FileSize, Iosb.Information);
+ FileSize = min(FileSize, (INT)Iosb.Information);
FileBuffer[FileSize] = '\0';
/* Enter critical section */