- Create a KD-compatible KiDebugRoutine and piggyback KDBG on it.

- Create separate GDB entry hack routine.
- Fix booting with /BREAK and continuing after an INT3/ASSERTion.

svn path=/trunk/; revision=24155
This commit is contained in:
Alex Ionescu
2006-09-17 07:06:35 +00:00
parent bee17dc290
commit 8ef78cb6e6
4 changed files with 108 additions and 60 deletions
+19 -9
View File
@@ -215,15 +215,12 @@ KdpGdbStubInit(
/* KD ROUTINES ***************************************************************/
KD_CONTINUE_TYPE
STDCALL
KdpEnterDebuggerException(
PEXCEPTION_RECORD ExceptionRecord,
KPROCESSOR_MODE PreviousMode,
PCONTEXT Context,
PKTRAP_FRAME TrapFrame,
BOOLEAN FirstChance,
BOOLEAN Gdb
BOOLEAN
NTAPI
KdpCallGdb(
IN PKTRAP_FRAME TrapFrame,
IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context
);
ULONG
@@ -245,6 +242,17 @@ KdpBochsDebugPrint(
/* KD GLOBALS ***************************************************************/
typedef
BOOLEAN
(NTAPI *PKDEBUG_ROUTINE)(
IN PKTRAP_FRAME TrapFrame,
IN PKEXCEPTION_FRAME ExceptionFrame,
IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context,
IN KPROCESSOR_MODE PreviousMode,
IN BOOLEAN SecondChance
);
/* serial debug connection */
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
#define DEFAULT_DEBUG_COM1_IRQ 4 /* COM1 IRQ */
@@ -337,5 +345,7 @@ extern LIST_ENTRY KdProviders;
/* Whether to enter KDB as early as possible or not */
extern BOOLEAN KdpEarlyBreak;
extern PKDEBUG_ROUTINE KiDebugRoutine;
#endif
#endif /* __INCLUDE_INTERNAL_KERNEL_DEBUGGER_H */
+46 -21
View File
@@ -96,17 +96,45 @@ KdpServiceDispatcher(ULONG Service,
return Result;
}
KD_CONTINUE_TYPE
STDCALL
KdpEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
KPROCESSOR_MODE PreviousMode,
PCONTEXT Context,
PKTRAP_FRAME TrapFrame,
BOOLEAN FirstChance,
BOOLEAN Gdb)
BOOLEAN
NTAPI
KdpEnterDebuggerException(IN PKTRAP_FRAME TrapFrame,
IN PKEXCEPTION_FRAME ExceptionFrame,
IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context,
IN KPROCESSOR_MODE PreviousMode,
IN BOOLEAN SecondChance)
{
KD_CONTINUE_TYPE Return;
/* HACK (just like all this routine */
if (ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) Context->Eip++;
/* Get out of here if the Debugger isn't connected */
if (KdDebuggerNotPresent) return kdHandleException;
if (KdDebuggerNotPresent) return FALSE;
/* Call KDBG if available */
Return = KdbEnterDebuggerException(ExceptionRecord,
PreviousMode,
Context,
TrapFrame,
!SecondChance);
/* Convert return to BOOLEAN */
if (Return == kdContinue) return TRUE;
return FALSE;
}
BOOLEAN
NTAPI
KdpCallGdb(IN PKTRAP_FRAME TrapFrame,
IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context)
{
KD_CONTINUE_TYPE Return = kdDoNotHandleException;
/* Get out of here if the Debugger isn't connected */
if (KdDebuggerNotPresent) return FALSE;
/* FIXME:
* Right now, the GDB wrapper seems to handle exceptions differntly
@@ -114,21 +142,16 @@ KdpEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
* one is only called once and that's it. I don't really have the knowledge
* to fix the GDB stub, so until then, we'll be using this hack
*/
if (Gdb)
if (WrapperInitRoutine)
{
/* Call the registered wrapper */
if (WrapperInitRoutine) return WrapperTable.
KdpExceptionRoutine(ExceptionRecord,
Context,
TrapFrame);
Return = WrapperTable.KdpExceptionRoutine(ExceptionRecord,
Context,
TrapFrame);
}
/* Call KDBG if available */
return KdbEnterDebuggerException(ExceptionRecord,
PreviousMode,
Context,
TrapFrame,
FirstChance);
/* Convert return to BOOLEAN */
if (Return == kdContinue) return TRUE;
return FALSE;
}
/* PUBLIC FUNCTIONS *********************************************************/
@@ -268,4 +291,6 @@ NtSetDebugFilterState(IN ULONG ComponentId,
return STATUS_SUCCESS;
}
PKDEBUG_ROUTINE KiDebugRoutine = KdpEnterDebuggerException;
/* EOF */
+42 -29
View File
@@ -407,7 +407,7 @@ KeContextToTrapFrame(IN PCONTEXT Context,
{
/* Set the Debug Flag */
KeGetCurrentThread()->DispatcherHeader.DebugActive =
(Context->Dr7 & DR7_ACTIVE);
(Context->Dr7 & DR7_ACTIVE) ? TRUE: FALSE;
}
}
@@ -601,7 +601,6 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
BOOLEAN FirstChance)
{
CONTEXT Context;
KD_CONTINUE_TYPE Action;
ULONG_PTR Stack, NewStack;
ULONG Size;
EXCEPTION_RECORD LocalExceptRecord;
@@ -647,30 +646,35 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
if (FirstChance == TRUE)
{
/* Break into the debugger for the first time */
Action = KdpEnterDebuggerException(ExceptionRecord,
PreviousMode,
&Context,
TrapFrame,
TRUE,
TRUE);
if (KiDebugRoutine(TrapFrame,
ExceptionFrame,
ExceptionRecord,
&Context,
PreviousMode,
FALSE))
{
/* Exception was handled */
goto Handled;
}
/* If the debugger said continue, then continue */
if (Action == kdContinue) goto Handled;
/* HACK: GDB Entry */
if (KdpCallGdb(TrapFrame, ExceptionRecord, &Context)) goto Handled;
/* If the Debugger couldn't handle it, dispatch the exception */
if (RtlDispatchException(ExceptionRecord, &Context)) goto Handled;
}
/* This is a second-chance exception, only for the debugger */
Action = KdpEnterDebuggerException(ExceptionRecord,
PreviousMode,
&Context,
TrapFrame,
FALSE,
FALSE);
/* If the debugger said continue, then continue */
if (Action == kdContinue) goto Handled;
if (KiDebugRoutine(TrapFrame,
ExceptionFrame,
ExceptionRecord,
&Context,
PreviousMode,
TRUE))
{
/* Exception was handled */
goto Handled;
}
/* Third strike; you're out */
KeBugCheckEx(KMODE_EXCEPTION_NOT_HANDLED,
@@ -685,17 +689,26 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
if (FirstChance)
{
/* Enter Debugger if available */
Action = KdpEnterDebuggerException(ExceptionRecord,
PreviousMode,
&Context,
TrapFrame,
TRUE,
TRUE);
if (PsGetCurrentProcess()->DebugPort)
{
/* FIXME : TODO */
ASSERT(FALSE);
}
else if (KiDebugRoutine(TrapFrame,
ExceptionFrame,
ExceptionRecord,
&Context,
PreviousMode,
FALSE))
{
/* Exception was handled */
goto Handled;
}
/* Exit if we're continuing */
if (Action == kdContinue) goto Handled;
/* HACK: GDB Entry */
if (KdpCallGdb(TrapFrame, ExceptionRecord, &Context)) goto Handled;
/* FIXME: Forward exception to user mode debugger */
/* Forward exception to user mode debugger */
if (DbgkForwardException(ExceptionRecord, TRUE, FALSE)) goto Exit;
/* Set up the user-stack */
@@ -797,7 +810,7 @@ DispatchToUser:
Handled:
/* Convert the context back into Trap/Exception Frames */
KeContextToTrapFrame(&Context,
NULL,
ExceptionFrame,
TrapFrame,
Context.ContextFlags,
PreviousMode);
+1 -1
View File
@@ -41,7 +41,7 @@ KiInitializePcr(IN ULONG ProcessorNumber,
Pcr->NtTib.Self = 0;
/* Set the Current Thread */
//Pcr->PrcbData.CurrentThread = IdleThread;
Pcr->PrcbData.CurrentThread = IdleThread;
/* Set pointers to ourselves */
Pcr->Self = (PKPCR)Pcr;