diff --git a/reactos/ntoskrnl/dbg/kdb.c b/reactos/ntoskrnl/dbg/kdb.c index 6295d956153..0738f1796bb 100644 --- a/reactos/ntoskrnl/dbg/kdb.c +++ b/reactos/ntoskrnl/dbg/kdb.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: kdb.c,v 1.34 2004/11/10 23:16:16 blight Exp $ +/* $Id: kdb.c,v 1.35 2004/11/18 02:10:28 arty Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/dbg/kdb.c @@ -58,6 +58,8 @@ static ULONG KdbBreakPointCount = 0; static KDB_ACTIVE_BREAKPOINT KdbActiveBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT]; +static BOOLEAN KdbHandleUmode = FALSE; +static BOOLEAN KdbHandleHandled = FALSE; static BOOLEAN KdbIgnoreNextSingleStep = FALSE; static ULONG KdbLastSingleStepFrom = 0xFFFFFFFF; @@ -70,6 +72,8 @@ VOID PsDumpThreads(BOOLEAN System); ULONG DbgContCommand(ULONG Argc, PCH Argv[], PKTRAP_FRAME Tf); +ULONG +DbgStopCondition(ULONG Aargc, PCH Argv[], PKTRAP_FRAME Tf); ULONG DbgEchoToggle(ULONG Argc, PCH Argv[], PKTRAP_FRAME Tf); ULONG @@ -124,6 +128,8 @@ struct } DebuggerCommands[] = { {"cont", "cont", "Exit the debugger", DbgContCommand}, {"echo", "echo", "Toggle serial echo", DbgEchoToggle}, + {"condition", "condition [all|umode|kmode]", "Kdbg enter condition", DbgStopCondition}, + {"regs", "regs", "Display general purpose registers", DbgRegsCommand}, {"dregs", "dregs", "Display debug registers", DbgDRegsCommand}, {"cregs", "cregs", "Display control registers", DbgCRegsCommand}, @@ -1328,6 +1334,24 @@ DbgContCommand(ULONG Argc, PCH Argv[], PKTRAP_FRAME Tf) return(0); } +ULONG +DbgStopCondition(ULONG Argc, PCH Argv[], PKTRAP_FRAME Tf) +{ + if( Argc == 1 ) { + if( KdbHandleHandled ) DbgPrint("all\n"); + else if( KdbHandleUmode ) DbgPrint("umode\n"); + else DbgPrint("kmode\n"); + } + else if( !strcmp(Argv[1],"all") ) + { KdbHandleHandled = TRUE; KdbHandleUmode = TRUE; } + else if( !strcmp(Argv[1],"umode") ) + { KdbHandleHandled = FALSE; KdbHandleUmode = TRUE; } + else if( !strcmp(Argv[1],"kmode") ) + { KdbHandleHandled = FALSE; KdbHandleUmode = FALSE; } + + return(TRUE); +} + ULONG DbgEchoToggle(ULONG Argc, PCH Argv[], PKTRAP_FRAME Tf) { @@ -1624,12 +1648,26 @@ KdbInternalEnter(PKTRAP_FRAME Tf) KD_CONTINUE_TYPE KdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord, + KPROCESSOR_MODE PreviousMode, PCONTEXT Context, - PKTRAP_FRAME TrapFrame) + PKTRAP_FRAME TrapFrame, + BOOLEAN AlwaysHandle) { LONG BreakPointNr; ULONG ExpNr = (ULONG)TrapFrame->DebugArgMark; + DbgPrint( ":KDBG:Entered:%s:%s\n", + PreviousMode==KernelMode ? "kmode" : "umode", + AlwaysHandle ? "always" : "if-unhandled" ); + + /* If we aren't handling umode exceptions then return */ + if( PreviousMode == UserMode && !KdbHandleUmode && !AlwaysHandle ) + return kdContinue; + + /* If the exception would be unhandled (and we care) then handle it */ + if( PreviousMode == KernelMode && !KdbHandleHandled && !AlwaysHandle ) + return kdContinue; + /* Exception inside the debugger? Game over. */ if (KdbEntryCount > 0) { diff --git a/reactos/ntoskrnl/ke/catch.c b/reactos/ntoskrnl/ke/catch.c index 1f2f4d529b4..a1e7f7f4ef0 100644 --- a/reactos/ntoskrnl/ke/catch.c +++ b/reactos/ntoskrnl/ke/catch.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: catch.c,v 1.53 2004/11/14 16:00:02 blight Exp $ +/* $Id: catch.c,v 1.54 2004/11/18 02:10:28 arty Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/ke/catch.c @@ -76,17 +76,8 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, { Action = KdEnterDebuggerException (ExceptionRecord, Context, Tf); } -#ifdef KDBG - else if (KdDebuggerEnabled && KdDebugState & KD_DEBUG_KDB) - { - Action = KdbEnterDebuggerException (ExceptionRecord, Context, Tf); - } -#endif /* KDBG */ - if (Action == kdContinue) - { - return; - } - else if (Action != kdDoNotHandleException) + + if (Action != kdDoNotHandleException) { if (PreviousMode == UserMode) { @@ -98,6 +89,11 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, PULONG pNewUserStack = (PULONG)(Tf->Esp - (12 + sizeof(EXCEPTION_RECORD) + sizeof(CONTEXT))); NTSTATUS StatusOfCopy; +#ifdef KDBG + KdbEnterDebuggerException (ExceptionRecord, PreviousMode, + Context, Tf, FALSE); +#endif + /* FIXME: Forward exception to user mode debugger */ /* FIXME: Check user mode stack for enough space */ @@ -139,17 +135,23 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, /* FIXME: Forward the exception to the process exception port */ +#ifdef KDBG + KdbEnterDebuggerException (ExceptionRecord, PreviousMode, + Context, Tf, TRUE); +#endif + /* Terminate the offending thread */ DPRINT1("Unhandled UserMode exception, terminating thread\n"); ZwTerminateThread(NtCurrentThread(), ExceptionRecord->ExceptionCode); - - /* If that fails then bugcheck */ - DPRINT1("Could not terminate thread\n"); - KEBUGCHECK(KMODE_EXCEPTION_NOT_HANDLED); } else { /* PreviousMode == KernelMode */ +#ifdef KDBG + KdbEnterDebuggerException (ExceptionRecord, PreviousMode, + Context, Tf, FALSE); +#endif + Value = RtlpDispatchException (ExceptionRecord, Context); DPRINT("RtlpDispatchException() returned with 0x%X\n", Value); @@ -162,7 +164,11 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, { DPRINT("ExceptionRecord->ExceptionAddress = 0x%x\n", ExceptionRecord->ExceptionAddress ); - KEBUGCHECKWITHTF(KMODE_EXCEPTION_NOT_HANDLED, 0, 0, 0, 0, Tf); +#ifdef KDBG + KdbEnterDebuggerException (ExceptionRecord, PreviousMode, + Context, Tf, TRUE); +#endif + KEBUGCHECKWITHTF(KMODE_EXCEPTION_NOT_HANDLED, 0, 0, 0, 0, Tf); } } }