Professor Norm Matloff
Dept. of Computer Science
University of California at Davis
Davis, CA 95616
You execute GDB commands in the GDB window; you view your source files, including setting breakpoints and following from line to line as you step through your code, in the source window. There is also a TTY window available, though I do not recommend it; see the material on terminal I/O below.
CGDB is a curses interface to GDB, a kind of middle ground between the text-based GDB and GUI interfaces such as DDD. For those who frequently use a machine via SSH without an X11 environment, or who dislike the startup time and screen footprint of DDD, but who find GDB's lack of a source code window frustrating, CGDB is a very nice compromise.
It should be noted that GDB itself has something similar, TUI mode, invoked via the -tui option on the command line. However, it is buggy, and CGDB has an additional advantage in that it is in color, with syntax highlighting in the source window.
Get the source from the CGDB home page. Unpack it and type
make; make install
If you do not have root privileges, you will need to specify a directory of your own in which CGDB will be installed, e.g.
If it complains that you do not have GNU readline, download the latter from its repository and build it first. To do that build, go through this same configure; make; make install sequence. Then when running configure to build CGDB, type, say
setenv LD_LIBRARY_PATH /usr/local/readline5.2/lib configure --with-readline=/usr/local/readline5.2
assuming that readline is in /usr/local/readline5.2. (This assumes the C shell. If you don't use the C shell, type csh to get into one before executing the above commands.)
To enter this window if you are not already there, hit the i key.
This is your interface to GDB. You submit your usual GDB commands here (including breakpoints if you wish, though you can also set them in the source window).
In newer versions of CGDB, your source code won't appear until you actually start your program. I recommend running GDB's start command, which will place a temporary breakpoint at main() and run your program. (You can also state command-line arguments, just like with run.) This will make the source code appear, and you can then continue from there.
To enter this window if you are not already there, hit the Esc key.
This window displays your source code. You can scroll through it using the up- and down-arrow keys, or "vi keys," e.g. k for up and j for down, / for search, etc. The line number at which you are focused (not necessarily where you are executing) is highlighted in black.
The line at which you are currently executing is marked by a > and has its line number highlighted in green. Breakpoints have their line numbers highlighted in red (except if the source is assembly language).
To set a breakpoint at the current line, hit the space bar. Hitting the space bar again clears it. Of course, you still have the full range of GDB's breakpoint commands to draw upon if you need finer control.
I recommend opening a separate window for keyboard/screen operations, rather than using CGDB's TTY window. (If you use SSH, you may find the Unix screen command to be useful here and also in general, non-debugging contexts.)
To set up terminal I/O for your debugging session, go to a separate window (i.e. not the one in which you are running CGDB), and first type
who am i
to determine your window's device name, e.g. /dev/pts/5. Then type
Finally, in CGDB, issue the GDB command
(suitably modified to your window's device name). You are now ready to run your program within CGDB.
GDB normally updates its view of a source file when it senses that you've recompiled it. To make sure CGDB does this too, place a line
in your file ~/.cgdb/cgdbrc.
More documentation is available at the CGDB home page.