Skip to content

Commit a496d60

Browse files
committed
docs: Add documentation on how to use GDB
Add documentation on how to use gdb with firecracker with examples on how to use the basic functionality to debug the guest kernel Signed-off-by: Jack Thomson <[email protected]>
1 parent cc55d3a commit a496d60

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

docs/gdb-debugging.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# GDB Debugging with Firecracker
2+
3+
Firecracker supports debugging the guest kernel via GDB remote serial protocol.
4+
This allows us to connect gdb to the firecracker process and step through debug
5+
the guest kernel.
6+
7+
## Prerequiesites
8+
9+
Firstly to enable GDB debugging we need to compile Firecracker with the `debug`
10+
feature enabled, this will enable the necessary components for the debugging
11+
process.
12+
13+
To build firecracker with the `debug` feature enabled we run:
14+
15+
```bash
16+
cargo build --features "debug"
17+
```
18+
19+
Secondly we need to compile a kernel with specific features enabled for
20+
debugging to work, the key features to enable on the kernel are:
21+
22+
```
23+
CONFIG_FRAME_POINTER=y
24+
CONFIG_KGDB=y
25+
CONFIG_KGDB_SERIAL_CONSOLE=y
26+
CONFIG_DEBUG_INFO
27+
```
28+
29+
It can also be worth disabling the multi core scheduler as this can cause issues
30+
with GDB these are set under these configs and can be disabled if you encounter
31+
issues
32+
33+
```
34+
CONFIG_SCHED_MC=y
35+
CONFIG_SCHED_MC_PRIO=y
36+
```
37+
38+
## Starting Firecracker with GDB
39+
40+
With all the prerequiesites in place you can now start firecracker ready to
41+
connect to GDB. When you start the firecracker binary now you'll notice it'll be
42+
blocked waiting for the GDB connection this is done to allow us to set
43+
breakpoints before the boot process begins.
44+
45+
With Firecracker running and waiting for GDB we are now able to start GDB and
46+
connect to Firecracker. You may need to set the permissions of `/tmp/gdb.socket`
47+
to `777` before connecting.
48+
49+
An example of the steps taken to start GDB, load the symbols and connect to
50+
Firecracker.
51+
52+
1. Start the GDB process
53+
54+
```bash
55+
gdb vmlinux
56+
```
57+
58+
1. When GDB has started set the target remote to `/tmp/gdb.socket` to connect to
59+
Firecracker
60+
61+
```bash
62+
(gdb) target remote /tmp/gdb.socket
63+
```
64+
65+
With these steps completed you'll now see GDB has stopped at the entry point
66+
ready for us to start inserting breakpoints and debugging.
67+
68+
## Notes
69+
70+
### Software Breakpoints not working on start
71+
72+
When at the initial paused state you'll notice software breakpoints won't work
73+
and only hardware breakpoints will until pages are setup. To circumvent this one
74+
solution is to set a hardware breakpoint at start_kernel and continue. Once
75+
you've hit the start_kernel set the regular breakpoints as you would do
76+
normally. E.G.
77+
78+
```bash
79+
> hbreak start_kernel
80+
> c
81+
```
82+
83+
### Stopping Firecracker while it's running
84+
85+
While Firecracker is running you can pause vcpu 1 by pressing `Ctrl+C` which
86+
will stop the VCPU and allow you to set breakpoints or inspect the current
87+
location

0 commit comments

Comments
 (0)