[NTOS:KD] Merge KdpReportExceptionStateChange() with kd64 version

This commit is contained in:
Hervé Poussineau 2020-04-09 14:31:47 +02:00
parent baa47fa5e0
commit 0c76bbfe98
5 changed files with 75 additions and 61 deletions

View file

@ -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
);

View file

@ -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;
}

View file

@ -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

View file

@ -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 */

View file

@ -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. */