Skip to content

Commit 2c57bac

Browse files
committed
Add gdb script and update docs
Signed-off-by: Simon Davies <[email protected]>
1 parent 6ee6dc7 commit 2c57bac

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

docs/how-to-debug-a-hyperlight-guest.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ To selectively disable this feature for a specific sandbox, you can set the `gue
226226
cfg.set_guest_core_dump(false); // Disable core dump for this sandbox
227227
```
228228

229-
### Creating a dump on demand
229+
## Creating a dump on demand
230230

231231
You can also create a core dump of the current state of the guest on demand by calling the `generate_crashdump` method on the `InitializedMultiUseSandbox` instance. This can be useful for debugging issues in the guest that do not cause crashes (e.g., a guest function that does not return).
232232

233233
This is only available when the `crashdump` feature is enabled and then only if the sandbox
234234
is also configured to allow core dumps (which is the default behavior).
235235

236-
# Examples
236+
### Example
237237

238238
Attach to your running process with gdb and call this function:
239239

@@ -252,7 +252,12 @@ sudo gdb -p <pid_of_your_process>
252252
# Call the crashdump function
253253
call sandbox.generate_crashdump()
254254
```
255-
The crashdump should be available in crash dump directory (see `HYPERLIGHT_CORE_DUMP_DIR` env var).
255+
The crashdump should be available `/tmp` or in the crash dump directory (see `HYPERLIGHT_CORE_DUMP_DIR` env var). To make this process easier, you can also create a gdb script that automates these steps. You can find an example script [here](../scripts/dump_all_sandboxes.gdb). This script will try and generate a crashdump for every active thread except thread 1 , it assumes that the variable sandbox exists in frame 15 on every thread. You can edit it to fit your needs. Then use it like this:
256+
257+
```shell
258+
(gdb) source scripts/dump_all_sandboxes.gdb
259+
(gdb) dump_all_sandboxes
260+
```
256261

257262
### Inspecting the core dump
258263

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
define dump_all_sandboxes
2+
set pagination off
3+
4+
# Get the total number of threads
5+
info threads
6+
7+
# Loop through all threads (adjust max if you have more than 200 threads)
8+
set $thread_num = 2
9+
while $thread_num <= 200
10+
# Try to switch to this thread
11+
thread $thread_num
12+
13+
# Check if thread switch succeeded (GDB sets $_thread to current thread)
14+
if $_thread == $thread_num
15+
echo \n=== Thread
16+
p $thread_num
17+
echo ===\n
18+
19+
# Go to frame 15
20+
frame 15
21+
22+
23+
set $sb = &sandbox
24+
call sandbox.generate_crashdump()
25+
26+
set $thread_num = $thread_num + 1
27+
else
28+
# No more threads, exit loop
29+
set $thread_num = 201
30+
end
31+
end
32+
33+
echo \nDone dumping all sandboxes\n
34+
set pagination on
35+
end
36+
37+
document dump_all_sandboxes
38+
Dump crashdumps for sandboxes on all threads (except thread 1).
39+
Assumes sandbox is in frame 15 on each thread.
40+
Usage: dump_all_sandboxes
41+
end

0 commit comments

Comments
 (0)