[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 34/46] windbg: debug exception subscribing
From: |
Mihail Abakumov |
Subject: |
[Qemu-devel] [PATCH v4 34/46] windbg: debug exception subscribing |
Date: |
Mon, 11 Dec 2017 16:24:33 +0300 |
User-agent: |
StGit/0.17.1-dirty |
Added handler registration of gdb debug exception. Its exception also can be
used for windbg.
Signed-off-by: Mihail Abakumov <address@hidden>
Signed-off-by: Pavel Dovgalyuk <address@hidden>
Signed-off-by: Dmitriy Koltunov <address@hidden>
---
cpus.c | 19 ++++++++++++++++++-
gdbstub.c | 4 ++++
include/sysemu/sysemu.h | 2 ++
windbgstub.c | 16 ++++++++++++----
4 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/cpus.c b/cpus.c
index 9bed61eefc..498b7e1dd9 100644
--- a/cpus.c
+++ b/cpus.c
@@ -77,6 +77,8 @@ int64_t max_advance;
static QEMUTimer *throttle_timer;
static unsigned int throttle_percentage;
+static void (*excp_debug_handler)(CPUState *cpu);
+
#define CPU_THROTTLE_PCT_MIN 1
#define CPU_THROTTLE_PCT_MAX 99
#define CPU_THROTTLE_TIMESLICE_NS 10000000
@@ -960,9 +962,24 @@ static bool cpu_can_run(CPUState *cpu)
return true;
}
+bool register_excp_debug_handler(void (*handler)(CPUState *cpu))
+{
+ if (excp_debug_handler == NULL) {
+ excp_debug_handler = handler;
+ return true;
+ } else {
+ error_report("Something debugger is already in use. '-gdb' and "
+ "'-windbg' cannot be used at the same time");
+ return false;
+ }
+}
+
static void cpu_handle_guest_debug(CPUState *cpu)
{
- gdb_set_stop_cpu(cpu);
+ if (excp_debug_handler != NULL) {
+ excp_debug_handler(cpu);
+ }
+
qemu_system_debug_request();
cpu->stopped = true;
}
diff --git a/gdbstub.c b/gdbstub.c
index 2a94030d3b..8c76f54117 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2006,6 +2006,10 @@ int gdbserver_start(const char *device)
s->mon_chr = mon_chr;
s->current_syscall_cb = NULL;
+ if (!register_excp_debug_handler(gdb_set_stop_cpu)) {
+ exit(1);
+ }
+
return 0;
}
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index b21369672a..34588c99b4 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -193,6 +193,8 @@ QemuOpts *qemu_get_machine_opts(void);
bool defaults_enabled(void);
+bool register_excp_debug_handler(void (*handler)(CPUState *cpu));
+
extern QemuOptsList qemu_legacy_drive_opts;
extern QemuOptsList qemu_common_drive_opts;
extern QemuOptsList qemu_drive_opts;
diff --git a/windbgstub.c b/windbgstub.c
index a534fe170b..d3c1317255 100755
--- a/windbgstub.c
+++ b/windbgstub.c
@@ -115,16 +115,20 @@ static void windbg_send_control_packet(uint16_t type)
windbg_state->ctrl_packet_id ^= 1;
}
-static void windbg_vm_stop(void)
+static void windbg_bp_handler(CPUState *cpu)
{
- CPUState *cpu = qemu_get_cpu(0);
- vm_stop(RUN_STATE_PAUSED);
-
SizedBuf buf = kd_gen_exception_sc(cpu);
windbg_send_data_packet(buf.data, buf.size, PACKET_TYPE_KD_STATE_CHANGE64);
g_free(buf.data);
}
+static void windbg_vm_stop(void)
+{
+ CPUState *cpu = qemu_get_cpu(0);
+ vm_stop(RUN_STATE_PAUSED);
+ windbg_bp_handler(cpu);
+}
+
static void windbg_process_manipulate_packet(ParsingContext *ctx)
{
CPUState *cpu;
@@ -432,6 +436,10 @@ int windbg_server_start(const char *device)
qemu_register_reset(windbg_handle_reset, NULL);
+ if (!register_excp_debug_handler(windbg_bp_handler)) {
+ exit(1);
+ }
+
atexit(windbg_exit);
return 0;
}
- [Qemu-devel] [PATCH v4 24/46] windbg: implemented kd_api_read_control_space and kd_api_write_control_space, (continued)
- [Qemu-devel] [PATCH v4 24/46] windbg: implemented kd_api_read_control_space and kd_api_write_control_space, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 25/46] windbg: implemented windbg_read_context, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 26/46] windbg: implemented windbg_write_context, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 28/46] windbg: implemented windbg_write_ks_regs, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 27/46] windbg: implemented windbg_read_ks_regs, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 29/46] windbg: implemented windbg_set_sr, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 30/46] windbg: implemented windbg_set_dr, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 31/46] windbg: implemented windbg_set_dr7, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 32/46] windbg: implemented windbg_hw_breakpoint_insert and windbg_hw_breakpoint_remove, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 33/46] windbg: implemented kd_api_write_breakpoint and kd_api_restore_breakpoint, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 34/46] windbg: debug exception subscribing,
Mihail Abakumov <=
- [Qemu-devel] [PATCH v4 35/46] windbg: implemented kd_api_continue, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 36/46] windbg: implemented kd_api_read_io_space and kd_api_write_io_space, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 37/46] windbg: implemented kd_api_read_physical_memory and kd_api_write_physical_memory, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 38/46] windbg: implemented kd_api_get_version, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 39/46] windbg: implemented kd_api_read_msr and kd_api_write_msr, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 40/46] windbg: implemented kd_api_search_memory, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 41/46] windbg: implemented kd_api_fill_memory, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 42/46] windbg: implemented kd_api_query_memory, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 43/46] windbg: added new api functions, Mihail Abakumov, 2017/12/11
- [Qemu-devel] [PATCH v4 44/46] windbg: implemented kd_api_get_context_ex and kd_api_set_context_ex, Mihail Abakumov, 2017/12/11