aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accel/kvm/kvm-all.c12
-rw-r--r--gdbstub.c10
-rw-r--r--include/sysemu/kvm.h15
3 files changed, 36 insertions, 1 deletions
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index eecd8031cf..2f5597572a 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -168,6 +168,8 @@ bool kvm_vm_attributes_allowed;
bool kvm_direct_msi_allowed;
bool kvm_ioeventfd_any_length_allowed;
bool kvm_msi_use_devid;
+bool kvm_has_guest_debug;
+int kvm_sstep_flags;
static bool kvm_immediate_exit;
static hwaddr kvm_max_slot_size = ~0;
@@ -2564,6 +2566,16 @@ static int kvm_init(MachineState *ms)
kvm_ioeventfd_any_length_allowed =
(kvm_check_extension(s, KVM_CAP_IOEVENTFD_ANY_LENGTH) > 0);
+#ifdef KVM_CAP_SET_GUEST_DEBUG
+ kvm_has_guest_debug =
+ (kvm_check_extension(s, KVM_CAP_SET_GUEST_DEBUG) > 0);
+#endif
+
+ kvm_sstep_flags = 0;
+ if (kvm_has_guest_debug) {
+ kvm_sstep_flags = SSTEP_ENABLE;
+ }
+
kvm_state = s;
ret = kvm_arch_init(ms, s);
diff --git a/gdbstub.c b/gdbstub.c
index a955175fd4..3c14c6a038 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -391,6 +391,8 @@ static void init_gdbserver_state(void)
*/
if (replay_mode != REPLAY_MODE_NONE) {
gdbserver_state.supported_sstep_flags = SSTEP_ENABLE;
+ } else if (kvm_enabled()) {
+ gdbserver_state.supported_sstep_flags = kvm_get_supported_sstep_flags();
} else {
gdbserver_state.supported_sstep_flags =
SSTEP_ENABLE | SSTEP_NOIRQ | SSTEP_NOTIMER;
@@ -400,7 +402,8 @@ static void init_gdbserver_state(void)
* By default use no IRQs and no timers while single stepping so as to
* make single stepping like an ICE HW step.
*/
- gdbserver_state.sstep_flags = gdbserver_state.supported_sstep_flags;
+ gdbserver_state.sstep_flags = SSTEP_ENABLE | SSTEP_NOIRQ | SSTEP_NOTIMER;
+ gdbserver_state.sstep_flags &= gdbserver_state.supported_sstep_flags;
}
@@ -3520,6 +3523,11 @@ int gdbserver_start(const char *device)
return -1;
}
+ if (kvm_enabled() && !kvm_supports_guest_debug()) {
+ error_report("gdbstub: KVM doesn't support guest debugging");
+ return -1;
+ }
+
if (!device)
return -1;
if (strcmp(device, "none") != 0) {
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 7b22aeb6ae..6eb39a088b 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -46,6 +46,8 @@ extern bool kvm_readonly_mem_allowed;
extern bool kvm_direct_msi_allowed;
extern bool kvm_ioeventfd_any_length_allowed;
extern bool kvm_msi_use_devid;
+extern bool kvm_has_guest_debug;
+extern int kvm_sstep_flags;
#define kvm_enabled() (kvm_allowed)
/**
@@ -167,6 +169,17 @@ extern bool kvm_msi_use_devid;
*/
#define kvm_msi_devid_required() (kvm_msi_use_devid)
+/*
+ * Does KVM support guest debugging
+ */
+#define kvm_supports_guest_debug() (kvm_has_guest_debug)
+
+/*
+ * kvm_supported_sstep_flags
+ * Returns: SSTEP_* flags that KVM supports for guest debug
+ */
+#define kvm_get_supported_sstep_flags() (kvm_sstep_flags)
+
#else
#define kvm_enabled() (0)
@@ -184,6 +197,8 @@ extern bool kvm_msi_use_devid;
#define kvm_direct_msi_enabled() (false)
#define kvm_ioeventfd_any_length_enabled() (false)
#define kvm_msi_devid_required() (false)
+#define kvm_supports_guest_debug() (false)
+#define kvm_get_supported_sstep_flags() (0)
#endif /* CONFIG_KVM_IS_POSSIBLE */