KDbg - User's Manual
Contents
Introduction
KDbg is a front-end for gdb, the GNU debugger.
At the moment there is not much documentation available.
For the really brave there's documentation about how KDbg
can understand types like QString.
What's it that I see here?
The main window of KDbg consist of four panes:
The upper left pane shows the source code. Mostly, source code
windows are opened automatically. To open a souce code window manually
choose File|Open Source from the menu. You can switch the opened
source code windows by choosing an open source file from the Window
menu.
The lower left pane displays the backtrace (aka stack frames),
i.e. the functions that the program has entered, but not left yet. The
innermost frame (where the program currently executes) is shown at the
top. Click on a stack frame to inspect the variables of that frame.
The upper right pane displays the local variables. Whenever the
progam stops, KDbg displays the values of the local variables in this pane.
The lower right pane displays expressions of your choice (such
expression is also called a watch). To add an expression, type it
into the edit field and press Enter or click Add. To remove an expression,
click on it (choose the root of the expression) and click Del.
The gearwheel in the toolbar indicates whether gdb is working, in which
case it rotates. It rotates fast while KDbg wouldn't accept execution commands,
and it rotates slowly while KDbg gets the variable values.
Using KDbg
To debug a program, choose File|Executable from the menu.
The program is loaded. An xterm window is opened which will show
the output of the debuggee. If you want to debug a core dump, you
must first load the executable that produced the core dump, then choose
File|Core
Dump from the menu. Now KDbg goes to the point in the program that
caused the core dump.
To run the program with arguments, set the working directory,
or set environment variables, choose Execution|Arguments.
See
below for more details.
You can also choose program specific settings that apply only to a certain
executable using File|Settings. More...
In the menu Execution you find the commands that you need to
run
the program, step through code, and to interrupt the program
(Break) while it is running. The important commands (Run
and all kinds of Step) are bound to function keys. For efficient
debugging I strongly recommend that you get used to using them.
The functions are not configurable, but perhaps you want
to contribute a bit of code that does it?
In the menu Breakpoint you find commands to set, clear, disable,
and enable permanent and temporary breakpoints. You can display
a list of active breakpoints. You can also set a breakpoint by clicking
at the left end of the source line (using the left mouse button), and you
can enable and disable a breakpoint by clicking it using the middle mouse
button.
In the menu View you find commands to show and hide various windows.
These are docking windows, which means that you can drag them around and
arrange them in any manner you like.
The breakpoint list
The breakpoint list can be displayed using View|Breakpoints. For
each breakpoint the following is shown: the breakpoint location, the hit
count, the ignore count if set, the condition if set. The icon in front
of the entry indicates whether the breakpoint is enabled (a red dot) or
disabled (a bright red dot), whether the breakpoint is temporary (a tiny
clock is overlaid) or whether the breakpoint is conditional (a tiny question
mark is overlaid).
You can set a condition on a breakpoint (so that the program
is only stopped if the condition is true) or set an ignore count
(so that the program is not stopped the next n times that the breakpoint
is hit). To do that, press the Conditional button and enter the
condition and/or ignore count.
Specifying program arguments, working directory,
environment variables
Choose Execution|Arguments to open a dialog where you can set program
arguments, the working directory for your program, and environment variables.
In the top edit box enter the arguments that shall be passed on to your
program. Next time the program is started, the new arguments will be used.
In the edit box below you can specify the working directory for your
program. The new working directory will be passed to gdb immediately, i.e.
gdb will work with the new setting as soon as you press OK. Your
program will use the new directory only when it is run the next time.
In the environment variables section type in an expression of the form
VARIABLE=value
to set the environment variable VARIABLE to the value value,
and click Modify. To remove a variable, select it from the list
below and click Remove. To change the value, edit the value in the
edit field and click Modify. If you change the name of the variable
and click Modify, you add a new variable! The new environment variables
will be used by your program the next time it is run.
An important environment variable to set if you are using glibc2 on
Linux is LD_BIND_NOW. It is very important that you set this variable
to 1 for all your debugging sessions. If it is not set, gdb cannot
step into and out of system functions that are imported from the shared
libc
and other libraries.
Global options
To specify some global options, choose File|Global Options. You
can set the following:
-
the command by which gdb is invoked,
-
the command that opens a terminal for the program's output,
-
whether the KDbg shall pop into the foreground when the program stops and
a timeout when it shall go back again,
-
the tab width.
How to invoke gdb
If you want to use a different version of gdb, you can specify it under
How
to invoke GDB. The default command is gdb --fullname --nx.
Be sure to also specify these options if you change the gdb executable.
If you leave them away, KDbg will not work. If you messed up the entry,
you can clear it to revert to the default setting.
How to invoke a terminal emulator
If you want to use a different terminal program to show the output of the
program, specify it under Terminal for program output. The default
setting is xterm -name kdbgio -title %T -e sh -c %C. In this entry,
%T
will be replaced by a title string, %C will be replaced by a Bourne
shell script that loops infinitely so that the terminal window doesn't
close. (No, it doesn't use CPU, it calls sleep 3600 in a loop
:) An alternative for this setting could be konsole -nowelcome -name
kdbgio -caption %T -e sh -c %C.
Pop into foreground
You can specify whether the KDbg window shall move itself into the foreground
as soon as the program being debugged stops (at a breakpoint or due to
a signal). The KDbg window is not activated, however (at least under KWM,
the KDE window manager). Some users may feel that this behavior is intrusive,
so this option is off by default.
If this option is on, KDbg will also retreat itself into the background
when the program is continued by any command, but it does so only after
a timeout that can be specified. This avoids that the debugger window flashes
back and fore each time you click any of the Step commands.
Tips and Tricks
-
Always set the environment variable LD_BIND_NOW=1 on glibc2 systems.
See
above.
-
You can use breakpoints as bookmarks: Just set a breakpoint and disable
it. Later, you can quickly come back to that breakpoint by double-clicking
it in the breakpoint list (or select it and click View Code). Since
breakpoints are persistent (i.e. KDbg remembers them across invocations
of a program), you get them back next time you invoke KDbg for that particular
program.
-
You can change a program variable's value: In the variable watch section
(in the lower right) type an assignment like this: var.member=17
and click Add. This immediately changes the value of the variable.
You should delete the expression from the list right away (by selecting
it in the window below and clicking Del). This is because the watch
expressions are evaluate each time the program stops, and by this the variable
would be changed to the specified value again and again!
-
You can display a value in the watch section in different way by prepending
gdb's format specifiers in front of the variable to display. E.g. /x
var.member displays the var.member in hexadecimal notation.
Known problems
gdb 4.16 has problems in handling C++ classes with virtual base classes.
(Such classes commonly occur in CORBA programs.) It dies quite often due
to a segmentation violation. KDbg reports when gdb exits unexpectedly.
Unfortunately, you cannot really do anything about it. You have to restart
gdb by choosing File|Executable, which restarts your debugging session
:-(.
KDbg's type recognition only works for libraries that are linked dynamically
to the program being debugged.
Author
KDbg is written by Johannes Sixt
with the help of many others.
KDbg homepage at http://members.telecom.at/~johsixt/kdbg.html.