Skip to content

Commit

Permalink
add documentation about the gdb debugging feature
Browse files Browse the repository at this point in the history
Signed-off-by: Doru Blânzeanu <[email protected]>
  • Loading branch information
dblnz committed Feb 4, 2025
1 parent 5476cdd commit d0db26e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This project is composed internally of several internal components, depicted in

* [Security guidance for developers](./security-guidance-for-developers.md)
* [Paging Development Notes](./paging-development-notes.md)
* [How to debug a Hyperlight guest](./how-to-debug-a-hyperlight-guest.md)
* [How to use Flatbuffers in Hyperlight](./how-to-use-flatbuffers.md)
* [How to make a Hyperlight release](./how-to-make-releases.md)
* [Getting Hyperlight Metrics, Logs, and Traces](./hyperlight-metrics-logs-and-traces.md)
Expand Down
41 changes: 41 additions & 0 deletions docs/how-to-debug-a-hyperlight-guest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# How to debug a Hyperlight guest

Hyperlight supports gdb debugging of a guest running inside a Hyperlight sandbox.
When Hyperlight is compiled with the `gdb` feature enabled, a Hyperlight sandbox can be configured
to start listening for a gdb connection.

## Example
The snipped of a rust host application below configures the Hyperlight Sandbox to
listen on port `9050` for a gdb client to connect.

```rust
let mut cfg = SandboxConfiguration::default();
cfg.set_guest_debug_port(9050);

// Create an uninitialized sandbox with a guest binary
let mut uninitialized_sandbox = UninitializedSandbox::new(
hyperlight_host::GuestBinary::FilePath(
hyperlight_testing::simple_guest_as_string().unwrap(),
),
Some(cfg), // configuration
None, // default run options
None, // default host print function
)?;
```

The execution of the guest will wait for gdb to attach.

One can use a simple gdb config to provide the symbols and desired configuration:

For the above snippet, the below contents of the `.gdbinit` file can be used to
provide configuration to gdb startup.
```gdb
file path/to/symbols.elf
target remote :9050
set disassembly-flavor intel
set disassemble-next-line on
enable pretty-printer
layout src
```

One can find more information about the `.gdbinit` file at [gdbinit(5)](https://www.man7.org/linux/man-pages/man5/gdbinit.5.html).

0 comments on commit d0db26e

Please sign in to comment.