Patchwork [v3,18/39] windbg: implement windbg_process_control_packet

login
register
mail settings
Submitter Mihail Abakumov
Date Dec. 6, 2018, noon
Message ID <154409761937.5432.17355379909741877238.stgit@Misha-PC.lan02.inno>
Download mbox | patch
Permalink /patch/674023/
State New
Headers show

Comments

Mihail Abakumov - Dec. 6, 2018, noon
Signed-off-by: Mikhail Abakumov <mikhail.abakumov@ispras.ru>
Signed-off-by: Pavel Dovgalyuk <dovgaluk@ispras.ru>
---
 windbgstub.c |   35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

Patch

diff --git a/windbgstub.c b/windbgstub.c
index fe0b007a06..f13c9a6c1e 100644
--- a/windbgstub.c
+++ b/windbgstub.c
@@ -91,7 +91,6 @@  static void windbg_store_packet(KD_PACKET *packet)
     stl_p(&packet->Checksum, packet->Checksum);
 }
 
-__attribute__ ((unused)) /* unused yet */
 static void windbg_send_data_packet(WindbgState *state, uint8_t *data,
                                     uint16_t byte_count, uint16_t type)
 {
@@ -141,6 +140,40 @@  static void windbg_process_data_packet(WindbgState *state)
 
 static void windbg_process_control_packet(WindbgState *state)
 {
+    ParsingContext *ctx = &state->ctx;
+
+    switch (ctx->packet.PacketType) {
+    case PACKET_TYPE_KD_ACKNOWLEDGE:
+        if (state->wait_packet_type == PACKET_TYPE_KD_ACKNOWLEDGE &&
+            (ctx->packet.PacketId == (state->curr_packet_id &
+                                      ~SYNC_PACKET_ID))) {
+            state->curr_packet_id ^= 1;
+            state->wait_packet_type = 0;
+        }
+        break;
+
+    case PACKET_TYPE_KD_RESET: {
+        state->curr_packet_id = INITIAL_PACKET_ID;
+        windbg_send_control_packet(state, PACKET_TYPE_KD_RESET, 0);
+
+        DBGKD_ANY_WAIT_STATE_CHANGE *sc = kd_state_change_ls(qemu_get_cpu(0));
+        windbg_send_data_packet(state, (uint8_t *) sc,
+                                sizeof(DBGKD_ANY_WAIT_STATE_CHANGE),
+                                PACKET_TYPE_KD_STATE_CHANGE64);
+        g_free(sc);
+        break;
+    }
+
+    case PACKET_TYPE_KD_RESEND:
+        break;
+
+    default:
+        WINDBG_ERROR("Caught unsupported control packet 0x%x",
+                     ctx->packet.PacketType);
+
+        windbg_send_control_packet(state, PACKET_TYPE_KD_RESEND, 0);
+        break;
+    }
 }
 
 static void windbg_ctx_handler(WindbgState *state)