Skip to content

Commit 10b725e

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 bb0264f commit 10b725e

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

docs/gdb-debugging.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 "gdb"
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+
For GDB debugging the `gdb-socket` option should be set in your config file in
39+
this example we set it to `/tmp/gdb.socket`
40+
41+
```
42+
{
43+
...
44+
"gdb-socket": "/tmp/gdb.socket"
45+
...
46+
}
47+
```
48+
49+
## Starting Firecracker with GDB
50+
51+
With all the prerequiesites in place you can now start firecracker ready to
52+
connect to GDB. When you start the firecracker binary now you'll notice it'll be
53+
blocked waiting for the GDB connection this is done to allow us to set
54+
breakpoints before the boot process begins.
55+
56+
With Firecracker running and waiting for GDB we are now able to start GDB and
57+
connect to Firecracker. You may need to set the permissions of your gdb socket
58+
e.g. `/tmp/gdb.socket` to `777` before connecting.
59+
60+
An example of the steps taken to start GDB, load the symbols and connect to
61+
Firecracker.
62+
63+
1. Start the GDB process, you can attach the symbols by appending the kernel
64+
blob for example here `vmlinux`
65+
66+
```bash
67+
gdb vmlinux
68+
```
69+
70+
1. When GDB has started set the target remote to `/tmp/gdb.socket` to connect to
71+
Firecracker
72+
73+
```bash
74+
(gdb) target remote /tmp/gdb.socket
75+
```
76+
77+
With these steps completed you'll now see GDB has stopped at the entry point
78+
ready for us to start inserting breakpoints and debugging.
79+
80+
## Notes
81+
82+
### Software Breakpoints not working on start
83+
84+
When at the initial paused state you'll notice software breakpoints won't work
85+
and only hardware breakpoints will until pages are setup. To circumvent this one
86+
solution is to set a hardware breakpoint at start_kernel and continue. Once
87+
you've hit the start_kernel set the regular breakpoints as you would do
88+
normally. E.G.
89+
90+
```bash
91+
> hbreak start_kernel
92+
> c
93+
```
94+
95+
### Pausing Firecracker while it's running
96+
97+
While Firecracker is running you can pause vcpu 1 by pressing `Ctrl+C` which
98+
will stop the VCPU and allow you to set breakpoints or inspect the current
99+
location
100+
101+
### Halting execution of GDB and Firecracker
102+
103+
To end the debugging session and shutdown Firecracker you can run the `exit`
104+
command in the GDB session which will terminate both

0 commit comments

Comments
 (0)