https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e5bffe49da21f5faf2a88…
commit e5bffe49da21f5faf2a88a0983ad4876d388e0ea
Author: Hervé Poussineau <hpoussin(a)reactos.org>
AuthorDate: Thu May 23 10:59:53 2019 +0200
Commit: Hervé Poussineau <hpoussin(a)reactos.org>
CommitDate: Thu May 23 11:04:40 2019 +0200
[NTOS:KDBG] Use CONTEXT instead of KTRAP_FRAME
Change KdbpTrapFrameToKdbTrapFrame to prefer CONTEXT (if available) over
KTRAP_FRAME.
---
ntoskrnl/include/internal/kd.h | 2 +-
ntoskrnl/kdbg/kdb.c | 115 ++++++++++++++++++++++++++++++-----------
ntoskrnl/kdbg/kdb.h | 11 ++--
ntoskrnl/kdbg/kdb_cli.c | 10 ++--
ntoskrnl/kdbg/kdb_expr.c | 6 +--
ntoskrnl/kdbg/kdb_symbols.c | 2 +-
6 files changed, 99 insertions(+), 47 deletions(-)
diff --git a/ntoskrnl/include/internal/kd.h b/ntoskrnl/include/internal/kd.h
index 162ece58f71..c336d3e0062 100644
--- a/ntoskrnl/include/internal/kd.h
+++ b/ntoskrnl/include/internal/kd.h
@@ -59,7 +59,7 @@ KdbSymProcessSymbols(
BOOLEAN
KdbSymPrintAddress(
IN PVOID Address,
- IN PKTRAP_FRAME Context
+ IN PCONTEXT Context
);
NTSTATUS
diff --git a/ntoskrnl/kdbg/kdb.c b/ntoskrnl/kdbg/kdb.c
index 6b9d4695581..5611de62ed6 100644
--- a/ntoskrnl/kdbg/kdb.c
+++ b/ntoskrnl/kdbg/kdb.c
@@ -134,40 +134,92 @@ KiEspToTrapFrame(
static VOID
KdbpTrapFrameToKdbTrapFrame(
+ PCONTEXT Context,
PKTRAP_FRAME TrapFrame,
PKDB_KTRAP_FRAME KdbTrapFrame)
{
- /* 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));
-
- 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 */
+ if (Context)
+ {
+ KdbTrapFrame->Tf = *Context;
+ }
+ else
+ {
+ ASSERT(TrapFrame);
+
+ 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();
+
+ /* FIXME: copy v86 registers if TrapFrame is a V86 trapframe */
+ }
}
static VOID
KdbpKdbTrapFrameToTrapFrame(
PKDB_KTRAP_FRAME KdbTrapFrame,
+ PCONTEXT Context,
PKTRAP_FRAME TrapFrame)
{
- /* Copy the TrapFrame only up to Eflags and zero the rest*/
- RtlCopyMemory(TrapFrame, &KdbTrapFrame->Tf, FIELD_OFFSET(KTRAP_FRAME,
HardwareEsp));
-
- /* 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 */
+ if (Context)
+ {
+ /* Update context */
+ *Context = KdbTrapFrame->Tf;
+ }
+
+ 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: copy v86 registers if TrapFrame is a V86 trapframe */
+ }
}
static VOID
@@ -185,8 +237,8 @@ KdbpKdbTrapFrameFromKernelStack(
KdbTrapFrame->Tf.Esi = StackPtr[5];
KdbTrapFrame->Tf.Ebx = StackPtr[6];
KdbTrapFrame->Tf.Eip = StackPtr[7];
- KdbTrapFrame->Tf.HardwareEsp = (ULONG) (StackPtr + 8);
- KdbTrapFrame->Tf.HardwareSegSs = KGDT_R0_DATA;
+ KdbTrapFrame->Tf.Esp = (ULONG) (StackPtr + 8);
+ KdbTrapFrame->Tf.SegSs = KGDT_R0_DATA;
KdbTrapFrame->Tf.SegCs = KGDT_R0_CODE;
KdbTrapFrame->Tf.SegDs = KGDT_R0_DATA;
KdbTrapFrame->Tf.SegEs = KGDT_R0_DATA;
@@ -1326,9 +1378,10 @@ KdbEnterDebuggerException(
IN PEXCEPTION_RECORD ExceptionRecord OPTIONAL,
IN KPROCESSOR_MODE PreviousMode,
IN PCONTEXT Context,
- IN OUT PKTRAP_FRAME TrapFrame,
+ IN OUT PKTRAP_FRAME InitialTrapFrame,
IN BOOLEAN FirstChance)
{
+ PKTRAP_FRAME TrapFrame = InitialTrapFrame;
KDB_ENTER_CONDITION EnterCondition;
KD_CONTINUE_TYPE ContinueType = kdHandleException;
PKDB_BREAKPOINT BreakPoint;
@@ -1447,7 +1500,7 @@ KdbEnterDebuggerException(
if (BreakPoint->Condition)
{
/* Setup the KDB trap frame */
- KdbpTrapFrameToKdbTrapFrame(TrapFrame, &KdbTrapFrame);
+ KdbpTrapFrameToKdbTrapFrame(Context, InitialTrapFrame, &KdbTrapFrame);
ull = 0;
if (!KdbpRpnEvaluateParsedExpression(BreakPoint->Condition,
&KdbTrapFrame, &ull, NULL, NULL))
@@ -1608,7 +1661,7 @@ KdbEnterDebuggerException(
KdbCurrentTrapFrame = &KdbTrapFrame;
/* Setup the KDB trap frame */
- KdbpTrapFrameToKdbTrapFrame(TrapFrame, &KdbTrapFrame);
+ KdbpTrapFrameToKdbTrapFrame(Context, InitialTrapFrame, &KdbTrapFrame);
/* Enter critical section */
OldEflags = __readeflags();
@@ -1655,8 +1708,8 @@ KdbEnterDebuggerException(
KeUnstackDetachProcess(&KdbApcState);
}
- /* Update the exception TrapFrame */
- KdbpKdbTrapFrameToTrapFrame(&KdbTrapFrame, TrapFrame);
+ /* Update the exception Context/TrapFrame */
+ KdbpKdbTrapFrameToTrapFrame(&KdbTrapFrame, Context, InitialTrapFrame);
/* Decrement the entry count */
InterlockedDecrement(&KdbEntryCount);
diff --git a/ntoskrnl/kdbg/kdb.h b/ntoskrnl/kdbg/kdb.h
index b6419079e61..f87381a9fa2 100644
--- a/ntoskrnl/kdbg/kdb.h
+++ b/ntoskrnl/kdbg/kdb.h
@@ -12,12 +12,11 @@
/* from kdb.c */
typedef struct _KDB_KTRAP_FRAME
{
- KTRAP_FRAME Tf;
- ULONG Cr0;
- ULONG Cr1; /* reserved/unused */
- ULONG Cr2;
- ULONG Cr3;
- ULONG Cr4;
+ CONTEXT Tf;
+ ULONG Cr0;
+ ULONG Cr2;
+ ULONG Cr3;
+ ULONG Cr4;
} KDB_KTRAP_FRAME, *PKDB_KTRAP_FRAME;
typedef enum _KDB_BREAKPOINT_TYPE
diff --git a/ntoskrnl/kdbg/kdb_cli.c b/ntoskrnl/kdbg/kdb_cli.c
index 4009e0a7319..32d2fe553a5 100644
--- a/ntoskrnl/kdbg/kdb_cli.c
+++ b/ntoskrnl/kdbg/kdb_cli.c
@@ -849,7 +849,7 @@ KdbpCmdRegs(
ULONG Argc,
PCHAR Argv[])
{
- PKTRAP_FRAME Tf = &KdbCurrentTrapFrame->Tf;
+ PCONTEXT 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->HardwareSegSs, Tf->HardwareEsp,
+ Tf->SegSs, Tf->Esp,
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->HardwareSegSs, Tf->HardwareSegSs >> 3,
(Tf->HardwareSegSs & (1 << 2)) ? 'L' : 'G',
Tf->HardwareSegSs & 3);
+ Tf->SegSs, Tf->SegSs >> 3, (Tf->SegSs & (1 <<
2)) ? 'L' : 'G', Tf->SegSs & 3);
}
else /* dregs */
{
@@ -986,7 +986,7 @@ KdbpCmdRegs(
static BOOLEAN
KdbpTrapFrameFromPrevTss(
- PKTRAP_FRAME TrapFrame)
+ PCONTEXT TrapFrame)
{
ULONG_PTR Eip, Ebp;
KDESCRIPTOR Gdtr;
@@ -1075,7 +1075,7 @@ KdbpCmdBackTrace(
ULONGLONG Result = 0;
ULONG_PTR Frame = KdbCurrentTrapFrame->Tf.Ebp;
ULONG_PTR Address;
- KTRAP_FRAME TrapFrame;
+ CONTEXT TrapFrame;
if (Argc >= 2)
{
diff --git a/ntoskrnl/kdbg/kdb_expr.c b/ntoskrnl/kdbg/kdb_expr.c
index de856536e08..9e3d15c6b20 100644
--- a/ntoskrnl/kdbg/kdb_expr.c
+++ b/ntoskrnl/kdbg/kdb_expr.c
@@ -106,7 +106,7 @@ RpnStack =
static const struct
{
PCHAR Name;
- UCHAR Offset;
+ ULONG 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.HardwareEsp),
RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.HardwareEsp)},
+ {"esp", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.Esp),
RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.Esp)},
{"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.HardwareSegSs),
RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.HardwareSegSs)},
+ {"ss", FIELD_OFFSET(KDB_KTRAP_FRAME, Tf.SegSs),
RTL_FIELD_SIZE(KDB_KTRAP_FRAME, Tf.SegSs)},
{"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)},
diff --git a/ntoskrnl/kdbg/kdb_symbols.c b/ntoskrnl/kdbg/kdb_symbols.c
index 1b2d8f695c8..07f55eba1ca 100644
--- a/ntoskrnl/kdbg/kdb_symbols.c
+++ b/ntoskrnl/kdbg/kdb_symbols.c
@@ -147,7 +147,7 @@ KdbpSymUnicodeToAnsi(IN PUNICODE_STRING Unicode,
BOOLEAN
KdbSymPrintAddress(
IN PVOID Address,
- IN PKTRAP_FRAME Context)
+ IN PCONTEXT Context)
{
PLDR_DATA_TABLE_ENTRY LdrEntry;
ULONG_PTR RelativeAddress;