[KDGDB]
authorJérôme Gardou <jerome.gardou@reactos.org>
Sun, 14 Sep 2014 14:27:58 +0000 (14:27 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Sun, 14 Sep 2014 14:27:58 +0000 (14:27 +0000)
 - Improve the 'm' (read memory) gdb request

svn path=/trunk/; revision=64145

reactos/drivers/base/kdgdb/gdb_input.c
reactos/drivers/base/kdgdb/gdb_send.c
reactos/drivers/base/kdgdb/kdgdb.h
reactos/drivers/base/kdgdb/kdpacket.c

index a048b51..0f8ab25 100644 (file)
@@ -275,6 +275,35 @@ handle_gdb_registers(
 }
 #endif
 
+static
+void
+ReadMemorySendHandler(
+    _In_ ULONG PacketType,
+    _In_ PSTRING MessageHeader,
+    _In_ PSTRING MessageData)
+{
+    DBGKD_MANIPULATE_STATE64* State = (DBGKD_MANIPULATE_STATE64*)MessageHeader->Buffer;
+
+    if (PacketType != PACKET_TYPE_KD_STATE_MANIPULATE)
+    {
+        // KdAssert
+        KDDBGPRINT("Wrong packet type (%lu) received after DbgKdReadVirtualMemoryApi request.\n", PacketType);
+        while (1);
+    }
+
+    if (State->ApiNumber != DbgKdReadVirtualMemoryApi)
+    {
+        KDDBGPRINT("Wrong API number (%lu) after DbgKdReadVirtualMemoryApi request.\n", State->ApiNumber);
+    }
+
+    /* Check status */
+    if (!NT_SUCCESS(State->ReturnStatus))
+        send_gdb_ntstatus(State->ReturnStatus);
+    else
+        send_gdb_memory(MessageData->Buffer, MessageData->Length);
+    KdpSendPacketHandler = NULL;
+}
+
 static
 KDSTATUS
 handle_gdb_read_mem(
@@ -292,6 +321,10 @@ handle_gdb_read_mem(
 
     State->u.ReadMemory.TargetBaseAddress = hex_to_address(&gdb_input[1]);
     State->u.ReadMemory.TransferCount = hex_to_address(strstr(&gdb_input[1], ",") + 1);
+
+    /* KD will reply with KdSendPacket. Catch it */
+    KdpSendPacketHandler = ReadMemorySendHandler;
+
     return KdPacketReceived;
 }
 
index 980498e..b31faeb 100644 (file)
@@ -185,3 +185,15 @@ gdb_send_exception(void)
     ptr += sprintf(ptr, "core:%x;", CurrentStateChange.Processor);
     send_gdb_packet(gdb_out);
 }
+
+void
+send_gdb_ntstatus(
+    _In_ NTSTATUS Status)
+{
+    /* Just build a EXX packet and send it */
+    char gdb_out[4];
+    gdb_out[0] = 'E';
+    exception_code_to_gdb(Status, &gdb_out[1]);
+    gdb_out[3] = '\0';
+    send_gdb_packet(gdb_out);
+}
index 03cac67..07a0eab 100644 (file)
@@ -52,6 +52,7 @@ void send_gdb_packet(_In_ CHAR* Buffer);
 void send_gdb_memory(_In_ VOID* Buffer, size_t Length);
 void gdb_send_debug_io(_In_ PSTRING String);
 void gdb_send_exception(void);
+void send_gdb_ntstatus(_In_ NTSTATUS Status);
 
 /* kdcom.c */
 KDSTATUS NTAPI KdpPollBreakIn(VOID);
index dee08a8..9d29826 100644 (file)
@@ -100,10 +100,6 @@ send_kd_state_manipulate(
         gdb_send_registers((CONTEXT*)MessageData->Buffer);
         return;
 #endif
-    case DbgKdReadVirtualMemoryApi:
-        /* Answer to 'm' GDB request */
-        send_gdb_memory(MessageData->Buffer, State->u.ReadMemory.ActualBytesRead);
-        break;
     case DbgKdGetVersionApi:
     {
         LIST_ENTRY* DebuggerDataList;