Skip to content

Commit ea73a87

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 ea73a87

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

docs/gdb-debugging.md

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

0 commit comments

Comments
 (0)