DIVISION OF ENGINEERING AND APPLIED SCIENCES
HARVARD UNIVERSITY

CS 161. Operating Systems

Matt Welsh
Spring 2005

Using screen(1) for Debugging

By Philip Zeyliger
(This is a new document; e-mail corrections.)

[CS161 Home Page]

You're going to be spending a lot of time in front of GDB this semester. It's worthwhile to invest some time now into your environment. I found it frustrating to setup the two windows needed for connecting gdb to a kernel, so I used screen(1) to split one (bigger) terminal into two, thereby enabling me to interact with kernel and gdb in one window, like so:


Here's how to set it up:
  1. Put the following (adjust directories as necessary) into ~/.screenrc.161:
    bindkey -k k1 screen 1
    bindkey -k k2 screen 2
    bind q quit
    bind j focus down
    bind k focus up
    startup_message off
    deflogin off
    
    screen -t "sys161" 1
    stuff "pushd ~/cs161/root^M"
    stuff "sys161 -w kernel^M"
    split
    focus down
    screen -t "GDB" 2 
    stuff "pushd ~/cs161/root^M"
    stuff "cs161-gdb kernel^M"
    sleep 1
    stuff "db161^M"
    
  2. Put the following into ~/.gdbinit (replace U/S/USERNAME):
    cd /nfs/home/U/S/USERNAME/cs161/src/kern/compile/ASST5
    define db161
    target remote unix:/nfs/home/U/S/USERNAME/cs161/root/.sockets/gdb
    b panic
    end
    
  3. Make an alias. For example, I did: "alias debug screen -c /home/U/S/USERNAME/.screenrc.161", and put that in my .tcshrc.
  4. Now you can type "debug" and get a cool split-screen debug window.
You'll need to navigate around it. Ctrl-A puts you into screen's "command" mode for one command. Then you can type "j" for down and "k" for up. "q" quits. If you type ESC, you can navigate through a scrollback buffer. Read screen's man page for more info.