https://git.reactos.org/?p=reactos.git;a=commitdiff;h=de369ce26ba0bfc657754…
commit de369ce26ba0bfc6577543ede93b41418098940a
Author: Jérôme Gardou <jerome.gardou(a)reactos.org>
AuthorDate: Fri Mar 20 10:32:19 2020 +0000
Commit: Jérôme Gardou <jerome.gardou(a)reactos.org>
CommitDate: Mon Mar 30 07:53:34 2020 +0000
[KDGDB] Various fixes and improvements
---
drivers/base/kdgdb/gdb_input.c | 14 +++++++-------
drivers/base/kdgdb/gdb_receive.c | 28 ++++++++++++++++++++--------
drivers/base/kdgdb/kdcom.c | 16 ++++++++++------
drivers/base/kdgdb/kdgdb.h | 1 +
drivers/base/kdgdb/kdpacket.c | 17 +++++++++++++++--
5 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/drivers/base/kdgdb/gdb_input.c b/drivers/base/kdgdb/gdb_input.c
index 9331dbd9e8c..ab2efdc10a4 100644
--- a/drivers/base/kdgdb/gdb_input.c
+++ b/drivers/base/kdgdb/gdb_input.c
@@ -368,15 +368,16 @@ handle_gdb_query(void)
PLDR_DATA_TABLE_ENTRY TableEntry = CONTAINING_RECORD(CurrentEntry,
LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
PVOID DllBase = (PVOID)((ULONG_PTR)TableEntry->DllBase + 0x1000);
LONG mem_length;
- char* ptr;
+ USHORT i;
/* Convert names to lower case. Yes this _is_ ugly */
- _snprintf(name_helper, 64, "%wZ",
&TableEntry->BaseDllName);
- for (ptr = name_helper; *ptr; ptr++)
+ for (i = 0; i < (TableEntry->BaseDllName.Length / sizeof(WCHAR)); i++)
{
- if (*ptr >= 'A' && *ptr <= 'Z')
- *ptr += 'a' - 'A';
+ name_helper[i] = (char)TableEntry->BaseDllName.Buffer[i];
+ if (name_helper[i] >= 'A' && name_helper[i] <=
'Z')
+ name_helper[i] += 'a' - 'A';
}
+ name_helper[i] = 0;
/* GDB doesn't load the file if you don't prefix it with a drive
letter... */
mem_length = _snprintf(str_helper, 256, "<library
name=\"C:\\%s\"><segment
address=\"0x%p\"/></library>", &name_helper, DllBase);
@@ -393,7 +394,7 @@ handle_gdb_query(void)
/* We're done for this pass */
return finish_gdb_packet();
}
-
+
Sent += send_gdb_partial_binary(str_helper, mem_length);
}
@@ -404,7 +405,6 @@ handle_gdb_query(void)
}
return finish_gdb_packet();
-
}
KDDBGPRINT("KDGDB: Unknown query: %s\n", gdb_input);
diff --git a/drivers/base/kdgdb/gdb_receive.c b/drivers/base/kdgdb/gdb_receive.c
index a246f5f3d51..b97769d1742 100644
--- a/drivers/base/kdgdb/gdb_receive.c
+++ b/drivers/base/kdgdb/gdb_receive.c
@@ -30,24 +30,22 @@ KDSTATUS
NTAPI
gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext)
{
- UCHAR* ByteBuffer = (UCHAR*)gdb_input;
+ UCHAR* ByteBuffer;
UCHAR Byte;
KDSTATUS Status;
- CHAR CheckSum = 0, ReceivedCheckSum;
+ CHAR CheckSum, ReceivedCheckSum;
do
{
Status = KdpReceiveByte(&Byte);
if (Status != KdPacketReceived)
return Status;
- if (Byte == 0x03)
- {
- KDDBGPRINT("BREAK!");
- KdContext->KdpControlCPending = TRUE;
- return KdPacketNeedsResend;
- }
} while (Byte != '$');
+get_packet:
+ CheckSum = 0;
+ ByteBuffer = (UCHAR*)gdb_input;
+
while (TRUE)
{
/* Try to get a byte from the port */
@@ -94,6 +92,20 @@ end:
return KdPacketNeedsResend;
}
+ /* Ensure there is nothing left in the pipe */
+ while (KdpPollByte(&Byte) == KdPacketReceived)
+ {
+ switch (Byte)
+ {
+ case '$':
+ KDDBGPRINT("Received new packet just after %s.\n", gdb_input);
+ goto get_packet;
+ case 0x03:
+ KdContext->KdpControlCPending = TRUE;
+ break;
+ }
+ }
+
/* Acknowledge */
KdpSendByte('+');
diff --git a/drivers/base/kdgdb/kdcom.c b/drivers/base/kdgdb/kdcom.c
index 1a798b74403..af9ec39829c 100644
--- a/drivers/base/kdgdb/kdcom.c
+++ b/drivers/base/kdgdb/kdcom.c
@@ -129,11 +129,9 @@ KdpPortInitialize(IN ULONG ComPortNumber,
{
return STATUS_INVALID_PARAMETER;
}
- else
- {
- KdComPortInUse = KdComPort.Address;
- return STATUS_SUCCESS;
- }
+
+ KdComPortInUse = KdComPort.Address;
+ return STATUS_SUCCESS;
}
/******************************************************************************
@@ -300,7 +298,13 @@ KDSTATUS
NTAPI
KdpReceiveByte(_Out_ PUCHAR OutByte)
{
- USHORT CpStatus = CpGetByte(&KdComPort, OutByte, TRUE, FALSE);
+ USHORT CpStatus;
+
+ do
+ {
+ CpStatus = CpGetByte(&KdComPort, OutByte, TRUE, FALSE);
+ } while (CpStatus == CP_GET_NODATA);
+
/* Get the byte */
if (CpStatus == CP_GET_SUCCESS)
{
diff --git a/drivers/base/kdgdb/kdgdb.h b/drivers/base/kdgdb/kdgdb.h
index d2f4cd1de34..d09ef74593b 100644
--- a/drivers/base/kdgdb/kdgdb.h
+++ b/drivers/base/kdgdb/kdgdb.h
@@ -96,6 +96,7 @@ extern const char hex_chars[];
KDSTATUS NTAPI KdpPollBreakIn(VOID);
VOID NTAPI KdpSendByte(_In_ UCHAR Byte);
KDSTATUS NTAPI KdpReceiveByte(_Out_ PUCHAR OutByte);
+KDSTATUS NTAPI KdpPollByte(OUT PUCHAR OutByte);
/* kdpacket.c */
extern DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange;
diff --git a/drivers/base/kdgdb/kdpacket.c b/drivers/base/kdgdb/kdpacket.c
index 3e6474a68bc..fe776eef55e 100644
--- a/drivers/base/kdgdb/kdpacket.c
+++ b/drivers/base/kdgdb/kdpacket.c
@@ -360,15 +360,25 @@ KdReceivePacket(
_Out_ PULONG DataLength,
_Inout_ PKD_CONTEXT KdContext)
{
- KDDBGPRINT("KdReceivePacket.\n");
+ KDDBGPRINT("KdReceivePacket --> ");
if (PacketType == PACKET_TYPE_KD_POLL_BREAKIN)
{
+ static BOOLEAN firstTime = TRUE;
+ KDDBGPRINT("Polling break in.\n");
+ if (firstTime)
+ {
+ /* Force debug break on init */
+ firstTime = FALSE;
+ return KdPacketReceived;
+ }
+
return KdpPollBreakIn();
}
if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
{
+ KDDBGPRINT("Debug prompt.\n");
/* HACK ! RtlAssert asks for (boipt), always say "o" --> break once.
*/
MessageData->Length = 1;
MessageData->Buffer[0] = 'o';
@@ -379,14 +389,17 @@ KdReceivePacket(
{
DBGKD_MANIPULATE_STATE64* State =
(DBGKD_MANIPULATE_STATE64*)MessageHeader->Buffer;
+ KDDBGPRINT("State manipulation: ");
+
/* Maybe we are in a send<->receive loop that GDB doesn't need to know
about */
if (KdpManipulateStateHandler != NULL)
{
- KDDBGPRINT("KDGBD: We have a manipulate state handler.\n");
+ KDDBGPRINT("We have a manipulate state handler.\n");
return KdpManipulateStateHandler(State, MessageData, DataLength, KdContext);
}
/* Receive data from GDB and interpret it */
+ KDDBGPRINT("Receiving data from GDB.\n");
return gdb_receive_and_interpret_packet(State, MessageData, DataLength,
KdContext);
}