- 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
This commit is contained in:
Alex Ionescu 2007-02-18 20:47:04 +00:00
parent ee1892a1a9
commit e126eb3077
8 changed files with 123 additions and 56 deletions

View file

@ -566,6 +566,17 @@ KdDebuggerInitialize0(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
/*
* @unimplemented
*/
NTSTATUS
NTAPI
KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
{
/* FIXME: TODO */
return STATUS_UNSUCCESSFUL;
}
/* /*
* @implemented * @implemented
*/ */

View file

@ -2,6 +2,7 @@ LIBRARY kdcom.dll
EXPORTS EXPORTS
KdDebuggerInitialize0@4 KdDebuggerInitialize0@4
KdDebuggerInitialize1@4
KdSave@4 KdSave@4
KdRestore@4 KdRestore@4
KdReceivePacket@20 KdReceivePacket@20

View file

@ -168,7 +168,7 @@ typedef struct _SYSDBG_TRIAGE_DUMP
typedef struct _KD_SYMBOLS_INFO typedef struct _KD_SYMBOLS_INFO
{ {
PVOID BaseOfDll; PVOID BaseOfDll;
PVOID ProcessId; ULONG_PTR ProcessId;
ULONG CheckSum; ULONG CheckSum;
ULONG SizeOfImage; ULONG SizeOfImage;
} KD_SYMBOLS_INFO, *PKD_SYMBOLS_INFO; } KD_SYMBOLS_INFO, *PKD_SYMBOLS_INFO;

View file

@ -2511,7 +2511,15 @@ NTAPI
DbgLoadImageSymbols( DbgLoadImageSymbols(
IN PANSI_STRING Name, IN PANSI_STRING Name,
IN PVOID Base, IN PVOID Base,
IN ULONG ProcessId IN ULONG_PTR ProcessId
);
VOID
NTAPI
DbgUnLoadImageSymbols(
IN PANSI_STRING Name,
IN PVOID Base,
IN ULONG_PTR ProcessId
); );
// //

View file

@ -7,6 +7,12 @@ KdDebuggerInitialize0(
IN PLOADER_PARAMETER_BLOCK LoaderBlock IN PLOADER_PARAMETER_BLOCK LoaderBlock
); );
NTSTATUS
NTAPI
KdDebuggerInitialize1(
IN PLOADER_PARAMETER_BLOCK LoaderBlock
);
ULONG ULONG
NTAPI NTAPI
KdReceivePacket( KdReceivePacket(

View file

@ -315,14 +315,14 @@ NTSTATUS
NTAPI NTAPI
DbgLoadImageSymbols(IN PANSI_STRING Name, DbgLoadImageSymbols(IN PANSI_STRING Name,
IN PVOID Base, IN PVOID Base,
IN ULONG ProcessId) IN ULONG_PTR ProcessId)
{ {
PIMAGE_NT_HEADERS NtHeader; PIMAGE_NT_HEADERS NtHeader;
KD_SYMBOLS_INFO SymbolInfo; KD_SYMBOLS_INFO SymbolInfo;
/* Setup the symbol data */ /* Setup the symbol data */
SymbolInfo.BaseOfDll = Base; SymbolInfo.BaseOfDll = Base;
SymbolInfo.ProcessId = UlongToPtr(ProcessId); SymbolInfo.ProcessId = ProcessId;
/* Get NT Headers */ /* Get NT Headers */
NtHeader = NULL; //RtlImageNtHeader(Base); NtHeader = NULL; //RtlImageNtHeader(Base);
@ -342,4 +342,25 @@ DbgLoadImageSymbols(IN PANSI_STRING Name,
DebugService2(Name, &SymbolInfo, BREAKPOINT_LOAD_SYMBOLS); DebugService2(Name, &SymbolInfo, BREAKPOINT_LOAD_SYMBOLS);
return STATUS_SUCCESS; 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 */ /* EOF */

View file

@ -1155,7 +1155,7 @@ Phase1InitializationDiscard(PVOID Context)
HalReportResourceUsage(); HalReportResourceUsage();
/* Call the debugger DLL once we have KD64 6.0 support */ /* Call the debugger DLL once we have KD64 6.0 support */
//KdDebuggerInitialize1(LoaderBlock); KdDebuggerInitialize1(LoaderBlock);
/* Setup PnP Manager in phase 1 */ /* Setup PnP Manager in phase 1 */
if (!PpInitSystem()) KeBugCheck(PP1_INITIALIZATION_FAILED); if (!PpInitSystem()) KeBugCheck(PP1_INITIALIZATION_FAILED);

View file

@ -427,13 +427,27 @@ KiDisplayBlueScreen(IN ULONG MessageId,
{ {
CHAR AnsiName[75]; 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 */ /* Check if this is a hard error */
if (IsHardError) if (IsHardError)
{ {
/* Display caption and message */ /* Display caption and message */
if (HardErrCaption) InbvDisplayString(HardErrCaption); if (HardErrCaption) InbvDisplayString(HardErrCaption);
if (HardErrMessage) InbvDisplayString(HardErrMessage); if (HardErrMessage) InbvDisplayString(HardErrMessage);
return;
} }
/* Begin the display */ /* Begin the display */
@ -514,7 +528,7 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
CONTEXT Context; CONTEXT Context;
ULONG MessageId; ULONG MessageId;
CHAR AnsiName[128]; CHAR AnsiName[128];
BOOLEAN IsSystem, IsHardError = FALSE; BOOLEAN IsSystem, IsHardError = FALSE, Reboot = FALSE;
PCHAR HardErrCaption = NULL, HardErrMessage = NULL; PCHAR HardErrCaption = NULL, HardErrMessage = NULL;
PVOID Eip = NULL, Memory; PVOID Eip = NULL, Memory;
PVOID DriverBase; PVOID DriverBase;
@ -543,9 +557,10 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
/* Capture the CPU Context */ /* Capture the CPU Context */
RtlCaptureContext(&Prcb->ProcessorState.ContextFrame); RtlCaptureContext(&Prcb->ProcessorState.ContextFrame);
KiSaveProcessorControlState(&Prcb->ProcessorState);
Context = Prcb->ProcessorState.ContextFrame; 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 */ /* Check which bugcode this is */
switch (BugCheckCode) switch (BugCheckCode)
@ -560,7 +575,6 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
case FAT_FILE_SYSTEM: case FAT_FILE_SYSTEM:
case NO_MORE_SYSTEM_PTES: case NO_MORE_SYSTEM_PTES:
case INACCESSIBLE_BOOT_DEVICE: case INACCESSIBLE_BOOT_DEVICE:
case KMODE_EXCEPTION_NOT_HANDLED:
/* Keep the same code */ /* Keep the same code */
MessageId = BugCheckCode; MessageId = BugCheckCode;
@ -568,33 +582,40 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
/* Check if this is a kernel-mode exception */ /* Check if this is a kernel-mode exception */
case KERNEL_MODE_EXCEPTION_NOT_HANDLED: case KERNEL_MODE_EXCEPTION_NOT_HANDLED:
//case SYSTEM_THREAD_EXCEPTION_NOT_HANDLED:
case KMODE_EXCEPTION_NOT_HANDLED:
/* Use the generic text message */ /* Use the generic text message */
MessageId = KMODE_EXCEPTION_NOT_HANDLED; MessageId = KMODE_EXCEPTION_NOT_HANDLED;
break;
/* File-system errors */ /* File-system errors */
case NTFS_FILE_SYSTEM: case NTFS_FILE_SYSTEM:
/* Use the generic message for FAT */ /* Use the generic message for FAT */
MessageId = FAT_FILE_SYSTEM; MessageId = FAT_FILE_SYSTEM;
break;
/* Check if this is a coruption of the Mm's Pool */ /* Check if this is a coruption of the Mm's Pool */
case DRIVER_CORRUPTED_MMPOOL: case DRIVER_CORRUPTED_MMPOOL:
/* Use generic corruption message */ /* Use generic corruption message */
MessageId = DRIVER_CORRUPTED_EXPOOL; MessageId = DRIVER_CORRUPTED_EXPOOL;
break;
/* Check if this is a signature check failure */ /* Check if this is a signature check failure */
case STATUS_SYSTEM_IMAGE_BAD_SIGNATURE: case STATUS_SYSTEM_IMAGE_BAD_SIGNATURE:
/* Use the generic corruption message */ /* Use the generic corruption message */
MessageId = BUGCODE_PSS_MESSAGE_SIGNATURE; MessageId = BUGCODE_PSS_MESSAGE_SIGNATURE;
break;
/* All other codes */ /* All other codes */
default: default:
/* Use the default bugcheck message */ /* Use the default bugcheck message */
MessageId = BUGCODE_PSS_MESSAGE; MessageId = BUGCODE_PSS_MESSAGE;
break;
} }
/* Save bugcheck data */ /* Save bugcheck data */
@ -721,9 +742,13 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
{ {
/* Get EIP */ /* Get EIP */
Eip = (PVOID)TrapFrame->Eip; Eip = (PVOID)TrapFrame->Eip;
KiBugCheckData[3] = (ULONG)Eip;
/* Find out if was in the kernel or drivers */ /* 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. * and update the bugcheck code appropriately.
*/ */
/* Check if we had a driver base */ /* Check if we didn't have a driver base */
if (DriverBase) if (!DriverBase)
{ {
/* Find the driver that unloaded at this address */ /* Find the driver that unloaded at this address */
KiBugCheckDriver = NULL; // FIXME: ROS can't locate KiBugCheckDriver = NULL; // FIXME: ROS can't locate
@ -757,10 +782,9 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
/* Check if the driver consumed too many PTEs */ /* Check if the driver consumed too many PTEs */
case DRIVER_USED_EXCESSIVE_PTES: case DRIVER_USED_EXCESSIVE_PTES:
/* Driver base is in parameter 1 */ /* Loader entry is in parameter 1 */
DriverBase = (PVOID)BugCheckParameter1; LdrEntry = (PVOID)BugCheckParameter1;
/* FIXME: LdrEntry is uninitialized for god's sake!!! KiBugCheckDriver = &LdrEntry->BaseDllName;
KiBugCheckDriver = &LdrEntry->BaseDllName; */
break; break;
/* Check if the driver has a stuck thread */ /* 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 */ /* Check if a debugger is connected */
if ((BugCheckCode != MANUALLY_INITIATED_CRASH) && (KdDebuggerEnabled)) if ((BugCheckCode != MANUALLY_INITIATED_CRASH) && (KdDebuggerEnabled))
@ -829,35 +854,13 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
/* Break in the debugger */ /* Break in the debugger */
KiBugCheckDebugBreak(DBG_STATUS_BUGCHECK_FIRST); 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 */ /* Raise IRQL to HIGH_LEVEL */
_disable(); _disable();
KeRaiseIrql(HIGH_LEVEL, &OldIrql); 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()) if (KernelAddressSpaceLock.Owner == KeGetCurrentThread())
{ {
MmUnlockAddressSpace(MmGetKernelAddressSpace()); MmUnlockAddressSpace(MmGetKernelAddressSpace());
@ -866,10 +869,10 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
/* Avoid recursion */ /* Avoid recursion */
if (!InterlockedDecrement((PLONG)&KeBugCheckCount)) if (!InterlockedDecrement((PLONG)&KeBugCheckCount))
{ {
#ifdef CONFIG_SMP
/* Set CPU that is bug checking now */ /* Set CPU that is bug checking now */
KeBugCheckOwner = Prcb->Number; KeBugCheckOwner = Prcb->Number;
#ifdef CONFIG_SMP
/* Freeze the other CPUs */ /* Freeze the other CPUs */
for (i = 0; i < KeNumberProcessors; i++) for (i = 0; i < KeNumberProcessors; i++)
{ {
@ -889,10 +892,17 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
HardErrMessage, HardErrMessage,
AnsiName); AnsiName);
/* FIXME: Enable debugger if it was pending */ /* Check if the debugger is disabled but we can enable it */
if (!(KdDebuggerEnabled) && !(KdPitchDebugger))
/* Print the last line */ {
/* Enable it */
KdEnableDebuggerWithLock(FALSE);
}
else
{
/* Otherwise, print the last line */
InbvDisplayString("\r\n"); InbvDisplayString("\r\n");
}
/* Save the context */ /* Save the context */
Prcb->ProcessorState.ContextFrame = Context; Prcb->ProcessorState.ContextFrame = Context;
@ -907,8 +917,9 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
KiBugCheckData[3], KiBugCheckData[3],
TrapFrame); TrapFrame);
} }
else
/* Increase recursioun count */ {
/* Increase recursion count */
KeBugCheckOwnerRecursionCount++; KeBugCheckOwnerRecursionCount++;
if (KeBugCheckOwnerRecursionCount == 2) if (KeBugCheckOwnerRecursionCount == 2)
{ {
@ -920,12 +931,21 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
/* Halt the CPU */ /* Halt the CPU */
for (;;) Ke386HaltProcessor(); for (;;) Ke386HaltProcessor();
} }
}
/* Call the Callbacks */ /* Call the Callbacks */
KiDoBugCheckCallbacks(); KiDoBugCheckCallbacks();
/* FIXME: Call Watchdog if enabled */ /* 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) */ /* Attempt to break in the debugger (otherwise halt CPU) */
KiBugCheckDebugBreak(DBG_STATUS_BUGCHECK_SECOND); KiBugCheckDebugBreak(DBG_STATUS_BUGCHECK_SECOND);
} }