Skip to content

Commit

Permalink
gdbstub: move guest debug support check to ops
Browse files Browse the repository at this point in the history
This removes the final hard coding of kvm_enabled() in gdbstub and
moves the check to an AccelOps.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
Message-Id: <20220929114231.583801-46-alex.bennee@linaro.org>
  • Loading branch information
stsquad committed Oct 6, 2022
1 parent ae7467b commit a48e7d9
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions accel/kvm/kvm-accel-ops.c
Expand Up @@ -99,6 +99,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data)
ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;

#ifdef KVM_CAP_SET_GUEST_DEBUG
ops->supports_guest_debug = kvm_supports_guest_debug;
ops->insert_breakpoint = kvm_insert_breakpoint;
ops->remove_breakpoint = kvm_remove_breakpoint;
ops->remove_all_breakpoints = kvm_remove_all_breakpoints;
Expand Down
6 changes: 6 additions & 0 deletions accel/kvm/kvm-all.c
Expand Up @@ -3287,6 +3287,12 @@ int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
return data.err;
}

bool kvm_supports_guest_debug(void)
{
/* probed during kvm_init() */
return kvm_has_guest_debug;
}

int kvm_insert_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len)
{
struct kvm_sw_breakpoint *bp;
Expand Down
1 change: 1 addition & 0 deletions accel/kvm/kvm-cpus.h
Expand Up @@ -18,6 +18,7 @@ void kvm_destroy_vcpu(CPUState *cpu);
void kvm_cpu_synchronize_post_reset(CPUState *cpu);
void kvm_cpu_synchronize_post_init(CPUState *cpu);
void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu);
bool kvm_supports_guest_debug(void);
int kvm_insert_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len);
int kvm_remove_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len);
void kvm_remove_all_breakpoints(CPUState *cpu);
Expand Down
6 changes: 6 additions & 0 deletions accel/tcg/tcg-accel-ops.c
Expand Up @@ -93,6 +93,11 @@ void tcg_handle_interrupt(CPUState *cpu, int mask)
}
}

static bool tcg_supports_guest_debug(void)
{
return true;
}

/* Translate GDB watchpoint type to a flags value for cpu_watchpoint_* */
static inline int xlat_gdb_type(CPUState *cpu, int gdbtype)
{
Expand Down Expand Up @@ -198,6 +203,7 @@ static void tcg_accel_ops_init(AccelOpsClass *ops)
}
}

ops->supports_guest_debug = tcg_supports_guest_debug;
ops->insert_breakpoint = tcg_insert_breakpoint;
ops->remove_breakpoint = tcg_remove_breakpoint;
ops->remove_all_breakpoints = tcg_remove_all_breakpoints;
Expand Down
5 changes: 2 additions & 3 deletions gdbstub/gdbstub.c
Expand Up @@ -45,7 +45,6 @@

#include "qemu/sockets.h"
#include "sysemu/hw_accel.h"
#include "sysemu/kvm.h"
#include "sysemu/runstate.h"
#include "semihosting/semihost.h"
#include "exec/exec-all.h"
Expand Down Expand Up @@ -3447,8 +3446,8 @@ int gdbserver_start(const char *device)
return -1;
}

if (kvm_enabled() && !kvm_supports_guest_debug()) {
error_report("gdbstub: KVM doesn't support guest debugging");
if (!gdb_supports_guest_debug()) {
error_report("gdbstub: current accelerator doesn't support guest debugging");
return -1;
}

Expand Down
1 change: 1 addition & 0 deletions gdbstub/internals.h
Expand Up @@ -9,6 +9,7 @@
#ifndef _INTERNALS_H_
#define _INTERNALS_H_

bool gdb_supports_guest_debug(void);
int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len);
int gdb_breakpoint_remove(CPUState *cs, int type, hwaddr addr, hwaddr len);
void gdb_breakpoint_remove_all(CPUState *cs);
Expand Down
9 changes: 9 additions & 0 deletions gdbstub/softmmu.c
Expand Up @@ -15,6 +15,15 @@
#include "sysemu/cpus.h"
#include "internals.h"

bool gdb_supports_guest_debug(void)
{
const AccelOpsClass *ops = cpus_get_accel();
if (ops->supports_guest_debug) {
return ops->supports_guest_debug();
}
return false;
}

int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len)
{
const AccelOpsClass *ops = cpus_get_accel();
Expand Down
6 changes: 6 additions & 0 deletions gdbstub/user.c
Expand Up @@ -14,6 +14,12 @@
#include "hw/core/cpu.h"
#include "internals.h"

bool gdb_supports_guest_debug(void)
{
/* user-mode == TCG == supported */
return true;
}

int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len)
{
CPUState *cpu;
Expand Down
1 change: 1 addition & 0 deletions include/sysemu/accel-ops.h
Expand Up @@ -47,6 +47,7 @@ struct AccelOpsClass {
int64_t (*get_elapsed_ticks)(void);

/* gdbstub hooks */
bool (*supports_guest_debug)(void);
int (*insert_breakpoint)(CPUState *cpu, int type, hwaddr addr, hwaddr len);
int (*remove_breakpoint)(CPUState *cpu, int type, hwaddr addr, hwaddr len);
void (*remove_all_breakpoints)(CPUState *cpu);
Expand Down
7 changes: 0 additions & 7 deletions include/sysemu/kvm.h
Expand Up @@ -46,7 +46,6 @@ 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;

#define kvm_enabled() (kvm_allowed)
/**
Expand Down Expand Up @@ -168,11 +167,6 @@ extern bool kvm_has_guest_debug;
*/
#define kvm_msi_devid_required() (kvm_msi_use_devid)

/*
* Does KVM support guest debugging
*/
#define kvm_supports_guest_debug() (kvm_has_guest_debug)

#else

#define kvm_enabled() (0)
Expand All @@ -190,7 +184,6 @@ extern bool kvm_has_guest_debug;
#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)

#endif /* CONFIG_KVM_IS_POSSIBLE */

Expand Down

0 comments on commit a48e7d9

Please sign in to comment.