Author: fireball Date: Fri Jul 6 13:02:16 2007 New Revision: 27419
URL: http://svn.reactos.org/svn/reactos?rev=27419&view=rev Log: - 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).
Modified: trunk/reactos/ntoskrnl/include/internal/kd.h trunk/reactos/ntoskrnl/kd/kdinit.c trunk/reactos/ntoskrnl/kd/kdmain.c trunk/reactos/ntoskrnl/kdbg/kdb.c trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c
Modified: trunk/reactos/ntoskrnl/include/internal/kd.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/k... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/kd.h (original) +++ trunk/reactos/ntoskrnl/include/internal/kd.h Fri Jul 6 13:02:16 2007 @@ -109,13 +109,11 @@ # 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 @@
VOID STDCALL -KdbSymInit( +KdpKdbgInit( struct _KD_DISPATCH_TABLE *DispatchTable, ULONG BootPhase);
@@ -267,7 +265,8 @@ #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
Modified: trunk/reactos/ntoskrnl/kd/kdinit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd/kdinit.c?rev=27... ============================================================================== --- trunk/reactos/ntoskrnl/kd/kdinit.c (original) +++ trunk/reactos/ntoskrnl/kd/kdinit.c Fri Jul 6 13:02:16 2007 @@ -37,7 +37,8 @@ PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit, KdpSerialInit, KdpInitDebugLog, - KdpBochsInit}; + KdpBochsInit, + KdpKdbgInit};
/* PRIVATE FUNCTIONS *********************************************************/
Modified: trunk/reactos/ntoskrnl/kd/kdmain.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd/kdmain.c?rev=27... ============================================================================== --- trunk/reactos/ntoskrnl/kd/kdmain.c (original) +++ trunk/reactos/ntoskrnl/kd/kdmain.c Fri Jul 6 13:02:16 2007 @@ -108,6 +108,7 @@ { 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 @@ (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++; @@ -133,6 +139,9 @@
/* 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, @@ -140,6 +149,19 @@ Context, 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;
Modified: trunk/reactos/ntoskrnl/kdbg/kdb.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kdbg/kdb.c?rev=274... ============================================================================== --- trunk/reactos/ntoskrnl/kdbg/kdb.c (original) +++ trunk/reactos/ntoskrnl/kdbg/kdb.c Fri Jul 6 13:02:16 2007 @@ -1303,7 +1303,7 @@ * 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 @@ Status = _SEH_GetExceptionCode(); } _SEH_END; - + return Status; }
Modified: trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c... ============================================================================== --- trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c (original) +++ trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c Fri Jul 6 13:02:16 2007 @@ -684,8 +684,8 @@ */ 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 @@ 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 */