https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0c76bbfe98d8dae267496…
commit 0c76bbfe98d8dae26749670cba355136413ba3ce
Author: Hervé Poussineau <hpoussin(a)reactos.org>
AuthorDate: Thu Apr 9 14:31:47 2020 +0200
Commit: Hervé Poussineau <hpoussin(a)reactos.org>
CommitDate: Mon Nov 16 08:55:04 2020 +0100
[NTOS:KD] Merge KdpReportExceptionStateChange() with kd64 version
---
ntoskrnl/include/internal/kd64.h | 4 ---
ntoskrnl/kd/kdio.c | 76 +++++++++++++++++++++++++++++++++++++++-
ntoskrnl/kd/kdmain.c | 46 ------------------------
ntoskrnl/kd64/kdapi.c | 6 ----
ntoskrnl/kd64/kdtrap.c | 4 ---
5 files changed, 75 insertions(+), 61 deletions(-)
diff --git a/ntoskrnl/include/internal/kd64.h b/ntoskrnl/include/internal/kd64.h
index 1806b2fcd09..4802c9c9f60 100644
--- a/ntoskrnl/include/internal/kd64.h
+++ b/ntoskrnl/include/internal/kd64.h
@@ -281,10 +281,6 @@ NTAPI
KdpReportExceptionStateChange(
IN PEXCEPTION_RECORD ExceptionRecord,
IN OUT PCONTEXT Context,
-#ifndef _WINKD_
- IN PKTRAP_FRAME TrapFrame,
- IN KPROCESSOR_MODE PreviousMode,
-#endif
IN BOOLEAN SecondChanceException
);
diff --git a/ntoskrnl/kd/kdio.c b/ntoskrnl/kd/kdio.c
index d98ab455419..20b3c142972 100644
--- a/ntoskrnl/kd/kdio.c
+++ b/ntoskrnl/kd/kdio.c
@@ -43,6 +43,12 @@ volatile ULONG KdbDmesgTotalWritten = 0;
volatile BOOLEAN KdbpIsInDmesgMode = FALSE;
static KSPIN_LOCK KdpDmesgLogSpinLock;
+static ULONG KdbgNextApiNumber = DbgKdContinueApi;
+static CONTEXT KdbgContext;
+static EXCEPTION_RECORD64 KdbgExceptionRecord;
+static BOOLEAN KdbgFirstChanceException;
+static NTSTATUS KdbgContinueStatus = STATUS_SUCCESS;
+
/* LOCKING FUNCTIONS *********************************************************/
KIRQL
@@ -560,6 +566,50 @@ KdSendPacket(
#endif
return;
}
+ else if (WaitStateChange->NewState == DbgKdExceptionStateChange)
+ {
+ KdbgNextApiNumber = DbgKdGetContextApi;
+ KdbgExceptionRecord = WaitStateChange->u.Exception.ExceptionRecord;
+ KdbgFirstChanceException = WaitStateChange->u.Exception.FirstChance;
+ return;
+ }
+ }
+ else if (PacketType == PACKET_TYPE_KD_STATE_MANIPULATE)
+ {
+ PDBGKD_MANIPULATE_STATE64 ManipulateState =
(PDBGKD_MANIPULATE_STATE64)MessageHeader->Buffer;
+ if (ManipulateState->ApiNumber == DbgKdGetContextApi)
+ {
+ KD_CONTINUE_TYPE Result;
+
+#ifdef KDBG
+ /* Check if this is an assertion failure */
+ if (KdbgExceptionRecord.ExceptionCode == STATUS_ASSERTION_FAILURE)
+ {
+ /* Bump EIP to the instruction following the int 2C */
+ KdbgContext.Eip += 2;
+ }
+
+ Result = KdbEnterDebuggerException(&KdbgExceptionRecord,
+ KernelMode, // FIXME
+ &KdbgContext,
+ KdbgFirstChanceException);
+#else
+ /* We'll manually dump the stack for the user... */
+ KeRosDumpStackFrames(NULL, 0);
+ Result = kdHandleException;
+#endif
+ if (Result != kdHandleException)
+ KdbgContinueStatus = STATUS_SUCCESS;
+ else
+ KdbgContinueStatus = STATUS_UNSUCCESSFUL;
+ KdbgNextApiNumber = DbgKdSetContextApi;
+ return;
+ }
+ else if (ManipulateState->ApiNumber == DbgKdSetContextApi)
+ {
+ KdbgNextApiNumber = DbgKdContinueApi;
+ return;
+ }
}
UNIMPLEMENTED;
}
@@ -586,8 +636,32 @@ KdReceivePacket(
if (PacketType == PACKET_TYPE_KD_STATE_MANIPULATE)
{
PDBGKD_MANIPULATE_STATE64 ManipulateState =
(PDBGKD_MANIPULATE_STATE64)MessageHeader->Buffer;
+ RtlZeroMemory(MessageHeader->Buffer, MessageHeader->MaximumLength);
+ if (KdbgNextApiNumber == DbgKdGetContextApi)
+ {
+ ManipulateState->ApiNumber = DbgKdGetContextApi;
+ MessageData->Length = 0;
+ MessageData->Buffer = (PCHAR)&KdbgContext;
+ return KdPacketReceived;
+ }
+ else if (KdbgNextApiNumber == DbgKdSetContextApi)
+ {
+ ManipulateState->ApiNumber = DbgKdSetContextApi;
+ MessageData->Length = sizeof(KdbgContext);
+ MessageData->Buffer = (PCHAR)&KdbgContext;
+ return KdPacketReceived;
+ }
+ else if (KdbgNextApiNumber != DbgKdContinueApi)
+ {
+ UNIMPLEMENTED;
+ }
ManipulateState->ApiNumber = DbgKdContinueApi;
- ManipulateState->u.Continue.ContinueStatus = STATUS_SUCCESS;
+ ManipulateState->u.Continue.ContinueStatus = KdbgContinueStatus;
+
+ /* Prepare for next time */
+ KdbgNextApiNumber = DbgKdContinueApi;
+ KdbgContinueStatus = STATUS_SUCCESS;
+
return KdPacketReceived;
}
diff --git a/ntoskrnl/kd/kdmain.c b/ntoskrnl/kd/kdmain.c
index dde2e1d67e7..76e28962a98 100644
--- a/ntoskrnl/kd/kdmain.c
+++ b/ntoskrnl/kd/kdmain.c
@@ -17,52 +17,6 @@ VOID NTAPI PspDumpThreads(BOOLEAN SystemThreads);
extern ANSI_STRING KdpLogFileName;
-/* PRIVATE FUNCTIONS *********************************************************/
-
-BOOLEAN
-NTAPI
-KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
- IN OUT PCONTEXT ContextRecord,
- IN PKTRAP_FRAME TrapFrame,
- IN KPROCESSOR_MODE PreviousMode,
- IN BOOLEAN SecondChanceException)
-{
- KD_CONTINUE_TYPE Return = kdHandleException;
-#ifdef KDBG
- EXCEPTION_RECORD64 ExceptionRecord64;
-
- /* Check if this is an assertion failure */
- if (ExceptionRecord->ExceptionCode == STATUS_ASSERTION_FAILURE)
- {
- /* Bump EIP to the instruction following the int 2C */
- ContextRecord->Eip += 2;
- }
-
- ExceptionRecord32To64((PEXCEPTION_RECORD32)ExceptionRecord,
- &ExceptionRecord64);
-#endif
-
- /* Get out of here if the Debugger isn't connected */
- if (KdDebuggerNotPresent) return FALSE;
-
-#ifdef KDBG
- /* Call KDBG if available */
- Return = KdbEnterDebuggerException(&ExceptionRecord64,
- PreviousMode,
- ContextRecord,
- !SecondChanceException);
-#else /* not KDBG */
- /* We'll manually dump the stack for the user... */
- KeRosDumpStackFrames(NULL, 0);
-#endif /* not KDBG */
-
- /* Debugger didn't handle it, please handle! */
- if (Return == kdHandleException) return FALSE;
-
- /* Debugger handled it */
- return TRUE;
-}
-
/* PUBLIC FUNCTIONS *********************************************************/
static PCHAR
diff --git a/ntoskrnl/kd64/kdapi.c b/ntoskrnl/kd64/kdapi.c
index f2c07de2f21..28438a699a2 100644
--- a/ntoskrnl/kd64/kdapi.c
+++ b/ntoskrnl/kd64/kdapi.c
@@ -1725,7 +1725,6 @@ KdpReportCommandStringStateChange(IN PSTRING NameString,
} while (Status == ContinueProcessorReselected);
}
-#ifdef _WINKD_
BOOLEAN
NTAPI
KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
@@ -1780,7 +1779,6 @@ KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
/* Return */
return Status;
}
-#endif
VOID
NTAPI
@@ -1844,10 +1842,6 @@ KdpSwitchProcessor(IN PEXCEPTION_RECORD ExceptionRecord,
/* Report a state change */
Status = KdpReportExceptionStateChange(ExceptionRecord,
ContextRecord,
-#ifndef _WINKD_
- NULL,
- KernelMode,
-#endif
SecondChanceException);
/* Restore the port data and return */
diff --git a/ntoskrnl/kd64/kdtrap.c b/ntoskrnl/kd64/kdtrap.c
index 8f098952ee2..dc78b11891e 100644
--- a/ntoskrnl/kd64/kdtrap.c
+++ b/ntoskrnl/kd64/kdtrap.c
@@ -116,10 +116,6 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
Handled = KdpReportExceptionStateChange(ExceptionRecord,
&Prcb->ProcessorState.
ContextFrame,
-#ifndef _WINKD_
- TrapFrame,
- PreviousMode,
-#endif
SecondChanceException);
/* Now restore the processor state, manually again. */