2005-04-25 14:44:48 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: ntoskrnl/kd/kdio.c
|
|
|
|
* PURPOSE: NT Kernel Debugger Input/Output Functions
|
|
|
|
*
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
2011-07-27 13:07:32 +00:00
|
|
|
#include <reactos/buildno.h>
|
2020-04-06 21:48:01 +00:00
|
|
|
|
2016-10-06 19:01:33 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2005-04-25 14:44:48 +00:00
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
2009-10-07 19:57:40 +00:00
|
|
|
#define KdpBufferSize (1024 * 512)
|
2019-11-17 15:44:22 +00:00
|
|
|
static BOOLEAN KdpLoggingEnabled = FALSE;
|
2021-02-15 22:20:15 +00:00
|
|
|
static BOOLEAN KdpLoggingStarting = FALSE;
|
2019-11-17 15:44:22 +00:00
|
|
|
static PCHAR KdpDebugBuffer = NULL;
|
|
|
|
static volatile ULONG KdpCurrentPosition = 0;
|
|
|
|
static volatile ULONG KdpFreeBytes = 0;
|
|
|
|
static KSPIN_LOCK KdpDebugLogSpinLock;
|
|
|
|
static KEVENT KdpLoggerThreadEvent;
|
|
|
|
static HANDLE KdpLogFileHandle;
|
2011-11-21 05:28:08 +00:00
|
|
|
ANSI_STRING KdpLogFileName = RTL_CONSTANT_STRING("\\SystemRoot\\debug.log");
|
2021-02-15 22:20:15 +00:00
|
|
|
extern ULONG ExpInitializationPhase;
|
2005-04-25 14:44:48 +00:00
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
static KSPIN_LOCK KdpSerialSpinLock;
|
2013-05-07 00:14:36 +00:00
|
|
|
ULONG SerialPortNumber = DEFAULT_DEBUG_PORT;
|
|
|
|
CPPORT SerialPortInfo = {0, DEFAULT_DEBUG_BAUD_RATE, 0};
|
2005-04-25 14:44:48 +00:00
|
|
|
|
2013-04-04 19:29:36 +00:00
|
|
|
#define KdpScreenLineLengthDefault 80
|
2019-11-17 15:44:22 +00:00
|
|
|
static CHAR KdpScreenLineBuffer[KdpScreenLineLengthDefault + 1] = "";
|
|
|
|
static ULONG KdpScreenLineBufferPos = 0, KdpScreenLineLength = 0;
|
2011-06-21 19:47:13 +00:00
|
|
|
|
2011-07-07 19:18:16 +00:00
|
|
|
const ULONG KdpDmesgBufferSize = 128 * 1024; // 512*1024; // 5*1024*1024;
|
|
|
|
PCHAR KdpDmesgBuffer = NULL;
|
|
|
|
volatile ULONG KdpDmesgCurrentPosition = 0;
|
|
|
|
volatile ULONG KdpDmesgFreeBytes = 0;
|
|
|
|
volatile ULONG KdbDmesgTotalWritten = 0;
|
2011-07-07 19:50:52 +00:00
|
|
|
volatile BOOLEAN KdbpIsInDmesgMode = FALSE;
|
2019-11-17 15:44:22 +00:00
|
|
|
static KSPIN_LOCK KdpDmesgLogSpinLock;
|
2011-07-07 19:18:16 +00:00
|
|
|
|
2020-04-12 07:30:32 +00:00
|
|
|
KDP_DEBUG_MODE KdpDebugMode;
|
|
|
|
LIST_ENTRY KdProviders = {&KdProviders, &KdProviders};
|
|
|
|
KD_DISPATCH_TABLE DispatchTable[KdMax];
|
|
|
|
|
|
|
|
PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit,
|
|
|
|
KdpSerialInit,
|
|
|
|
KdpDebugLogInit,
|
|
|
|
KdpKdbgInit};
|
|
|
|
|
2020-04-09 12:31:47 +00:00
|
|
|
static ULONG KdbgNextApiNumber = DbgKdContinueApi;
|
|
|
|
static CONTEXT KdbgContext;
|
|
|
|
static EXCEPTION_RECORD64 KdbgExceptionRecord;
|
|
|
|
static BOOLEAN KdbgFirstChanceException;
|
|
|
|
static NTSTATUS KdbgContinueStatus = STATUS_SUCCESS;
|
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
/* LOCKING FUNCTIONS *********************************************************/
|
|
|
|
|
|
|
|
KIRQL
|
|
|
|
NTAPI
|
|
|
|
KdpAcquireLock(IN PKSPIN_LOCK SpinLock)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Acquire the spinlock without waiting at raised IRQL */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Loop until the spinlock becomes available */
|
|
|
|
while (!KeTestSpinLock(SpinLock));
|
|
|
|
|
|
|
|
/* Spinlock is free, raise IRQL to high level */
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &OldIrql);
|
|
|
|
|
|
|
|
/* Try to get the spinlock */
|
|
|
|
if (KeTryToAcquireSpinLockAtDpcLevel(SpinLock))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Someone else got the spinlock, lower IRQL back */
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OldIrql;
|
|
|
|
}
|
2005-04-25 14:44:48 +00:00
|
|
|
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2019-11-17 15:44:22 +00:00
|
|
|
KdpReleaseLock(IN PKSPIN_LOCK SpinLock,
|
|
|
|
IN KIRQL OldIrql)
|
|
|
|
{
|
|
|
|
/* Release the spinlock */
|
|
|
|
KiReleaseSpinLock(SpinLock);
|
|
|
|
// KeReleaseSpinLockFromDpcLevel(SpinLock);
|
|
|
|
|
|
|
|
/* Restore the old IRQL */
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FILE DEBUG LOG FUNCTIONS **************************************************/
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
NTAPI
|
2009-10-07 19:57:40 +00:00
|
|
|
KdpLoggerThread(PVOID Context)
|
2005-04-25 14:44:48 +00:00
|
|
|
{
|
2009-10-07 19:57:40 +00:00
|
|
|
ULONG beg, end, num;
|
2005-04-25 14:44:48 +00:00
|
|
|
IO_STATUS_BLOCK Iosb;
|
|
|
|
|
2020-11-12 00:22:46 +00:00
|
|
|
ASSERT(ExGetPreviousMode() == KernelMode);
|
|
|
|
|
2009-10-07 19:57:40 +00:00
|
|
|
KdpLoggingEnabled = TRUE;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2019-11-17 15:44:22 +00:00
|
|
|
KeWaitForSingleObject(&KdpLoggerThreadEvent, Executive, KernelMode, FALSE, NULL);
|
2009-10-07 19:57:40 +00:00
|
|
|
|
|
|
|
/* Bug */
|
2011-07-07 19:18:16 +00:00
|
|
|
/* Keep KdpCurrentPosition and KdpFreeBytes values in local
|
|
|
|
* variables to avoid their possible change from Producer part,
|
|
|
|
* KdpPrintToLogFile function
|
|
|
|
*/
|
2009-10-07 19:57:40 +00:00
|
|
|
end = KdpCurrentPosition;
|
|
|
|
num = KdpFreeBytes;
|
2011-07-07 19:18:16 +00:00
|
|
|
|
|
|
|
/* Now securely calculate values, based on local variables */
|
2009-10-07 19:57:40 +00:00
|
|
|
beg = (end + num) % KdpBufferSize;
|
|
|
|
num = KdpBufferSize - num;
|
|
|
|
|
|
|
|
/* Nothing to do? */
|
|
|
|
if (num == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (end > beg)
|
|
|
|
{
|
|
|
|
NtWriteFile(KdpLogFileHandle, NULL, NULL, NULL, &Iosb,
|
|
|
|
KdpDebugBuffer + beg, num, NULL, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NtWriteFile(KdpLogFileHandle, NULL, NULL, NULL, &Iosb,
|
|
|
|
KdpDebugBuffer + beg, KdpBufferSize - beg, NULL, NULL);
|
|
|
|
|
|
|
|
NtWriteFile(KdpLogFileHandle, NULL, NULL, NULL, &Iosb,
|
|
|
|
KdpDebugBuffer, end, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:04:17 +00:00
|
|
|
(VOID)InterlockedExchangeAddUL(&KdpFreeBytes, num);
|
2009-10-07 19:57:40 +00:00
|
|
|
}
|
2005-04-25 14:44:48 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
static VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2019-11-17 15:44:22 +00:00
|
|
|
KdpPrintToLogFile(PCHAR String,
|
2009-10-07 19:57:40 +00:00
|
|
|
ULONG StringLength)
|
2005-04-25 14:44:48 +00:00
|
|
|
{
|
2009-10-07 19:57:40 +00:00
|
|
|
KIRQL OldIrql;
|
2019-11-17 15:44:22 +00:00
|
|
|
ULONG beg, end, num;
|
2021-02-15 22:20:15 +00:00
|
|
|
BOOLEAN DoReinit = FALSE;
|
2009-10-07 19:57:40 +00:00
|
|
|
|
|
|
|
if (KdpDebugBuffer == NULL) return;
|
|
|
|
|
|
|
|
/* Acquire the printing spinlock without waiting at raised IRQL */
|
2019-11-17 15:44:22 +00:00
|
|
|
OldIrql = KdpAcquireLock(&KdpDebugLogSpinLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-07 19:57:40 +00:00
|
|
|
beg = KdpCurrentPosition;
|
|
|
|
num = KdpFreeBytes;
|
|
|
|
if (StringLength < num)
|
|
|
|
num = StringLength;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-07 19:57:40 +00:00
|
|
|
if (num != 0)
|
2005-07-26 15:15:18 +00:00
|
|
|
{
|
2009-10-07 19:57:40 +00:00
|
|
|
end = (beg + num) % KdpBufferSize;
|
|
|
|
KdpCurrentPosition = end;
|
|
|
|
KdpFreeBytes -= num;
|
|
|
|
|
|
|
|
if (end > beg)
|
|
|
|
{
|
|
|
|
RtlCopyMemory(KdpDebugBuffer + beg, String, num);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlCopyMemory(KdpDebugBuffer + beg, String, KdpBufferSize - beg);
|
|
|
|
RtlCopyMemory(KdpDebugBuffer, String + KdpBufferSize - beg, end);
|
|
|
|
}
|
2005-07-26 15:15:18 +00:00
|
|
|
}
|
2009-10-07 19:57:40 +00:00
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
/* Release the spinlock */
|
2021-02-15 22:20:15 +00:00
|
|
|
if (OldIrql == PASSIVE_LEVEL && !KdpLoggingStarting && !KdpLoggingEnabled && ExpInitializationPhase >= 2)
|
|
|
|
{
|
|
|
|
DoReinit = TRUE;
|
|
|
|
}
|
2019-11-17 15:44:22 +00:00
|
|
|
KdpReleaseLock(&KdpDebugLogSpinLock, OldIrql);
|
2009-10-07 19:57:40 +00:00
|
|
|
|
2021-02-15 22:20:15 +00:00
|
|
|
if (DoReinit)
|
|
|
|
{
|
|
|
|
KdpLoggingStarting = TRUE;
|
|
|
|
KdpDebugLogInit(NULL, 3);
|
|
|
|
}
|
|
|
|
|
2009-10-07 19:57:40 +00:00
|
|
|
/* Signal the logger thread */
|
|
|
|
if (OldIrql <= DISPATCH_LEVEL && KdpLoggingEnabled)
|
2019-11-17 15:44:22 +00:00
|
|
|
KeSetEvent(&KdpLoggerThreadEvent, IO_NO_INCREMENT, FALSE);
|
2005-04-25 14:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2019-11-17 15:44:22 +00:00
|
|
|
KdpDebugLogInit(PKD_DISPATCH_TABLE DispatchTable,
|
2005-04-25 14:44:48 +00:00
|
|
|
ULONG BootPhase)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING FileName;
|
2009-10-07 19:57:40 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
2005-05-09 01:38:29 +00:00
|
|
|
IO_STATUS_BLOCK Iosb;
|
2009-10-07 19:57:40 +00:00
|
|
|
HANDLE ThreadHandle;
|
|
|
|
KPRIORITY Priority;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-07-30 16:25:35 +00:00
|
|
|
if (!KdpDebugMode.File) return;
|
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
if (BootPhase == 0)
|
|
|
|
{
|
2009-01-19 23:22:22 +00:00
|
|
|
KdComPortInUse = NULL;
|
2006-06-22 21:26:31 +00:00
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
/* Write out the functions that we support for now */
|
2019-11-17 15:44:22 +00:00
|
|
|
DispatchTable->KdpInitRoutine = KdpDebugLogInit;
|
2009-10-07 19:57:40 +00:00
|
|
|
DispatchTable->KdpPrintRoutine = KdpPrintToLogFile;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
/* Register as a Provider */
|
|
|
|
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
|
2009-10-07 19:57:40 +00:00
|
|
|
}
|
|
|
|
else if (BootPhase == 1)
|
|
|
|
{
|
|
|
|
/* Allocate a buffer for debug log */
|
|
|
|
KdpDebugBuffer = ExAllocatePool(NonPagedPool, KdpBufferSize);
|
|
|
|
KdpFreeBytes = KdpBufferSize;
|
|
|
|
|
|
|
|
/* Initialize spinlock */
|
|
|
|
KeInitializeSpinLock(&KdpDebugLogSpinLock);
|
2021-02-15 22:20:15 +00:00
|
|
|
|
2013-10-13 23:04:13 +00:00
|
|
|
HalDisplayString("\r\n File log debugging enabled\r\n\r\n");
|
2005-04-25 14:44:48 +00:00
|
|
|
}
|
|
|
|
else if (BootPhase == 3)
|
|
|
|
{
|
2009-10-07 19:57:40 +00:00
|
|
|
/* Setup the log name */
|
2011-11-21 05:28:08 +00:00
|
|
|
Status = RtlAnsiStringToUnicodeString(&FileName, &KdpLogFileName, TRUE);
|
|
|
|
if (!NT_SUCCESS(Status)) return;
|
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&FileName,
|
2019-11-17 15:44:22 +00:00
|
|
|
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
2005-04-25 14:44:48 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-07 19:57:40 +00:00
|
|
|
/* Create the log file */
|
2021-02-26 07:44:51 +00:00
|
|
|
Status = ZwCreateFile(&KdpLogFileHandle,
|
2009-10-07 19:57:40 +00:00
|
|
|
FILE_APPEND_DATA | SYNCHRONIZE,
|
2005-04-25 14:44:48 +00:00
|
|
|
&ObjectAttributes,
|
|
|
|
&Iosb,
|
|
|
|
NULL,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
FILE_SUPERSEDE,
|
|
|
|
FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT,
|
|
|
|
NULL,
|
|
|
|
0);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2011-11-21 05:28:08 +00:00
|
|
|
RtlFreeUnicodeString(&FileName);
|
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2021-02-26 07:44:51 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Failed to open log file: 0x%08x\n", Status);
|
2019-11-17 15:44:22 +00:00
|
|
|
return;
|
2021-02-26 07:44:51 +00:00
|
|
|
}
|
2009-10-07 19:57:40 +00:00
|
|
|
|
|
|
|
KeInitializeEvent(&KdpLoggerThreadEvent, SynchronizationEvent, TRUE);
|
|
|
|
|
|
|
|
/* Create the logger thread */
|
|
|
|
Status = PsCreateSystemThread(&ThreadHandle,
|
|
|
|
THREAD_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
KdpLoggerThread,
|
|
|
|
NULL);
|
2019-11-17 15:44:22 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2021-02-26 07:44:51 +00:00
|
|
|
ZwClose(KdpLogFileHandle);
|
2019-11-17 15:44:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-07 19:57:40 +00:00
|
|
|
|
|
|
|
Priority = 7;
|
2021-02-26 07:44:51 +00:00
|
|
|
ZwSetInformationThread(ThreadHandle,
|
2009-10-07 19:57:40 +00:00
|
|
|
ThreadPriority,
|
|
|
|
&Priority,
|
|
|
|
sizeof(Priority));
|
2020-11-12 00:22:46 +00:00
|
|
|
|
|
|
|
ZwClose(ThreadHandle);
|
2005-04-25 14:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SERIAL FUNCTIONS **********************************************************/
|
|
|
|
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2019-11-17 15:44:22 +00:00
|
|
|
KdpSerialDebugPrint(PCHAR Message,
|
- More sharing between ntdll/ntoskrnl: shared Dbg code.
- Added NtCreateDebugObject, NtDebugContinue, NtQueryDebugFilterState, NtSetDebugFilterState, NtWaitForDebugEvent to system call list.
- Added some debug constants to headers
- Updated RtlpCheckForActiveDebugger in ntoskrnl to return whatever we're expecting as the "normal" case.
- Added RtlpSetInDbgPrint to rtl support library for special DbgPrint implementation difference in user-mode
- Removed all the deprecated debug APIs in ntdll.
- Implemented NtQueryDebugFilterState and NtSetDebugFilterState based on royce's implementation.
- Started modifications on KeDebugService, and implemented DebugService in rtl
- Implemented all the Dbg* APIs in RTL.
- Implemented DbgUiConnectToDbg, DbgUiContinue, DbgUiWaitStateChange, DbgUiRemoteBreakin, DbgUiIssueRemoteBreakin
- Changed KD Print callbacks to also receive the length of the string.
Right now, one call that should be shared still isn't (the final DebugPrint call) because calling KeDebugService from kernel-mode seems to cause a hang. Also, DebugService does not currently cause an exception like it should (instead it still calls the Kdp handler), because those changes would've made the patch even bigger and are still untested.
svn path=/trunk/; revision=18078
2005-09-26 04:59:48 +00:00
|
|
|
ULONG Length)
|
2005-04-25 14:44:48 +00:00
|
|
|
{
|
2019-11-17 15:44:22 +00:00
|
|
|
PCHAR pch = (PCHAR)Message;
|
2009-03-29 13:15:03 +00:00
|
|
|
KIRQL OldIrql;
|
2005-04-25 14:44:48 +00:00
|
|
|
|
2009-03-29 13:15:03 +00:00
|
|
|
/* Acquire the printing spinlock without waiting at raised IRQL */
|
2019-11-17 15:44:22 +00:00
|
|
|
OldIrql = KdpAcquireLock(&KdpSerialSpinLock);
|
2009-03-29 13:15:03 +00:00
|
|
|
|
|
|
|
/* Output the message */
|
2017-12-12 11:38:45 +00:00
|
|
|
while (pch < Message + Length && *pch != '\0')
|
2005-04-25 14:44:48 +00:00
|
|
|
{
|
|
|
|
if (*pch == '\n')
|
|
|
|
{
|
|
|
|
KdPortPutByteEx(&SerialPortInfo, '\r');
|
|
|
|
}
|
|
|
|
KdPortPutByteEx(&SerialPortInfo, *pch);
|
|
|
|
pch++;
|
|
|
|
}
|
2009-03-29 13:15:03 +00:00
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
/* Release the spinlock */
|
|
|
|
KdpReleaseLock(&KdpSerialSpinLock, OldIrql);
|
2005-04-25 14:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2005-04-25 14:44:48 +00:00
|
|
|
KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable,
|
|
|
|
ULONG BootPhase)
|
|
|
|
{
|
|
|
|
if (!KdpDebugMode.Serial) return;
|
|
|
|
|
|
|
|
if (BootPhase == 0)
|
|
|
|
{
|
|
|
|
/* Write out the functions that we support for now */
|
|
|
|
DispatchTable->KdpInitRoutine = KdpSerialInit;
|
|
|
|
DispatchTable->KdpPrintRoutine = KdpSerialDebugPrint;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
/* Initialize the Port */
|
2013-05-07 00:14:36 +00:00
|
|
|
if (!KdPortInitializeEx(&SerialPortInfo, SerialPortNumber))
|
2005-10-02 09:42:12 +00:00
|
|
|
{
|
|
|
|
KdpDebugMode.Serial = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2013-05-07 00:14:36 +00:00
|
|
|
KdComPortInUse = SerialPortInfo.Address;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-03-29 13:15:03 +00:00
|
|
|
/* Initialize spinlock */
|
|
|
|
KeInitializeSpinLock(&KdpSerialSpinLock);
|
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
/* Register as a Provider */
|
|
|
|
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
|
|
|
|
}
|
2021-02-15 22:20:15 +00:00
|
|
|
else if (BootPhase == 1)
|
2005-04-25 14:44:48 +00:00
|
|
|
{
|
2013-10-13 23:04:13 +00:00
|
|
|
HalDisplayString("\r\n Serial debugging enabled\r\n\r\n");
|
2005-05-09 01:38:29 +00:00
|
|
|
}
|
2005-04-25 14:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SCREEN FUNCTIONS **********************************************************/
|
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
VOID
|
|
|
|
KdpScreenAcquire(VOID)
|
|
|
|
{
|
|
|
|
if (InbvIsBootDriverInstalled() /* &&
|
|
|
|
!InbvCheckDisplayOwnership() */)
|
|
|
|
{
|
|
|
|
/* Acquire ownership and reset the display */
|
|
|
|
InbvAcquireDisplayOwnership();
|
|
|
|
InbvResetDisplay();
|
2020-05-09 14:20:57 +00:00
|
|
|
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_BLACK);
|
|
|
|
InbvSetTextColor(BV_COLOR_WHITE);
|
2019-11-17 15:44:22 +00:00
|
|
|
InbvInstallDisplayStringFilter(NULL);
|
|
|
|
InbvEnableDisplayString(TRUE);
|
2020-04-06 21:48:01 +00:00
|
|
|
InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
|
2019-11-17 15:44:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-26 16:19:11 +00:00
|
|
|
// extern VOID NTAPI InbvSetDisplayOwnership(IN BOOLEAN DisplayOwned);
|
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
VOID
|
|
|
|
KdpScreenRelease(VOID)
|
|
|
|
{
|
|
|
|
if (InbvIsBootDriverInstalled()&&
|
|
|
|
InbvCheckDisplayOwnership())
|
|
|
|
{
|
|
|
|
/* Release the display */
|
2019-12-26 16:19:11 +00:00
|
|
|
// InbvSetDisplayOwnership(FALSE);
|
2019-11-17 15:44:22 +00:00
|
|
|
InbvNotifyDisplayOwnershipLost(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-07 19:18:16 +00:00
|
|
|
/*
|
|
|
|
* Screen debug logger function KdpScreenPrint() writes text messages into
|
|
|
|
* KdpDmesgBuffer, using it as a circular buffer. KdpDmesgBuffer contents could
|
|
|
|
* be later (re)viewed using dmesg command of kdbg. KdpScreenPrint() protects
|
|
|
|
* KdpDmesgBuffer from simultaneous writes by use of KdpDmesgLogSpinLock.
|
|
|
|
*/
|
2019-11-17 15:44:22 +00:00
|
|
|
static VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2019-11-17 15:44:22 +00:00
|
|
|
KdpScreenPrint(PCHAR Message,
|
- More sharing between ntdll/ntoskrnl: shared Dbg code.
- Added NtCreateDebugObject, NtDebugContinue, NtQueryDebugFilterState, NtSetDebugFilterState, NtWaitForDebugEvent to system call list.
- Added some debug constants to headers
- Updated RtlpCheckForActiveDebugger in ntoskrnl to return whatever we're expecting as the "normal" case.
- Added RtlpSetInDbgPrint to rtl support library for special DbgPrint implementation difference in user-mode
- Removed all the deprecated debug APIs in ntdll.
- Implemented NtQueryDebugFilterState and NtSetDebugFilterState based on royce's implementation.
- Started modifications on KeDebugService, and implemented DebugService in rtl
- Implemented all the Dbg* APIs in RTL.
- Implemented DbgUiConnectToDbg, DbgUiContinue, DbgUiWaitStateChange, DbgUiRemoteBreakin, DbgUiIssueRemoteBreakin
- Changed KD Print callbacks to also receive the length of the string.
Right now, one call that should be shared still isn't (the final DebugPrint call) because calling KeDebugService from kernel-mode seems to cause a hang. Also, DebugService does not currently cause an exception like it should (instead it still calls the Kdp handler), because those changes would've made the patch even bigger and are still untested.
svn path=/trunk/; revision=18078
2005-09-26 04:59:48 +00:00
|
|
|
ULONG Length)
|
|
|
|
{
|
2019-11-17 15:44:22 +00:00
|
|
|
PCHAR pch = (PCHAR)Message;
|
2011-07-07 19:18:16 +00:00
|
|
|
KIRQL OldIrql;
|
2019-11-17 15:44:22 +00:00
|
|
|
ULONG beg, end, num;
|
2011-06-21 19:47:13 +00:00
|
|
|
|
2017-12-12 11:38:45 +00:00
|
|
|
while (pch < Message + Length && *pch)
|
2011-06-21 19:47:13 +00:00
|
|
|
{
|
2019-11-17 15:44:22 +00:00
|
|
|
if (*pch == '\b')
|
2011-06-21 19:47:13 +00:00
|
|
|
{
|
|
|
|
/* HalDisplayString does not support '\b'. Workaround it and use '\r' */
|
2019-11-17 15:44:22 +00:00
|
|
|
if (KdpScreenLineLength > 0)
|
2011-06-21 19:47:13 +00:00
|
|
|
{
|
|
|
|
/* Remove last character from buffer */
|
|
|
|
KdpScreenLineBuffer[--KdpScreenLineLength] = '\0';
|
|
|
|
KdpScreenLineBufferPos = KdpScreenLineLength;
|
|
|
|
|
|
|
|
/* Clear row and print line again */
|
|
|
|
HalDisplayString("\r");
|
|
|
|
HalDisplayString(KdpScreenLineBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
KdpScreenLineBuffer[KdpScreenLineLength++] = *pch;
|
|
|
|
KdpScreenLineBuffer[KdpScreenLineLength] = '\0';
|
|
|
|
}
|
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
if (*pch == '\n' || KdpScreenLineLength == KdpScreenLineLengthDefault)
|
2011-06-21 19:47:13 +00:00
|
|
|
{
|
|
|
|
/* Print buffered characters */
|
2019-11-17 15:44:22 +00:00
|
|
|
if (KdpScreenLineBufferPos != KdpScreenLineLength)
|
2011-06-21 19:47:13 +00:00
|
|
|
HalDisplayString(KdpScreenLineBuffer + KdpScreenLineBufferPos);
|
|
|
|
|
|
|
|
/* Clear line buffer */
|
|
|
|
KdpScreenLineBuffer[0] = '\0';
|
|
|
|
KdpScreenLineLength = KdpScreenLineBufferPos = 0;
|
|
|
|
}
|
2011-07-07 19:18:16 +00:00
|
|
|
|
2011-06-21 19:47:13 +00:00
|
|
|
++pch;
|
|
|
|
}
|
2011-07-07 19:18:16 +00:00
|
|
|
|
2011-06-21 19:47:13 +00:00
|
|
|
/* Print buffered characters */
|
2019-11-17 15:44:22 +00:00
|
|
|
if (KdpScreenLineBufferPos != KdpScreenLineLength)
|
2011-06-21 19:47:13 +00:00
|
|
|
{
|
|
|
|
HalDisplayString(KdpScreenLineBuffer + KdpScreenLineBufferPos);
|
|
|
|
KdpScreenLineBufferPos = KdpScreenLineLength;
|
|
|
|
}
|
2011-07-07 19:18:16 +00:00
|
|
|
|
|
|
|
/* Dmesg: store Message in the buffer to show it later */
|
|
|
|
if (KdbpIsInDmesgMode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (KdpDmesgBuffer == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Acquire the printing spinlock without waiting at raised IRQL */
|
2019-11-17 15:44:22 +00:00
|
|
|
OldIrql = KdpAcquireLock(&KdpDmesgLogSpinLock);
|
2011-07-07 19:18:16 +00:00
|
|
|
|
|
|
|
/* Invariant: always_true(KdpDmesgFreeBytes == KdpDmesgBufferSize);
|
|
|
|
* set num to min(KdpDmesgFreeBytes, Length).
|
|
|
|
*/
|
2012-09-19 06:09:22 +00:00
|
|
|
num = (Length < KdpDmesgFreeBytes) ? Length : KdpDmesgFreeBytes;
|
2011-07-07 19:18:16 +00:00
|
|
|
beg = KdpDmesgCurrentPosition;
|
|
|
|
if (num != 0)
|
|
|
|
{
|
|
|
|
end = (beg + num) % KdpDmesgBufferSize;
|
|
|
|
if (end > beg)
|
|
|
|
{
|
|
|
|
RtlCopyMemory(KdpDmesgBuffer + beg, Message, Length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlCopyMemory(KdpDmesgBuffer + beg, Message, KdpDmesgBufferSize - beg);
|
|
|
|
RtlCopyMemory(KdpDmesgBuffer, Message + (KdpDmesgBufferSize - beg), end);
|
|
|
|
}
|
|
|
|
KdpDmesgCurrentPosition = end;
|
|
|
|
|
|
|
|
/* Counting the total bytes written */
|
|
|
|
KdbDmesgTotalWritten += num;
|
|
|
|
}
|
|
|
|
|
2019-11-17 15:44:22 +00:00
|
|
|
/* Release the spinlock */
|
|
|
|
KdpReleaseLock(&KdpDmesgLogSpinLock, OldIrql);
|
2011-07-07 19:18:16 +00:00
|
|
|
|
|
|
|
/* Optional step(?): find out a way to notify about buffer exhaustion,
|
|
|
|
* and possibly fall into kbd to use dmesg command: user will read
|
|
|
|
* debug messages before they will be wiped over by next writes.
|
|
|
|
*/
|
- More sharing between ntdll/ntoskrnl: shared Dbg code.
- Added NtCreateDebugObject, NtDebugContinue, NtQueryDebugFilterState, NtSetDebugFilterState, NtWaitForDebugEvent to system call list.
- Added some debug constants to headers
- Updated RtlpCheckForActiveDebugger in ntoskrnl to return whatever we're expecting as the "normal" case.
- Added RtlpSetInDbgPrint to rtl support library for special DbgPrint implementation difference in user-mode
- Removed all the deprecated debug APIs in ntdll.
- Implemented NtQueryDebugFilterState and NtSetDebugFilterState based on royce's implementation.
- Started modifications on KeDebugService, and implemented DebugService in rtl
- Implemented all the Dbg* APIs in RTL.
- Implemented DbgUiConnectToDbg, DbgUiContinue, DbgUiWaitStateChange, DbgUiRemoteBreakin, DbgUiIssueRemoteBreakin
- Changed KD Print callbacks to also receive the length of the string.
Right now, one call that should be shared still isn't (the final DebugPrint call) because calling KeDebugService from kernel-mode seems to cause a hang. Also, DebugService does not currently cause an exception like it should (instead it still calls the Kdp handler), because those changes would've made the patch even bigger and are still untested.
svn path=/trunk/; revision=18078
2005-09-26 04:59:48 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2005-04-25 14:44:48 +00:00
|
|
|
KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable,
|
|
|
|
ULONG BootPhase)
|
|
|
|
{
|
|
|
|
if (!KdpDebugMode.Screen) return;
|
|
|
|
|
|
|
|
if (BootPhase == 0)
|
|
|
|
{
|
|
|
|
/* Write out the functions that we support for now */
|
|
|
|
DispatchTable->KdpInitRoutine = KdpScreenInit;
|
- More sharing between ntdll/ntoskrnl: shared Dbg code.
- Added NtCreateDebugObject, NtDebugContinue, NtQueryDebugFilterState, NtSetDebugFilterState, NtWaitForDebugEvent to system call list.
- Added some debug constants to headers
- Updated RtlpCheckForActiveDebugger in ntoskrnl to return whatever we're expecting as the "normal" case.
- Added RtlpSetInDbgPrint to rtl support library for special DbgPrint implementation difference in user-mode
- Removed all the deprecated debug APIs in ntdll.
- Implemented NtQueryDebugFilterState and NtSetDebugFilterState based on royce's implementation.
- Started modifications on KeDebugService, and implemented DebugService in rtl
- Implemented all the Dbg* APIs in RTL.
- Implemented DbgUiConnectToDbg, DbgUiContinue, DbgUiWaitStateChange, DbgUiRemoteBreakin, DbgUiIssueRemoteBreakin
- Changed KD Print callbacks to also receive the length of the string.
Right now, one call that should be shared still isn't (the final DebugPrint call) because calling KeDebugService from kernel-mode seems to cause a hang. Also, DebugService does not currently cause an exception like it should (instead it still calls the Kdp handler), because those changes would've made the patch even bigger and are still untested.
svn path=/trunk/; revision=18078
2005-09-26 04:59:48 +00:00
|
|
|
DispatchTable->KdpPrintRoutine = KdpScreenPrint;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
/* Register as a Provider */
|
|
|
|
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
|
|
|
|
}
|
2011-07-07 19:18:16 +00:00
|
|
|
else if (BootPhase == 1)
|
|
|
|
{
|
2012-09-19 06:09:22 +00:00
|
|
|
/* Allocate a buffer for dmesg log buffer. +1 for terminating null,
|
|
|
|
* see kdbp_cli.c:KdbpCmdDmesg()/2
|
|
|
|
*/
|
|
|
|
KdpDmesgBuffer = ExAllocatePool(NonPagedPool, KdpDmesgBufferSize + 1);
|
|
|
|
RtlZeroMemory(KdpDmesgBuffer, KdpDmesgBufferSize + 1);
|
|
|
|
KdpDmesgFreeBytes = KdpDmesgBufferSize;
|
|
|
|
KdbDmesgTotalWritten = 0;
|
|
|
|
|
|
|
|
/* Take control of the display */
|
2019-11-17 15:44:22 +00:00
|
|
|
KdpScreenAcquire();
|
2012-09-19 06:09:22 +00:00
|
|
|
|
|
|
|
/* Initialize spinlock */
|
|
|
|
KeInitializeSpinLock(&KdpDmesgLogSpinLock);
|
2021-02-15 22:20:15 +00:00
|
|
|
|
2013-10-13 23:04:13 +00:00
|
|
|
HalDisplayString("\r\n Screen debugging enabled\r\n\r\n");
|
2005-05-09 01:38:29 +00:00
|
|
|
}
|
2005-04-25 14:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* GENERAL FUNCTIONS *********************************************************/
|
|
|
|
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
BOOLEAN
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2017-12-08 13:41:41 +00:00
|
|
|
KdpPrintString(
|
2020-03-07 22:33:57 +00:00
|
|
|
_In_ PSTRING Output);
|
2005-11-21 18:38:09 +00:00
|
|
|
|
2020-03-07 22:33:57 +00:00
|
|
|
extern STRING KdbPromptString;
|
2017-12-08 13:41:41 +00:00
|
|
|
|
2020-03-07 22:33:57 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KdSendPacket(
|
|
|
|
IN ULONG PacketType,
|
|
|
|
IN PSTRING MessageHeader,
|
|
|
|
IN PSTRING MessageData,
|
|
|
|
IN OUT PKD_CONTEXT Context)
|
|
|
|
{
|
|
|
|
if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
|
2005-04-25 14:44:48 +00:00
|
|
|
{
|
2020-03-07 22:33:57 +00:00
|
|
|
PSTRING Output = MessageData;
|
|
|
|
PLIST_ENTRY CurrentEntry;
|
|
|
|
PKD_DISPATCH_TABLE CurrentTable;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2020-03-07 22:33:57 +00:00
|
|
|
if (!KdpDebugMode.Value) return;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2020-03-07 22:33:57 +00:00
|
|
|
/* Call the registered handlers */
|
|
|
|
CurrentEntry = KdProviders.Flink;
|
|
|
|
while (CurrentEntry != &KdProviders)
|
|
|
|
{
|
|
|
|
/* Get the current table */
|
|
|
|
CurrentTable = CONTAINING_RECORD(CurrentEntry,
|
|
|
|
KD_DISPATCH_TABLE,
|
|
|
|
KdProvidersList);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2020-03-07 22:33:57 +00:00
|
|
|
/* Call it */
|
|
|
|
CurrentTable->KdpPrintRoutine(Output->Buffer, Output->Length);
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
|
2020-03-07 22:33:57 +00:00
|
|
|
/* Next Table */
|
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-03-09 23:00:00 +00:00
|
|
|
else if (PacketType == PACKET_TYPE_KD_STATE_CHANGE64)
|
|
|
|
{
|
|
|
|
PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange = (PDBGKD_ANY_WAIT_STATE_CHANGE)MessageHeader->Buffer;
|
|
|
|
if (WaitStateChange->NewState == DbgKdLoadSymbolsStateChange)
|
|
|
|
{
|
|
|
|
#ifdef KDBG
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
2021-06-22 17:46:27 +00:00
|
|
|
/* Load symbols. Currently implemented only for KDBG! */
|
|
|
|
if (KdbpSymFindModule((PVOID)(ULONG_PTR)WaitStateChange->u.LoadSymbols.BaseOfDll, -1, &LdrEntry))
|
2020-03-09 23:00:00 +00:00
|
|
|
{
|
2021-06-22 17:46:27 +00:00
|
|
|
KdbSymProcessSymbols(LdrEntry, !WaitStateChange->u.LoadSymbols.UnloadSymbols);
|
2020-03-09 23:00:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2020-04-09 12:31:47 +00:00
|
|
|
else if (WaitStateChange->NewState == DbgKdExceptionStateChange)
|
|
|
|
{
|
|
|
|
KdbgNextApiNumber = DbgKdGetContextApi;
|
|
|
|
KdbgExceptionRecord = WaitStateChange->u.Exception.ExceptionRecord;
|
|
|
|
KdbgFirstChanceException = WaitStateChange->u.Exception.FirstChance;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (PacketType == PACKET_TYPE_KD_STATE_MANIPULATE)
|
|
|
|
{
|
|
|
|
PDBGKD_MANIPULATE_STATE64 ManipulateState = (PDBGKD_MANIPULATE_STATE64)MessageHeader->Buffer;
|
|
|
|
if (ManipulateState->ApiNumber == DbgKdGetContextApi)
|
|
|
|
{
|
|
|
|
KD_CONTINUE_TYPE Result;
|
|
|
|
|
|
|
|
#ifdef KDBG
|
|
|
|
/* Check if this is an assertion failure */
|
|
|
|
if (KdbgExceptionRecord.ExceptionCode == STATUS_ASSERTION_FAILURE)
|
|
|
|
{
|
|
|
|
/* Bump EIP to the instruction following the int 2C */
|
2021-04-27 08:23:37 +00:00
|
|
|
KeSetContextPc(&KdbgContext, KeGetContextPc(&KdbgContext) + 2);
|
2020-04-09 12:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result = KdbEnterDebuggerException(&KdbgExceptionRecord,
|
2020-11-22 17:13:51 +00:00
|
|
|
KdbgContext.SegCs & 1,
|
2020-04-09 12:31:47 +00:00
|
|
|
&KdbgContext,
|
|
|
|
KdbgFirstChanceException);
|
|
|
|
#else
|
|
|
|
/* We'll manually dump the stack for the user... */
|
|
|
|
KeRosDumpStackFrames(NULL, 0);
|
|
|
|
Result = kdHandleException;
|
|
|
|
#endif
|
|
|
|
if (Result != kdHandleException)
|
|
|
|
KdbgContinueStatus = STATUS_SUCCESS;
|
|
|
|
else
|
|
|
|
KdbgContinueStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
KdbgNextApiNumber = DbgKdSetContextApi;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (ManipulateState->ApiNumber == DbgKdSetContextApi)
|
|
|
|
{
|
|
|
|
KdbgNextApiNumber = DbgKdContinueApi;
|
|
|
|
return;
|
|
|
|
}
|
2020-03-09 23:00:00 +00:00
|
|
|
}
|
2020-03-07 22:33:57 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
KDSTATUS
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
NTAPI
|
2020-03-07 22:33:57 +00:00
|
|
|
KdReceivePacket(
|
|
|
|
IN ULONG PacketType,
|
|
|
|
OUT PSTRING MessageHeader,
|
|
|
|
OUT PSTRING MessageData,
|
|
|
|
OUT PULONG DataLength,
|
|
|
|
IN OUT PKD_CONTEXT Context)
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
{
|
2020-03-28 23:30:53 +00:00
|
|
|
#ifdef KDBG
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
KIRQL OldIrql;
|
|
|
|
STRING StringChar;
|
|
|
|
CHAR Response;
|
|
|
|
USHORT i;
|
|
|
|
ULONG DummyScanCode;
|
2020-03-07 22:33:57 +00:00
|
|
|
CHAR MessageBuffer[100];
|
|
|
|
STRING ResponseString;
|
|
|
|
#endif
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
|
2020-03-09 23:00:00 +00:00
|
|
|
if (PacketType == PACKET_TYPE_KD_STATE_MANIPULATE)
|
|
|
|
{
|
|
|
|
PDBGKD_MANIPULATE_STATE64 ManipulateState = (PDBGKD_MANIPULATE_STATE64)MessageHeader->Buffer;
|
2020-04-09 12:31:47 +00:00
|
|
|
RtlZeroMemory(MessageHeader->Buffer, MessageHeader->MaximumLength);
|
|
|
|
if (KdbgNextApiNumber == DbgKdGetContextApi)
|
|
|
|
{
|
|
|
|
ManipulateState->ApiNumber = DbgKdGetContextApi;
|
|
|
|
MessageData->Length = 0;
|
|
|
|
MessageData->Buffer = (PCHAR)&KdbgContext;
|
|
|
|
return KdPacketReceived;
|
|
|
|
}
|
|
|
|
else if (KdbgNextApiNumber == DbgKdSetContextApi)
|
|
|
|
{
|
|
|
|
ManipulateState->ApiNumber = DbgKdSetContextApi;
|
|
|
|
MessageData->Length = sizeof(KdbgContext);
|
|
|
|
MessageData->Buffer = (PCHAR)&KdbgContext;
|
|
|
|
return KdPacketReceived;
|
|
|
|
}
|
|
|
|
else if (KdbgNextApiNumber != DbgKdContinueApi)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
}
|
2020-03-09 23:00:00 +00:00
|
|
|
ManipulateState->ApiNumber = DbgKdContinueApi;
|
2020-04-09 12:31:47 +00:00
|
|
|
ManipulateState->u.Continue.ContinueStatus = KdbgContinueStatus;
|
|
|
|
|
|
|
|
/* Prepare for next time */
|
|
|
|
KdbgNextApiNumber = DbgKdContinueApi;
|
|
|
|
KdbgContinueStatus = STATUS_SUCCESS;
|
|
|
|
|
2020-03-09 23:00:00 +00:00
|
|
|
return KdPacketReceived;
|
|
|
|
}
|
|
|
|
|
2020-03-07 22:33:57 +00:00
|
|
|
if (PacketType != PACKET_TYPE_KD_DEBUG_IO)
|
|
|
|
return KdPacketTimedOut;
|
|
|
|
|
|
|
|
#ifdef KDBG
|
|
|
|
ResponseString.Buffer = MessageBuffer;
|
|
|
|
ResponseString.Length = 0;
|
|
|
|
ResponseString.MaximumLength = min(sizeof(MessageBuffer), MessageData->MaximumLength);
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
StringChar.Buffer = &Response;
|
|
|
|
StringChar.Length = StringChar.MaximumLength = sizeof(Response);
|
|
|
|
|
|
|
|
/* Display the string and print a new line for log neatness */
|
|
|
|
*StringChar.Buffer = '\n';
|
|
|
|
KdpPrintString(&StringChar);
|
|
|
|
|
|
|
|
/* Print the kdb prompt */
|
|
|
|
KdpPrintString(&KdbPromptString);
|
|
|
|
|
|
|
|
// TODO: Use an improved KdbpReadCommand() function for our purposes.
|
|
|
|
|
|
|
|
/* Acquire the printing spinlock without waiting at raised IRQL */
|
|
|
|
OldIrql = KdpAcquireLock(&KdpSerialSpinLock);
|
|
|
|
|
2019-12-26 16:19:11 +00:00
|
|
|
if (!(KdbDebugState & KD_DEBUG_KDSERIAL))
|
|
|
|
KbdDisableMouse();
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
|
|
|
|
/* Loop the whole string */
|
2020-03-07 22:33:57 +00:00
|
|
|
for (i = 0; i < ResponseString.MaximumLength; i++)
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
{
|
|
|
|
/* Check if this is serial debugging mode */
|
|
|
|
if (KdbDebugState & KD_DEBUG_KDSERIAL)
|
|
|
|
{
|
|
|
|
/* Get the character from serial */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Response = KdbpTryGetCharSerial(MAXULONG);
|
|
|
|
} while (Response == -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the response from the keyboard */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Response = KdbpTryGetCharKeyboard(&DummyScanCode, MAXULONG);
|
|
|
|
} while (Response == -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for return */
|
|
|
|
if (Response == '\r')
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We might need to discard the next '\n'.
|
|
|
|
* Wait a bit to make sure we receive it.
|
|
|
|
*/
|
|
|
|
KeStallExecutionProcessor(100000);
|
|
|
|
|
|
|
|
/* Check the mode */
|
|
|
|
if (KdbDebugState & KD_DEBUG_KDSERIAL)
|
|
|
|
{
|
|
|
|
/* Read and discard the next character, if any */
|
|
|
|
KdbpTryGetCharSerial(5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Read and discard the next character, if any */
|
|
|
|
KdbpTryGetCharKeyboard(&DummyScanCode, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Null terminate the output string -- documentation states that
|
|
|
|
* DbgPrompt does not null terminate, but it does
|
|
|
|
*/
|
2020-03-07 22:33:57 +00:00
|
|
|
*(PCHAR)(ResponseString.Buffer + i) = 0;
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write it back and print it to the log */
|
2020-03-07 22:33:57 +00:00
|
|
|
*(PCHAR)(ResponseString.Buffer + i) = Response;
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
KdpReleaseLock(&KdpSerialSpinLock, OldIrql);
|
|
|
|
KdpPrintString(&StringChar);
|
|
|
|
OldIrql = KdpAcquireLock(&KdpSerialSpinLock);
|
|
|
|
}
|
|
|
|
|
2021-06-22 10:00:46 +00:00
|
|
|
/* Release the spinlock */
|
|
|
|
KdpReleaseLock(&KdpSerialSpinLock, OldIrql);
|
|
|
|
|
2020-03-07 22:33:57 +00:00
|
|
|
/* Print a new line */
|
|
|
|
*StringChar.Buffer = '\n';
|
|
|
|
KdpPrintString(&StringChar);
|
|
|
|
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
/* Return the length */
|
2020-03-07 22:33:57 +00:00
|
|
|
RtlCopyMemory(MessageData->Buffer, ResponseString.Buffer, i);
|
|
|
|
*DataLength = i;
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
|
2019-12-26 16:19:11 +00:00
|
|
|
if (!(KdbDebugState & KD_DEBUG_KDSERIAL))
|
|
|
|
KbdEnableMouse();
|
[NTOS:KD/KD64/KDBG] Share some code between our legacy KD/KDBG and KD64.
Our legacy KD module is slowly being phased out for the more recent KD64
Kernel Debugger that supports WinDbg, but at the same time we must retain
support for GCC debugging and the KDBG interface.
For the time being few #ifdef _WINKD_ have been introduced in KD64 so that
some of its code/data does not completely get shared yet with the legacy KD,
until the latter becomes phased out.
KD Modifications:
=================
- Remove the implementation of NtQueryDebugFilterState() /
NtSetDebugFilterState() that now comes entirely from KD64.
- Remove KD variables that are now shared with KD64.
- Share common code with KD64: KdpMoveMemory(), KdpZeroMemory(),
KdpCopyMemoryChunks(), KdpPrint(), KdpPrompt().
- KDBG: Remove the duplicated KdpCopyMemoryChunks() function.
- In KdpServiceDispatcher() and KdpEnterDebuggerException(), call the
KdpPrint() worker function that correctly probes and captures its arguments.
- Temporarily stub out KdEnterDebugger() and KdExitDebugger() that is used
by the shared code, until KD is removed and only the KD64 version of these
functions remain.
- Re-implement the KD/KDBG KdpPrompt() function using a custom KdpPromptString()
helper compatible with KD64, that is called by the KD64 implementation of
KdpPrompt(). This KdpPromptString() helper now issues the prompt on all
the KD loggers: e.g. if you use both at the same time COM-port and SCREEN
debugging, the prompt will appear on both. Before that the prompt was always
being displayed on COM port even if e.g. a SCREEN-only debug session was used...
- ppc_irq.c: Fix the prototype of KdpServiceDispatcher().
KD64 Fixes:
===========
- Initialize the MaximumLength member of the counted STRING variables
before using them elsewhere.
- Get rid of alloca() within SEH block in KdpPrint() (addendum to 7b95fcf9).
- Add the ROS-specific handy dump commands in KdSystemDebugControl().
2019-11-17 21:55:36 +00:00
|
|
|
|
2020-03-28 23:30:53 +00:00
|
|
|
#endif
|
2020-03-07 22:33:57 +00:00
|
|
|
return KdPacketReceived;
|
2020-03-07 10:39:37 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 14:44:48 +00:00
|
|
|
/* EOF */
|