Author: ion Date: Sun Feb 18 23:47:04 2007 New Revision: 25837
URL: http://svn.reactos.org/svn/reactos?rev=25837&view=rev Log: - 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.
Modified: branches/alex-kd-branch/reactos/drivers/base/kdcom/kdbg.c branches/alex-kd-branch/reactos/drivers/base/kdcom/kdcom.def branches/alex-kd-branch/reactos/include/ndk/kdtypes.h branches/alex-kd-branch/reactos/include/ndk/rtlfuncs.h branches/alex-kd-branch/reactos/include/reactos/kddll.h branches/alex-kd-branch/reactos/lib/rtl/debug.c branches/alex-kd-branch/reactos/ntoskrnl/ex/init.c branches/alex-kd-branch/reactos/ntoskrnl/ke/bug.c
Modified: branches/alex-kd-branch/reactos/drivers/base/kdcom/kdbg.c URL: http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/drivers/b... ============================================================================== --- branches/alex-kd-branch/reactos/drivers/base/kdcom/kdbg.c (original) +++ branches/alex-kd-branch/reactos/drivers/base/kdcom/kdbg.c Sun Feb 18 23:47:04 2007 @@ -567,6 +567,17 @@ }
/* + * @unimplemented + */ +NTSTATUS +NTAPI +KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL) +{ + /* FIXME: TODO */ + return STATUS_UNSUCCESSFUL; +} + +/* * @implemented */ NTSTATUS
Modified: branches/alex-kd-branch/reactos/drivers/base/kdcom/kdcom.def URL: http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/drivers/b... ============================================================================== --- branches/alex-kd-branch/reactos/drivers/base/kdcom/kdcom.def (original) +++ branches/alex-kd-branch/reactos/drivers/base/kdcom/kdcom.def Sun Feb 18 23:47:04 2007 @@ -2,6 +2,7 @@ EXPORTS
KdDebuggerInitialize0@4 +KdDebuggerInitialize1@4 KdSave@4 KdRestore@4 KdReceivePacket@20
Modified: branches/alex-kd-branch/reactos/include/ndk/kdtypes.h URL: http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/include/n... ============================================================================== --- branches/alex-kd-branch/reactos/include/ndk/kdtypes.h (original) +++ branches/alex-kd-branch/reactos/include/ndk/kdtypes.h Sun Feb 18 23:47:04 2007 @@ -168,7 +168,7 @@ typedef struct _KD_SYMBOLS_INFO { PVOID BaseOfDll; - PVOID ProcessId; + ULONG_PTR ProcessId; ULONG CheckSum; ULONG SizeOfImage; } KD_SYMBOLS_INFO, *PKD_SYMBOLS_INFO;
Modified: branches/alex-kd-branch/reactos/include/ndk/rtlfuncs.h URL: http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/include/n... ============================================================================== --- branches/alex-kd-branch/reactos/include/ndk/rtlfuncs.h (original) +++ branches/alex-kd-branch/reactos/include/ndk/rtlfuncs.h Sun Feb 18 23:47:04 2007 @@ -2511,7 +2511,15 @@ 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 );
//
Modified: branches/alex-kd-branch/reactos/include/reactos/kddll.h URL: http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/include/r... ============================================================================== --- branches/alex-kd-branch/reactos/include/reactos/kddll.h (original) +++ branches/alex-kd-branch/reactos/include/reactos/kddll.h Sun Feb 18 23:47:04 2007 @@ -4,6 +4,12 @@ NTSTATUS NTAPI KdDebuggerInitialize0( + IN PLOADER_PARAMETER_BLOCK LoaderBlock +); + +NTSTATUS +NTAPI +KdDebuggerInitialize1( IN PLOADER_PARAMETER_BLOCK LoaderBlock );
Modified: branches/alex-kd-branch/reactos/lib/rtl/debug.c URL: http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/lib/rtl/d... ============================================================================== --- branches/alex-kd-branch/reactos/lib/rtl/debug.c (original) +++ branches/alex-kd-branch/reactos/lib/rtl/debug.c Sun Feb 18 23:47:04 2007 @@ -315,14 +315,14 @@ 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 @@ 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 */
Modified: branches/alex-kd-branch/reactos/ntoskrnl/ex/init.c URL: http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/ntoskrnl/... ============================================================================== --- branches/alex-kd-branch/reactos/ntoskrnl/ex/init.c (original) +++ branches/alex-kd-branch/reactos/ntoskrnl/ex/init.c Sun Feb 18 23:47:04 2007 @@ -1155,7 +1155,7 @@ 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);
Modified: branches/alex-kd-branch/reactos/ntoskrnl/ke/bug.c URL: http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/ntoskrnl/... ============================================================================== --- branches/alex-kd-branch/reactos/ntoskrnl/ke/bug.c (original) +++ branches/alex-kd-branch/reactos/ntoskrnl/ke/bug.c Sun Feb 18 23:47:04 2007 @@ -427,13 +427,27 @@ { 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 @@ 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 @@
/* 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 @@ 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 @@
/* 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 @@ { /* 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 @@ * 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 @@ /* 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 @@ } }
- /* 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 @@ /* 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 @@ /* 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 @@ 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,24 +917,34 @@ KiBugCheckData[3], TrapFrame); } - - /* Increase recursioun count */ - KeBugCheckOwnerRecursionCount++; - if (KeBugCheckOwnerRecursionCount == 2) - { - /* Break in the debugger */ - KiBugCheckDebugBreak(DBG_STATUS_BUGCHECK_SECOND); - } - else if (KeBugCheckOwnerRecursionCount > 2) - { - /* Halt the CPU */ - for (;;) Ke386HaltProcessor(); + else + { + /* 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 */ KiDoBugCheckCallbacks();
/* 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);