From 6d53c91bed93d407aba530a53bf7b56f8ea75e58 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Fri, 6 Jul 2007 09:02:16 +0000 Subject: [PATCH] - Start turning KDBG into a KD wrapper (and thus removing where possible KDBG-specific hacks in various places of the kernel). - KdbSymInit() became a general initialization routine. - KdpEnterDebuggerException() is modified to: * Call KDBG's symbol-loading hook when BREAKPOINT_LOAD_SYMBOLS is hit. * If KDBG is turned on, and it's a breakpoint, the Eip is incremented (thus fixing the inability to "cont" after breaking into the KDBG debugger). svn path=/trunk/; revision=27419 --- reactos/ntoskrnl/include/internal/kd.h | 7 +++---- reactos/ntoskrnl/kd/kdinit.c | 3 ++- reactos/ntoskrnl/kd/kdmain.c | 22 ++++++++++++++++++++++ reactos/ntoskrnl/kdbg/kdb.c | 4 ++-- reactos/ntoskrnl/kdbg/kdb_symbols.c | 6 +++--- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/kd.h b/reactos/ntoskrnl/include/internal/kd.h index cc470ce799f..2f0e315699b 100644 --- a/reactos/ntoskrnl/include/internal/kd.h +++ b/reactos/ntoskrnl/include/internal/kd.h @@ -109,13 +109,11 @@ typedef struct _KDB_MODULE_INFO # define KDB_LOADUSERMODULE_HOOK(LDRMOD) KdbSymLoadUserModuleSymbols(LDRMOD) # define KDB_LOADDRIVER_HOOK(FILENAME, MODULE) KdbSymLoadDriverSymbols(FILENAME, MODULE) # define KDB_UNLOADDRIVER_HOOK(MODULE) KdbSymUnloadDriverSymbols(MODULE) -# define KDB_LOADERINIT_HOOK(NTOS, HAL) KdbSymInit(NTOS, HAL) # define KDB_SYMBOLFILE_HOOK(FILENAME) KdbSymProcessBootSymbols(FILENAME) #else # define KDB_LOADUSERMODULE_HOOK(LDRMOD) do { } while (0) # define KDB_LOADDRIVER_HOOK(FILENAME, MODULE) do { } while (0) # define KDB_UNLOADDRIVER_HOOK(MODULE) do { } while (0) -# define KDB_LOADERINIT_HOOK(NTOS, HAL) do { } while (0) # define KDB_SYMBOLFILE_HOOK(FILENAME) do { } while (0) # define KDB_CREATE_THREAD_HOOK(CONTEXT) do { } while (0) #endif @@ -211,7 +209,7 @@ KdpGdbStubInit( VOID STDCALL -KdbSymInit( +KdpKdbgInit( struct _KD_DISPATCH_TABLE *DispatchTable, ULONG BootPhase); @@ -267,7 +265,8 @@ BOOLEAN #define KdSerial 1 #define KdFile 2 #define KdBochs 3 -#define KdMax 4 +#define KdKdbg 4 +#define KdMax 5 /* KD Private Debug Modes */ typedef struct _KDP_DEBUG_MODE diff --git a/reactos/ntoskrnl/kd/kdinit.c b/reactos/ntoskrnl/kd/kdinit.c index 1764cbe78b3..048bff02c4f 100644 --- a/reactos/ntoskrnl/kd/kdinit.c +++ b/reactos/ntoskrnl/kd/kdinit.c @@ -37,7 +37,8 @@ KD_DISPATCH_TABLE DispatchTable[KdMax]; PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit, KdpSerialInit, KdpInitDebugLog, - KdpBochsInit}; + KdpBochsInit, + KdpKdbgInit}; /* PRIVATE FUNCTIONS *********************************************************/ diff --git a/reactos/ntoskrnl/kd/kdmain.c b/reactos/ntoskrnl/kd/kdmain.c index 02e2e20ac7f..ab173d17f18 100644 --- a/reactos/ntoskrnl/kd/kdmain.c +++ b/reactos/ntoskrnl/kd/kdmain.c @@ -108,6 +108,7 @@ KdpEnterDebuggerException(IN PKTRAP_FRAME TrapFrame, { KD_CONTINUE_TYPE Return; ULONG ExceptionCommand = ExceptionRecord->ExceptionInformation[0]; + ULONG EipOld; /* Check if this was a breakpoint due to DbgPrint or Load/UnloadSymbols */ if ((ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) && @@ -125,6 +126,11 @@ KdpEnterDebuggerException(IN PKTRAP_FRAME TrapFrame, (PVOID)ExceptionRecord->ExceptionInformation[1], ExceptionRecord->ExceptionInformation[2]); } + else if (ExceptionCommand == BREAKPOINT_LOAD_SYMBOLS) + { + /* Load symbols. Currently implemented only for KDBG! */ + KDB_SYMBOLFILE_HOOK((PANSI_STRING)ExceptionRecord->ExceptionInformation[1]); + } /* This we can handle: simply bump EIP */ Context->Eip++; @@ -134,6 +140,9 @@ KdpEnterDebuggerException(IN PKTRAP_FRAME TrapFrame, /* Get out of here if the Debugger isn't connected */ if (KdDebuggerNotPresent) return FALSE; + /* Save old EIP value */ + EipOld = Context->Eip; + /* Call KDBG if available */ Return = KdbEnterDebuggerException(ExceptionRecord, PreviousMode, @@ -141,6 +150,19 @@ KdpEnterDebuggerException(IN PKTRAP_FRAME TrapFrame, TrapFrame, !SecondChance); + /* Bump EIP over int 3 if debugger did not already change it */ + if (ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) + { +#ifdef KDBG + if (Context->Eip == EipOld) + Context->Eip++; +#else + /* We simulate the original behaviour when KDBG is turned off. + Return var is set to kdHandleException, thus we always return FALSE */ + Context->Eip = EipOld; +#endif + } + /* Convert return to BOOLEAN */ if (Return == kdContinue) return TRUE; return FALSE; diff --git a/reactos/ntoskrnl/kdbg/kdb.c b/reactos/ntoskrnl/kdbg/kdb.c index 4bbd0cfbfd8..830e61d8e7c 100644 --- a/reactos/ntoskrnl/kdbg/kdb.c +++ b/reactos/ntoskrnl/kdbg/kdb.c @@ -1303,7 +1303,7 @@ KdbEnterDebuggerException( * The breakpoint will point to the next instruction by default so * point it back to the start of original instruction. */ - TrapFrame->Eip--; + //TrapFrame->Eip--; /* * ... and restore the original instruction. @@ -1642,7 +1642,7 @@ KdbpSafeReadMemory(OUT PVOID Dest, Status = _SEH_GetExceptionCode(); } _SEH_END; - + return Status; } diff --git a/reactos/ntoskrnl/kdbg/kdb_symbols.c b/reactos/ntoskrnl/kdbg/kdb_symbols.c index 7bf0d7b381d..9e6b4425924 100644 --- a/reactos/ntoskrnl/kdbg/kdb_symbols.c +++ b/reactos/ntoskrnl/kdbg/kdb_symbols.c @@ -684,8 +684,8 @@ KdbDebugPrint(PCH Message, ULONG Length) */ VOID STDCALL -KdbSymInit(PKD_DISPATCH_TABLE DispatchTable, - ULONG BootPhase) +KdpKdbgInit(PKD_DISPATCH_TABLE DispatchTable, + ULONG BootPhase) { PCHAR p1, p2; int Found; @@ -697,7 +697,7 @@ KdbSymInit(PKD_DISPATCH_TABLE DispatchTable, if (BootPhase == 0) { /* Write out the functions that we support for now */ - DispatchTable->KdpInitRoutine = KdbSymInit; + DispatchTable->KdpInitRoutine = KdpKdbgInit; DispatchTable->KdpPrintRoutine = KdbDebugPrint; /* Register as a Provider */