You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- improve documentation
- improve gdb errors by adding a specific error variant for when the
rflags conversion from u64 to u32 fails
- fix clippy issue on windows
Signed-off-by: Doru Blânzeanu <[email protected]>
Copy file name to clipboardExpand all lines: docs/how-to-debug-a-hyperlight-guest.md
+76-6Lines changed: 76 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,54 @@
1
-
# How to debug a Hyperlight guest
1
+
# How to debug a Hyperlight guest using gdb
2
2
3
3
Hyperlight supports gdb debugging of a guest running inside a Hyperlight sandbox.
4
4
When Hyperlight is compiled with the `gdb` feature enabled, a Hyperlight sandbox can be configured
5
5
to start listening for a gdb connection.
6
6
7
+
## Supported features
8
+
9
+
The Hyperlight `gdb` feature enables:
10
+
11
+
1. KVM guest debugging:
12
+
- an entry point breakpoint is automatically set for the guest to stop
13
+
- add and remove HW breakpoints (maximum 4 set breakpoints at a time)
14
+
- add and remove SW breakpoints
15
+
- read and write registers
16
+
- read and write addresses
17
+
- step/continue
18
+
- get code offset from target
19
+
20
+
## Expected behavior
21
+
22
+
Below is a list describing some cases of expected behavior from a gdb debug
23
+
session of a guest binary running inside a Hyperlight sandbox.
24
+
25
+
- when the `gdb` feature is enabled and a SandboxConfiguration is provided a
26
+
debug port, the created sandbox will wait for a gdb client to connect on the
27
+
configured port
28
+
- when the gdb client attaches, the guest vCPU is expected to be stopped at the
29
+
entrypoint
30
+
- if a gdb client disconnects unexpectedly, the debug session will be closed and
31
+
the guest will continue executing disregarding any prior breakpoints
32
+
33
+
## How it works
34
+
35
+
The gdb feature is designed to work like a Request - Response protocol between
36
+
a thread that accepts commands from a gdb cliend and the hypervisor handler over
37
+
a communication channel.
38
+
39
+
All the functionality is implemented on the hypervisor side so it has access to
40
+
the shared memory and the vCPU.
41
+
42
+
The gdb thread uses the `gdbstub` crate to handle the communication with the gdb client.
43
+
When the gdb client requests one of the supported features mentioned above, a request
44
+
is sent over the communication channel to the hypervisor handler for the sandbox
45
+
to resolve.
46
+
7
47
## Example
8
-
The snipped of a rust host application below configures the Hyperlight Sandbox to
48
+
49
+
### Sandbox configuration
50
+
51
+
The snippet of a rust host application below configures the Hyperlight Sandbox to
9
52
listen on port `9050` for a gdb client to connect.
10
53
11
54
```rust
@@ -25,17 +68,44 @@ listen on port `9050` for a gdb client to connect.
25
68
26
69
The execution of the guest will wait for gdb to attach.
27
70
28
-
One can use a simple gdb config to provide the symbols and desired configuration:
71
+
### Gdb configuration
72
+
73
+
One can use a simple gdb config to provide the symbols and desired configuration.
74
+
75
+
The below contents of the `.gdbinit` file can be used to provide a basic configuration
76
+
to gdb startup.
29
77
30
-
For the above snippet, the below contents of the `.gdbinit` file can be used to
31
-
provide configuration to gdb startup.
32
78
```gdb
79
+
# Path to symbols
33
80
file path/to/symbols.elf
81
+
# The port on which Hyperlight listens for a connection
34
82
target remote :9050
35
83
set disassembly-flavor intel
36
84
set disassemble-next-line on
37
85
enable pretty-printer
38
86
layout src
39
87
```
40
-
41
88
One can find more information about the `.gdbinit` file at [gdbinit(5)](https://www.man7.org/linux/man-pages/man5/gdbinit.5.html).
89
+
90
+
### End to end example
91
+
92
+
Using the [Sandbox configuration](#sandbox-configuration) above to configure the [hello-world](https://github.com/hyperlight-dev/hyperlight/blob/main/src/hyperlight_host/examples/hello-world/main.rs) example
93
+
in Hyperlight one can run the below commands to debug the guest binary:
0 commit comments