mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
[KDGDB] Avoid looping for ever when something unexpected happens
This commit is contained in:
parent
2413530acf
commit
3ee1eb42a5
3 changed files with 33 additions and 30 deletions
|
@ -430,7 +430,7 @@ handle_gdb_registers(
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
BOOLEAN
|
||||||
ReadMemorySendHandler(
|
ReadMemorySendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -442,12 +442,13 @@ ReadMemorySendHandler(
|
||||||
{
|
{
|
||||||
// KdAssert
|
// KdAssert
|
||||||
KDDBGPRINT("Wrong packet type (%lu) received after DbgKdReadVirtualMemoryApi request.\n", PacketType);
|
KDDBGPRINT("Wrong packet type (%lu) received after DbgKdReadVirtualMemoryApi request.\n", PacketType);
|
||||||
while (1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (State->ApiNumber != DbgKdReadVirtualMemoryApi)
|
if (State->ApiNumber != DbgKdReadVirtualMemoryApi)
|
||||||
{
|
{
|
||||||
KDDBGPRINT("Wrong API number (%lu) after DbgKdReadVirtualMemoryApi request.\n", State->ApiNumber);
|
KDDBGPRINT("Wrong API number (%lu) after DbgKdReadVirtualMemoryApi request.\n", State->ApiNumber);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check status. Allow to send partial data. */
|
/* Check status. Allow to send partial data. */
|
||||||
|
@ -469,6 +470,8 @@ ReadMemorySendHandler(
|
||||||
if (ProcessListHead->Flink)
|
if (ProcessListHead->Flink)
|
||||||
__writecr3(PsGetCurrentProcess()->Pcb.DirectoryTableBase[0]);
|
__writecr3(PsGetCurrentProcess()->Pcb.DirectoryTableBase[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -531,7 +534,7 @@ handle_gdb_read_mem(
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
BOOLEAN
|
||||||
WriteMemorySendHandler(
|
WriteMemorySendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -543,12 +546,13 @@ WriteMemorySendHandler(
|
||||||
{
|
{
|
||||||
// KdAssert
|
// KdAssert
|
||||||
KDDBGPRINT("Wrong packet type (%lu) received after DbgKdWriteVirtualMemoryApi request.\n", PacketType);
|
KDDBGPRINT("Wrong packet type (%lu) received after DbgKdWriteVirtualMemoryApi request.\n", PacketType);
|
||||||
while (1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (State->ApiNumber != DbgKdWriteVirtualMemoryApi)
|
if (State->ApiNumber != DbgKdWriteVirtualMemoryApi)
|
||||||
{
|
{
|
||||||
KDDBGPRINT("Wrong API number (%lu) after DbgKdWriteVirtualMemoryApi request.\n", State->ApiNumber);
|
KDDBGPRINT("Wrong API number (%lu) after DbgKdWriteVirtualMemoryApi request.\n", State->ApiNumber);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check status */
|
/* Check status */
|
||||||
|
@ -570,6 +574,7 @@ WriteMemorySendHandler(
|
||||||
if (ProcessListHead->Flink)
|
if (ProcessListHead->Flink)
|
||||||
__writecr3(PsGetCurrentProcess()->Pcb.DirectoryTableBase[0]);
|
__writecr3(PsGetCurrentProcess()->Pcb.DirectoryTableBase[0]);
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -669,7 +674,7 @@ handle_gdb_write_mem(
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
BOOLEAN
|
||||||
WriteBreakPointSendHandler(
|
WriteBreakPointSendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -681,12 +686,13 @@ WriteBreakPointSendHandler(
|
||||||
{
|
{
|
||||||
// KdAssert
|
// KdAssert
|
||||||
KDDBGPRINT("Wrong packet type (%lu) received after DbgKdWriteBreakPointApi request.\n", PacketType);
|
KDDBGPRINT("Wrong packet type (%lu) received after DbgKdWriteBreakPointApi request.\n", PacketType);
|
||||||
while (1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (State->ApiNumber != DbgKdWriteBreakPointApi)
|
if (State->ApiNumber != DbgKdWriteBreakPointApi)
|
||||||
{
|
{
|
||||||
KDDBGPRINT("Wrong API number (%lu) after DbgKdWriteBreakPointApi request.\n", State->ApiNumber);
|
KDDBGPRINT("Wrong API number (%lu) after DbgKdWriteBreakPointApi request.\n", State->ApiNumber);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check status */
|
/* Check status */
|
||||||
|
@ -712,6 +718,7 @@ WriteBreakPointSendHandler(
|
||||||
}
|
}
|
||||||
KdpSendPacketHandler = NULL;
|
KdpSendPacketHandler = NULL;
|
||||||
KdpManipulateStateHandler = NULL;
|
KdpManipulateStateHandler = NULL;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -767,7 +774,7 @@ handle_gdb_insert_breakpoint(
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
BOOLEAN
|
||||||
RestoreBreakPointSendHandler(
|
RestoreBreakPointSendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -780,12 +787,13 @@ RestoreBreakPointSendHandler(
|
||||||
{
|
{
|
||||||
// KdAssert
|
// KdAssert
|
||||||
KDDBGPRINT("Wrong packet type (%lu) received after DbgKdRestoreBreakPointApi request.\n", PacketType);
|
KDDBGPRINT("Wrong packet type (%lu) received after DbgKdRestoreBreakPointApi request.\n", PacketType);
|
||||||
while (1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (State->ApiNumber != DbgKdRestoreBreakPointApi)
|
if (State->ApiNumber != DbgKdRestoreBreakPointApi)
|
||||||
{
|
{
|
||||||
KDDBGPRINT("Wrong API number (%lu) after DbgKdRestoreBreakPointApi request.\n", State->ApiNumber);
|
KDDBGPRINT("Wrong API number (%lu) after DbgKdRestoreBreakPointApi request.\n", State->ApiNumber);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We ignore failure here. If DbgKdRestoreBreakPointApi fails,
|
/* We ignore failure here. If DbgKdRestoreBreakPointApi fails,
|
||||||
|
@ -804,6 +812,7 @@ RestoreBreakPointSendHandler(
|
||||||
|
|
||||||
KdpSendPacketHandler = NULL;
|
KdpSendPacketHandler = NULL;
|
||||||
KdpManipulateStateHandler = NULL;
|
KdpManipulateStateHandler = NULL;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
|
|
@ -57,7 +57,7 @@ InitManipulateFromStateChange(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callbacks to simulate a KdReceive <-> KdSend loop without GDB being aware of it */
|
/* Callbacks to simulate a KdReceive <-> KdSend loop without GDB being aware of it */
|
||||||
typedef VOID (*KDP_SEND_HANDLER)(
|
typedef BOOLEAN (*KDP_SEND_HANDLER)(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
_In_ PSTRING MessageData
|
_In_ PSTRING MessageData
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
/* LOCALS *********************************************************************/
|
/* LOCALS *********************************************************************/
|
||||||
static
|
static
|
||||||
VOID
|
BOOLEAN
|
||||||
FirstSendHandler(
|
FirstSendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -33,7 +33,7 @@ PETHREAD TheIdleThread;
|
||||||
/* PRIVATE FUNCTIONS **********************************************************/
|
/* PRIVATE FUNCTIONS **********************************************************/
|
||||||
|
|
||||||
static
|
static
|
||||||
VOID
|
BOOLEAN
|
||||||
GetContextSendHandler(
|
GetContextSendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -47,14 +47,14 @@ GetContextSendHandler(
|
||||||
|| (State->ApiNumber != DbgKdGetContextApi)
|
|| (State->ApiNumber != DbgKdGetContextApi)
|
||||||
|| (MessageData->Length < sizeof(*Context)))
|
|| (MessageData->Length < sizeof(*Context)))
|
||||||
{
|
{
|
||||||
/* Should we bugcheck ? */
|
|
||||||
KDDBGPRINT("ERROR: Received wrong packet from KD.\n");
|
KDDBGPRINT("ERROR: Received wrong packet from KD.\n");
|
||||||
while (1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Just copy it */
|
/* Just copy it */
|
||||||
RtlCopyMemory(&CurrentContext, Context, sizeof(*Context));
|
RtlCopyMemory(&CurrentContext, Context, sizeof(*Context));
|
||||||
KdpSendPacketHandler = NULL;
|
KdpSendPacketHandler = NULL;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -80,7 +80,7 @@ GetContextManipulateHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
VOID
|
BOOLEAN
|
||||||
SetContextSendHandler(
|
SetContextSendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -96,10 +96,11 @@ SetContextSendHandler(
|
||||||
{
|
{
|
||||||
/* Should we bugcheck ? */
|
/* Should we bugcheck ? */
|
||||||
KDDBGPRINT("BAD BAD BAD not manipulating state for sending context.\n");
|
KDDBGPRINT("BAD BAD BAD not manipulating state for sending context.\n");
|
||||||
while (1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
KdpSendPacketHandler = NULL;
|
KdpSendPacketHandler = NULL;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
KDSTATUS
|
KDSTATUS
|
||||||
|
@ -236,7 +237,7 @@ ContinueManipulateStateHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
VOID
|
BOOLEAN
|
||||||
GetVersionSendHandler(
|
GetVersionSendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -250,9 +251,8 @@ GetVersionSendHandler(
|
||||||
|| (State->ApiNumber != DbgKdGetVersionApi)
|
|| (State->ApiNumber != DbgKdGetVersionApi)
|
||||||
|| !NT_SUCCESS(State->ReturnStatus))
|
|| !NT_SUCCESS(State->ReturnStatus))
|
||||||
{
|
{
|
||||||
/* FIXME: should detach from KD and go along without debugging */
|
|
||||||
KDDBGPRINT("Wrong packet received after asking for data.\n");
|
KDDBGPRINT("Wrong packet received after asking for data.\n");
|
||||||
while(1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the relevant data */
|
/* Copy the relevant data */
|
||||||
|
@ -265,6 +265,7 @@ GetVersionSendHandler(
|
||||||
/* Now we can get the context for the current state */
|
/* Now we can get the context for the current state */
|
||||||
KdpSendPacketHandler = NULL;
|
KdpSendPacketHandler = NULL;
|
||||||
KdpManipulateStateHandler = GetContextManipulateHandler;
|
KdpManipulateStateHandler = GetContextManipulateHandler;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -288,7 +289,7 @@ GetVersionManipulateStateHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
VOID
|
BOOLEAN
|
||||||
FirstSendHandler(
|
FirstSendHandler(
|
||||||
_In_ ULONG PacketType,
|
_In_ ULONG PacketType,
|
||||||
_In_ PSTRING MessageHeader,
|
_In_ PSTRING MessageHeader,
|
||||||
|
@ -297,18 +298,10 @@ FirstSendHandler(
|
||||||
DBGKD_ANY_WAIT_STATE_CHANGE* StateChange = (DBGKD_ANY_WAIT_STATE_CHANGE*)MessageHeader->Buffer;
|
DBGKD_ANY_WAIT_STATE_CHANGE* StateChange = (DBGKD_ANY_WAIT_STATE_CHANGE*)MessageHeader->Buffer;
|
||||||
PETHREAD Thread;
|
PETHREAD Thread;
|
||||||
|
|
||||||
if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
|
|
||||||
{
|
|
||||||
/* This is not the packet we are waiting for */
|
|
||||||
send_kd_debug_io((DBGKD_DEBUG_IO*)MessageHeader->Buffer, MessageData);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PacketType != PACKET_TYPE_KD_STATE_CHANGE64)
|
if (PacketType != PACKET_TYPE_KD_STATE_CHANGE64)
|
||||||
{
|
{
|
||||||
KDDBGPRINT("First KD packet is not a state change!\n");
|
KDDBGPRINT("First KD packet is not a state change!\n");
|
||||||
/* FIXME: What should we send back to KD ? */
|
return FALSE;
|
||||||
while(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KDDBGPRINT("KDGDB: START!\n");
|
KDDBGPRINT("KDGDB: START!\n");
|
||||||
|
@ -332,6 +325,7 @@ FirstSendHandler(
|
||||||
/* The next receive call will be asking for the version data */
|
/* The next receive call will be asking for the version data */
|
||||||
KdpSendPacketHandler = NULL;
|
KdpSendPacketHandler = NULL;
|
||||||
KdpManipulateStateHandler = GetVersionManipulateStateHandler;
|
KdpManipulateStateHandler = GetVersionManipulateStateHandler;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PUBLIC FUNCTIONS ***********************************************************/
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
||||||
|
@ -426,9 +420,9 @@ KdSendPacket(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Maybe we are in a send <-> receive loop that GDB doesn't need to know about */
|
/* Maybe we are in a send <-> receive loop that GDB doesn't need to know about */
|
||||||
if (KdpSendPacketHandler)
|
if (KdpSendPacketHandler
|
||||||
|
&& KdpSendPacketHandler(PacketType, MessageHeader, MessageData))
|
||||||
{
|
{
|
||||||
KdpSendPacketHandler(PacketType, MessageHeader, MessageData);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue