Skip to content

Commit d90c6f0

Browse files
committed
[NTOS:KD] Merge KdpReportExceptionStateChange() with kd64 version
1 parent f814311 commit d90c6f0

File tree

5 files changed

+75
-61
lines changed

5 files changed

+75
-61
lines changed

ntoskrnl/include/internal/kd64.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,6 @@ NTAPI
281281
KdpReportExceptionStateChange(
282282
IN PEXCEPTION_RECORD ExceptionRecord,
283283
IN OUT PCONTEXT Context,
284-
#ifndef _WINKD_
285-
IN PKTRAP_FRAME TrapFrame,
286-
IN KPROCESSOR_MODE PreviousMode,
287-
#endif
288284
IN BOOLEAN SecondChanceException
289285
);
290286

ntoskrnl/kd/kdio.c

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ volatile ULONG KdbDmesgTotalWritten = 0;
4343
volatile BOOLEAN KdbpIsInDmesgMode = FALSE;
4444
static KSPIN_LOCK KdpDmesgLogSpinLock;
4545

46+
static ULONG KdbgNextApiNumber = DbgKdContinueApi;
47+
static CONTEXT KdbgContext;
48+
static EXCEPTION_RECORD64 KdbgExceptionRecord;
49+
static BOOLEAN KdbgFirstChanceException;
50+
static NTSTATUS KdbgContinueStatus = STATUS_SUCCESS;
51+
4652
/* LOCKING FUNCTIONS *********************************************************/
4753

4854
KIRQL
@@ -549,6 +555,50 @@ KdSendPacket(
549555
{
550556
return;
551557
}
558+
else if (WaitStateChange->NewState == DbgKdExceptionStateChange)
559+
{
560+
KdbgNextApiNumber = DbgKdGetContextApi;
561+
KdbgExceptionRecord = WaitStateChange->u.Exception.ExceptionRecord;
562+
KdbgFirstChanceException = WaitStateChange->u.Exception.FirstChance;
563+
return;
564+
}
565+
}
566+
else if (PacketType == PACKET_TYPE_KD_STATE_MANIPULATE)
567+
{
568+
PDBGKD_MANIPULATE_STATE64 ManipulateState = (PDBGKD_MANIPULATE_STATE64)MessageHeader->Buffer;
569+
if (ManipulateState->ApiNumber == DbgKdGetContextApi)
570+
{
571+
KD_CONTINUE_TYPE Result;
572+
573+
#ifdef KDBG
574+
/* Check if this is an assertion failure */
575+
if (KdbgExceptionRecord.ExceptionCode == STATUS_ASSERTION_FAILURE)
576+
{
577+
/* Bump EIP to the instruction following the int 2C */
578+
KdbgContext.Eip += 2;
579+
}
580+
581+
Result = KdbEnterDebuggerException(&KdbgExceptionRecord,
582+
KernelMode, // FIXME
583+
&KdbgContext,
584+
KdbgFirstChanceException);
585+
#else
586+
/* We'll manually dump the stack for the user... */
587+
KeRosDumpStackFrames(NULL, 0);
588+
Result = kdHandleException;
589+
#endif
590+
if (Result != kdHandleException)
591+
KdbgContinueStatus = STATUS_SUCCESS;
592+
else
593+
KdbgContinueStatus = STATUS_UNSUCCESSFUL;
594+
KdbgNextApiNumber = DbgKdSetContextApi;
595+
return;
596+
}
597+
else if (ManipulateState->ApiNumber == DbgKdSetContextApi)
598+
{
599+
KdbgNextApiNumber = DbgKdContinueApi;
600+
return;
601+
}
552602
}
553603
UNIMPLEMENTED;
554604
}
@@ -575,8 +625,32 @@ KdReceivePacket(
575625
if (PacketType == PACKET_TYPE_KD_STATE_MANIPULATE)
576626
{
577627
PDBGKD_MANIPULATE_STATE64 ManipulateState = (PDBGKD_MANIPULATE_STATE64)MessageHeader->Buffer;
628+
RtlZeroMemory(MessageHeader->Buffer, MessageHeader->MaximumLength);
629+
if (KdbgNextApiNumber == DbgKdGetContextApi)
630+
{
631+
ManipulateState->ApiNumber = DbgKdGetContextApi;
632+
MessageData->Length = 0;
633+
MessageData->Buffer = (PCHAR)&KdbgContext;
634+
return KdPacketReceived;
635+
}
636+
else if (KdbgNextApiNumber == DbgKdSetContextApi)
637+
{
638+
ManipulateState->ApiNumber = DbgKdSetContextApi;
639+
MessageData->Length = sizeof(KdbgContext);
640+
MessageData->Buffer = (PCHAR)&KdbgContext;
641+
return KdPacketReceived;
642+
}
643+
else if (KdbgNextApiNumber != DbgKdContinueApi)
644+
{
645+
UNIMPLEMENTED;
646+
}
578647
ManipulateState->ApiNumber = DbgKdContinueApi;
579-
ManipulateState->u.Continue.ContinueStatus = STATUS_SUCCESS;
648+
ManipulateState->u.Continue.ContinueStatus = KdbgContinueStatus;
649+
650+
/* Prepare for next time */
651+
KdbgNextApiNumber = DbgKdContinueApi;
652+
KdbgContinueStatus = STATUS_SUCCESS;
653+
580654
return KdPacketReceived;
581655
}
582656

ntoskrnl/kd/kdmain.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,6 @@ VOID NTAPI PspDumpThreads(BOOLEAN SystemThreads);
1717

1818
extern ANSI_STRING KdpLogFileName;
1919

20-
/* PRIVATE FUNCTIONS *********************************************************/
21-
22-
BOOLEAN
23-
NTAPI
24-
KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
25-
IN OUT PCONTEXT ContextRecord,
26-
IN PKTRAP_FRAME TrapFrame,
27-
IN KPROCESSOR_MODE PreviousMode,
28-
IN BOOLEAN SecondChanceException)
29-
{
30-
KD_CONTINUE_TYPE Return = kdHandleException;
31-
#ifdef KDBG
32-
EXCEPTION_RECORD64 ExceptionRecord64;
33-
34-
/* Check if this is an assertion failure */
35-
if (ExceptionRecord->ExceptionCode == STATUS_ASSERTION_FAILURE)
36-
{
37-
/* Bump EIP to the instruction following the int 2C */
38-
ContextRecord->Eip += 2;
39-
}
40-
41-
ExceptionRecord32To64((PEXCEPTION_RECORD32)ExceptionRecord,
42-
&ExceptionRecord64);
43-
#endif
44-
45-
/* Get out of here if the Debugger isn't connected */
46-
if (KdDebuggerNotPresent) return FALSE;
47-
48-
#ifdef KDBG
49-
/* Call KDBG if available */
50-
Return = KdbEnterDebuggerException(&ExceptionRecord64,
51-
PreviousMode,
52-
ContextRecord,
53-
!SecondChanceException);
54-
#else /* not KDBG */
55-
/* We'll manually dump the stack for the user... */
56-
KeRosDumpStackFrames(NULL, 0);
57-
#endif /* not KDBG */
58-
59-
/* Debugger didn't handle it, please handle! */
60-
if (Return == kdHandleException) return FALSE;
61-
62-
/* Debugger handled it */
63-
return TRUE;
64-
}
65-
6620
/* PUBLIC FUNCTIONS *********************************************************/
6721

6822
static PCHAR

ntoskrnl/kd64/kdapi.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,6 @@ KdpReportCommandStringStateChange(IN PSTRING NameString,
17251725
} while (Status == ContinueProcessorReselected);
17261726
}
17271727

1728-
#ifdef _WINKD_
17291728
BOOLEAN
17301729
NTAPI
17311730
KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
@@ -1780,7 +1779,6 @@ KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
17801779
/* Return */
17811780
return Status;
17821781
}
1783-
#endif
17841782

17851783
VOID
17861784
NTAPI
@@ -1844,10 +1842,6 @@ KdpSwitchProcessor(IN PEXCEPTION_RECORD ExceptionRecord,
18441842
/* Report a state change */
18451843
Status = KdpReportExceptionStateChange(ExceptionRecord,
18461844
ContextRecord,
1847-
#ifndef _WINKD_
1848-
NULL,
1849-
KernelMode,
1850-
#endif
18511845
SecondChanceException);
18521846

18531847
/* Restore the port data and return */

ntoskrnl/kd64/kdtrap.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
116116
Handled = KdpReportExceptionStateChange(ExceptionRecord,
117117
&Prcb->ProcessorState.
118118
ContextFrame,
119-
#ifndef _WINKD_
120-
TrapFrame,
121-
PreviousMode,
122-
#endif
123119
SecondChanceException);
124120

125121
/* Now restore the processor state, manually again. */

0 commit comments

Comments
 (0)