Kernel Debugging: Difference between revisions

[unchecked revision][unchecked revision]
Line 57:
This is however rather tricky, since it requires additional hardware, and special support coded into your kernel. You might want to read the [http://web.archive.org/web/20070415113206/http://www.kernelhacking.org/docs/kernelhacking-HOWTO/indexs09.html kernel hacking how-to] and (at minimum) [http://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Debugging.html#Remote-Debugging chapter 20 of the GDB manual], and chances are likely that your debugger will introduce even more bugs at first.
 
== Use gdb with QemuQEMU ==
 
You can run QemuQEMU to listen for a "gdbGDB connection" before it starts executing any code to debug it.
 
qemu -s -S <harddrive.img>
 
...will setup QemuQEMU to listen on port 1234 and wait for a gdbGDB connection to it. Then, from a remote or local shell:
 
gdb
Line 70:
(Replace localhost with remote IP / URL if necessary.) Then start execution:
 
But that's not all, you can compile your source code under gccGCC with debugging symbols using "-g". This will add all the debugging symbols in the kernel image itself (Thus making it bigger ). There is also a way to put all of the debugging information in a separate file using the "objcopy" tool, which is part of the GNU binutilsBinutils package.
 
objcopy --only-keep-debug kernel.elf kernel.sym
Line 84:
To produce a flat binary which can be debugged using the previously extracted debug information
 
You can import the symbols in gdbGDB by pointing gdbGDB to the file containing debug information
 
(gdb) symbol-file kernel.elf ;kernel.elf is the actual unstripped kernel image in this case
 
From there, you can see the actual C source code as it runs line per line! (Use the stepi instruction in gdbGDB to execute the code line per line.)
 
Example :
Line 115:
(gdb) info registers
 
I won't start explaining all the nice things about gdbGDB, but as you can see, it is a very powerful tool for debugging OSes.
 
== GUI frontends ==
Anonymous user