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: 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.

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.

Tips and Tricks

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.