2014-09-11 20:55:42 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: GPL, see COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: drivers/base/kddll/kdpacket.c
|
|
|
|
* PURPOSE: Base functions for the kernel debugger.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kdgdb.h"
|
|
|
|
|
2014-09-14 20:45:30 +00:00
|
|
|
/* LOCALS *********************************************************************/
|
|
|
|
static
|
2021-04-23 13:26:33 +00:00
|
|
|
BOOLEAN
|
2014-09-14 20:45:30 +00:00
|
|
|
FirstSendHandler(
|
|
|
|
_In_ ULONG PacketType,
|
|
|
|
_In_ PSTRING MessageHeader,
|
|
|
|
_In_ PSTRING MessageData);
|
2014-09-15 22:05:21 +00:00
|
|
|
static BOOLEAN InException = FALSE;
|
2014-09-11 20:55:42 +00:00
|
|
|
|
2014-09-14 20:45:30 +00:00
|
|
|
/* GLOBALS ********************************************************************/
|
2014-09-11 20:55:42 +00:00
|
|
|
DBGKD_GET_VERSION64 KdVersion;
|
|
|
|
KDDEBUGGER_DATA64* KdDebuggerDataBlock;
|
2014-09-15 22:05:21 +00:00
|
|
|
LIST_ENTRY* ProcessListHead;
|
2016-09-01 22:58:15 +00:00
|
|
|
LIST_ENTRY* ModuleListHead;
|
2014-09-12 20:23:08 +00:00
|
|
|
/* Callbacks used to communicate with KD aside from GDB */
|
2014-09-14 20:45:30 +00:00
|
|
|
KDP_SEND_HANDLER KdpSendPacketHandler = FirstSendHandler;
|
2014-09-12 20:23:08 +00:00
|
|
|
KDP_MANIPULATESTATE_HANDLER KdpManipulateStateHandler = NULL;
|
2014-09-14 20:45:30 +00:00
|
|
|
/* Data describing the current exception */
|
|
|
|
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange;
|
|
|
|
CONTEXT CurrentContext;
|
2014-09-15 22:05:21 +00:00
|
|
|
PEPROCESS TheIdleProcess;
|
|
|
|
PETHREAD TheIdleThread;
|
2014-09-11 20:55:42 +00:00
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
2014-09-14 20:45:30 +00:00
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
static
|
2021-04-23 13:26:33 +00:00
|
|
|
BOOLEAN
|
2014-09-14 20:45:30 +00:00
|
|
|
GetContextSendHandler(
|
|
|
|
_In_ ULONG PacketType,
|
|
|
|
_In_ PSTRING MessageHeader,
|
|
|
|
_In_ PSTRING MessageData
|
|
|
|
)
|
2014-09-11 20:55:42 +00:00
|
|
|
{
|
2014-09-14 20:45:30 +00:00
|
|
|
DBGKD_MANIPULATE_STATE64* State = (DBGKD_MANIPULATE_STATE64*)MessageHeader->Buffer;
|
|
|
|
const CONTEXT* Context = (const CONTEXT*)MessageData->Buffer;
|
2014-09-11 20:55:42 +00:00
|
|
|
|
2014-09-14 20:45:30 +00:00
|
|
|
if ((PacketType != PACKET_TYPE_KD_STATE_MANIPULATE)
|
|
|
|
|| (State->ApiNumber != DbgKdGetContextApi)
|
|
|
|
|| (MessageData->Length < sizeof(*Context)))
|
|
|
|
{
|
|
|
|
KDDBGPRINT("ERROR: Received wrong packet from KD.\n");
|
2021-04-23 13:26:33 +00:00
|
|
|
return FALSE;
|
2014-09-14 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Just copy it */
|
|
|
|
RtlCopyMemory(&CurrentContext, Context, sizeof(*Context));
|
|
|
|
KdpSendPacketHandler = NULL;
|
2021-04-23 13:26:33 +00:00
|
|
|
return TRUE;
|
2014-09-14 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
KDSTATUS
|
|
|
|
GetContextManipulateHandler(
|
|
|
|
_Out_ DBGKD_MANIPULATE_STATE64* State,
|
|
|
|
_Out_ PSTRING MessageData,
|
|
|
|
_Out_ PULONG MessageLength,
|
|
|
|
_Inout_ PKD_CONTEXT KdContext
|
|
|
|
)
|
|
|
|
{
|
|
|
|
State->ApiNumber = DbgKdGetContextApi;
|
|
|
|
State->Processor = CurrentStateChange.Processor;
|
|
|
|
State->ReturnStatus = STATUS_SUCCESS;
|
|
|
|
State->ProcessorLevel = CurrentStateChange.ProcessorLevel;
|
|
|
|
MessageData->Length = 0;
|
|
|
|
|
|
|
|
/* Update the send <-> receive loop handler */
|
|
|
|
KdpSendPacketHandler = GetContextSendHandler;
|
|
|
|
KdpManipulateStateHandler = NULL;
|
2014-09-11 20:55:42 +00:00
|
|
|
|
2014-09-14 20:45:30 +00:00
|
|
|
return KdPacketReceived;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-04-23 13:26:33 +00:00
|
|
|
BOOLEAN
|
2014-09-14 20:45:30 +00:00
|
|
|
SetContextSendHandler(
|
|
|
|
_In_ ULONG PacketType,
|
|
|
|
_In_ PSTRING MessageHeader,
|
|
|
|
_In_ PSTRING MessageData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DBGKD_MANIPULATE_STATE64* State = (DBGKD_MANIPULATE_STATE64*)MessageHeader->Buffer;
|
|
|
|
|
|
|
|
/* We just confirm that all went well */
|
|
|
|
if ((PacketType != PACKET_TYPE_KD_STATE_MANIPULATE)
|
|
|
|
|| (State->ApiNumber != DbgKdSetContextApi)
|
|
|
|
|| (State->ReturnStatus != STATUS_SUCCESS))
|
2014-09-11 20:55:42 +00:00
|
|
|
{
|
2014-09-14 20:45:30 +00:00
|
|
|
/* Should we bugcheck ? */
|
2016-08-01 22:16:58 +00:00
|
|
|
KDDBGPRINT("BAD BAD BAD not manipulating state for sending context.\n");
|
2021-04-23 13:26:33 +00:00
|
|
|
return FALSE;
|
2014-09-11 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-14 20:45:30 +00:00
|
|
|
KdpSendPacketHandler = NULL;
|
2021-04-23 13:26:33 +00:00
|
|
|
return TRUE;
|
2014-09-14 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KDSTATUS
|
|
|
|
SetContextManipulateHandler(
|
|
|
|
_Out_ DBGKD_MANIPULATE_STATE64* State,
|
|
|
|
_Out_ PSTRING MessageData,
|
|
|
|
_Out_ PULONG MessageLength,
|
|
|
|
_Inout_ PKD_CONTEXT KdContext
|
|
|
|
)
|
|
|
|
{
|
|
|
|
State->ApiNumber = DbgKdSetContextApi;
|
|
|
|
State->Processor = CurrentStateChange.Processor;
|
|
|
|
State->ReturnStatus = STATUS_SUCCESS;
|
|
|
|
State->ProcessorLevel = CurrentStateChange.ProcessorLevel;
|
|
|
|
MessageData->Length = sizeof(CurrentContext);
|
|
|
|
|
|
|
|
if (MessageData->MaximumLength < sizeof(CurrentContext))
|
|
|
|
{
|
2016-08-01 22:16:58 +00:00
|
|
|
KDDBGPRINT("Wrong message length %u.\n", MessageData->MaximumLength);
|
2014-09-14 20:45:30 +00:00
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlCopyMemory(MessageData->Buffer, &CurrentContext, sizeof(CurrentContext));
|
|
|
|
|
|
|
|
/* Update the send <-> receive loop handlers */
|
|
|
|
KdpSendPacketHandler = SetContextSendHandler;
|
|
|
|
KdpManipulateStateHandler = NULL;
|
|
|
|
|
|
|
|
return KdPacketReceived;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
send_kd_state_change(DBGKD_ANY_WAIT_STATE_CHANGE* StateChange)
|
|
|
|
{
|
2014-09-15 22:05:21 +00:00
|
|
|
InException = TRUE;
|
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
switch (StateChange->NewState)
|
|
|
|
{
|
|
|
|
case DbgKdLoadSymbolsStateChange:
|
|
|
|
case DbgKdExceptionStateChange:
|
2014-09-15 22:05:21 +00:00
|
|
|
{
|
|
|
|
PETHREAD Thread = (PETHREAD)(ULONG_PTR)StateChange->Thread;
|
2014-09-14 20:45:30 +00:00
|
|
|
/* Save current state for later GDB queries */
|
|
|
|
CurrentStateChange = *StateChange;
|
2014-09-15 22:05:21 +00:00
|
|
|
KDDBGPRINT("Exception 0x%08x in thread p%p.%p.\n",
|
|
|
|
StateChange->u.Exception.ExceptionRecord.ExceptionCode,
|
|
|
|
PsGetThreadProcessId(Thread),
|
|
|
|
PsGetThreadId(Thread));
|
|
|
|
/* Set the current debugged process/thread accordingly */
|
|
|
|
gdb_dbg_tid = handle_to_gdb_tid(PsGetThreadId(Thread));
|
2016-08-01 22:16:58 +00:00
|
|
|
#if MONOPROCESS
|
|
|
|
gdb_dbg_pid = 0;
|
|
|
|
#else
|
2014-09-15 22:05:21 +00:00
|
|
|
gdb_dbg_pid = handle_to_gdb_pid(PsGetThreadProcessId(Thread));
|
2016-08-01 22:16:58 +00:00
|
|
|
#endif
|
2016-08-22 22:24:30 +00:00
|
|
|
gdb_send_exception();
|
2014-09-14 20:45:30 +00:00
|
|
|
/* Next receive call will ask for the context */
|
|
|
|
KdpManipulateStateHandler = GetContextManipulateHandler;
|
2014-09-11 20:55:42 +00:00
|
|
|
break;
|
2014-09-15 22:05:21 +00:00
|
|
|
}
|
2014-09-11 20:55:42 +00:00
|
|
|
default:
|
2016-08-01 22:16:58 +00:00
|
|
|
KDDBGPRINT("Unknown StateChange %u.\n", StateChange->NewState);
|
2014-09-11 20:55:42 +00:00
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
send_kd_debug_io(
|
|
|
|
_In_ DBGKD_DEBUG_IO* DebugIO,
|
|
|
|
_In_ PSTRING String)
|
|
|
|
{
|
2014-09-15 22:05:21 +00:00
|
|
|
if (InException)
|
2014-09-14 22:50:10 +00:00
|
|
|
return;
|
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
switch (DebugIO->ApiNumber)
|
|
|
|
{
|
|
|
|
case DbgKdPrintStringApi:
|
2016-08-26 21:07:27 +00:00
|
|
|
case DbgKdGetStringApi:
|
2016-08-01 22:16:58 +00:00
|
|
|
gdb_send_debug_io(String, TRUE);
|
2014-09-11 20:55:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
2016-08-01 22:16:58 +00:00
|
|
|
KDDBGPRINT("Unknown ApiNumber %u.\n", DebugIO->ApiNumber);
|
2014-09-11 20:55:42 +00:00
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
send_kd_state_manipulate(
|
|
|
|
_In_ DBGKD_MANIPULATE_STATE64* State,
|
|
|
|
_In_ PSTRING MessageData)
|
|
|
|
{
|
|
|
|
switch (State->ApiNumber)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
case DbgKdGetContextApi:
|
|
|
|
/* This is an answer to a 'g' GDB request */
|
|
|
|
gdb_send_registers((CONTEXT*)MessageData->Buffer);
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
default:
|
2016-08-01 22:16:58 +00:00
|
|
|
KDDBGPRINT("Unknown ApiNumber %u.\n", State->ApiNumber);
|
2014-09-11 20:55:42 +00:00
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-14 20:45:30 +00:00
|
|
|
KDSTATUS
|
|
|
|
ContinueManipulateStateHandler(
|
|
|
|
_Out_ DBGKD_MANIPULATE_STATE64* State,
|
|
|
|
_Out_ PSTRING MessageData,
|
|
|
|
_Out_ PULONG MessageLength,
|
|
|
|
_Inout_ PKD_CONTEXT KdContext
|
|
|
|
)
|
|
|
|
{
|
|
|
|
/* Let's go on */
|
|
|
|
State->ApiNumber = DbgKdContinueApi;
|
|
|
|
State->ReturnStatus = STATUS_SUCCESS; /* ? */
|
|
|
|
State->Processor = CurrentStateChange.Processor;
|
|
|
|
State->ProcessorLevel = CurrentStateChange.ProcessorLevel;
|
|
|
|
if (MessageData)
|
|
|
|
MessageData->Length = 0;
|
|
|
|
*MessageLength = 0;
|
|
|
|
State->u.Continue.ContinueStatus = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
/* We definitely are at the end of the send <-> receive loop, if any */
|
|
|
|
KdpSendPacketHandler = NULL;
|
|
|
|
KdpManipulateStateHandler = NULL;
|
2014-09-15 22:05:21 +00:00
|
|
|
/* We're not handling an exception anymore */
|
|
|
|
InException = FALSE;
|
|
|
|
|
2014-09-14 20:45:30 +00:00
|
|
|
return KdPacketReceived;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-04-23 13:26:33 +00:00
|
|
|
BOOLEAN
|
2014-09-14 20:45:30 +00:00
|
|
|
GetVersionSendHandler(
|
|
|
|
_In_ ULONG PacketType,
|
|
|
|
_In_ PSTRING MessageHeader,
|
|
|
|
_In_ PSTRING MessageData)
|
|
|
|
{
|
|
|
|
DBGKD_MANIPULATE_STATE64* State = (DBGKD_MANIPULATE_STATE64*)MessageHeader->Buffer;
|
2023-04-05 00:47:10 +00:00
|
|
|
PLIST_ENTRY DebuggerDataList;
|
2014-09-14 20:45:30 +00:00
|
|
|
|
|
|
|
/* Confirm that all went well */
|
|
|
|
if ((PacketType != PACKET_TYPE_KD_STATE_MANIPULATE)
|
|
|
|
|| (State->ApiNumber != DbgKdGetVersionApi)
|
|
|
|
|| !NT_SUCCESS(State->ReturnStatus))
|
|
|
|
{
|
|
|
|
KDDBGPRINT("Wrong packet received after asking for data.\n");
|
2021-04-23 13:26:33 +00:00
|
|
|
return FALSE;
|
2014-09-14 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the relevant data */
|
|
|
|
RtlCopyMemory(&KdVersion, &State->u.GetVersion64, sizeof(KdVersion));
|
2023-04-05 00:47:10 +00:00
|
|
|
DebuggerDataList = *(PLIST_ENTRY*)&KdVersion.DebuggerDataList;
|
2014-09-14 20:45:30 +00:00
|
|
|
KdDebuggerDataBlock = CONTAINING_RECORD(DebuggerDataList->Flink, KDDEBUGGER_DATA64, Header.List);
|
2023-04-05 00:47:10 +00:00
|
|
|
ProcessListHead = *(PLIST_ENTRY*)&KdDebuggerDataBlock->PsActiveProcessHead;
|
|
|
|
ModuleListHead = *(PLIST_ENTRY*)&KdDebuggerDataBlock->PsLoadedModuleList;
|
2014-09-14 20:45:30 +00:00
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
/* Now we can get the context for the current state */
|
2014-09-14 20:45:30 +00:00
|
|
|
KdpSendPacketHandler = NULL;
|
2014-09-15 22:05:21 +00:00
|
|
|
KdpManipulateStateHandler = GetContextManipulateHandler;
|
2021-04-23 13:26:33 +00:00
|
|
|
return TRUE;
|
2014-09-14 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
KDSTATUS
|
|
|
|
GetVersionManipulateStateHandler(
|
|
|
|
_Out_ DBGKD_MANIPULATE_STATE64* State,
|
|
|
|
_Out_ PSTRING MessageData,
|
|
|
|
_Out_ PULONG MessageLength,
|
|
|
|
_Inout_ PKD_CONTEXT KdContext)
|
|
|
|
{
|
|
|
|
/* Ask for the version data */
|
|
|
|
State->ApiNumber = DbgKdGetVersionApi;
|
|
|
|
State->Processor = CurrentStateChange.Processor;
|
|
|
|
State->ProcessorLevel = CurrentStateChange.ProcessorLevel;
|
|
|
|
|
|
|
|
/* The next send call will serve this query */
|
|
|
|
KdpSendPacketHandler = GetVersionSendHandler;
|
|
|
|
KdpManipulateStateHandler = NULL;
|
|
|
|
|
|
|
|
return KdPacketReceived;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2021-04-23 13:26:33 +00:00
|
|
|
BOOLEAN
|
2014-09-14 20:45:30 +00:00
|
|
|
FirstSendHandler(
|
|
|
|
_In_ ULONG PacketType,
|
|
|
|
_In_ PSTRING MessageHeader,
|
|
|
|
_In_ PSTRING MessageData)
|
|
|
|
{
|
|
|
|
DBGKD_ANY_WAIT_STATE_CHANGE* StateChange = (DBGKD_ANY_WAIT_STATE_CHANGE*)MessageHeader->Buffer;
|
2014-09-15 22:05:21 +00:00
|
|
|
PETHREAD Thread;
|
2014-09-14 20:45:30 +00:00
|
|
|
|
|
|
|
if (PacketType != PACKET_TYPE_KD_STATE_CHANGE64)
|
|
|
|
{
|
|
|
|
KDDBGPRINT("First KD packet is not a state change!\n");
|
2021-04-23 13:26:33 +00:00
|
|
|
return FALSE;
|
2014-09-14 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
KDDBGPRINT("KDGDB: START!\n");
|
|
|
|
|
|
|
|
Thread = (PETHREAD)(ULONG_PTR)StateChange->Thread;
|
|
|
|
|
|
|
|
/* Set up the current state */
|
2014-09-14 20:45:30 +00:00
|
|
|
CurrentStateChange = *StateChange;
|
2014-09-15 22:05:21 +00:00
|
|
|
gdb_dbg_tid = handle_to_gdb_tid(PsGetThreadId(Thread));
|
2016-08-01 22:16:58 +00:00
|
|
|
#if MONOPROCESS
|
|
|
|
gdb_dbg_pid = 0;
|
|
|
|
#else
|
2014-09-15 22:05:21 +00:00
|
|
|
gdb_dbg_pid = handle_to_gdb_pid(PsGetThreadProcessId(Thread));
|
2016-08-01 22:16:58 +00:00
|
|
|
#endif
|
2014-09-15 22:05:21 +00:00
|
|
|
/* This is the idle process. Save it! */
|
|
|
|
TheIdleThread = Thread;
|
|
|
|
TheIdleProcess = (PEPROCESS)Thread->Tcb.ApcState.Process;
|
|
|
|
|
|
|
|
KDDBGPRINT("Pid Tid of the first message: %" PRIxPTR", %" PRIxPTR ".\n", gdb_dbg_pid, gdb_dbg_tid);
|
2014-09-14 20:45:30 +00:00
|
|
|
|
|
|
|
/* The next receive call will be asking for the version data */
|
|
|
|
KdpSendPacketHandler = NULL;
|
|
|
|
KdpManipulateStateHandler = GetVersionManipulateStateHandler;
|
2021-04-23 13:26:33 +00:00
|
|
|
return TRUE;
|
2014-09-14 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* \name KdReceivePacket
|
|
|
|
* \brief Receive a packet from the KD port.
|
|
|
|
* \param [in] PacketType Describes the type of the packet to receive.
|
|
|
|
* This can be one of the PACKET_TYPE_ constants.
|
|
|
|
* \param [out] MessageHeader Pointer to a STRING structure for the header.
|
|
|
|
* \param [out] MessageData Pointer to a STRING structure for the data.
|
|
|
|
* \return KdPacketReceived if successful, KdPacketTimedOut if the receive
|
|
|
|
* timed out, KdPacketNeedsResend to signal that the last packet needs
|
|
|
|
* to be sent again.
|
|
|
|
* \note If PacketType is PACKET_TYPE_KD_POLL_BREAKIN, the function doesn't
|
|
|
|
* wait for any data, but returns KdPacketTimedOut instantly if no breakin
|
|
|
|
* packet byte is received.
|
|
|
|
* \sa http://www.nynaeve.net/?p=169
|
|
|
|
*/
|
|
|
|
KDSTATUS
|
|
|
|
NTAPI
|
|
|
|
KdReceivePacket(
|
|
|
|
_In_ ULONG PacketType,
|
|
|
|
_Out_ PSTRING MessageHeader,
|
|
|
|
_Out_ PSTRING MessageData,
|
|
|
|
_Out_ PULONG DataLength,
|
|
|
|
_Inout_ PKD_CONTEXT KdContext)
|
|
|
|
{
|
2020-03-20 10:32:19 +00:00
|
|
|
KDDBGPRINT("KdReceivePacket --> ");
|
2016-09-01 22:58:15 +00:00
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
if (PacketType == PACKET_TYPE_KD_POLL_BREAKIN)
|
|
|
|
{
|
2020-03-20 10:32:19 +00:00
|
|
|
static BOOLEAN firstTime = TRUE;
|
|
|
|
KDDBGPRINT("Polling break in.\n");
|
|
|
|
if (firstTime)
|
|
|
|
{
|
|
|
|
/* Force debug break on init */
|
|
|
|
firstTime = FALSE;
|
|
|
|
return KdPacketReceived;
|
|
|
|
}
|
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
return KdpPollBreakIn();
|
|
|
|
}
|
|
|
|
|
2016-08-26 21:07:27 +00:00
|
|
|
if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
|
2014-09-11 20:55:42 +00:00
|
|
|
{
|
2021-02-10 11:26:31 +00:00
|
|
|
static BOOLEAN ignore = 0;
|
2020-03-20 10:32:19 +00:00
|
|
|
KDDBGPRINT("Debug prompt.\n");
|
2021-02-10 11:26:31 +00:00
|
|
|
/* HACK ! Debug prompt asks for break or ignore. First break, then ignore. */
|
2016-08-26 21:07:27 +00:00
|
|
|
MessageData->Length = 1;
|
2021-02-10 11:26:31 +00:00
|
|
|
MessageData->Buffer[0] = ignore ? 'i' : 'b';
|
|
|
|
ignore = !ignore;
|
2016-08-26 21:07:27 +00:00
|
|
|
return KdPacketReceived;
|
2014-09-11 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 21:07:27 +00:00
|
|
|
if (PacketType == PACKET_TYPE_KD_STATE_MANIPULATE)
|
|
|
|
{
|
|
|
|
DBGKD_MANIPULATE_STATE64* State = (DBGKD_MANIPULATE_STATE64*)MessageHeader->Buffer;
|
|
|
|
|
2020-03-20 10:32:19 +00:00
|
|
|
KDDBGPRINT("State manipulation: ");
|
|
|
|
|
2016-08-26 21:07:27 +00:00
|
|
|
/* Maybe we are in a send<->receive loop that GDB doesn't need to know about */
|
|
|
|
if (KdpManipulateStateHandler != NULL)
|
2016-09-01 22:58:15 +00:00
|
|
|
{
|
2020-03-20 10:32:19 +00:00
|
|
|
KDDBGPRINT("We have a manipulate state handler.\n");
|
2016-08-26 21:07:27 +00:00
|
|
|
return KdpManipulateStateHandler(State, MessageData, DataLength, KdContext);
|
2016-09-01 22:58:15 +00:00
|
|
|
}
|
2014-09-11 20:55:42 +00:00
|
|
|
|
2016-08-26 21:07:27 +00:00
|
|
|
/* Receive data from GDB and interpret it */
|
2020-03-20 10:32:19 +00:00
|
|
|
KDDBGPRINT("Receiving data from GDB.\n");
|
2016-08-26 21:07:27 +00:00
|
|
|
return gdb_receive_and_interpret_packet(State, MessageData, DataLength, KdContext);
|
|
|
|
}
|
2014-09-12 20:23:08 +00:00
|
|
|
|
2016-08-26 21:07:27 +00:00
|
|
|
/* What should we do ? */
|
|
|
|
while (1);
|
|
|
|
return KdPacketNeedsResend;
|
2014-09-11 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KdSendPacket(
|
|
|
|
IN ULONG PacketType,
|
|
|
|
IN PSTRING MessageHeader,
|
|
|
|
IN PSTRING MessageData,
|
|
|
|
IN OUT PKD_CONTEXT KdContext)
|
|
|
|
{
|
2016-08-22 22:24:30 +00:00
|
|
|
/* Override if we have some debug print from KD. */
|
|
|
|
if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
|
|
|
|
{
|
|
|
|
send_kd_debug_io((DBGKD_DEBUG_IO*)MessageHeader->Buffer, MessageData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-12 20:23:08 +00:00
|
|
|
/* Maybe we are in a send <-> receive loop that GDB doesn't need to know about */
|
2021-04-23 13:26:33 +00:00
|
|
|
if (KdpSendPacketHandler
|
|
|
|
&& KdpSendPacketHandler(PacketType, MessageHeader, MessageData))
|
2014-09-12 20:23:08 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
switch (PacketType)
|
|
|
|
{
|
|
|
|
case PACKET_TYPE_KD_STATE_CHANGE64:
|
|
|
|
send_kd_state_change((DBGKD_ANY_WAIT_STATE_CHANGE*)MessageHeader->Buffer);
|
|
|
|
return;
|
|
|
|
case PACKET_TYPE_KD_DEBUG_IO:
|
|
|
|
send_kd_debug_io((DBGKD_DEBUG_IO*)MessageHeader->Buffer, MessageData);
|
|
|
|
break;
|
|
|
|
case PACKET_TYPE_KD_STATE_MANIPULATE:
|
|
|
|
send_kd_state_manipulate((DBGKD_MANIPULATE_STATE64*)MessageHeader->Buffer, MessageData);
|
|
|
|
break;
|
|
|
|
default:
|
2016-08-01 22:16:58 +00:00
|
|
|
KDDBGPRINT("Unknown packet type %u.\n", PacketType);
|
2014-09-11 20:55:42 +00:00
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|