-
Notifications
You must be signed in to change notification settings - Fork 879
Guest debugging support #66
Comments
Thanks! This is a very nice feature to have, and your summary really helps me understand how breakpoints work.
#BP doesn't really cause a VM exit by default. There is a VMCS exception bitmap per CPU that controls which CPU exceptions should be handled by the host/hypervisor and which by the guest (see Intel SDM Vol. 3C: 25.2 Other Causes of VM Exits). So I believe you need to (conditionally) set the bits for Line 1187 in e23a8dd
and handle them properly in In addition, if you search for "debug" in Intel SDM Vol. 3C, there are a lot more details about how hardware (VT) can help enable guest debugging support. 32.2: Virtualization Support for Debugging Facilities gives a good summary, and I've also made my own reading list:
Ideally, we should support both the QEMU GDB (for debugging the guest itself) and GDB running in the guest (for debugging an app that runs in guest user space). I need to read more to understand how we can achieve this. |
Thank you, indeed I forgot to enable This might be caused by wrong drN values: I've noticed the VMCS structure only offers a Lines 3695 to 3700 in e9f8c89
Similarly, However, I have not found anyhere in the codebase a mechanism to load such values into the guest debug registers... I'm assuming this is unimplemented: Should we include |
Great, congrats! Here's my understanding of how hardware breakpoints roughly work:
Based on this:
|
Thanks for your detailed overview on hardware breakpoints, I've added the missing features on AlexAltea@f2808d8. Hardware breakpoints are now successfully triggered:
The only thing missing now is single-stepping, which for some reasons triggers a triple-fault. I'm trying to figure out why this happens without much success. As soon as I'm finished, I'll submit a PR for this feature.
I think that issue cannot be solved by HAXM. As soon as such QEMU developer uses hardware breakpoints, the corresponding dr7 bits will be enabled, but before entering the guest VM, the guest dr0-dr3 registers are restored. What if the host instructions right afterwards are mapped to the same addresses pointed by any of the guest hardware breakpoints? This could only be fixed at hardware-level by adding GUEST_DR0 to GUEST_DR3 to the VMCS fields. Meanwhile the only approach to debugging QEMU/HAXM, while debugging a virtual machine, is using hardware breakpoints only in either host or guest, and using software breakpoints everywhere else.
Thank you, that was helpful, and it does indeed cover dr6 register. |
This sounds reasonable. How does GDB choose between inserting a hardware BP and inserting a software BP? If we can't rely on it to make the right decision in the hypothetical scenario, should we check host DR7 before restoring guest DR{0, 1, 2, 3}?
Cool. I just skimmed through your code and spotted a couple of typos--not sure if they are actually related to the triple fault: https://github.com/AlexAltea/haxm/blob/f2808d8fa83754d2305e2df199e564069b659f39/core/vcpu.c#L1377 https://github.com/AlexAltea/haxm/blob/f2808d8fa83754d2305e2df199e564069b659f39/core/vcpu.c#L1403 In both cases |
That's decided by the command entered by the user:
Thanks! Seems unrelated to the triple-fault, but worth fixing anyway. :-) |
This issue should be closed since #81 was merged. |
Opening this issue as follow-up to the discussion in qemu-devel:
https://lists.gnu.org/archive/html/qemu-devel/2018-04/msg00030.html
Summarizing: Guest debugging is extremely relevant to debugging bootloaders/microkernels, or in my case, kernels that do not include debugging backends. Aside from the intrinsic value of this feature, it's also really beneficial to developers/researchers as neither WHPX (Windows) nor HVF (macOS) support guest debugging and while they remain closed-source this probably won't change.
This week I've started experimenting with guest debugging support on HAXM, but it's still too early to submit any patches (plus, this should probably coordinated with QEMU somehow). These are the key ideas (inspired by KVM):
HAX_VCPU_IOCTL_DEBUG
ioctl (i.e. QEMU-to-HAXM) with a structure containing:This is meant to manage the guest state accordingly: e.g. if guest debugging via hardware breakpoints is enabled we should protect the guest drN values in the
exit_dr_access
handler. Additionally, to know where to redirect #BP, e.g. if software breakpoints are enabled forward to QEMU, otherwise forward to VM.They already are a self-contained way of describing hardware breakpoints, so no need to wrap that information in another layer of abstraction.
HAX_EXIT_DEBUG
exit (i.e. HAXM-to-QEMU) with a structure containing:int 3h
(0xCC). Its lifecycle is:break *
command.hax_sw_brakpoint
object and patches instruction withint 3h
.#BP
.continue
command.drN
register through the previously described ioctl.Current experiments can be found in AlexAltea/orbital-qemu@77d61c7 (QEMU) and https://github.com/AlexAltea/haxm/tree/debug (HAXM). I'm facing some issues still:
#BP
.Disclaimer: I haven't much experience with debuggers, so any feedback will be helpful.
The text was updated successfully, but these errors were encountered: