|
| 1 | +# How to debug a Hyperlight guest |
| 2 | + |
| 3 | +Hyperlight supports gdb debugging of a guest running inside a Hyperlight sandbox. |
| 4 | +When Hyperlight is compiled with the `gdb` feature enabled, a Hyperlight sandbox can be configured |
| 5 | +to start listening for a gdb connection. |
| 6 | + |
| 7 | +## Example |
| 8 | +The snipped of a rust host application below configures the Hyperlight Sandbox to |
| 9 | +listen on port `9050` for a gdb client to connect. |
| 10 | + |
| 11 | +```rust |
| 12 | + let mut cfg = SandboxConfiguration::default(); |
| 13 | + cfg.set_guest_debug_port(9050); |
| 14 | + |
| 15 | + // Create an uninitialized sandbox with a guest binary |
| 16 | + let mut uninitialized_sandbox = UninitializedSandbox::new( |
| 17 | + hyperlight_host::GuestBinary::FilePath( |
| 18 | + hyperlight_testing::simple_guest_as_string().unwrap(), |
| 19 | + ), |
| 20 | + Some(cfg), // configuration |
| 21 | + None, // default run options |
| 22 | + None, // default host print function |
| 23 | + )?; |
| 24 | +``` |
| 25 | + |
| 26 | +The execution of the guest will wait for gdb to attach. |
| 27 | + |
| 28 | +One can use a simple gdb config to provide the symbols and desired configuration: |
| 29 | + |
| 30 | +For the above snippet, the below contents of the `.gdbinit` file can be used to |
| 31 | +provide configuration to gdb startup. |
| 32 | +```gdb |
| 33 | +file path/to/symbols.elf |
| 34 | +target remote :9050 |
| 35 | +set disassembly-flavor intel |
| 36 | +set disassemble-next-line on |
| 37 | +enable pretty-printer |
| 38 | +layout src |
| 39 | +``` |
| 40 | + |
| 41 | +One can find more information about the `.gdbinit` file at [gdbinit(5)](https://www.man7.org/linux/man-pages/man5/gdbinit.5.html). |
0 commit comments