Skip to content

Commit

Permalink
whpx: Added support for breakpoints and stepping
Browse files Browse the repository at this point in the history
Below is the updated version of the patch adding debugging support to WHPX.
It incorporates feedback from Alex Bennée and Peter Maydell regarding not
changing the emulation logic depending on the gdb connection status.

Instead of checking for an active gdb connection to determine whether QEMU
should intercept the INT1 exceptions, it now checks whether any breakpoints
have been set, or whether gdb has explicitly requested one or more CPUs to
do single-stepping. Having none of these condition present now has the same
effect as not using gdb at all.

Message-Id: <0e7f01d82e9e$00e9c360$02bd4a20$@sysprogs.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
sysprogs authored and bonzini committed Apr 3, 2022
1 parent 1368737 commit d567bd3
Show file tree
Hide file tree
Showing 8 changed files with 815 additions and 18 deletions.
10 changes: 9 additions & 1 deletion gdbstub.c
Expand Up @@ -518,7 +518,15 @@ static int gdb_continue_partial(char *newstates)
int flag = 0;

if (!runstate_needs_reset()) {
if (vm_prepare_start()) {
bool step_requested = false;
CPU_FOREACH(cpu) {
if (newstates[cpu->cpu_index] == 's') {
step_requested = true;
break;
}
}

if (vm_prepare_start(step_requested)) {
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions include/sysemu/accel-ops.h
Expand Up @@ -38,6 +38,7 @@ struct AccelOpsClass {
void (*synchronize_post_init)(CPUState *cpu);
void (*synchronize_state)(CPUState *cpu);
void (*synchronize_pre_loadvm)(CPUState *cpu);
void (*synchronize_pre_resume)(bool step_pending);

void (*handle_interrupt)(CPUState *cpu, int mask);

Expand Down
8 changes: 7 additions & 1 deletion include/sysemu/runstate.h
Expand Up @@ -34,7 +34,13 @@ static inline bool shutdown_caused_by_guest(ShutdownCause cause)
}

void vm_start(void);
int vm_prepare_start(void);

/**
* vm_prepare_start: Prepare for starting/resuming the VM
*
* @step_pending: whether any of the CPUs is about to be single-stepped by gdb
*/
int vm_prepare_start(bool step_pending);
int vm_stop(RunState state);
int vm_stop_force_state(RunState state);
int vm_shutdown(void);
Expand Down
12 changes: 10 additions & 2 deletions softmmu/cpus.c
Expand Up @@ -672,7 +672,7 @@ int vm_stop(RunState state)
* Returns -1 if the vCPUs are not to be restarted (e.g. if they are already
* running or in case of an error condition), 0 otherwise.
*/
int vm_prepare_start(void)
int vm_prepare_start(bool step_pending)
{
RunState requested;

Expand All @@ -692,6 +692,14 @@ int vm_prepare_start(void)
return -1;
}

/*
* WHPX accelerator needs to know whether we are going to step
* any CPUs, before starting the first one.
*/
if (cpus_accel->synchronize_pre_resume) {
cpus_accel->synchronize_pre_resume(step_pending);
}

/* We are sending this now, but the CPUs will be resumed shortly later */
qapi_event_send_resume();

Expand All @@ -703,7 +711,7 @@ int vm_prepare_start(void)

void vm_start(void)
{
if (!vm_prepare_start()) {
if (!vm_prepare_start(false)) {
resume_all_vcpus();
}
}
Expand Down
1 change: 1 addition & 0 deletions target/i386/whpx/whpx-accel-ops.c
Expand Up @@ -100,6 +100,7 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, void *data)
ops->synchronize_post_init = whpx_cpu_synchronize_post_init;
ops->synchronize_state = whpx_cpu_synchronize_state;
ops->synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm;
ops->synchronize_pre_resume = whpx_cpu_synchronize_pre_resume;
}

static const TypeInfo whpx_accel_ops_type = {
Expand Down
1 change: 1 addition & 0 deletions target/i386/whpx/whpx-accel-ops.h
Expand Up @@ -21,6 +21,7 @@ void whpx_cpu_synchronize_state(CPUState *cpu);
void whpx_cpu_synchronize_post_reset(CPUState *cpu);
void whpx_cpu_synchronize_post_init(CPUState *cpu);
void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu);
void whpx_cpu_synchronize_pre_resume(bool step_pending);

/* state subset only touched by the VCPU itself during runtime */
#define WHPX_SET_RUNTIME_STATE 1
Expand Down

0 comments on commit d567bd3

Please sign in to comment.