Patchwork [v3,20/39] windbg: implement windbg_process_manipulate_packet

login
register
mail settings
Submitter Mihail Abakumov
Date Dec. 6, 2018, noon
Message ID <154409763050.5432.9603759721356480431.stgit@Misha-PC.lan02.inno>
Download mbox | patch
Permalink /patch/674031/
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>
---
 include/exec/windbgstub-utils.h |    2 ++
 windbgstub-utils.c              |    7 +++++++
 windbgstub.c                    |   27 +++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)

Patch

diff --git a/include/exec/windbgstub-utils.h b/include/exec/windbgstub-utils.h
index 794cb387b0..1c577ddd49 100644
--- a/include/exec/windbgstub-utils.h
+++ b/include/exec/windbgstub-utils.h
@@ -67,6 +67,8 @@  typedef struct PacketData {
 const char *kd_api_name(int id);
 const char *kd_pkt_type_name(int id);
 
+void kd_api_unsupported(CPUState *cs, PacketData *pd);
+
 DBGKD_ANY_WAIT_STATE_CHANGE *kd_state_change_exc(CPUState *cs);
 DBGKD_ANY_WAIT_STATE_CHANGE *kd_state_change_ls(CPUState *cs);
 
diff --git a/windbgstub-utils.c b/windbgstub-utils.c
index 6c5a86f667..1455693975 100644
--- a/windbgstub-utils.c
+++ b/windbgstub-utils.c
@@ -200,6 +200,13 @@  InitedAddr windbg_search_vmaddr(CPUState *cs, target_ulong start,
     return ret;
 }
 
+void kd_api_unsupported(CPUState *cs, PacketData *pd)
+{
+    WINDBG_ERROR("Caught unimplemented api %s", kd_api_name(pd->m64.ApiNumber));
+    pd->m64.ReturnStatus = STATUS_UNSUCCESSFUL;
+    pd->extra_size = 0;
+}
+
 const char *kd_api_name(int id)
 {
     return (id >= DbgKdMinimumManipulate && id < DbgKdMaximumManipulate)
diff --git a/windbgstub.c b/windbgstub.c
index 8cbece40da..6ed93b8ce9 100644
--- a/windbgstub.c
+++ b/windbgstub.c
@@ -136,6 +136,33 @@  static void windbg_vm_stop(void)
 
 static void windbg_process_manipulate_packet(WindbgState *state)
 {
+    CPUState *cs;
+    ParsingContext *ctx = &state->ctx;
+    PacketData *data = &ctx->data;
+
+    data->extra_size = ctx->packet.ByteCount - sizeof(DBGKD_MANIPULATE_STATE64);
+    data->m64.ReturnStatus = STATUS_SUCCESS;
+
+    cs = qemu_get_cpu(data->m64.Processor);
+    if (cs == NULL) {
+        cs = qemu_get_cpu(0);
+    }
+
+    switch (data->m64.ApiNumber) {
+    default:
+        kd_api_unsupported(cs, data);
+        break;
+    }
+
+    if (data->m64.ReturnStatus == STATUS_UNSUCCESSFUL) {
+        WINDBG_ERROR("Caught error at %s", kd_api_name(data->m64.ApiNumber));
+    }
+
+    stl_p(&data->m64.ReturnStatus, data->m64.ReturnStatus);
+
+    windbg_send_data_packet(state, data->buf,
+                            data->extra_size + sizeof(DBGKD_MANIPULATE_STATE64),
+                            ctx->packet.PacketType);
 }
 
 static void windbg_process_data_packet(WindbgState *state)