GDB

GDB is a debugger that will allow us to debug the kernel under a virtual machine.

From the first terminal run qemu, but we need to add options to enable debugging

make qemu-debug

Which will be controlled by GDB once we start it here (from a new shell)

make gdb

Commands

Here are some useful commands, note that commands can be abbreviated so next can become n. There are many other commands so make sure to read the docs and help menus.

General Commands

CommandMeaning
qquit gdb
killkill debugged process (in our case ukoOS)
info rlist register values
file fileload symbols from file
tui enableenable tui (to split screen source and gdb)
help cmdhelp for cmd

Running Commands

CommandMeaning
nnext line
sstep (like next line, but enters function calls)
ccontinue until next breakpoint (or end)
sistep instruction
ninext instruction

Breakpoints

CommandMeaning
badd breakpoint at current point
b symboladd breakpoint to symbol (symbol is a function name, etc.)
en nenable breakpoint n
dis ndisable breakpoint n
info blist breakpoints

Printing

The p command can do quite a lot:

CommandMeaning
p *addrprint value at address addr
p exprprint out some c-like expression, e.g. p struct->name
p/s *addrprint c-string at addr

Demo

These are from the first day docs.

The first terminal, running make qemu-debug will look like this

And the second, running make gdb