Skip to content

Commit

Permalink
docs: Add documentation on how to use GDB
Browse files Browse the repository at this point in the history
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 <jackabt@amazon.com>
  • Loading branch information
JackThomson2 committed Sep 17, 2024
1 parent cc55d3a commit ea73a87
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions docs/gdb-debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# GDB Debugging with Firecracker

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.

## Prerequiesites

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.

To build firecracker with the `debug` feature enabled we run:

```bash
cargo build --features "debug"
```

Secondly we need to compile a kernel with specific features enabled for debugging to work, the key features to enable on the kernel are:

```
CONFIG_FRAME_POINTER=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
CONFIG_DEBUG_INFO
```

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

```
CONFIG_SCHED_MC=y
CONFIG_SCHED_MC_PRIO=y
```

## Starting Firecracker with GDB

With all the prerequiesites in place you can now start firecracker ready to connect to GDB.
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.

With Firecracker running and waiting for GDB we are now able to start GDB and connect to Firecracker.
You may need to set the permissions of `/tmp/gdb.socket` to `777` before connecting.

An example of the steps taken to start GDB, load the symbols and connect to Firecracker.

1. Start the GDB process
```bash
gdb vmlinux
```

2. When GDB has started set the target remote to `/tmp/gdb.socket` to connect to Firecracker
```bash
(gdb) target remote /tmp/gdb.socket
```

With these steps completed you'll now see GDB has stopped at the entry point ready for us to start inserting breakpoints and debugging.
## Notes
### Software Breakpoints not working on start
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.

```bash
> hbreak start_kernel
> c
```

### Stopping Firecracker while it's running

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

0 comments on commit ea73a87

Please sign in to comment.