Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Hyperlight KVM guest debugging using gdb #111

Merged
merged 21 commits into from
Feb 21, 2025

Conversation

dblnz
Copy link
Contributor

@dblnz dblnz commented Dec 13, 2024

The current implementation supports:

  • add/remove HW breakpoints (max 4)
  • add/remove SW breakpoints
  • read/write registers
  • read/write addresses
  • step/continue
  • get code offset from target

The overall architecture is designed to work like a Request - Response protocol from the gdb thread to the hypervisor handler over a DebugCommChannel.

  • All the functionality is implemented on the hypervisor side so it has access to the shared memory and VcpuFd
  • The gdb thread uses gdbstub to handle the communication with the gdb client
  • when the gdb client requests the supported features mentioned above, a request is sent forward to the hypervisor handler for the running sandbox to run

@dblnz dblnz added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Dec 13, 2024
@dblnz dblnz self-assigned this Dec 13, 2024
@dblnz dblnz marked this pull request as draft December 13, 2024 17:54
@dblnz dblnz force-pushed the gdb-support-latest branch 2 times, most recently from be21b85 to ca61def Compare December 19, 2024 11:41
Copy link
Contributor

@devigned devigned left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super excited to see this landing. Nice work! My feedback mostly consists of nits and questions.

@dblnz dblnz force-pushed the gdb-support-latest branch from 4a44b2e to 16492de Compare January 22, 2025 15:40
@dblnz dblnz marked this pull request as ready for review January 22, 2025 16:07
@dblnz dblnz changed the title Initial support for gdb debugging in Hyperlight KVM guest Add support for Hyperlight KVM guest debugging using gdb Jan 22, 2025
@dblnz dblnz force-pushed the gdb-support-latest branch from 2a36f06 to d0db26e Compare February 4, 2025 21:07
ludfjig
ludfjig previously approved these changes Feb 5, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!! Looked briefly though everything and I will give a more in-depth review tomorrow

ludfjig
ludfjig previously approved these changes Feb 7, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. I tried it out and it works great. Left some more comments, feel free to dismiss if you disagree with any of them. I realize some of them might be hard to implement as well. GREAT WORK!!

Copy link
Contributor

@simongdavies simongdavies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few minor issues, but overall this is great. I don't know why the spelling issues are not getting picked up by the spell check in GH actions

Copy link
Contributor

@syntactically syntactically left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how this looks overall! I've left a few small things in the code comments. I also have a couple of nits about the commit organization:

Commit message for 579b324: s/tread/thread/

Commits b175f41, af0a52a, 6cc6184, and 98ac60e: please convert
each one to a series of fixup! commits to the original commits
introducing code, so that we can autosquash before merging, or just
rebase the changes into the original commits now if nobody else
objects to that.

@dblnz dblnz force-pushed the gdb-support-latest branch from 98ac60e to 459b1c9 Compare February 13, 2025 17:29
@dblnz dblnz requested a review from devigned February 13, 2025 17:59
@dblnz dblnz force-pushed the gdb-support-latest branch 6 times, most recently from 4e8d0d1 to 21d3079 Compare February 18, 2025 17:13
ludfjig
ludfjig previously approved these changes Feb 19, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

simongdavies
simongdavies previously approved these changes Feb 19, 2025
devigned
devigned previously approved these changes Feb 19, 2025
Copy link
Contributor

@devigned devigned left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Great work, @dblnz!

dblnz added 17 commits February 21, 2025 12:16
…en gdb feature is on

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- this type will be used by the gdb and the hypervisor handler
to send requests and receive responses

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- the target implements the  traits to provide callbacks
for the gdb commands

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- adds a specific handler for the vcpu exit debug that waits for
debug messages and processes them

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- also adds handling of gdb client disconnect by resuming execution

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- sometimes gdb tries to read from an address where the vcpu translate
  method fails, so we need to handle that in such a way that the
  hypervisor handler doesn't crash

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
@dblnz dblnz dismissed stale reviews from devigned, simongdavies, and ludfjig via c722d03 February 21, 2025 12:34
@dblnz dblnz force-pushed the gdb-support-latest branch from 21d3079 to c722d03 Compare February 21, 2025 12:34
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- this helps with separation and testing

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- replace `expect` statements with logic to propagate error up the call
  chain
- improve log messages and comments

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
@dblnz dblnz force-pushed the gdb-support-latest branch from c722d03 to 7ab2149 Compare February 21, 2025 12:47
@dblnz dblnz merged commit 757fb9b into hyperlight-dev:main Feb 21, 2025
21 checks passed
@dblnz dblnz mentioned this pull request Mar 4, 2025
@dblnz dblnz deleted the gdb-support-latest branch March 4, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants