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

feat: Enable gdb debugging on x86 #4797

Merged

Conversation

JackThomson2
Copy link
Contributor

This PR is adding GDB support into Firecracker. This is will allow us to connect GDB to the guest kernel and enable step through debugging.

This is achieved by leveraging https://github.com/daniel5151/gdbstub which allows us to debug the kernel over the GDB Remote Serial Protocol. The way this is managed is through a new GDB thread which is used to manage the interaction between the VCPUs and the GDB server.

A list of the current features supported in x86

  • Multithreaded Debugging (multi core VM's)
  • Register Read/Write
  • Guest Memory Read/Write
  • Software Breakpoints Add/Remove
  • Hardware Breakpoints Add/Remove
  • Single Step
  • Continue

The implementation is feature gated behind the debug flag which aims to allow us to remove all the dependencies at compiletime

Changes

  • Adding GDB support for guest kernel debugging
  • Added new debug feature to firecracker which when enabled will start the GDB server and block the boot until GDB connects and resumes the execution

Reason

  • Allow us to debug the guest kernel with GDB

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this
    PR.
  • API changes follow the Runbook for Firecracker API changes.
  • User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • New TODOs link to an issue.
  • Commits meet
    contribution quality standards.

  • This functionality cannot be added in rust-vmm.

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 33.72093% with 57 lines in your changes missing coverage. Please review.

Project coverage is 83.96%. Comparing base (36ecc4f) to head (898ee9a).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/vmm/src/gdb/arch/aarch64.rs 4.76% 40 Missing ⚠️
src/vmm/src/builder.rs 55.26% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4797      +/-   ##
==========================================
- Coverage   84.38%   83.96%   -0.43%     
==========================================
  Files         249      250       +1     
  Lines       27496    27758     +262     
==========================================
+ Hits        23203    23306     +103     
- Misses       4293     4452     +159     
Flag Coverage Δ
5.10-c5n.metal 84.58% <61.36%> (-0.04%) ⬇️
5.10-m5n.metal 84.56% <61.36%> (-0.05%) ⬇️
5.10-m6a.metal 83.86% <61.36%> (-0.05%) ⬇️
5.10-m6g.metal 80.51% <33.72%> (-0.44%) ⬇️
5.10-m6i.metal 84.56% <61.36%> (-0.05%) ⬇️
5.10-m7g.metal 80.51% <33.72%> (-0.44%) ⬇️
6.1-c5n.metal 84.58% <61.36%> (-0.04%) ⬇️
6.1-m5n.metal 84.56% <61.36%> (-0.05%) ⬇️
6.1-m6a.metal 83.85% <61.36%> (-0.05%) ⬇️
6.1-m6g.metal 80.51% <33.72%> (-0.43%) ⬇️
6.1-m6i.metal 84.56% <61.36%> (-0.05%) ⬇️
6.1-m7g.metal 80.51% <33.72%> (-0.44%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
@JackThomson2 JackThomson2 force-pushed the feat/gdb_server_x86 branch 4 times, most recently from ea73a87 to a496d60 Compare September 17, 2024 14:33
@JackThomson2 JackThomson2 marked this pull request as ready for review September 18, 2024 08:31
Copy link
Contributor

@ShadowCurse ShadowCurse left a comment

Choose a reason for hiding this comment

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

Please squash 1 and 2 commits.

src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/server.rs Outdated Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
Copy link
Contributor

@roypat roypat left a comment

Choose a reason for hiding this comment

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

I've had a very haphazard look at it. Mostly it's just nits about Rust style things. The one thing I'd like to discuss is the passing of Tids all over the place. I outlined in a comment how we might be able to avoid this. Could you have a look at that? :o

src/vmm/src/gdb/event_loop.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/event_loop.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/event_loop.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/server.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/server.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
@JackThomson2 JackThomson2 force-pushed the feat/gdb_server_x86 branch 4 times, most recently from 49973fb to 15d5537 Compare September 26, 2024 09:14
src/vmm/src/gdb/hw_breakpoint_store.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
roypat
roypat previously approved these changes Sep 26, 2024
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
@roypat roypat dismissed their stale review September 26, 2024 14:36

clicked the wrong button, sorry

src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/kvm_debug.rs Outdated Show resolved Hide resolved
src/vmm/Cargo.toml Outdated Show resolved Hide resolved
@JackThomson2 JackThomson2 force-pushed the feat/gdb_server_x86 branch 4 times, most recently from 5497cdc to 4b02872 Compare October 2, 2024 12:14
Copy link
Contributor

@ShadowCurse ShadowCurse left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@roypat roypat left a comment

Choose a reason for hiding this comment

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

Overall, looks good to me, good job! No concerns really, just a bunch of small things. I guess the biggest open question is how to deal with someone doing cargo build --feature gdb --target aarch64-unknown-linux-gnu. At least it should give a nice error message about that not being supported.

src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/mod.rs Outdated Show resolved Hide resolved
tests/integration_tests/build/test_gdb.py Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
src/vmm/src/gdb/target.rs Show resolved Hide resolved
src/vmm/src/gdb/target.rs Outdated Show resolved Hide resolved
@JackThomson2 JackThomson2 force-pushed the feat/gdb_server_x86 branch 4 times, most recently from 360a6fd to 0dc3bc8 Compare October 8, 2024 12:52
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Outdated Show resolved Hide resolved
docs/gdb-debugging.md Show resolved Hide resolved
tests/integration_tests/build/test_gdb.py Outdated Show resolved Hide resolved
@JackThomson2 JackThomson2 force-pushed the feat/gdb_server_x86 branch 2 times, most recently from 964ccab to 4d022b2 Compare October 9, 2024 12:50
Enabling GDB support for debugging the guest kernel. This allows us to
connect a gdb server to firecracker and debug the guest.

Signed-off-by: Jack Thomson <jackabt@amazon.com>
@JackThomson2 JackThomson2 force-pushed the feat/gdb_server_x86 branch 2 times, most recently from d9b94da to b36cfff Compare October 9, 2024 13:02
Add documentation on how to use gdb with firecracker with examples on
how to use the basic functionality to debug the guest kernel

Signed-off-by: Jack Thomson <jackabt@amazon.com>
Adding a test to ensure that firecracker will build with the gdb flag
enabled

Signed-off-by: Jack Thomson <jackabt@amazon.com>
Copy link
Contributor

@kalyazin kalyazin left a comment

Choose a reason for hiding this comment

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

doc LGTM

@JackThomson2 JackThomson2 merged commit 32332d9 into firecracker-microvm:main Oct 10, 2024
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants