From ae5cb55a9c4a2adfa7fb4738c1ba7cfbb376ae4d Mon Sep 17 00:00:00 2001 From: Dmitry Gorbachev Date: Mon, 22 Jun 2009 11:32:58 +0000 Subject: [PATCH] - If KDBG is not compiled in, try to use GDB instead. - Check WrapperTable.KdpPrintRoutine. - Allow to use GDB (/DEBUGPORT=GDB) and have debug output (/DEBUGPORT=COM1) at the same time. svn path=/trunk/; revision=41534 --- reactos/ntoskrnl/kd/kdinit.c | 92 ++++++++++++++++-------------------- reactos/ntoskrnl/kd/kdio.c | 4 +- reactos/ntoskrnl/kd/kdmain.c | 10 ++++ 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/reactos/ntoskrnl/kd/kdinit.c b/reactos/ntoskrnl/kd/kdinit.c index 1633af11efd..aae380e922a 100644 --- a/reactos/ntoskrnl/kd/kdinit.c +++ b/reactos/ntoskrnl/kd/kdinit.c @@ -42,47 +42,6 @@ PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit, /* PRIVATE FUNCTIONS *********************************************************/ -PCHAR -NTAPI -KdpGetWrapperDebugMode(PCHAR Currentp2, - PLOADER_PARAMETER_BLOCK LoaderBlock) -{ - PCHAR p2 = Currentp2; - - /* Check for GDB Debugging */ - if (!_strnicmp(p2, "GDB", 3)) - { - /* Enable it */ - p2 += 3; - KdpDebugMode.Gdb = TRUE; - - /* Enable Debugging */ - KdDebuggerEnabled = TRUE; - KdDebuggerNotPresent = FALSE; - WrapperInitRoutine = KdpGdbStubInit; - } - - /* Check for PICE Debugging */ - else if (!_strnicmp(p2, "PICE", 4)) - { - /* Enable it */ - p2 += 4; - KdpDebugMode.Pice = TRUE; - - /* Enable Debugging */ - KdDebuggerEnabled = TRUE; - KdDebuggerNotPresent = FALSE; - } - -#ifdef KDBG - /* Get the KDBG Settings and enable it */ - KdDebuggerEnabled = TRUE; - KdDebuggerNotPresent = FALSE; - KdbpGetCommandLineSettings(LoaderBlock->LoadOptions); -#endif - return p2; -} - PCHAR NTAPI KdpGetDebugMode(PCHAR Currentp2) @@ -129,6 +88,31 @@ KdpGetDebugMode(PCHAR Currentp2) KdpDebugMode.Bochs = TRUE; } + /* Check for GDB Debugging */ + else if (!_strnicmp(p2, "GDB", 3)) + { + /* Enable it */ + p2 += 3; + KdpDebugMode.Gdb = TRUE; + + /* Enable Debugging */ + KdDebuggerEnabled = TRUE; + KdDebuggerNotPresent = FALSE; + WrapperInitRoutine = KdpGdbStubInit; + } + + /* Check for PICE Debugging */ + else if (!_strnicmp(p2, "PICE", 4)) + { + /* Enable it */ + p2 += 4; + KdpDebugMode.Pice = TRUE; + + /* Enable Debugging */ + KdDebuggerEnabled = TRUE; + KdDebuggerNotPresent = FALSE; + } + return p2; } @@ -179,7 +163,7 @@ KdInitSystem(ULONG BootPhase, /* Upcase it */ _strupr(CommandLine); - /* Check for settings that we support */ + /* XXX Check for settings that we support */ if (strstr(CommandLine, "BREAK")) KdpEarlyBreak = TRUE; if (strstr(CommandLine, "NODEBUG")) KdDebuggerEnabled = FALSE; if (strstr(CommandLine, "CRASHDEBUG")) KdDebuggerEnabled = FALSE; @@ -190,16 +174,23 @@ KdInitSystem(ULONG BootPhase, KdpDebugMode.Serial = TRUE; } +#ifdef KDBG + /* Get the KDBG Settings and enable it */ + KdDebuggerEnabled = TRUE; + KdDebuggerNotPresent = FALSE; + KdbpGetCommandLineSettings(LoaderBlock->LoadOptions); +#endif + /* Get the port and baud rate */ Port = strstr(CommandLine, "DEBUGPORT"); BaudRate = strstr(CommandLine, "BAUDRATE"); Irq = strstr(CommandLine, "IRQ"); - /* Check if we got the /DEBUGPORT parameter */ - if (Port) + /* Check if we got the /DEBUGPORT parameter(s) */ + while (Port) { /* Move past the actual string, to reach the port*/ - Port += strlen("DEBUGPORT"); + Port += sizeof("DEBUGPORT") - 1; /* Now get past any spaces and skip the equal sign */ while (*Port == ' ') Port++; @@ -207,15 +198,14 @@ KdInitSystem(ULONG BootPhase, /* Get the debug mode and wrapper */ Port = KdpGetDebugMode(Port); - Port = KdpGetWrapperDebugMode(Port, LoaderBlock); - KdDebuggerEnabled = TRUE; + Port = strstr(Port, "DEBUGPORT"); } /* Check if we got a baud rate */ if (BaudRate) { /* Move past the actual string, to reach the rate */ - BaudRate += strlen("BAUDRATE"); + BaudRate += sizeof("BAUDRATE") - 1; /* Now get past any spaces */ while (*BaudRate == ' ') BaudRate++; @@ -233,7 +223,7 @@ KdInitSystem(ULONG BootPhase, if (Irq) { /* Move past the actual string, to reach the rate */ - Irq += strlen("IRQ"); + Irq += sizeof("IRQ") - 1; /* Now get past any spaces */ while (*Irq == ' ') Irq++; @@ -257,7 +247,7 @@ KdInitSystem(ULONG BootPhase, if (WrapperInitRoutine) WrapperInitRoutine(&WrapperTable, 0); return TRUE; } - else + else /* BootPhase > 0 */ { #ifdef _M_IX86 KdpEnableSafeMem(); @@ -271,4 +261,4 @@ KdInitSystem(ULONG BootPhase, return TRUE; } - /* EOF */ +/* EOF */ diff --git a/reactos/ntoskrnl/kd/kdio.c b/reactos/ntoskrnl/kd/kdio.c index a2fa6a0dc0f..6a520e49868 100644 --- a/reactos/ntoskrnl/kd/kdio.c +++ b/reactos/ntoskrnl/kd/kdio.c @@ -293,11 +293,11 @@ KdpPrintString(LPSTR String, } /* Call the Wrapper Routine */ - if (WrapperInitRoutine) WrapperTable.KdpPrintRoutine(String, Length); + if (WrapperTable.KdpPrintRoutine) + WrapperTable.KdpPrintRoutine(String, Length); /* Return the Length */ return Length; } /* EOF */ - diff --git a/reactos/ntoskrnl/kd/kdmain.c b/reactos/ntoskrnl/kd/kdmain.c index 1b4876582b6..2d736a8ecfe 100644 --- a/reactos/ntoskrnl/kd/kdmain.c +++ b/reactos/ntoskrnl/kd/kdmain.c @@ -163,12 +163,22 @@ KdpEnterDebuggerException(IN PKTRAP_FRAME TrapFrame, EipOld = Context->Eip; #endif +#ifdef KDBG /* Call KDBG if available */ Return = KdbEnterDebuggerException(ExceptionRecord, PreviousMode, Context, TrapFrame, !SecondChance); +#else /* not KDBG */ + if (WrapperInitRoutine) + { + /* Call GDB */ + Return = WrapperTable.KdpExceptionRoutine(ExceptionRecord, + Context, + TrapFrame); + } +#endif /* not KDBG */ /* Bump EIP over int 3 if debugger did not already change it */ if (ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT)