Part 1 described how Hyperlight stops an ARM64 guest, presents its registers, and resumes execution under GDB’s control.
That is enough for register inspection and hardware stepping. A software breakpoint requires something more: the debugger must replace a guest instruction with BRK, then later restore the original bytes.
Two boundaries make that operation less direct than it sounds. The address belongs to the guest rather than the host, and ARM64 instruction fetch may continue using a cached instruction after memory has changed. This post explains how Hyperlight crosses both boundaries while preserving the stopped guest context.
An address belongs to an address space
Reading guest memory is also more than copying from a pointer.
There are three addresses to keep separate:
Guest virtual address
|
guest translation
|
Guest physical address
|
sandbox memory mapping
|
Host virtual address
The address GDB asks about belongs to the guest. Hyperlight translates it through the backend, then accesses the corresponding host-backed memory.
The memory-access loop repeats translation at guest page boundaries. Adjacent guest virtual pages can refer to unrelated physical pages.
For example, consider a 32-byte read starting 16 bytes before the end of a 4 KiB guest page. Hyperlight must translate and read the first 16 bytes, then translate the next guest page before reading the remaining 16 bytes.
Translating the first address and copying all 32 bytes assumes physical contiguity that the guest never promised.
The relevant boundary is the guest’s page size. A host using larger pages does not make the guest’s 4 KiB translations any larger. This is the kind of mistake that can remain invisible on one machine and appear immediately on another.
The instruction is in memory. Will the CPU execute it?
A software breakpoint changes code through the host’s memory mapping.
Reading that memory back can show the correct BRK bytes while the guest processor still has the original instruction in its instruction cache. Correct memory contents do not, by themselves, prove that instruction fetch will observe the patch.
The Windows ARM64 WHP backend handles this with a small cache-synchronization program in a reserved guest physical page.
Its essential sequence is:
dsb ish // Finish earlier memory writes before changing the cache.
ic iallu // Invalidate this processor's entire instruction cache.
dsb ish // Wait until the cache invalidation has completed.
isb // Discard prefetched instructions and fetch them again.
hvc #0x4858 // Return control to the host through a reserved hypercall.
The first data-synchronization barrier ensures that the debugger’s patched
instruction has reached memory before the cache is invalidated. IC IALLU
removes the processor’s cached instruction copies. The second barrier waits
for that invalidation to finish, and ISB flushes the instruction pipeline so
later execution fetches the new bytes. The final hypercall tells the host that
the maintenance program has completed.
The host saves the affected processor state, temporarily disables address translation and single-step, and runs this program at the reserved physical address. It checks that execution ended at the expected hypercall, then restores the saved state.
This is why the cache page exists. It lets the virtual processor perform the guest-side cache maintenance needed after a debugger write.
The page is readable and executable by the guest, but not writable. Hyperlight also rejects sandbox mappings that overlap it. If guest code could replace the trampoline, the host could not rely on the program it is about to execute.
The debugger should still present the same stopped guest context after this maintenance. The extra execution is an implementation detail of making the memory write take effect.
Debugging a snapshot
Snapshots make an attractive debugging workflow:
Load a known snapshot
|
Debug a particular execution
|
Discard the sandbox
This is supported. The original snapshot remains available for another attempt.
Creating a snapshot from a debug-configured sandbox is a different operation. A debugger can modify registers and memory in ways that ordinary guest execution would never produce. Such state may violate assumptions needed by later calls or restores.
The snapshot policy is to reject snapshot creation for debug-configured sandboxes on both x86_64 and ARM64.
The restriction remains after GDB detaches. Detaching ends debugger control, but it does not undo arbitrary register and memory edits. It is not a certificate that the guest is in a valid state.
Restoring an existing snapshot is supported. In a ready sandbox, software breakpoints must be removed first because their bookkeeping refers to the current memory contents. Recovery of a poisoned sandbox discards that bookkeeping before restoring clean snapshot memory.
Similarly, a crash stop permits inspection, but rejects writes, stepping, and continuation. The debugger can help explain the failure without treating the crashed guest as safe to resume.
Testing the whole path
A unit test can verify the bytes used for BRK. It cannot establish that the processor executes those bytes, that the hypervisor reports the event, or that GDB interprets the returned context correctly.
The native tests exercise those boundaries. They cover real breakpoint execution, stepping, register preservation, and recovery. Separate tests use an actual GDB client to exercise the protocol and guest execution together.
Native ARM64 GDB tests have passed on KVM, WHP, and MSHV. The shared recovery tests also cover the initial stop for an initialized snapshot, restore restrictions, and debugger detach.
Conclusion
A debugger write is complete only when the virtual processor will observe it. Reaching that point requires translating the guest address at every page boundary, modifying the host-backed memory, and synchronizing the guest instruction cache without changing the state GDB is inspecting.
The cache trampoline is extra guest execution performed to preserve the debugger’s abstraction. GDB still sees one stopped machine. Hyperlight and the backend do the hidden work required to make that view true.