-
Notifications
You must be signed in to change notification settings - Fork 110
Debugging
Kevin Wern edited this page Jan 28, 2018
·
5 revisions
NOTE: This is just one way to debug. Anything to help flesh out or generify this guide is appreciated.
This requires the relevant PR to be merged.
To complete these instructions, you need:
- qemu
- The i686-elf version of gdb.
From inside the src
directory, run:
qemu-system-i386 -cdrom basekernel.iso -s -S
You should get a qemu instance with nothing happening.
Then just run gdb:
i686-elf-gdb
You should get something like this:
0x0000fff0 in ?? ()
add symbol table from file "kernel.elf" at
.text_addr = 0x10000
add symbol table from file "test.elf" at
.text_addr = 0x80000000
(gdb)
You should then be able to reference a symbol and set breakpoints like a normal debugger, i.e.:
(gdb) break kernel_main
Breakpoint 1 at 0x10634: file main.c, line 40.
(gdb) continue
Continuing.
Breakpoint 1, kernel_main () at main.c:40
40 {
(gdb) next
41 struct graphics *g = graphics_create_root();
(gdb) next
This is made possible by two changes: first, the Makefile compiles sources as ELF files with symbols before using objcopy to convert the executable to flat binary; second, there is a .gdbinit file that establishes the connection to qemu and loads the symbol-table on startup.