Skip to content

Commit a48e7d9

Browse files
committed
gdbstub: move guest debug support check to ops
This removes the final hard coding of kvm_enabled() in gdbstub and moves the check to an AccelOps. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Reviewed-by: Mads Ynddal <[email protected]> Message-Id: <[email protected]>
1 parent ae7467b commit a48e7d9

File tree

10 files changed

+33
-10
lines changed

10 files changed

+33
-10
lines changed

accel/kvm/kvm-accel-ops.c

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data)
9999
ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;
100100

101101
#ifdef KVM_CAP_SET_GUEST_DEBUG
102+
ops->supports_guest_debug = kvm_supports_guest_debug;
102103
ops->insert_breakpoint = kvm_insert_breakpoint;
103104
ops->remove_breakpoint = kvm_remove_breakpoint;
104105
ops->remove_all_breakpoints = kvm_remove_all_breakpoints;

accel/kvm/kvm-all.c

+6
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,12 @@ int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
32873287
return data.err;
32883288
}
32893289

3290+
bool kvm_supports_guest_debug(void)
3291+
{
3292+
/* probed during kvm_init() */
3293+
return kvm_has_guest_debug;
3294+
}
3295+
32903296
int kvm_insert_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len)
32913297
{
32923298
struct kvm_sw_breakpoint *bp;

accel/kvm/kvm-cpus.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void kvm_destroy_vcpu(CPUState *cpu);
1818
void kvm_cpu_synchronize_post_reset(CPUState *cpu);
1919
void kvm_cpu_synchronize_post_init(CPUState *cpu);
2020
void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu);
21+
bool kvm_supports_guest_debug(void);
2122
int kvm_insert_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len);
2223
int kvm_remove_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len);
2324
void kvm_remove_all_breakpoints(CPUState *cpu);

accel/tcg/tcg-accel-ops.c

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ void tcg_handle_interrupt(CPUState *cpu, int mask)
9393
}
9494
}
9595

96+
static bool tcg_supports_guest_debug(void)
97+
{
98+
return true;
99+
}
100+
96101
/* Translate GDB watchpoint type to a flags value for cpu_watchpoint_* */
97102
static inline int xlat_gdb_type(CPUState *cpu, int gdbtype)
98103
{
@@ -198,6 +203,7 @@ static void tcg_accel_ops_init(AccelOpsClass *ops)
198203
}
199204
}
200205

206+
ops->supports_guest_debug = tcg_supports_guest_debug;
201207
ops->insert_breakpoint = tcg_insert_breakpoint;
202208
ops->remove_breakpoint = tcg_remove_breakpoint;
203209
ops->remove_all_breakpoints = tcg_remove_all_breakpoints;

gdbstub/gdbstub.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
#include "qemu/sockets.h"
4747
#include "sysemu/hw_accel.h"
48-
#include "sysemu/kvm.h"
4948
#include "sysemu/runstate.h"
5049
#include "semihosting/semihost.h"
5150
#include "exec/exec-all.h"
@@ -3447,8 +3446,8 @@ int gdbserver_start(const char *device)
34473446
return -1;
34483447
}
34493448

3450-
if (kvm_enabled() && !kvm_supports_guest_debug()) {
3451-
error_report("gdbstub: KVM doesn't support guest debugging");
3449+
if (!gdb_supports_guest_debug()) {
3450+
error_report("gdbstub: current accelerator doesn't support guest debugging");
34523451
return -1;
34533452
}
34543453

gdbstub/internals.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef _INTERNALS_H_
1010
#define _INTERNALS_H_
1111

12+
bool gdb_supports_guest_debug(void);
1213
int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len);
1314
int gdb_breakpoint_remove(CPUState *cs, int type, hwaddr addr, hwaddr len);
1415
void gdb_breakpoint_remove_all(CPUState *cs);

gdbstub/softmmu.c

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
#include "sysemu/cpus.h"
1616
#include "internals.h"
1717

18+
bool gdb_supports_guest_debug(void)
19+
{
20+
const AccelOpsClass *ops = cpus_get_accel();
21+
if (ops->supports_guest_debug) {
22+
return ops->supports_guest_debug();
23+
}
24+
return false;
25+
}
26+
1827
int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len)
1928
{
2029
const AccelOpsClass *ops = cpus_get_accel();

gdbstub/user.c

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
#include "hw/core/cpu.h"
1515
#include "internals.h"
1616

17+
bool gdb_supports_guest_debug(void)
18+
{
19+
/* user-mode == TCG == supported */
20+
return true;
21+
}
22+
1723
int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len)
1824
{
1925
CPUState *cpu;

include/sysemu/accel-ops.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct AccelOpsClass {
4747
int64_t (*get_elapsed_ticks)(void);
4848

4949
/* gdbstub hooks */
50+
bool (*supports_guest_debug)(void);
5051
int (*insert_breakpoint)(CPUState *cpu, int type, hwaddr addr, hwaddr len);
5152
int (*remove_breakpoint)(CPUState *cpu, int type, hwaddr addr, hwaddr len);
5253
void (*remove_all_breakpoints)(CPUState *cpu);

include/sysemu/kvm.h

-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ extern bool kvm_readonly_mem_allowed;
4646
extern bool kvm_direct_msi_allowed;
4747
extern bool kvm_ioeventfd_any_length_allowed;
4848
extern bool kvm_msi_use_devid;
49-
extern bool kvm_has_guest_debug;
5049

5150
#define kvm_enabled() (kvm_allowed)
5251
/**
@@ -168,11 +167,6 @@ extern bool kvm_has_guest_debug;
168167
*/
169168
#define kvm_msi_devid_required() (kvm_msi_use_devid)
170169

171-
/*
172-
* Does KVM support guest debugging
173-
*/
174-
#define kvm_supports_guest_debug() (kvm_has_guest_debug)
175-
176170
#else
177171

178172
#define kvm_enabled() (0)
@@ -190,7 +184,6 @@ extern bool kvm_has_guest_debug;
190184
#define kvm_direct_msi_enabled() (false)
191185
#define kvm_ioeventfd_any_length_enabled() (false)
192186
#define kvm_msi_devid_required() (false)
193-
#define kvm_supports_guest_debug() (false)
194187

195188
#endif /* CONFIG_KVM_IS_POSSIBLE */
196189

0 commit comments

Comments
 (0)