     [file version.texi not included]

CGDB
****

This manual is for GNU CGDB (version VERSION, UPDATED), the GNU ncurses based front end to GDB.

Copyright © 2006 Free Software Foundation, Inc.

     Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,'' and with the Back-Cover Texts as in (a) below.  A copy of the license is included in the section entitled ``GNU Free Documentation License.''

     (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify this GNU Manual, like GNU software.  Copies published by the Free Software Foundation raise funds for GNU development.''

Summary of CGDB
***************

CGDB is a curses-based interface to the GNU Debugger (GDB).  The goal of CGDB is to be lightweight and responsive; not encumbered with unnecessary features.

The interface is designed to deliver the familiar GDB text interface, with a split screen showing the source as it executes.  The UI is modeled on the classic Unix text editor, vi.  Those familiar with vi should feel right at home using CGDB.

The library responsible for communicating with GDB is called Trivial GDB (tgdb, or more accurately, libtgdb).  This abstraction allows the UI code to be independent of the debugger, as well as greatly simplifying its implementation.

Those wanting to develop other interfaces to GDB are welcome to use libtgdb as the basis for their program.  Many of the headaches of parsing GDB's output and annotations can be avoided by using it.

Some features offered by CGDB are:

  * Syntax-highlighted source window

  * Visual breakpoint setting

  * Keyboard shortcuts for common functions

  * Searching source window (using regexp)

Getting In and Out of CGDB
**************************

This chapter discusses how to start CGDB, and how to get out of it. The essentials are:

  * type cgdb to start CGDB.

  * type quit or C-d in the GDB window to exit.

  * type :quit in the source window to exit.  This even works if GDB is currently hanging, or operating a long command.

Understanding the core concepts of CGDB
***************************************

The CGDB user interface currently consists of two windows and a status bar. The source window is currently on the top and the GDB window is on the bottom.  The status bar currently separates the two windows.

The interface has several modes depending on which window is focused. CGDB mode is when the source window is focused, GDB mode is when the GDB window is focused and TTY mode is when the TTY window is focused.

Beginning with CGDB version 1.0, the windows are movable, and the user will be able to create as many or as few that is desired. Currently however, all of my time is spent developing the interface between CGDB and GDB. Once this is complete, the UI of CGDB will become much more polished.  If you are a ncurses developer, and have spare time to work on this task, please contact me.

Understanding the source window.
================================

The source window is the window that provides you a view of the source code that the debugged program is made up of.  It will display to the user a single source file at a time.  While the user is debugging, via next and step, CGDB will update the source file and line number to keep you informed as to where GDB is debugging.

CGDB has several features that make debugging easier than using plain old GDB. One feature you will notice right away while debugging a C, C++ or ADA program, is that the source files are syntax highlighted.  This allows the user to easily navigate through the source file to look for certain places in the source code.  If you would like to see another source language highlighted, contact us.  To understanding how to navigate through the source window look at the commands in CGDB Mode.

In addition to showing the source code, CGDB also displays to the user the currently executing line. The line number will be highlighted green, to represent that the particular line, is the current line being debugged by GDB. Also, CGDB will display an arrow extending from the line number, to the source line.  You can configure what type of arrow CGDB uses with the :set arrowstyle configuration option. By default, the short arrow is used.  However, my personal favorite is the long arrow.

As you navigate through the source window, the current line the cursor is on will be highlighted white.  This simply helps you keep track of where you are in the file.

Also, you can set or delete breakpoints in CGDB from the source window.  Simply navigate to the line that you are interested in setting a breakpoint, and hit the space bar.  This will set a breakpoint on the line if one did not already exist.  The line number should turn red to indicate that a breakpoint has been set.  Hitting the space bar again will delete the breakpoint.  If you disable the breakpoint, the line number will turn yellow, to represent the disabled breakpoint.

CGDB also supports regular expression searching within the source window.  If you type / or ? you can search in the source window for a string of interest.  The C library regular expression functions are used to perform this search, which honors things like * or +.

The full list of commands that are available in the source window is in CGDB Mode.

Understanding the GDB window.
=============================

The GDB window is how CGDB allows the user to interface with the GNU debugger.  If you wish to pass a command to GDB, simply type it into this window and GDB will receive the command.  This interface is intended to be 100% identical to using GDB on a terminal.

There is a limited set of keys that can be typed into this window that CGDB interprets and handles, instead of sending to GDB.  They are all available in GDB Mode.

CGDB attempts to buffer commands the same way they would be if you typed them at the terminal.  So, if you type several commands before a single one finishes, they will each be run in order.  There will be no way to stop these commands from being run besides from typing Ctrl-C, like you would at any normal terminal when working with GDB.

Understanding the file dialog window.
=====================================

The file dialog window is available to help the user view and select which file they would like to view.  It provides the user with a list of all the files that make up the program being debugged.  If there are no files available, because there is no program being debugged or because there is no debug symbols, then the file dialog will not open and a message will be displayed at the status bar.

You can get to the file dialog by hitting o when you are at the source window.  Once you enter the file dialog, it is possible to leave it by hitting q.  You can navigate the file dialog using the standard direction keys and you can even use regular expression to find your file.  This can save a lot of time as the number of files grow.

The full list of commands that are available in the source window is in File Dialog Mode.

Understanding the TTY window.
=============================

The TTY window is available to allow the user to pass input to the program being debugged. This window will act similar to the GDB window, except that the data you type will get sent to the program being debugged. See Sending I/O to Inferior.

You will notice that the TTY window has a terminal device between it and the program being debugged.  So, if the program being debugged uses say readline, which allows command line editing, the same interface will be provided via the TTY window as at the terminal.  You can see the name of the terminal device in the TTY status bar.

The full list of commands that are available in the source window is in TTY Mode.

Sending I/O to the program being debugged can be confusing.  It is described better in Sending I/O to Inferior.  Unless the I/O with the program being debugged is simple, I usually prefer starting the application on a separate terminal and attaching to it with CGDB.

Understanding the status bar.
=============================

The status bar is the general purpose way for CGDB to show the user which commands they are currently typing or report errors to the user when they occur.  CGDB does not use popup's or other forms of I/O to alert the user of information or problems.

While CGDB is running, you can configure it with any of the commands that are valid in CGDB's configuration file.  Simply type : in the source window, and you will see the colon, and the rest of the command you type appear in the status bar.  When you are finished typing the command that you are interested in, type enter.  This will alert CGDB to execute the command.

The full list of commands that are available in the source window is in Configuring CGDB.

Switch between windows
======================

When CGDB is invoked, the interface is in GDB mode.  A * at the right of the status bar indicates that input will be passed to GDB.  To change the focus to the source window, hit ESC.  The interface is now in CGDB mode.

To switch back into GDB mode, press i.  This syntax is based on the popular Unix text-editor, vi.

CGDB commands
*************

CGDB can be controlled in a variety of different ways.  Each mode that CGDB is in acts differently. Currently CGDB implicitly changes modes depending on which window is active.  The following information will help you determine what commands are accessible during which modes.

Commands available during CGDB mode
===================================

When you are in the source window, you are implicitly in CGDB mode. All of the below commands are available during this mode.  This mode is primarily available for the user to view the current source file, search it, or switch to a different mode.

ESC
     Puts the user into command mode. However, you are already in this mode.

i
     Puts the user into GDB mode.

I
     Puts the user into TTY mode.

T
     Opens a window to give input to the debugged program.

Ctrl-T
     Opens a new tty for the debugged program.

k
up arrow
     Move up a line.

j
down arrow
     Move down a line.

h
left arrow
     Move left a line.

l
right arrow
     Move right a line.

Ctrl-b
page up
     Move up a page.

Ctrl-u
     Move up 1/2 a page.

Ctrl-f
page down
     Move down a page.

Ctrl-d
     Move down 1/2 a page.

gg
     Move to the top of file.

G
     Move to the bottom of file.

/
     search from current cursor position.

?
     reverse search from current cursor position.

n
     next forward search.

N
     next reverse search.

o
     open the file dialog.

spacebar
     Sets a breakpoint at the current line number.

t
     Sets a temporary breakpoint at the current line number.

-
     Shrink source window 1 line.

=
     Grow source window 1 line.

_
     Shrink source window 25% (or, shrink tty window 1 line, if visible).

+
     Grow source window 25% (or, grow tty window 1 line, if visible).

Ctrl-l
     Clear and redraw the screen.

If you have the shortcut option turned on, then the source window will have several more commands available.  These commands override the above commands.

r
     Send a run command to GDB.

n
     Send a next command to GDB.

s
     Send a step command to GDB.

c
     Send a continue command to GDB.

f
     Send a finish command to GDB.

u
     Send an up command to GDB.

d
     Send a down command to GDB.

Commands available during GDB mode
==================================

When in GDB mode, the user is mostly interested in working with the GDB console.  That is, sending commands to GDB and receiving data back from GDB. Almost all data passed into this window is directly sent to readline and then to GDB.

It is important to understand that CGDB parses the keys entered in the GDB window and has the first chance at dealing with them.  If it is interested in the keys, it will handle them. Below is a list of keys that CGDB is interested in, and does not pass along any further.

ESC
     Switch back to source window.

page up
     Move up a page.

page down
     Move down a page.

F11
     Go to the beginning of the GDB buffer.

F12
     Go to the end of the GDB buffer.

Any other keys, besides the ones above, CGDB is currently not interested in. CGDB will pass along these keys to the readline library. When readline has determined that a command has been received, it alerts CGDB, and a command is then sent to GDB. This is the same method used when invoking GDB directly.

Commands available during the file dialog mode
==============================================

The file dialog is primarily used to allow the user to find and open a source file that the program they are debugging is made up of.  The file dialog will be full screen, and will list each file that the debugged program is made up of.  A usual instance of the file dialog would be to open it up from the source window using the o key, and then to search for the file of interest. If you are looking for foo.c type /foo.c, press enter once to finish the regular expression and again to select the file.

The commands available in the file dialog are:

q
     Will exit the file dialog, and return to the source window.

k
up arrow
     Move up a line.

j
down arrow
     Move down a line.

h
left arrow
     Move left a line.

l
right arrow
     Move right a line.

Ctrl-b
page up
     Move up a page.

Ctrl-f
page down
     Move down a page.

/
     search from current cursor position.

?
     reverse search from current cursor position.

n
     next forward search.

N
     next reverse search.

enter
     Select the current file.

Commands available during TTY mode
==================================

ESC
     Switch back to source window.

page up
     Move up a page.

page down
     Move down a page.

F11
     Go to the beginning of the GDB buffer.

F12
     Go to the end of the GDB buffer.

CGDB configuration commands
***************************

There may be several features that you find useful in CGDB.  CGDB is capable of automating any of these commands through the use of the config file called cgdbrc.  It looks in $HOME/.cgdb/ for that file.  If it exists, CGDB executes each line in the file in order.  It is as if the user typed in all the commands into the status bar after the tui was initialized.

The following variables change the behavior of some aspect of CGDB.  Many of these commands may be abbreviated in some way, and all boolean commands my be negated by appending no to the front.  For example: :set ignorecase turns on case-insensitive searching; while :set noignorecase turns on case-sensitive searching.

:set as=STYLE
:set arrowstyle=STYLE
     Set the arrow style to STYLE.  Possible values for STYLE are short, long, and highlight.  Changes the style of the arrow that is used to indicate the currently executing line in the source viewer.  The default value is short.  A longer arrow is available, for easier readability.  Finally, the highlight option draws no arrow at all, instead drawing the entire line in inverse video.

:set asr
:set autosourcereload
     If this is on, CGDB will automatically reload a source file if it has changed since CGDB has opened it.  If it is off, the file will never be reloaded, until you start CGDB again. The default is off. This feature is useful when you are debugging a program, then you modify a source file, recompile, and type r in GDB's CLI window. The file in this case will be updated to show the new version.  Note, CGDB only looks at the timestamp of the source file to determine if it has changed. So if you modify the source file, and didn't recompile yet, CGDB will still pick up on the changes.

:set escdelay=DELAY
     Set the length of time to wait before timing out and treating the ESC keystroke as the ESC character rather than combining it with other characters in the buffer to create a key sequence.  The variable is measured in milli seconds.  If DELAY is 0, the system immediately composes the ESCAPE response without waiting for more information from the buffer.  DELAY may be any value between 0 and 10000, inclusive.  The default setting for the DELAY variable is 40 (forty hundredths of a second).

:set ic
:set ignorecase
     Sets searching case insensitive.  The default is off.

:set sc
:set shortcut
     Enables shortcut commands typed in source window.  The default is off. See CGDB Mode.

:set stc
:set showtgdbcommands
     If this is on, CGDB will show all of the commands that it sends to GDB. If it is off, CGDB will not show the commands that it gives to GDB. The default is off.

:set syn=STYLE
:set syntax=STYLE
     Sets the current highlighting mode of the current file to have the syntax STYLE.  Possible values for SYNTAX are c, ada, and off.  Normally, the user will never have to do this, since CGDB automatically detects what syntax a file should be based on its file extension.  However, this feature can currently be useful for debugging purposes.

:set ts=NUMBER
:set tabstop=NUMBER
     Sets the number of spaces that should be rendered on the screen for TAB characters.  The default value for NUMBER is 8.

:set wmh=NUMBER
:set winminheight=NUMBER
     The minimal height of a window.  Windows will never become smaller than this value.  The default value for NUMBER is 0.

:set winsplit=STYLE
     Set the split point between source and GDB window.  This is especially useful as an init setting in your cgdbrc file.  See Configuring CGDB.  The possible values for STYLE are top_full, top_big, even, bottom_big, and bottom_full.

:set ws
:set wrapscan
     Searches wrap around the end of file.  The default is on.

:continue
     Send a continue command to GDB.

:e
:edit
     reloads the file in the source window.  this can be useful if the file has changed since it was opened by cgdb.

:finish
     Send a finish command to GDB.

:help
     This will display the current manual in text format, in the source window.

:hi GROUP cterm=ATTRIBUTES ctermfg=COLOR ctermbg=COLOR term=ATTRIBUTES
:highlight GROUP cterm=ATTRIBUTES ctermfg=COLOR ctermbg=COLOR term=ATTRIBUTES
     Set the COLOR and ATTRIBUTES for a highlighting group.  The syntax mimics vim's ``highlight'' command.  Possible values for GROUP, ATTRIBUTES and COLOR are available in Highlighting Groups.

     You can give as many or as few of the name=value pairs as you wish, in any order.  ctermfg and ctermbg set the foreground and background colors.  These can be specified by color number or by using the same color names that vim uses.  When CGDB is linked with ncurses, the number you use to represent the color can be between -1 and COLORS.  When CGDB is linked against curses, it must be between 0 and COLORS.

     cterm sets the video attributes for color terminals.  term sets the video attributes for monochrome terminals.  Some examples are,

          :highlight Logo cterm=bold,underline ctermfg=Red ctermbg=Black
          :highlight Normal cterm=reverse ctermfg=White ctermbg=Black
          :hi Normal term=bold

:insert
     Move focus to the GDB window.

:next
     Send a next command to GDB.

:q
:quit
     Quit CGDB.

:run
     Send a run command to GDB.

:step
     Send a step command to GDB.

:syntax
     Turn the syntax on or off.

CGDB highlighting groups
************************

CGDB is capable of using colors if the terminal it is run in supports them. Until version 0.6.1, CGDB did not allow the user to configure these colors in any way.  CGDB color use is now fully configurable.

CGDB's modeled its use of color highlighting after vim.  Any data that will be colored in the terminal is represented by a highlighting group. A highlighting group represents data that should be formatted using foreground colors, background colors and attributes.  There are currently several types of highlighting groups in CGDB.  There are syntax highlighting groups, which represent syntax highlighting of sources files.  There are also User Interface groups, which represent things like CGDB's logo, or the status bar.

Each highlighting group has a default set of attributes and colors associated with it.  You can modify a highlighting groups properties by using the highlight command.  See Configuring CGDB.

Note that CGDB currently supports using the same background color the terminal was using before CGDB was started.  However, this only works when CGDB was linked with ncurses.  If you link CGDB with curses, then CGDB will force the background to Black.

The different highlighting groups
=================================

Below is a list of all the highlighting groups that CDGB will use when syntax highlighting source files.

Statement
     This represents the keywords a language defines.

Type
     This represents the types a language defines.

Constant
     This represents either a string or numeric value.

Comment
     This represents the comments in a source file.

PreProc
     This represents the C/C++ preprocessor commands.

Normal
     This represents all normal text.

Below is a list of all the highlighting groups that CGDB will use when it is displaying it's User Interface.

StatusLine
     This represents the status bar in CGDB.  The file dialog's status bar also uses this group.

IncSearch
     This represents the group used when the user is searching in either the source window, or the file dialog window.

Arrow
     This represents the arrow that CGDB draws to point to the currently viewed line.

LineHighlight
     This represents the group used when the user has the arrowstyle option set to highlight.

Breakpoint
     This represents the group that is used when CGDB displays a line that has a breakpoint set.

DisabledBreakpoint
     This represents the group that is used when CGDB displays a line that has a disabled breakpoint set.

Logo
     This is the group CGDB uses to display its logo on startup when no source file can be auto detected.

The different attributes
========================

CGDB supports many of the attributes that curses provides.  It will apply the attributes to the output window, but it is up to the terminal you are using to support such features.

The list of attributes that CGDB currently supports is below.

normal
NONE
     This will leave the text normal.  Uses A_NORMAL curses attribute.

bold
     This will make the text appear bold.  Uses A_BOLD curses attribute.

underline
     This will underline the text.  Uses A_UNDERLINE curses attribute.

reverse
inverse
     This will reverse the foreground and background colors.  Uses A_REVERSE curses attribute.

standout
     This is the best highlighting mode of the terminal.  Uses A_STANDOUT curses attribute.

blink
     This will cause the text to blink.  Uses A_BLINK curses attribute.

dim
     This will cause the text to be 1/2 bright.  Uses A_DIM curses attribute.

The different colors
====================

CGDB supports several colors, depending on how many colors your terminal supports.  Below is a chart of the colors that CGDB provides.  The heading NR-16 is used to represent terminals that support at least 16 colors.  The heading NR-8 is used to represent terminals that support at least 8 colors. The integer values for each color represent the values passed to the curses function init_pair() to ask curses to create a new color.

COLOR NAME
NR-16
NR-8
NR-8 bold attribute
Black
0
0
No
DarkBlue
1
4
No
DarkGreen
2
2
No
DarkCyan
3
6
No
DarkRed
4
1
No
DarkMagenta
5
5
No
Brown, DarkYellow
6
3
No
LightGray, LightGrey, Gray, Grey
7
7
No
DarkGray, DarkGrey
8
0
Yes
Blue, LightBlue
9
4
Yes
Green, LightGreen
10
2
Yes
Cyan, LightCyan
11
6
Yes
Red, LightRed
12
1
Yes
Magenta, LightMagenta
13
5
Yes
Yellow, LightYellow
14
3
Yes
White
15
7
Yes

Sending I/O to the program being debugged
*****************************************

If the program being debugged takes input on the terminal it is recommended that the user start the program on one terminal, and attach to it with CGDB from another terminal.  This is the easiest way to pass input to the debugged program.

However, if the user wishes to pass input to the program being debugged from within CGDB, there is a mechanism available for doing so.  As of this writing, the technique described below does not work on windows, using a natively compiled GDB.  It may work when using the GDB that comes with Cygwin.

This technique is similar to getting in and out of GDB mode.  The tty window is not visible by default.  This is because it is only needed if the user wishes to send data to the program being debugged.  To display the tty window, hit T while in command mode.  After hitting T you will notice that there is another window in the middle of the source window and the gdb window.  This is called the tty window. You will also see a new status bar called the tty status bar.  There will be a * on the tty status bar after the T was hit.  This is because when the window is opened with the T command, CGDB automatically puts the user into TTY mode.  To get out of this window hit ESC.  This will put you back into command mode.  To make the tty window appear and disappear hit the T key while in command mode.  It is a toggle.

Once the tty window is already open, the user can then hit I in command mode to get into TTY mode.  The user can then hit ESC in TTY mode to get back into command mode.

When the tty window is open, all data that comes from the program, goes there.  Any data typed into the tty window will ONLY go to the program being debugged.  It will not go to GDB. When the tty window is closed, all output from the debugged program will go to the GDB window AND to the tty window (for viewing later when the tty window is opened).

If the user wishes to get a new tty for the program being debugged then they can type Ctrl-T.  This will delete all the buffered data waiting to be read into the debugged program. This might be useful when you rerun or start a new program.

Allowing terminal control flow in CGDB
**************************************

A user can typically set there control flow behavior by using the stty command like so stty -ixon -ixoff.  This will disable control flow on the terminal where CGDB is started.  If you want to turn control flow back on you can type stty ixon ixoff.  If flow control is on, when the user types Ctrl-s, the terminal stops.  When the user types Ctrl-q, the terminal restarts.  When using readline, the Ctrl-s character usually does a forward search.  So, if you want to get this, or other functionality out of readline, simply turn off control flow and start CGDB.

Building CGDB from source
*************************

Building CGDB from source requires several packages. First, CGDB is hosted at http://sf.net/projects/cgdb. You can determine how to get CGDB from source by looking here: http://sourceforge.net/svn/?group_id=72581.

Once you have the source to CGDB, now you can begin to build it.  You will of course need many packages to build CGDB. Below is a list of all of them that are required to build CGDB.

GNU Make
     I have successfully used version 3.79.1, however, older versions probably will work.

GNU GCC
     The GNU C compiler. I've compiled CGDB with versions as old as 2.9.5, and as new as 4.0.2.

GNU Readline
     The GNU readline library version 5.1. CGDB will not work with versions before 5.1.  Readline was modified specifically to work with CGDB.

GNU Ncurses
     I have successfully used libncurses.so.5 successfully.  However, older versions probably will work.

Below is a list of optional packages you will need, if modifying certain files in CGDB.

GNU Flex
     If you modify any files with an extension of .l, you will have to have flex installed.  I have used flex 2.5.4 to build CGDB.

GNU Texinfo
     If you modify doc/cgdb.texinfo, then you will be required to have this package installed.  I have used version 4.7 to build the documentation for CGDB.

help2man
     If you are doing a release, then you will be required to have this package installed.  In the doc/ build directory, you can execute the command make cgdb.1, and the CGDB man page will be generated.

CGDB uses autoconf/automake to build its configure scripts and makefiles.  So, if you change any of the autoconf/automake files, you will need this software installed.

GNU Automake
     This has the program aclocal, and must be version Version 1.9.5.

GNU Autoconf
     This has the program autoconf, and must be version 2.59.

GNU m4
     This has the program m4, and must be version 1.4.3.

Copying This Manual
*******************

     [file fdl.texi not included]