-
Notifications
You must be signed in to change notification settings - Fork 109
Debugging the Harvey kernel using gdb
This is a short note describing how to debug Harvey using gdb. This was tested in Ubuntu, but the procedure should be the same for other linux distros.
Terminal output us shown in like this
, and input in in bold
You'll need four terminal windows:
- Terminal 1 - Qemu monitor
- Terminal 2 - gdb window
- Terminal 3 - To run the Harvey script
- Terminal 4 - Telnet window to connect to Harvey while its running. This one is optional, you could always type directly into the Qemu window if you prefer.
Find out the terminal for Terminal 1 name using the tty command, then sleep the terminal before the debugger starts:
keef@envy:~/src/harvey$ tty /dev/pts/24 keef@envy:~/src/harvey$ sleep 4000
keep this name handy, you'll need it for the Harvey start command.
in Terminal 3, enter the start command:
keef@envy:~/src/harvey$ (export HARVEY=$(pwd) && cd sys/src/9/amd64 && sh ../../../../util/GO9PRUN --monitor /dev/pts/24)
Terminal 1 should print a message like:
keef@envy:~/src/harvey$ QEMU 2.2.0 monitor - type 'help' for more information
(qemu)
Switch to terminal 2 and start gdb:
keef@envy:~/src/harvey$ gdb sys/src/9/amd64/harvey GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9 Copyright (C) 2015 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later ... (gdb) target remote localhost:1234 Remote debugging using localhost:1234 hardhalt () at l64v.S:471
You're now connected to Harvey and can set breakpoints, as an example, I'll set a breakpoint in procopen of the proc (#p) driver (NB, this line number may change, so check the source in sys/src/9/port/devproc.c first):
(gdb) break devproc.c:407 Breakpoint 1 at 0xfffffffff019def5: file ../port/devproc.c, line 407.
Now start Harvey:
(gdb) cont Continuing.
You should see the usual boot messages in the Qemu window.
Now, I'll connect to Harvey and use the ns
command, which will call procopen:
In Terminal 4, telnet onto Harvey machine and connect the file server with entire Harvey's tree:
~/src/harvey$ `util/telnet localhost:5555 harvey@cpu% srv tcp!10.0.2.2!5640 k post...` harvey@cpu% mount -a /srv/k / harvey@cpu% /amd64/bin/ns
The gdb window should print a message that the breakpoint has been reached:
Breakpoint 1, procopen (c=0xfffffffff0ff2cd0, omode=0) at ../port/devproc.c:407
407 if(c->qid.type & QTDIR)
You can now debug using gdb as usual.
You can also use a gui debugger if you prefer, for example using kdbg; start the debugger using:
keef@envy:~/src/harvey$ kdbg -r localhost:1234 sys/src/9/amd64/harvey
And away you go.