Revert "[NTOS:KDBG] Use CONTEXT instead of KTRAP_FRAME"

This reverts commit e5bffe49da.

CORE-16231
This commit is contained in:
Hervé Poussineau 2019-10-19 00:12:41 +02:00
parent 2da92ac67b
commit 7390376753
6 changed files with 41 additions and 93 deletions

View file

@ -59,7 +59,7 @@ KdbSymProcessSymbols(
BOOLEAN
KdbSymPrintAddress(
IN PVOID Address,
IN PCONTEXT Context
IN PKTRAP_FRAME Context
);
NTSTATUS

View file

@ -134,92 +134,40 @@ KiEspToTrapFrame(
static VOID
KdbpTrapFrameToKdbTrapFrame(
PCONTEXT Context,
PKTRAP_FRAME TrapFrame,
PKDB_KTRAP_FRAME KdbTrapFrame)
{
if (Context)
{
KdbTrapFrame->Tf = *Context;
}
else
{
ASSERT(TrapFrame);
/* Copy the TrapFrame only up to Eflags and zero the rest*/
RtlCopyMemory(&KdbTrapFrame->Tf, TrapFrame, FIELD_OFFSET(KTRAP_FRAME, HardwareEsp));
RtlZeroMemory((PVOID)((ULONG_PTR)&KdbTrapFrame->Tf + FIELD_OFFSET(KTRAP_FRAME, HardwareEsp)),
sizeof(KTRAP_FRAME) - FIELD_OFFSET(KTRAP_FRAME, HardwareEsp));
RtlZeroMemory(KdbTrapFrame, sizeof(KDB_KTRAP_FRAME));
KdbTrapFrame->Tf.Dr0 = TrapFrame->Dr0;
KdbTrapFrame->Tf.Dr1 = TrapFrame->Dr1;
KdbTrapFrame->Tf.Dr2 = TrapFrame->Dr2;
KdbTrapFrame->Tf.Dr3 = TrapFrame->Dr3;
KdbTrapFrame->Tf.Dr6 = TrapFrame->Dr6;
KdbTrapFrame->Tf.Dr7 = TrapFrame->Dr7;
KdbTrapFrame->Tf.SegGs = TrapFrame->SegGs;
KdbTrapFrame->Tf.SegEs = TrapFrame->SegEs;
KdbTrapFrame->Tf.SegDs = TrapFrame->SegDs;
KdbTrapFrame->Tf.Edx = TrapFrame->Edx;
KdbTrapFrame->Tf.Ecx = TrapFrame->Ecx;
KdbTrapFrame->Tf.Eax = TrapFrame->Eax;
KdbTrapFrame->Tf.SegFs = TrapFrame->SegFs;
KdbTrapFrame->Tf.Edi = TrapFrame->Edi;
KdbTrapFrame->Tf.Esi = TrapFrame->Esi;
KdbTrapFrame->Tf.Ebx = TrapFrame->Ebx;
KdbTrapFrame->Tf.Ebp = TrapFrame->Ebp;
KdbTrapFrame->Tf.Eip = TrapFrame->Eip;
KdbTrapFrame->Tf.SegCs = TrapFrame->SegCs;
KdbTrapFrame->Tf.EFlags = TrapFrame->EFlags;
KdbTrapFrame->Tf.Esp = KiEspFromTrapFrame(TrapFrame);
KdbTrapFrame->Tf.SegSs = (USHORT)(KiSsFromTrapFrame(TrapFrame) & 0xFFFF);
KdbTrapFrame->Cr0 = __readcr0();
KdbTrapFrame->Cr2 = __readcr2();
KdbTrapFrame->Cr3 = __readcr3();
KdbTrapFrame->Cr4 = __readcr4();
KdbTrapFrame->Cr0 = __readcr0();
KdbTrapFrame->Cr2 = __readcr2();
KdbTrapFrame->Cr3 = __readcr3();
KdbTrapFrame->Cr4 = __readcr4();
KdbTrapFrame->Tf.HardwareEsp = KiEspFromTrapFrame(TrapFrame);
KdbTrapFrame->Tf.HardwareSegSs = (USHORT)(KiSsFromTrapFrame(TrapFrame) & 0xFFFF);
/* FIXME: copy v86 registers if TrapFrame is a V86 trapframe */
}
/* FIXME: copy v86 registers if TrapFrame is a V86 trapframe */
}
static VOID
KdbpKdbTrapFrameToTrapFrame(
PKDB_KTRAP_FRAME KdbTrapFrame,
PCONTEXT Context,
PKTRAP_FRAME TrapFrame)
{
if (Context)
{
/* Update context */
*Context = KdbTrapFrame->Tf;
}
/* Copy the TrapFrame only up to Eflags and zero the rest*/
RtlCopyMemory(TrapFrame, &KdbTrapFrame->Tf, FIELD_OFFSET(KTRAP_FRAME, HardwareEsp));
if (TrapFrame)
{
TrapFrame->Dr0 = KdbTrapFrame->Tf.Dr0;
TrapFrame->Dr1 = KdbTrapFrame->Tf.Dr1;
TrapFrame->Dr2 = KdbTrapFrame->Tf.Dr2;
TrapFrame->Dr3 = KdbTrapFrame->Tf.Dr3;
TrapFrame->Dr6 = KdbTrapFrame->Tf.Dr6;
TrapFrame->Dr7 = KdbTrapFrame->Tf.Dr7;
TrapFrame->SegGs = KdbTrapFrame->Tf.SegGs;
TrapFrame->SegEs = KdbTrapFrame->Tf.SegEs;
TrapFrame->SegDs = KdbTrapFrame->Tf.SegDs;
TrapFrame->Edx = KdbTrapFrame->Tf.Edx;
TrapFrame->Ecx = KdbTrapFrame->Tf.Ecx;
TrapFrame->Eax = KdbTrapFrame->Tf.Eax;
TrapFrame->SegFs = KdbTrapFrame->Tf.SegFs;
TrapFrame->Edi = KdbTrapFrame->Tf.Edi;
TrapFrame->Esi = KdbTrapFrame->Tf.Esi;
TrapFrame->Ebx = KdbTrapFrame->Tf.Ebx;
TrapFrame->Ebp = KdbTrapFrame->Tf.Ebp;
TrapFrame->Eip = KdbTrapFrame->Tf.Eip;
TrapFrame->SegCs = KdbTrapFrame->Tf.SegCs;
TrapFrame->EFlags = KdbTrapFrame->Tf.EFlags;
KiSsToTrapFrame(TrapFrame, KdbTrapFrame->Tf.SegSs);
KiEspToTrapFrame(TrapFrame, KdbTrapFrame->Tf.Esp);
/* FIXME: write cr0, cr2, cr3 and cr4 (not needed atm) */
/* FIXME: write cr0, cr2, cr3 and cr4 (not needed atm) */
KiSsToTrapFrame(TrapFrame, KdbTrapFrame->Tf.HardwareSegSs);
KiEspToTrapFrame(TrapFrame, KdbTrapFrame->Tf.HardwareEsp);
/* FIXME: copy v86 registers if TrapFrame is a V86 trapframe */
}
/* FIXME: copy v86 registers if TrapFrame is a V86 trapframe */
}
static VOID
@ -237,8 +185,8 @@ KdbpKdbTrapFrameFromKernelStack(
KdbTrapFrame->Tf.Esi = StackPtr[5];
KdbTrapFrame->Tf.Ebx = StackPtr[6];
KdbTrapFrame->Tf.Eip = StackPtr[7];
KdbTrapFrame->Tf.Esp = (ULONG) (StackPtr + 8);
KdbTrapFrame->Tf.SegSs = KGDT_R0_DATA;
KdbTrapFrame->Tf.HardwareEsp = (ULONG) (StackPtr + 8);
KdbTrapFrame->Tf.HardwareSegSs = KGDT_R0_DATA;
KdbTrapFrame->Tf.SegCs = KGDT_R0_CODE;
KdbTrapFrame->Tf.SegDs = KGDT_R0_DATA;
KdbTrapFrame->Tf.SegEs = KGDT_R0_DATA;
@ -1378,10 +1326,9 @@ KdbEnterDebuggerException(
IN PEXCEPTION_RECORD ExceptionRecord OPTIONAL,
IN KPROCESSOR_MODE PreviousMode,
IN PCONTEXT Context,
IN OUT PKTRAP_FRAME InitialTrapFrame,
IN OUT PKTRAP_FRAME TrapFrame,
IN BOOLEAN FirstChance)
{
PKTRAP_FRAME TrapFrame = InitialTrapFrame;
KDB_ENTER_CONDITION EnterCondition;
KD_CONTINUE_TYPE ContinueType = kdHandleException;
PKDB_BREAKPOINT BreakPoint;
@ -1500,7 +1447,7 @@ KdbEnterDebuggerException(
if (BreakPoint->Condition)
{
/* Setup the KDB trap frame */
KdbpTrapFrameToKdbTrapFrame(Context, InitialTrapFrame, &KdbTrapFrame);
KdbpTrapFrameToKdbTrapFrame(TrapFrame, &KdbTrapFrame);
ull = 0;
if (!KdbpRpnEvaluateParsedExpression(BreakPoint->Condition, &KdbTrapFrame, &ull, NULL, NULL))
@ -1661,7 +1608,7 @@ KdbEnterDebuggerException(
KdbCurrentTrapFrame = &KdbTrapFrame;
/* Setup the KDB trap frame */
KdbpTrapFrameToKdbTrapFrame(Context, InitialTrapFrame, &KdbTrapFrame);
KdbpTrapFrameToKdbTrapFrame(TrapFrame, &KdbTrapFrame);
/* Enter critical section */
OldEflags = __readeflags();
@ -1708,8 +1655,8 @@ KdbEnterDebuggerException(
KeUnstackDetachProcess(&KdbApcState);
}
/* Update the exception Context/TrapFrame */
KdbpKdbTrapFrameToTrapFrame(&KdbTrapFrame, Context, InitialTrapFrame);
/* Update the exception TrapFrame */
KdbpKdbTrapFrameToTrapFrame(&KdbTrapFrame, TrapFrame);
/* Decrement the entry count */
InterlockedDecrement(&KdbEntryCount);

View file

@ -12,11 +12,12 @@
/* from kdb.c */
typedef struct _KDB_KTRAP_FRAME
{
CONTEXT Tf;
ULONG Cr0;
ULONG Cr2;
ULONG Cr3;
ULONG Cr4;
KTRAP_FRAME Tf;
ULONG Cr0;
ULONG Cr1; /* reserved/unused */
ULONG Cr2;
ULONG Cr3;
ULONG Cr4;
} KDB_KTRAP_FRAME, *PKDB_KTRAP_FRAME;
typedef enum _KDB_BREAKPOINT_TYPE

View file

@ -849,7 +849,7 @@ KdbpCmdRegs(
ULONG Argc,
PCHAR Argv[])
{
PCONTEXT Tf = &KdbCurrentTrapFrame->Tf;
PKTRAP_FRAME Tf = &KdbCurrentTrapFrame->Tf;
INT i;
static const PCHAR EflagsBits[32] = { " CF", NULL, " PF", " BIT3", " AF", " BIT5",
" ZF", " SF", " TF", " IF", " DF", " OF",
@ -868,7 +868,7 @@ KdbpCmdRegs(
" ESI 0x%08x EDI 0x%08x\n"
" EBP 0x%08x\n",
Tf->SegCs & 0xFFFF, Tf->Eip,
Tf->SegSs, Tf->Esp,
Tf->HardwareSegSs, Tf->HardwareEsp,
Tf->Eax, Tf->Ebx,
Tf->Ecx, Tf->Edx,
Tf->Esi, Tf->Edi,
@ -966,7 +966,7 @@ KdbpCmdRegs(
KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
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->SegSs, Tf->SegSs >> 3, (Tf->SegSs & (1 << 2)) ? 'L' : 'G', Tf->SegSs & 3);
Tf->HardwareSegSs, Tf->HardwareSegSs >> 3, (Tf->HardwareSegSs & (1 << 2)) ? 'L' : 'G', Tf->HardwareSegSs & 3);
}
else /* dregs */
{
@ -986,7 +986,7 @@ KdbpCmdRegs(
static BOOLEAN
KdbpTrapFrameFromPrevTss(
PCONTEXT TrapFrame)
PKTRAP_FRAME TrapFrame)
{
ULONG_PTR Eip, Ebp;
KDESCRIPTOR Gdtr;
@ -1075,7 +1075,7 @@ KdbpCmdBackTrace(
ULONGLONG Result = 0;
ULONG_PTR Frame = KdbCurrentTrapFrame->Tf.Ebp;
ULONG_PTR Address;
CONTEXT TrapFrame;
KTRAP_FRAME TrapFrame;
if (Argc >= 2)
{

View file

@ -106,7 +106,7 @@ RpnStack =
static const struct
{
PCHAR Name;
ULONG Offset;
UCHAR Offset;
UCHAR Size;
}
RegisterToTrapFrame[] =
@ -119,14 +119,14 @@ RegisterToTrapFrame[] =
{"edx", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Edx), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Edx)},
{"esi", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Esi), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Esi)},
{"edi", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Edi), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Edi)},
{"esp", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Esp), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Esp)},
{"esp", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.HardwareEsp), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.HardwareEsp)},
{"ebp", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Ebp), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Ebp)},
{"cs", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.SegCs), 2 }, /* Use only the lower 2 bytes */
{"ds", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.SegDs), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.SegDs)},
{"es", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.SegEs), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.SegEs)},
{"fs", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.SegFs), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.SegFs)},
{"gs", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.SegGs), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.SegGs)},
{"ss", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.SegSs), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.SegSs)},
{"ss", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.HardwareSegSs), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.HardwareSegSs)},
{"dr0", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Dr0), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Dr0)},
{"dr1", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Dr1), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Dr1)},
{"dr2", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Dr2), RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Dr2)},

View file

@ -147,7 +147,7 @@ KdbpSymUnicodeToAnsi(IN PUNICODE_STRING Unicode,
BOOLEAN
KdbSymPrintAddress(
IN PVOID Address,
IN PCONTEXT Context)
IN PKTRAP_FRAME Context)
{
PLDR_DATA_TABLE_ENTRY LdrEntry;
ULONG_PTR RelativeAddress;