Skip to content

feat(gdb): share ARM64 debugger support across backends - #2050

Open
cshung wants to merge 6 commits into
hyperlight-dev:mainfrom
cshung:cshung/gdb-shared
Open

cshung wants to merge 6 commits into
hyperlight-dev:mainfrom
cshung:cshung/gdb-shared

Conversation

@cshung

@cshung cshung commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Shared GDB support

Architecture adapters and common debugger handling support ARM64 register
packets, software breakpoints, page-sized memory access, guest debug vectors,
and snapshot, cancellation and crash-detach recovery.

The existing x86_64 platform guard remains. Backend PRs enable ARM64 GDB.

Related PRs

Backend integration is in #1907 for WHP, #2016 for KVM, and #2052 for MSHV.
The MSHV backend is part of main through #1626.

Validation

November 23, base f297a914:

  • Windows x64 formatting, fresh debug/release Rust and C guests, build, Clippy, the full just test recipe, and focused debugger tests pass.
  • ARM64 cross-Clippy passes with default, KVM-only, and MSHV-only GDB features.
  • WHP integration passes Windows ARM64 cross-Clippy and Linux just clippyw.

November 19 native ARM64 MSHV validation through #2052 passed 481 library
tests (13 ignored), five concurrency tests, and seven real GDB client tests.
Native ARM64 runtime tests have not been repeated on this base.

@cshung cshung added the C-enhancement For PRs adding features, improving functionality, docs, tests, etc. label Nov 11, 2026
Copilot AI balanced review requested due to automatic review settings November 11, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Resume translation errors can terminate the debugger session, and partially successful code writes can return without synchronizing the guest instruction cache.

2 open issues
What changed in this PR

This PR provides shared ARM64 debugger infrastructure for Hyperlight’s WHP, KVM and MSHV backends. ARM64 platform enablement remains in separate backend PRs.

Changes:

  • Adds architecture-specific register handling, breakpoint support and shared debugger request processing.
  • Adds guest-page-sized memory access, cache synchronization hooks and snapshot recovery safeguards.
  • Adds debugger tests, guest exception forwarding and backend-layer documentation.
File Description
src/​hyperlight_host/​src/​sandbox/​uninitialized_evolve.rs Initializes ARM64 guest debug vectors.
src/​hyperlight_host/​src/​sandbox/​snapshot/​memory/​backing.rs Exposes backing ranges for cache synchronization.
src/​hyperlight_host/​src/​sandbox/​initialized.rs Adds breakpoint guards, recovery handling and tests.
src/​hyperlight_host/​src/​mem/​mgr.rs Exposes guest backing host ranges to debugging code.
src/​hyperlight_host/​src/​mem/​exe.rs Carries debug-vector addresses in load metadata.
src/​hyperlight_host/​src/​mem/​elf.rs Finds and relocates guest debug-vector symbols.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​whp/​x86_64.rs Adopts the shared address-translation interface.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​mshv/​x86_64.rs Adopts the shared address-translation interface.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​mod.rs Adds ARM64 debug exit and initialization types.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​kvm/​x86_64.rs Adopts the shared address-translation interface.
src/​hyperlight_host/​src/​hypervisor/​hyperlight_vm/​x86_64.rs Uses shared debugger handling and breakpoint storage.
src/​hyperlight_host/​src/​hypervisor/​hyperlight_vm/​mod.rs Integrates shared debug state and stop handling.
src/​hyperlight_host/​src/​hypervisor/​hyperlight_vm/​debug.rs Implements shared requests, breakpoints and ARM64 stepping.
src/​hyperlight_host/​src/​hypervisor/​hyperlight_vm/​aarch64.rs Adds debugger initialization and reset hooks.
src/​hyperlight_host/​src/​hypervisor/​gdb/​target.rs Supports ARM64 register packets and conversion tests.
src/​hyperlight_host/​src/​hypervisor/​gdb/​mod.rs Adds page-table translation and cache synchronization hooks.
src/​hyperlight_host/​src/​hypervisor/​gdb/​event_loop.rs Handles ARM64 initial-stop notifications.
src/​hyperlight_host/​src/​hypervisor/​gdb/​arch/​x86_64.rs Contains x86_64 breakpoint and stop classification logic.
src/​hyperlight_host/​src/​hypervisor/​gdb/​arch/​aarch64.rs Defines ARM64 BRK encoding and alignment checks.
src/​hyperlight_host/​src/​hypervisor/​gdb/​arch.rs Selects the architecture-specific debugger adapter.
src/​hyperlight_host/​examples/​guest-debugging/​main.rs Adds ARM64 GDB client scenarios.
src/​hyperlight_guest_bin/​src/​arch/​aarch64/​exception/​entry.rs Exports debug vectors and forwards synchronous exceptions.
src/​hyperlight_common/​src/​arch/​aarch64/​exn.rs Defines the debug exception HVC immediate.
Justfile Includes shared debugger and recovery test filters.
docs/​gdb-commit-layers.md Documents backend dependencies and validation requirements.
CHANGELOG.md Records debugger memory-access and recovery fixes.

Review effort: Balanced

@cshung cshung added the S-needs-review PR is ready for (re-)review label Nov 11, 2026
@cshung
cshung force-pushed the cshung/gdb-shared branch 2 times, most recently from a1e7706 to 1790d3c Compare November 12, 2026 00:12
@hyperlight-gh-bot

This comment has been minimized.

@hyperlight-gh-bot

This comment has been minimized.

@yoshuawuyts yoshuawuyts added the O-aarch64 Specific to 64-bit Arm processors label Nov 16, 2026
@hyperlight-gh-bot

This comment has been minimized.

@hyperlight-gh-bot

This comment has been minimized.

@hyperlight-gh-bot

This comment has been minimized.

@hyperlight-gh-bot

This comment has been minimized.

@dblnz dblnz left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work, @cshung !! The overall approach looks good 😃 .
I left some feedback on the PR and some suggested cosmetics changes.

self.handle_initial_debug_stop(mem_mgr)
.map_err(super::RunVmError::DebugHandler)?;

self.run(mem_mgr, host_funcs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The handle_initial_debug_stop eventually calls handle_debug, why can't this be handled by the default path through the self.run here?

.set_regs(&regs)
.map_err(DispatchGuestCallError::SetupRegs)?;
#[cfg(gdb)]
self.handle_initial_debug_stop(mem_mgr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be done only on initialise step? Or is this the case for an already initialised sandbox loaded from a snapshot?

#[cfg(gdb)]
if self.gdb_conn.is_some() {
self.vm
.set_single_step(false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this really needed?
The x86 variants already reset the debug registers when the vm.reset_vcpu is called, so this is not needed for x86.
I think the need for it in AARCH64 stems from the default implementation for the Trait of the set_single_step. Maybe it would be better, semantically speaking, to implement it explicitly and return not supported to avoid always setting single step to false here (that always returns Ok).

}

#[cfg(target_arch = "aarch64")]
fn begin_software_step(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure what the motivation was to do SW breakpoint stepping, but when I've implemented the x86 debugging support, I didn't have to do that because most debuggers (gdb especially) do this by themselves. When you want to step (software step, the usual approach), it adds a SW breakpoint at the next instruction automatically by calculating what the offset is. It's separate from the hardware stepping.

The Hardware stepping is done by specifically invoking si in gdb, that only steps one CPU instruction.
Maybe we can get away from having to do this SW breakpoint stepping ourselves.

}
}
#[cfg(target_arch = "aarch64")]
let stop_reason = if self.pending_software_step.is_some() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See the SW stepping comment I left in debug.rs maybe all this SW stepping logic can go away.

@dblnz

dblnz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Maybe it would be helpful to use the stacked PRs feature of GH to chain these PRs together.

@hyperlight-gh-bot

This comment has been minimized.

cshung and others added 4 commits November 25, 2026 10:41
Architecture adapters, software breakpoints, page-sized memory access and recovery handling are shared by backend layers. Guest debug vectors and common tests support ARM64. Backend layers control platform enablement.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
ARM64 page-table translation lives with the architecture helpers. Software breakpoint storage stays behind its methods. Debug-exit bindings and cfg placement follow the surrounding style.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Keep the initial stop in the run loop. Let GDB own software breakpoint step-over and use hardware single-step for step requests. Apply snapshot breakpoint guards to both architectures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Debugger register and memory edits can violate guest invariants. Reject snapshot creation for the lifetime of debug-configured sandboxes on x86_64 and ARM64, including after detach. Keep loading and restoring existing snapshots available with the existing breakpoint safeguards.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
cshung and others added 2 commits November 25, 2026 11:20
Match the error directly so the regression test does not require Snapshot to implement Debug.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
The initialized-snapshot regression builds a memory manager inside the ARM64-only test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: cfaca4a9391c
Baseline commit: c46735cd076c

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 297.28 ns (➖ 1.10x slower)
vec_bytes 79.22 ns (➖ 1.00x slower)
372.14 µs (➖ 1.04x faster)

payload_allocation

slot_pool_segmented
65536 146.97 ns (➖ 1.04x slower)
262144 536.42 ns (➖ 1.13x faster)

sandboxes

create_initialized_and_drop
medium 13.63 ms (➖ 1.00x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
7.68 ns (➖ 1.00x slower) 7.68 ns (➖ 1.02x faster) 7.68 ns (➖ 1.01x faster)

snapshot_files

load_snapshot_unverified
small 108.08 µs (➖ 1.00x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 1.91 µs (➖ 1.10x faster) 2.04 µs (➖ 1.07x slower)
262144 7.14 µs (➖ 1.01x slower) 7.23 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 6.10 µs (➖ 1.07x faster) 6.10 µs (➖ 1.06x faster)
262144 28.66 µs (➖ 1.05x slower)
8192 1.05 µs (➖ 1.04x slower) 1.03 µs (➖ 1.09x faster)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 318.53 ns (➖ 1.13x faster)
vec_bytes 96.61 ns (➖ 1.02x faster)
765.34 µs (➖ 1.02x slower)

payload_allocation

slot_pool_segmented
65536 162.10 ns (➖ 1.03x slower)
262144 599.56 ns (➖ 1.03x slower)

sandboxes

create_initialized_and_drop
medium 15.75 ms (➖ 1.02x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
8.25 ns (➖ 1.02x slower) 8.26 ns (➖ 1.01x slower) 8.28 ns (➖ 1.03x slower)

snapshot_files

load_snapshot_unverified
small 63.10 µs (➖ 1.03x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.57 µs (➖ 1.04x slower) 2.53 µs (➖ 1.02x slower)
262144 9.07 µs (➖ 1.04x slower) 9.02 µs (➖ 1.03x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.27 µs (➖ 1.02x faster) 8.32 µs (➖ 1.02x faster)
262144 34.89 µs (➖ 1.01x slower)
8192 852.89 ns (➖ 1.00x faster) 862.00 ns (➖ 1.00x slower)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 363.84 ns (➖ 1.04x faster)
vec_bytes 96.11 ns (➖ 1.01x faster)
331.07 µs (➖ 1.02x slower)

payload_allocation

slot_pool_segmented
65536 195.17 ns (➖ 1.04x faster)
262144 732.20 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 64.16 ms (➖ 1.02x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
9.90 ns (➖ 1.00x slower) 9.97 ns (➖ 1.00x faster) 9.89 ns (➖ 1.00x slower)

snapshot_files

load_snapshot_unverified
small 96.40 µs (➖ 1.01x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.22 µs (➖ 1.00x slower) 2.47 µs (➖ 1.01x slower)
262144 9.88 µs (➖ 1.04x slower) 10.98 µs (➖ 1.05x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.44 µs (➖ 1.17x faster) 8.35 µs (➖ 1.17x faster)
262144 35.91 µs (➖ 1.07x faster)
8192 1.23 µs (➖ 1.01x slower) 1.22 µs (➖ 1.10x faster)
mshv3 / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 353.79 ns (➖ 1.00x slower)
vec_bytes 85.80 ns (➖ 1.01x slower)
843.32 µs (➖ 1.04x slower)

payload_allocation

slot_pool_segmented
65536 171.24 ns (➖ 1.01x faster)
262144 633.45 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 86.88 ms (➖ 1.03x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
8.72 ns (➖ 1.01x faster) 9.14 ns (➖ 1.01x faster) 8.73 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 55.93 µs (➖ 1.00x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.32 µs (➖ 1.02x slower) 2.28 µs (➖ 1.01x faster)
262144 7.98 µs (➖ 1.00x slower) 8.01 µs (➖ 1.00x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 7.56 µs (➖ 1.01x slower) 7.50 µs (➖ 1.00x faster)
262144 39.02 µs (➖ 1.01x faster)
8192 904.94 ns (➖ 1.02x faster) 919.32 ns (➖ 1.00x faster)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 552.12 ns (➖ 1.00x slower)
vec_bytes 161.59 ns (➖ 1.06x faster)
2.26 ms (➖ 1.03x slower)

payload_allocation

slot_pool_segmented
65536 230.53 ns (➖ 1.00x faster)
262144 792.85 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 13.97 ms (➖ 1.01x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
10.39 ns (➖ 1.00x slower) 10.09 ns (➖ 1.00x faster) 10.35 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 833.15 µs (➖ 1.03x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.35 µs (➖ 1.00x faster) 2.31 µs (➖ 1.03x faster)
262144 9.10 µs (➖ 1.01x slower) 8.94 µs (➖ 1.02x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.91 µs (➖ 1.02x slower) 8.93 µs (➖ 1.01x slower)
262144 40.17 µs (➖ 1.01x slower)
8192 1.25 µs (➖ 1.01x slower) 1.28 µs (➖ 1.03x slower)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 572.73 ns (➖ 1.02x slower)
vec_bytes 163.28 ns (➖ 1.03x slower)
3.24 ms (➖ 1.06x slower)

payload_allocation

slot_pool_segmented
65536 210.98 ns (➖ 1.01x slower)
262144 748.57 ns (➖ 1.02x faster)

sandboxes

create_initialized_and_drop
medium 14.15 ms (➖ 1.03x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
10.34 ns (➖ 1.03x slower) 9.72 ns (➖ 1.00x slower) 9.82 ns (➖ 1.05x faster)

snapshot_files

load_snapshot_unverified
small 591.97 µs (➖ 1.13x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.29 µs (➖ 1.00x faster) 2.28 µs (➖ 1.00x faster)
262144 7.69 µs (➖ 1.00x faster) 7.67 µs (➖ 1.01x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.49 µs (➖ 1.01x faster) 8.36 µs (➖ 1.02x faster)
262144 41.24 µs (➖ 1.19x faster)
8192 1.04 µs (➖ 1.12x faster) 1.05 µs (➖ 1.02x slower)

Reported by cargo ci bench-report --candidate run:45688506234 --config-file bench_report.toml.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement For PRs adding features, improving functionality, docs, tests, etc. O-aarch64 Specific to 64-bit Arm processors S-needs-review PR is ready for (re-)review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants