Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
hvf: add guest debugging handlers for Apple Silicon hosts
Guests can now be debugged through the gdbstub. Support is added for
single-stepping, software breakpoints, hardware breakpoints and
watchpoints. The code has been structured like the KVM counterpart.

While guest debugging is enabled, the guest can still read and write the
DBG*_EL1 registers but they don't have any effect.

Signed-off-by: Francesco Cagnin <fcagnin@quarkslab.com>
Message-id: 20230601153107.81955-5-fcagnin@quarkslab.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
integeruser authored and pm215 committed Jun 6, 2023
1 parent f415204 commit eb2edc4
Show file tree
Hide file tree
Showing 7 changed files with 520 additions and 2 deletions.
10 changes: 10 additions & 0 deletions accel/hvf/hvf-accel-ops.c
Expand Up @@ -343,12 +343,18 @@ static int hvf_accel_init(MachineState *ms)
return hvf_arch_init();
}

static inline int hvf_gdbstub_sstep_flags(void)
{
return SSTEP_ENABLE | SSTEP_NOIRQ;
}

static void hvf_accel_class_init(ObjectClass *oc, void *data)
{
AccelClass *ac = ACCEL_CLASS(oc);
ac->name = "HVF";
ac->init_machine = hvf_accel_init;
ac->allowed = &hvf_allowed;
ac->gdbstub_supported_sstep_flags = hvf_gdbstub_sstep_flags;
}

static const TypeInfo hvf_accel_type = {
Expand Down Expand Up @@ -398,6 +404,8 @@ static int hvf_init_vcpu(CPUState *cpu)
cpu->vcpu_dirty = 1;
assert_hvf_ok(r);

cpu->hvf->guest_debug_enabled = false;

return hvf_arch_init_vcpu(cpu);
}

Expand Down Expand Up @@ -582,6 +590,8 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, void *data)
ops->insert_breakpoint = hvf_insert_breakpoint;
ops->remove_breakpoint = hvf_remove_breakpoint;
ops->remove_all_breakpoints = hvf_remove_all_breakpoints;
ops->update_guest_debug = hvf_update_guest_debug;
ops->supports_guest_debug = hvf_arch_supports_guest_debug;
};
static const TypeInfo hvf_accel_ops_type = {
.name = ACCEL_OPS_NAME("hvf"),
Expand Down
6 changes: 6 additions & 0 deletions accel/hvf/hvf-all.c
Expand Up @@ -61,3 +61,9 @@ int hvf_sw_breakpoints_active(CPUState *cpu)
{
return !QTAILQ_EMPTY(&hvf_state->hvf_sw_breakpoints);
}

int hvf_update_guest_debug(CPUState *cpu)
{
hvf_arch_update_guest_debug(cpu);
return 0;
}
15 changes: 15 additions & 0 deletions include/sysemu/hvf.h
Expand Up @@ -56,6 +56,21 @@ int hvf_arch_insert_hw_breakpoint(target_ulong addr, target_ulong len,
int hvf_arch_remove_hw_breakpoint(target_ulong addr, target_ulong len,
int type);
void hvf_arch_remove_all_hw_breakpoints(void);

/*
* hvf_update_guest_debug:
* @cs: CPUState for the CPU to update
*
* Update guest to enable or disable debugging. Per-arch specifics will be
* handled by calling down to hvf_arch_update_guest_debug.
*/
int hvf_update_guest_debug(CPUState *cpu);
void hvf_arch_update_guest_debug(CPUState *cpu);

/*
* Return whether the guest supports debugging.
*/
bool hvf_arch_supports_guest_debug(void);
#endif /* NEED_CPU_H */

#endif
1 change: 1 addition & 0 deletions include/sysemu/hvf_int.h
Expand Up @@ -54,6 +54,7 @@ struct hvf_vcpu_state {
void *exit;
bool vtimer_masked;
sigset_t unblock_ipi_mask;
bool guest_debug_enabled;
};

void assert_hvf_ok(hv_return_t ret);
Expand Down

0 comments on commit eb2edc4

Please sign in to comment.