NetBSD Documentation:Debugging the NetBSD kernel with GDB HOWTO |
The advantage of KGDB over DDB is that you can step through the source code of the kernel, rather than through disassembled machine code. As a matter of fact, nearly all GDB facilities work, including any of the various graphical frontends for gdb (eg - ddd).
TARGET - the machine that will be running the debug kernel REMOTE - the machine that will run/display gdbIt is possible to build gdb hosted on one architecture and targeted for another, but that is currently beyond the scope of this document.
(NOTE: It may be best to build the kernels on the REMOTE machine. That way all the proper source and symbol files are already there when it comes time to debug.)
#options DDB # in-kernel debugger #options DDB_HISTORY_SIZE=100 # enable history editingand uncomment (or add) the following three lines:
options KGDB # remote debugger options "KGDB_DEVNAME=\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600 makeoptions DEBUG="-g" # compile full symbol tableChange KGDB_DEVADDR to match the IO address of the serial port you will use on the TARGET (0x3f8 is tty00, 0x2f8 is tty01), and KGDB_DEVRATE to match the serial bitrate you want to use.
Copy the file "netbsd" from the kernel build directory to the root directory of the TARGET machine. DO NOT INSTALL THIS KERNEL ON THE REMOTE MACHINE (especially if you're using the same tty on both machines!)
tty01 "/usr/libexec/getty std.9600" unknown off localThe important parts here are "off" (so that init won't run getty on the port) and "local". This is because `ttyflags' sets up the defaults for the port according the /etc/ttys at boottime, and gdb requires "local" to be set so that it doesn't wait for DTR.
You may also want to change the "std.9600" to a different bitrate - it should match the rate you set in the kernel options for the TARGET as well as the remotebaudrate you set in gdb (below). Make sure there is actually an entry in /etc/gettytab to match the name you give here.
boot -dThis will cause the kernel to load, after which the message "waiting for kgdb" will be printed, and the TARGET will stop.
gdb netbsd.gdbAfter a couple seconds of churning, you will get the (gdb) prompt.
# this one lets you stop the TARGET any time with Ctrl-C (gdb) set remotebreak 1 # this sets the baudrate gdb will use (default 9600, # MUST match the setting in the kernel installed on the TARGET) (gdb) set remotebaud 9600 # this one speeds up retransmissions of debugger # commands when there is a line error on the serial (gdb) set remotetimeout 3
target remote /dev/tty01
You should be greeted with something like the following:
Remote debugging using /dev/tty01 kgdb_connect (verbose=1) at ../../../../arch/i386/i386/kgdb_machdep.c:244 244 if (verbose) (gdb)
If GDB instead appears to "hang", you may have something wrong with your serial hardware, cable, or settings. See the troubleshooting section below.
file netbsd.gdb set remotebreak 1 set remotebaud 9600 target remote /dev/tty01
Now you can start debugging by just typing "gdb".
com0 at isa0 port 0x3f8-0x3ff irq4: ns16550a, working fifo com0: kgdb
* put the following lines in /etc/remote on both the TARGET and the REMOTE machines:
tty00-9600:dv=/dev/tty00:br#9600:pa=none:dc:
tty01-9600:dv=/dev/tty01:br#9600:pa=none:dc:
* on the TARGET, give the command "tip tty00-9600", and on the REMOTE do "tip tty01-9600".
* type characters at the keyboard of each machine - the characters should echo to *the other* machine's display.
* put /dev/tty0* in group "wheel" (if it isn't already)
* add your username to the "wheel" line in /etc/group
* add your username to the "dialer" line in /etc/group
(2) will allow your gdb process (and other processes run by you) to open the tty, (3) will allow you to run tip.
|
|