2009-10-12 03:35:35 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: ntoskrnl/kd64/kdprint.c
|
|
|
|
* PURPOSE: KD64 Trap Handler Routines
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
2009-10-23 22:51:39 +00:00
|
|
|
* Stefan Ginsberg (stefan.ginsberg@reactos.org)
|
2009-10-12 03:35:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* 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
|
|
|
#ifdef _WINKD_
|
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2019-11-17 21:28:42 +00:00
|
|
|
KdpPrintString(
|
|
|
|
_In_ PSTRING Output)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
|
|
|
STRING Data, Header;
|
|
|
|
DBGKD_DEBUG_IO DebugIo;
|
2015-10-15 12:56:19 +00:00
|
|
|
USHORT Length;
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Copy the string */
|
2015-10-15 12:56:19 +00:00
|
|
|
KdpMoveMemory(KdpMessageBuffer,
|
|
|
|
Output->Buffer,
|
|
|
|
Output->Length);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Make sure we don't exceed the KD Packet size */
|
2015-10-15 12:56:19 +00:00
|
|
|
Length = Output->Length;
|
2009-10-12 03:35:35 +00:00
|
|
|
if ((sizeof(DBGKD_DEBUG_IO) + Length) > PACKET_MAX_SIZE)
|
|
|
|
{
|
|
|
|
/* Normalize length */
|
|
|
|
Length = PACKET_MAX_SIZE - sizeof(DBGKD_DEBUG_IO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the packet header */
|
|
|
|
DebugIo.ApiNumber = DbgKdPrintStringApi;
|
2011-08-20 10:41:44 +00:00
|
|
|
DebugIo.ProcessorLevel = (USHORT)KeProcessorLevel;
|
2009-10-12 03:35:35 +00:00
|
|
|
DebugIo.Processor = KeGetCurrentPrcb()->Number;
|
|
|
|
DebugIo.u.PrintString.LengthOfString = Length;
|
|
|
|
Header.Length = sizeof(DBGKD_DEBUG_IO);
|
|
|
|
Header.Buffer = (PCHAR)&DebugIo;
|
|
|
|
|
|
|
|
/* Build the data */
|
|
|
|
Data.Length = Length;
|
|
|
|
Data.Buffer = KdpMessageBuffer;
|
|
|
|
|
|
|
|
/* Send the packet */
|
|
|
|
KdSendPacket(PACKET_TYPE_KD_DEBUG_IO, &Header, &Data, &KdpContext);
|
|
|
|
|
|
|
|
/* Check if the user pressed CTRL+C */
|
|
|
|
return KdpPollBreakInWithPortLock();
|
|
|
|
}
|
|
|
|
|
2009-10-23 22:51:39 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2019-11-17 21:28:42 +00:00
|
|
|
KdpPromptString(
|
|
|
|
_In_ PSTRING PromptString,
|
|
|
|
_In_ PSTRING ResponseString)
|
2009-10-23 22:51:39 +00:00
|
|
|
{
|
|
|
|
STRING Data, Header;
|
|
|
|
DBGKD_DEBUG_IO DebugIo;
|
2015-10-15 12:56:19 +00:00
|
|
|
ULONG Length;
|
2009-10-23 22:51:39 +00:00
|
|
|
KDSTATUS Status;
|
|
|
|
|
|
|
|
/* Copy the string to the message buffer */
|
2015-10-15 12:56:19 +00:00
|
|
|
KdpMoveMemory(KdpMessageBuffer,
|
2009-10-23 22:51:39 +00:00
|
|
|
PromptString->Buffer,
|
|
|
|
PromptString->Length);
|
|
|
|
|
|
|
|
/* Make sure we don't exceed the KD Packet size */
|
2015-10-15 12:56:19 +00:00
|
|
|
Length = PromptString->Length;
|
2009-10-23 22:51:39 +00:00
|
|
|
if ((sizeof(DBGKD_DEBUG_IO) + Length) > PACKET_MAX_SIZE)
|
|
|
|
{
|
|
|
|
/* Normalize length */
|
|
|
|
Length = PACKET_MAX_SIZE - sizeof(DBGKD_DEBUG_IO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the packet header */
|
|
|
|
DebugIo.ApiNumber = DbgKdGetStringApi;
|
2011-08-20 10:41:44 +00:00
|
|
|
DebugIo.ProcessorLevel = (USHORT)KeProcessorLevel;
|
2009-10-23 22:51:39 +00:00
|
|
|
DebugIo.Processor = KeGetCurrentPrcb()->Number;
|
|
|
|
DebugIo.u.GetString.LengthOfPromptString = Length;
|
|
|
|
DebugIo.u.GetString.LengthOfStringRead = ResponseString->MaximumLength;
|
|
|
|
Header.Length = sizeof(DBGKD_DEBUG_IO);
|
|
|
|
Header.Buffer = (PCHAR)&DebugIo;
|
|
|
|
|
|
|
|
/* Build the data */
|
2015-10-15 12:56:19 +00:00
|
|
|
Data.Length = Length;
|
2009-10-23 22:51:39 +00:00
|
|
|
Data.Buffer = KdpMessageBuffer;
|
|
|
|
|
|
|
|
/* Send the packet */
|
|
|
|
KdSendPacket(PACKET_TYPE_KD_DEBUG_IO, &Header, &Data, &KdpContext);
|
|
|
|
|
|
|
|
/* Set the maximum lengths for the receive */
|
|
|
|
Header.MaximumLength = sizeof(DBGKD_DEBUG_IO);
|
|
|
|
Data.MaximumLength = sizeof(KdpMessageBuffer);
|
|
|
|
|
|
|
|
/* Enter receive loop */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Get our reply */
|
|
|
|
Status = KdReceivePacket(PACKET_TYPE_KD_DEBUG_IO,
|
|
|
|
&Header,
|
|
|
|
&Data,
|
|
|
|
&Length,
|
|
|
|
&KdpContext);
|
|
|
|
|
|
|
|
/* Return TRUE if we need to resend */
|
|
|
|
if (Status == KdPacketNeedsResend) return TRUE;
|
|
|
|
|
|
|
|
/* Loop until we succeed */
|
|
|
|
} while (Status != KdPacketReceived);
|
|
|
|
|
2009-10-24 09:57:37 +00:00
|
|
|
/* Don't copy back a larger response than there is room for */
|
2015-10-15 12:56:19 +00:00
|
|
|
Length = min(Length,
|
|
|
|
ResponseString->MaximumLength);
|
2009-10-23 22:51:39 +00:00
|
|
|
|
|
|
|
/* Copy back the string and return the length */
|
2015-10-15 12:56:19 +00:00
|
|
|
KdpMoveMemory(ResponseString->Buffer,
|
|
|
|
KdpMessageBuffer,
|
|
|
|
Length);
|
2011-08-20 10:41:44 +00:00
|
|
|
ResponseString->Length = (USHORT)Length;
|
2009-10-23 22:51:39 +00:00
|
|
|
|
|
|
|
/* Success; we don't need to resend */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
2009-11-02 17:45:51 +00:00
|
|
|
KdpCommandString(IN PSTRING NameString,
|
|
|
|
IN PSTRING CommandString,
|
2009-10-12 03:35:35 +00:00
|
|
|
IN KPROCESSOR_MODE PreviousMode,
|
|
|
|
IN PCONTEXT ContextRecord,
|
|
|
|
IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN PKEXCEPTION_FRAME ExceptionFrame)
|
|
|
|
{
|
2009-11-08 01:13:49 +00:00
|
|
|
BOOLEAN Enable;
|
2009-11-02 17:45:51 +00:00
|
|
|
PKPRCB Prcb = KeGetCurrentPrcb();
|
|
|
|
|
|
|
|
/* Check if we need to do anything */
|
|
|
|
if ((PreviousMode != KernelMode) || (KdDebuggerNotPresent)) return;
|
|
|
|
|
|
|
|
/* Enter the debugger */
|
2009-11-08 01:13:49 +00:00
|
|
|
Enable = KdEnterDebugger(TrapFrame, ExceptionFrame);
|
2009-11-02 17:45:51 +00:00
|
|
|
|
|
|
|
/* Save the CPU Control State and save the context */
|
|
|
|
KiSaveProcessorControlState(&Prcb->ProcessorState);
|
2015-10-15 12:56:19 +00:00
|
|
|
KdpMoveMemory(&Prcb->ProcessorState.ContextFrame,
|
2009-11-02 17:45:51 +00:00
|
|
|
ContextRecord,
|
|
|
|
sizeof(CONTEXT));
|
|
|
|
|
|
|
|
/* Send the command string to the debugger */
|
|
|
|
KdpReportCommandStringStateChange(NameString,
|
|
|
|
CommandString,
|
|
|
|
&Prcb->ProcessorState.ContextFrame);
|
|
|
|
|
|
|
|
/* Restore the processor state */
|
2015-10-15 12:56:19 +00:00
|
|
|
KdpMoveMemory(ContextRecord,
|
2009-11-02 17:45:51 +00:00
|
|
|
&Prcb->ProcessorState.ContextFrame,
|
|
|
|
sizeof(CONTEXT));
|
|
|
|
KiRestoreProcessorControlState(&Prcb->ProcessorState);
|
|
|
|
|
|
|
|
/* Exit the debugger and return */
|
2009-11-08 01:13:49 +00:00
|
|
|
KdExitDebugger(Enable);
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KdpSymbol(IN PSTRING DllPath,
|
2009-10-25 15:56:38 +00:00
|
|
|
IN PKD_SYMBOLS_INFO SymbolInfo,
|
2009-10-12 03:35:35 +00:00
|
|
|
IN BOOLEAN Unload,
|
|
|
|
IN KPROCESSOR_MODE PreviousMode,
|
|
|
|
IN PCONTEXT ContextRecord,
|
|
|
|
IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN PKEXCEPTION_FRAME ExceptionFrame)
|
|
|
|
{
|
2009-11-08 01:13:49 +00:00
|
|
|
BOOLEAN Enable;
|
2009-10-12 03:35:35 +00:00
|
|
|
PKPRCB Prcb = KeGetCurrentPrcb();
|
|
|
|
|
|
|
|
/* Check if we need to do anything */
|
|
|
|
if ((PreviousMode != KernelMode) || (KdDebuggerNotPresent)) return;
|
|
|
|
|
|
|
|
/* Enter the debugger */
|
2009-11-08 01:13:49 +00:00
|
|
|
Enable = KdEnterDebugger(TrapFrame, ExceptionFrame);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Save the CPU Control State and save the context */
|
|
|
|
KiSaveProcessorControlState(&Prcb->ProcessorState);
|
2015-10-15 12:56:19 +00:00
|
|
|
KdpMoveMemory(&Prcb->ProcessorState.ContextFrame,
|
2009-10-12 03:35:35 +00:00
|
|
|
ContextRecord,
|
|
|
|
sizeof(CONTEXT));
|
|
|
|
|
|
|
|
/* Report the new state */
|
2009-11-02 17:45:51 +00:00
|
|
|
KdpReportLoadSymbolsStateChange(DllPath,
|
|
|
|
SymbolInfo,
|
|
|
|
Unload,
|
|
|
|
&Prcb->ProcessorState.ContextFrame);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2009-11-02 17:45:51 +00:00
|
|
|
/* Restore the processor state */
|
2015-10-15 12:56:19 +00:00
|
|
|
KdpMoveMemory(ContextRecord,
|
2009-10-12 03:35:35 +00:00
|
|
|
&Prcb->ProcessorState.ContextFrame,
|
|
|
|
sizeof(CONTEXT));
|
|
|
|
KiRestoreProcessorControlState(&Prcb->ProcessorState);
|
|
|
|
|
2009-11-02 17:45:51 +00:00
|
|
|
/* Exit the debugger and return */
|
2009-11-08 01:13:49 +00:00
|
|
|
KdExitDebugger(Enable);
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
[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
|
|
|
#else
|
|
|
|
|
|
|
|
extern
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KdpPrintString(
|
|
|
|
_In_ PSTRING Output);
|
|
|
|
|
|
|
|
extern
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KdpPromptString(
|
|
|
|
_In_ PSTRING PromptString,
|
|
|
|
_In_ PSTRING ResponseString);
|
|
|
|
|
|
|
|
#endif // _WINKD_
|
|
|
|
|
2009-10-23 22:51:39 +00:00
|
|
|
USHORT
|
2009-10-12 03:35:35 +00:00
|
|
|
NTAPI
|
2019-11-17 21:28:42 +00:00
|
|
|
KdpPrompt(
|
|
|
|
_In_reads_bytes_(PromptLength) PCHAR PromptString,
|
|
|
|
_In_ USHORT PromptLength,
|
|
|
|
_Out_writes_bytes_(MaximumResponseLength) PCHAR ResponseString,
|
|
|
|
_In_ USHORT MaximumResponseLength,
|
|
|
|
_In_ KPROCESSOR_MODE PreviousMode,
|
|
|
|
_In_ PKTRAP_FRAME TrapFrame,
|
|
|
|
_In_ PKEXCEPTION_FRAME ExceptionFrame)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
2009-10-23 22:51:39 +00:00
|
|
|
STRING PromptBuffer, ResponseBuffer;
|
2009-11-08 01:13:49 +00:00
|
|
|
BOOLEAN Enable, Resend;
|
2019-11-17 21:28:42 +00:00
|
|
|
PCHAR SafeResponseString;
|
2017-12-12 11:44:44 +00:00
|
|
|
CHAR CapturedPrompt[512];
|
|
|
|
CHAR SafeResponseBuffer[512];
|
2009-10-23 22:51:39 +00:00
|
|
|
|
|
|
|
/* Normalize the lengths */
|
2015-10-15 12:56:19 +00:00
|
|
|
PromptLength = min(PromptLength,
|
2017-12-12 11:44:44 +00:00
|
|
|
sizeof(CapturedPrompt));
|
2015-10-15 12:56:19 +00:00
|
|
|
MaximumResponseLength = min(MaximumResponseLength,
|
2017-12-12 11:44:44 +00:00
|
|
|
sizeof(SafeResponseBuffer));
|
2009-10-23 22:51:39 +00:00
|
|
|
|
|
|
|
/* Check if we need to verify the string */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
2015-10-15 12:56:19 +00:00
|
|
|
/* Handle user-mode buffers safely */
|
2015-09-01 17:23:56 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Probe and capture the prompt */
|
|
|
|
ProbeForRead(PromptString, PromptLength, 1);
|
|
|
|
KdpMoveMemory(CapturedPrompt, PromptString, PromptLength);
|
2015-09-01 17:23:56 +00:00
|
|
|
PromptString = CapturedPrompt;
|
|
|
|
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Probe and make room for the response */
|
|
|
|
ProbeForWrite(ResponseString, MaximumResponseLength, 1);
|
2017-12-12 11:44:44 +00:00
|
|
|
SafeResponseString = SafeResponseBuffer;
|
2015-09-01 17:23:56 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Bad string pointer, bail out */
|
2015-09-01 17:23:56 +00:00
|
|
|
_SEH2_YIELD(return 0);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
2015-11-14 08:55:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SafeResponseString = ResponseString;
|
|
|
|
}
|
2009-10-23 22:51:39 +00:00
|
|
|
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Setup the prompt and response buffers */
|
2009-10-23 22:51:39 +00:00
|
|
|
PromptBuffer.Buffer = PromptString;
|
[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
|
|
|
PromptBuffer.Length = PromptBuffer.MaximumLength = PromptLength;
|
2015-11-14 08:55:46 +00:00
|
|
|
ResponseBuffer.Buffer = SafeResponseString;
|
2009-10-23 22:51:39 +00:00
|
|
|
ResponseBuffer.Length = 0;
|
|
|
|
ResponseBuffer.MaximumLength = MaximumResponseLength;
|
|
|
|
|
|
|
|
/* Log the print */
|
|
|
|
//KdLogDbgPrint(&PromptBuffer);
|
|
|
|
|
|
|
|
/* Enter the debugger */
|
2009-11-08 01:13:49 +00:00
|
|
|
Enable = KdEnterDebugger(TrapFrame, ExceptionFrame);
|
2009-10-23 22:51:39 +00:00
|
|
|
|
|
|
|
/* Enter prompt loop */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Send the prompt and receive the response */
|
|
|
|
Resend = KdpPromptString(&PromptBuffer, &ResponseBuffer);
|
|
|
|
|
|
|
|
/* Loop while we need to resend */
|
|
|
|
} while (Resend);
|
|
|
|
|
|
|
|
/* Exit the debugger */
|
2009-11-08 01:13:49 +00:00
|
|
|
KdExitDebugger(Enable);
|
2009-10-23 22:51:39 +00:00
|
|
|
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Copy back the response if required */
|
2015-09-01 17:23:56 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Safely copy back the response to user mode */
|
2015-10-15 12:56:19 +00:00
|
|
|
KdpMoveMemory(ResponseString,
|
|
|
|
ResponseBuffer.Buffer,
|
|
|
|
ResponseBuffer.Length);
|
2015-09-01 17:23:56 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2019-11-17 21:28:42 +00:00
|
|
|
/* String became invalid after we exited, fail */
|
2015-09-01 17:23:56 +00:00
|
|
|
_SEH2_YIELD(return 0);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
|
|
|
|
2009-10-23 22:51:39 +00:00
|
|
|
/* Return the number of characters received */
|
|
|
|
return ResponseBuffer.Length;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2019-11-17 21:28:42 +00:00
|
|
|
KdpPrint(
|
|
|
|
_In_ ULONG ComponentId,
|
|
|
|
_In_ ULONG Level,
|
|
|
|
_In_reads_bytes_(Length) PCHAR String,
|
|
|
|
_In_ USHORT Length,
|
|
|
|
_In_ KPROCESSOR_MODE PreviousMode,
|
|
|
|
_In_ PKTRAP_FRAME TrapFrame,
|
|
|
|
_In_ PKEXCEPTION_FRAME ExceptionFrame,
|
|
|
|
_Out_ PBOOLEAN Handled)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
2019-11-17 21:28:42 +00:00
|
|
|
NTSTATUS Status;
|
2009-11-08 01:13:49 +00:00
|
|
|
BOOLEAN Enable;
|
2009-10-25 15:56:38 +00:00
|
|
|
STRING OutputString;
|
[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
|
|
|
CHAR CapturedString[512];
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2019-12-19 18:01:30 +00:00
|
|
|
if (NtQueryDebugFilterState(ComponentId, Level) == (NTSTATUS)FALSE)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
|
|
|
/* Mask validation failed */
|
2009-11-08 01:13:49 +00:00
|
|
|
*Handled = TRUE;
|
2009-11-02 17:45:51 +00:00
|
|
|
return STATUS_SUCCESS;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 18:01:30 +00:00
|
|
|
/* Assume failure */
|
|
|
|
*Handled = FALSE;
|
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
/* Normalize the 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
|
|
|
Length = min(Length, sizeof(CapturedString));
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Check if we need to verify the string */
|
2009-10-12 03:35:35 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
2015-09-01 17:23:56 +00:00
|
|
|
/* Capture user-mode buffers */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Probe and capture the string */
|
|
|
|
ProbeForRead(String, Length, 1);
|
|
|
|
KdpMoveMemory(CapturedString, String, Length);
|
2015-09-01 17:23:56 +00:00
|
|
|
String = CapturedString;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2019-11-17 21:28:42 +00:00
|
|
|
/* Bad string pointer, bail out */
|
2015-09-01 17:23:56 +00:00
|
|
|
_SEH2_YIELD(return STATUS_ACCESS_VIOLATION);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
2009-10-25 15:56:38 +00:00
|
|
|
/* Setup the output string */
|
|
|
|
OutputString.Buffer = String;
|
[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
|
|
|
OutputString.Length = OutputString.MaximumLength = Length;
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Log the print */
|
2009-10-25 15:56:38 +00:00
|
|
|
//KdLogDbgPrint(&OutputString);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Check for a debugger */
|
|
|
|
if (KdDebuggerNotPresent)
|
|
|
|
{
|
|
|
|
/* Fail */
|
2009-11-08 01:13:49 +00:00
|
|
|
*Handled = TRUE;
|
2009-10-12 03:35:35 +00:00
|
|
|
return STATUS_DEVICE_NOT_CONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enter the debugger */
|
2009-11-08 01:13:49 +00:00
|
|
|
Enable = KdEnterDebugger(TrapFrame, ExceptionFrame);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Print the string */
|
2009-10-25 15:56:38 +00:00
|
|
|
if (KdpPrintString(&OutputString))
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
|
|
|
/* User pressed CTRL-C, breakpoint on return */
|
2019-11-17 21:28:42 +00:00
|
|
|
Status = STATUS_BREAKPOINT;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* String was printed */
|
2019-11-17 21:28:42 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Exit the debugger and return */
|
2009-11-08 01:13:49 +00:00
|
|
|
KdExitDebugger(Enable);
|
|
|
|
*Handled = TRUE;
|
2019-11-17 21:28:42 +00:00
|
|
|
return Status;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
__cdecl
|
2019-11-17 21:28:42 +00:00
|
|
|
KdpDprintf(
|
|
|
|
_In_ PCHAR Format,
|
|
|
|
...)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
|
|
|
STRING String;
|
|
|
|
USHORT Length;
|
|
|
|
va_list ap;
|
2019-11-17 21:28:42 +00:00
|
|
|
CHAR Buffer[100];
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Format the string */
|
|
|
|
va_start(ap, Format);
|
|
|
|
Length = (USHORT)_vsnprintf(Buffer,
|
|
|
|
sizeof(Buffer),
|
|
|
|
Format,
|
|
|
|
ap);
|
[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
|
|
|
va_end(ap);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Set it up */
|
|
|
|
String.Buffer = Buffer;
|
[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
|
|
|
String.Length = String.MaximumLength = Length;
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Send it to the debugger directly */
|
|
|
|
KdpPrintString(&String);
|
|
|
|
}
|