[PATCH 8/11] QEMU/KVM: Support for SMP guest debugging

Jan Kiszka
2008-05-26T22:10:27Z

Enables debugging of SMP guests via the new KVM debug interface. It
updates the monitored CPU on breakpoints and unsures that breakpoint
changes are propagested to all virtual CPUs.

Signed-off-by: Jan Kiszka <jan.kiszka@web.de>
---
qemu/qemu-kvm.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

Index: b/qemu/qemu-kvm.c
===================================================================
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -19,6 +19,7 @@ int kvm_pit = 1;
#include "qemu-common.h"
#include "console.h"
#include "block.h"
+#include "monitor.h"

#include "qemu-kvm.h"
#include <libkvm.h>
@@ -58,7 +59,7 @@ pthread_t io_thread;
static int io_thread_fd = -1;
static int io_thread_sigfd = -1;

-static int kvm_debug_stop_requested;
+static CPUState *kvm_debug_cpu_requested;

static inline unsigned long kvm_get_thread_id(void)
{
@@ -534,9 +535,10 @@ int kvm_main_loop(void)
qemu_system_powerdown();
else if (qemu_reset_requested())
qemu_kvm_system_reset();
- else if (kvm_debug_stop_requested) {
+ else if (kvm_debug_cpu_requested) {
+ mon_set_cpu(kvm_debug_cpu_requested);
vm_stop(EXCP_DEBUG);
- kvm_debug_stop_requested = 0;
+ kvm_debug_cpu_requested = NULL;
}
}

@@ -552,7 +554,7 @@ int kvm_debug(void *opaque, int vcpu, st
int handle = kvm_arch_debug(arch_info);

if (handle) {
- kvm_debug_stop_requested = 1;
+ kvm_debug_cpu_requested = cpu_single_env;
vcpu_info[vcpu].stopped = 1;
}
return handle;
@@ -846,7 +848,12 @@ int kvm_insert_breakpoint(CPUState *env,
if (err)
return err;
}
- return kvm_update_guest_debug(env, 0);
+ foreach_cpu(env) {
+ err = kvm_update_guest_debug(env, 0);
+ if (err)
+ break;
+ }
+ return err;
}

int kvm_remove_breakpoint(CPUState *env, target_ulong addr,
@@ -882,7 +889,12 @@ int kvm_remove_breakpoint(CPUState *env,
if (err)
return err;
}
- return kvm_update_guest_debug(env, 0);
+ foreach_cpu(env) {
+ err = kvm_update_guest_debug(env, 0);
+ if (err)
+ break;
+ }
+ return err;
}

#else /* !KVM_CAP_SET_GUEST_DEBUG */