@@ -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,23 @@ 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("ERROR: Something debugger already using");
+ 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;
}
@@ -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;
}
@@ -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;
@@ -112,16 +112,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);
SBUF_FREE(buf);
}
+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;
@@ -406,6 +410,10 @@ int windbg_server_start(const char *device)
qemu_chr_fe_set_handlers(&windbg_state->chr, windbg_chr_can_receive,
windbg_chr_receive, NULL, NULL, NULL, NULL, true);
+ if (!register_excp_debug_handler(windbg_bp_handler)) {
+ exit(1);
+ }
+
atexit(windbg_exit);
return 0;
}