Skip to content

Commit d0db26e

Browse files
committed
add documentation about the gdb debugging feature
Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 5476cdd commit d0db26e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ This project is composed internally of several internal components, depicted in
3434

3535
* [Security guidance for developers](./security-guidance-for-developers.md)
3636
* [Paging Development Notes](./paging-development-notes.md)
37+
* [How to debug a Hyperlight guest](./how-to-debug-a-hyperlight-guest.md)
3738
* [How to use Flatbuffers in Hyperlight](./how-to-use-flatbuffers.md)
3839
* [How to make a Hyperlight release](./how-to-make-releases.md)
3940
* [Getting Hyperlight Metrics, Logs, and Traces](./hyperlight-metrics-logs-and-traces.md)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)