From e126eb3077c7ad0fbe253fee8fe716066926928a Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sun, 18 Feb 2007 20:47:04 +0000 Subject: [PATCH] - Add KdDebuggerInitialize1 and enable call to it. - Fix KD_SYMBOLS_INFO definition and DbgLoadImageSymbols prototype. - Implement DbgUnLoadImageSymbols. - Fix some small bugs in KeBugCheckWithTf and add various debugger calls/checks where needed. - Fix bugcheck recursion code which was incorrect. svn path=/branches/alex-kd-branch/; revision=25837 --- reactos/drivers/base/kdcom/kdbg.c | 11 +++ reactos/drivers/base/kdcom/kdcom.def | 1 + reactos/include/ndk/kdtypes.h | 2 +- reactos/include/ndk/rtlfuncs.h | 10 ++- reactos/include/reactos/kddll.h | 6 ++ reactos/lib/rtl/debug.c | 25 +++++- reactos/ntoskrnl/ex/init.c | 2 +- reactos/ntoskrnl/ke/bug.c | 122 ++++++++++++++++----------- 8 files changed, 123 insertions(+), 56 deletions(-) diff --git a/reactos/drivers/base/kdcom/kdbg.c b/reactos/drivers/base/kdcom/kdbg.c index 5a79f80a2d6..6924d408879 100644 --- a/reactos/drivers/base/kdcom/kdbg.c +++ b/reactos/drivers/base/kdcom/kdbg.c @@ -566,6 +566,17 @@ KdDebuggerInitialize0(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL) return STATUS_UNSUCCESSFUL; } +/* + * @unimplemented + */ +NTSTATUS +NTAPI +KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL) +{ + /* FIXME: TODO */ + return STATUS_UNSUCCESSFUL; +} + /* * @implemented */ diff --git a/reactos/drivers/base/kdcom/kdcom.def b/reactos/drivers/base/kdcom/kdcom.def index 1c6bd4091e2..6a3f8dc6175 100644 --- a/reactos/drivers/base/kdcom/kdcom.def +++ b/reactos/drivers/base/kdcom/kdcom.def @@ -2,6 +2,7 @@ LIBRARY kdcom.dll EXPORTS KdDebuggerInitialize0@4 +KdDebuggerInitialize1@4 KdSave@4 KdRestore@4 KdReceivePacket@20 diff --git a/reactos/include/ndk/kdtypes.h b/reactos/include/ndk/kdtypes.h index b8fafc04451..26eb130cc57 100644 --- a/reactos/include/ndk/kdtypes.h +++ b/reactos/include/ndk/kdtypes.h @@ -168,7 +168,7 @@ typedef struct _SYSDBG_TRIAGE_DUMP typedef struct _KD_SYMBOLS_INFO { PVOID BaseOfDll; - PVOID ProcessId; + ULONG_PTR ProcessId; ULONG CheckSum; ULONG SizeOfImage; } KD_SYMBOLS_INFO, *PKD_SYMBOLS_INFO; diff --git a/reactos/include/ndk/rtlfuncs.h b/reactos/include/ndk/rtlfuncs.h index c85f9762216..70aacd9ba6b 100644 --- a/reactos/include/ndk/rtlfuncs.h +++ b/reactos/include/ndk/rtlfuncs.h @@ -2511,7 +2511,15 @@ NTAPI DbgLoadImageSymbols( IN PANSI_STRING Name, IN PVOID Base, - IN ULONG ProcessId + IN ULONG_PTR ProcessId +); + +VOID +NTAPI +DbgUnLoadImageSymbols( + IN PANSI_STRING Name, + IN PVOID Base, + IN ULONG_PTR ProcessId ); // diff --git a/reactos/include/reactos/kddll.h b/reactos/include/reactos/kddll.h index 7b835e062e5..b83bf20ecba 100644 --- a/reactos/include/reactos/kddll.h +++ b/reactos/include/reactos/kddll.h @@ -7,6 +7,12 @@ KdDebuggerInitialize0( IN PLOADER_PARAMETER_BLOCK LoaderBlock ); +NTSTATUS +NTAPI +KdDebuggerInitialize1( + IN PLOADER_PARAMETER_BLOCK LoaderBlock +); + ULONG NTAPI KdReceivePacket( diff --git a/reactos/lib/rtl/debug.c b/reactos/lib/rtl/debug.c index 0972f017b21..dbcfc1e4b6c 100644 --- a/reactos/lib/rtl/debug.c +++ b/reactos/lib/rtl/debug.c @@ -315,14 +315,14 @@ NTSTATUS NTAPI DbgLoadImageSymbols(IN PANSI_STRING Name, IN PVOID Base, - IN ULONG ProcessId) + IN ULONG_PTR ProcessId) { PIMAGE_NT_HEADERS NtHeader; KD_SYMBOLS_INFO SymbolInfo; /* Setup the symbol data */ SymbolInfo.BaseOfDll = Base; - SymbolInfo.ProcessId = UlongToPtr(ProcessId); + SymbolInfo.ProcessId = ProcessId; /* Get NT Headers */ NtHeader = NULL; //RtlImageNtHeader(Base); @@ -342,4 +342,25 @@ DbgLoadImageSymbols(IN PANSI_STRING Name, DebugService2(Name, &SymbolInfo, BREAKPOINT_LOAD_SYMBOLS); return STATUS_SUCCESS; } + +/* +* @implemented +*/ +VOID +NTAPI +DbgUnLoadImageSymbols(IN PANSI_STRING Name, + IN PVOID Base, + IN ULONG_PTR ProcessId) +{ + KD_SYMBOLS_INFO SymbolInfo; + + /* Setup the symbol data */ + SymbolInfo.BaseOfDll = Base; + SymbolInfo.ProcessId = ProcessId; + SymbolInfo.CheckSum = SymbolInfo.SizeOfImage = 0; + + /* Load the symbols */ + DebugService2(Name, &SymbolInfo, BREAKPOINT_UNLOAD_SYMBOLS); +} + /* EOF */ diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index d65b5354dff..0112e79fbe6 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -1155,7 +1155,7 @@ Phase1InitializationDiscard(PVOID Context) HalReportResourceUsage(); /* Call the debugger DLL once we have KD64 6.0 support */ - //KdDebuggerInitialize1(LoaderBlock); + KdDebuggerInitialize1(LoaderBlock); /* Setup PnP Manager in phase 1 */ if (!PpInitSystem()) KeBugCheck(PP1_INITIALIZATION_FAILED); diff --git a/reactos/ntoskrnl/ke/bug.c b/reactos/ntoskrnl/ke/bug.c index 20e8d601066..f4ae4f64978 100644 --- a/reactos/ntoskrnl/ke/bug.c +++ b/reactos/ntoskrnl/ke/bug.c @@ -427,13 +427,27 @@ KiDisplayBlueScreen(IN ULONG MessageId, { CHAR AnsiName[75]; + /* Check if bootvid is installed */ + if (InbvIsBootDriverInstalled()) + { + /* Acquire ownership and reset the display */ + InbvAcquireDisplayOwnership(); + InbvResetDisplay(); + + /* Display blue screen */ + InbvSolidColorFill(0, 0, 639, 479, 4); + InbvSetTextColor(15); + InbvInstallDisplayStringFilter(NULL); + InbvEnableDisplayString(TRUE); + InbvSetScrollRegion(0, 0, 639, 479); + } + /* Check if this is a hard error */ if (IsHardError) { /* Display caption and message */ if (HardErrCaption) InbvDisplayString(HardErrCaption); if (HardErrMessage) InbvDisplayString(HardErrMessage); - return; } /* Begin the display */ @@ -514,7 +528,7 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, CONTEXT Context; ULONG MessageId; CHAR AnsiName[128]; - BOOLEAN IsSystem, IsHardError = FALSE; + BOOLEAN IsSystem, IsHardError = FALSE, Reboot = FALSE; PCHAR HardErrCaption = NULL, HardErrMessage = NULL; PVOID Eip = NULL, Memory; PVOID DriverBase; @@ -543,9 +557,10 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, /* Capture the CPU Context */ RtlCaptureContext(&Prcb->ProcessorState.ContextFrame); + KiSaveProcessorControlState(&Prcb->ProcessorState); Context = Prcb->ProcessorState.ContextFrame; - /* FIXME: Call the Watchdog if it's regsitered */ + /* FIXME: Call the Watchdog if it's registered */ /* Check which bugcode this is */ switch (BugCheckCode) @@ -560,7 +575,6 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, case FAT_FILE_SYSTEM: case NO_MORE_SYSTEM_PTES: case INACCESSIBLE_BOOT_DEVICE: - case KMODE_EXCEPTION_NOT_HANDLED: /* Keep the same code */ MessageId = BugCheckCode; @@ -568,33 +582,40 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, /* Check if this is a kernel-mode exception */ case KERNEL_MODE_EXCEPTION_NOT_HANDLED: + //case SYSTEM_THREAD_EXCEPTION_NOT_HANDLED: + case KMODE_EXCEPTION_NOT_HANDLED: /* Use the generic text message */ MessageId = KMODE_EXCEPTION_NOT_HANDLED; + break; /* File-system errors */ case NTFS_FILE_SYSTEM: /* Use the generic message for FAT */ MessageId = FAT_FILE_SYSTEM; + break; /* Check if this is a coruption of the Mm's Pool */ case DRIVER_CORRUPTED_MMPOOL: /* Use generic corruption message */ MessageId = DRIVER_CORRUPTED_EXPOOL; + break; /* Check if this is a signature check failure */ case STATUS_SYSTEM_IMAGE_BAD_SIGNATURE: /* Use the generic corruption message */ MessageId = BUGCODE_PSS_MESSAGE_SIGNATURE; + break; /* All other codes */ default: /* Use the default bugcheck message */ MessageId = BUGCODE_PSS_MESSAGE; + break; } /* Save bugcheck data */ @@ -721,9 +742,13 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, { /* Get EIP */ Eip = (PVOID)TrapFrame->Eip; + KiBugCheckData[3] = (ULONG)Eip; /* Find out if was in the kernel or drivers */ - DriverBase = KiPcToFileHeader(Eip, &LdrEntry, FALSE, &IsSystem); + DriverBase = KiPcToFileHeader(Eip, + &LdrEntry, + FALSE, + &IsSystem); } /* @@ -732,8 +757,8 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, * and update the bugcheck code appropriately. */ - /* Check if we had a driver base */ - if (DriverBase) + /* Check if we didn't have a driver base */ + if (!DriverBase) { /* Find the driver that unloaded at this address */ KiBugCheckDriver = NULL; // FIXME: ROS can't locate @@ -757,10 +782,9 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, /* Check if the driver consumed too many PTEs */ case DRIVER_USED_EXCESSIVE_PTES: - /* Driver base is in parameter 1 */ - DriverBase = (PVOID)BugCheckParameter1; - /* FIXME: LdrEntry is uninitialized for god's sake!!! - KiBugCheckDriver = &LdrEntry->BaseDllName; */ + /* Loader entry is in parameter 1 */ + LdrEntry = (PVOID)BugCheckParameter1; + KiBugCheckDriver = &LdrEntry->BaseDllName; break; /* Check if the driver has a stuck thread */ @@ -794,7 +818,8 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, } } - /* FIXME: Check if we need to save the context for KD */ + /* Check if we need to save the context for KD */ + if (!KdPitchDebugger) KdDebuggerDataBlock.SavedContext = (ULONG)&Context; /* Check if a debugger is connected */ if ((BugCheckCode != MANUALLY_INITIATED_CRASH) && (KdDebuggerEnabled)) @@ -829,35 +854,13 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, /* Break in the debugger */ KiBugCheckDebugBreak(DBG_STATUS_BUGCHECK_FIRST); } - else - { - /* - * ROS HACK. - * Ok, so debugging is enabled, but KDBG isn't there. - * We'll manually dump the stack for the user. - */ - KeRosDumpStackFrames(NULL, 0); - } - } - - /* Use the boot video driver to clear, fill and write to screen. */ - if (InbvIsBootDriverInstalled()) - { - /* FIXME: This should happen in KiDisplayBlueScreen!!! */ - InbvAcquireDisplayOwnership(); - InbvResetDisplay(); - InbvSolidColorFill(0, 0, 639, 479, 4); - InbvSetTextColor(15); - InbvInstallDisplayStringFilter(NULL); - InbvEnableDisplayString(TRUE); - InbvSetScrollRegion(0, 0, 639, 479); } /* Raise IRQL to HIGH_LEVEL */ _disable(); KeRaiseIrql(HIGH_LEVEL, &OldIrql); - /* Unlock the Kernel Adress Space if we own it */ + /* ROS HACK: Unlock the Kernel Address Space if we own it */ if (KernelAddressSpaceLock.Owner == KeGetCurrentThread()) { MmUnlockAddressSpace(MmGetKernelAddressSpace()); @@ -866,10 +869,10 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, /* Avoid recursion */ if (!InterlockedDecrement((PLONG)&KeBugCheckCount)) { +#ifdef CONFIG_SMP /* Set CPU that is bug checking now */ KeBugCheckOwner = Prcb->Number; -#ifdef CONFIG_SMP /* Freeze the other CPUs */ for (i = 0; i < KeNumberProcessors; i++) { @@ -889,10 +892,17 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, HardErrMessage, AnsiName); - /* FIXME: Enable debugger if it was pending */ - - /* Print the last line */ - InbvDisplayString("\r\n"); + /* Check if the debugger is disabled but we can enable it */ + if (!(KdDebuggerEnabled) && !(KdPitchDebugger)) + { + /* Enable it */ + KdEnableDebuggerWithLock(FALSE); + } + else + { + /* Otherwise, print the last line */ + InbvDisplayString("\r\n"); + } /* Save the context */ Prcb->ProcessorState.ContextFrame = Context; @@ -907,18 +917,20 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, KiBugCheckData[3], TrapFrame); } - - /* Increase recursioun count */ - KeBugCheckOwnerRecursionCount++; - if (KeBugCheckOwnerRecursionCount == 2) + else { - /* Break in the debugger */ - KiBugCheckDebugBreak(DBG_STATUS_BUGCHECK_SECOND); - } - else if (KeBugCheckOwnerRecursionCount > 2) - { - /* Halt the CPU */ - for (;;) Ke386HaltProcessor(); + /* Increase recursion count */ + KeBugCheckOwnerRecursionCount++; + if (KeBugCheckOwnerRecursionCount == 2) + { + /* Break in the debugger */ + KiBugCheckDebugBreak(DBG_STATUS_BUGCHECK_SECOND); + } + else if (KeBugCheckOwnerRecursionCount > 2) + { + /* Halt the CPU */ + for (;;) Ke386HaltProcessor(); + } } /* Call the Callbacks */ @@ -926,6 +938,14 @@ KeBugCheckWithTf(IN ULONG BugCheckCode, /* FIXME: Call Watchdog if enabled */ + /* Check if we have to reboot */ + if (Reboot) + { + /* Unload symbols */ + DbgUnLoadImageSymbols(NULL, NtCurrentProcess(), 0); + HalReturnToFirmware(HalRebootRoutine); + } + /* Attempt to break in the debugger (otherwise halt CPU) */ KiBugCheckDebugBreak(DBG_STATUS_BUGCHECK_SECOND); }