You must set the environment variable KDE_DEBUG (to 1 or whatever you want in fact).

+

===How do I avoid Dr Konqi?===

+

You must set the environment variable KDE_DEBUG (to 1 or whatever you want in fact).

−

==What is a core file? How do I get a core file?==

+

To get Dr Konqi back, unset the KDE_DEBUG environment variable.

+

+

Example:<br />

+

*To avoid Dr Konqi:<br />

+

::<tt>export KDE_DEBUG=1</tt>

+

*To see Dr Konqi:<br />

+

::<tt>unset KDE_DEBUG</tt>

+

+

===What is a core file? How do I get a core file?===

A core file is an image of the memory when your application crashed. Using the core file, you can now which variables were set and where your application crashed.

A core file is an image of the memory when your application crashed. Using the core file, you can now which variables were set and where your application crashed.

Line 11:

Line 20:

For more information about how to use gdb, see this page.

For more information about how to use gdb, see this page.

−

==Is there a preferred way to print debug output on stderr?==

+

===What tools are available to debug my application?===

−

Yes, you must use kdDebug():

+

−

+

−

<code cppqt>

+

−

#include <kdebug.h>

+

−

kdDebug() << "KMyApp just started" << endl;

+

−

</code>

+

−

+

−

The syntax is much like cout, you can use many native types between the "<<". This will print out a debugging message, which will automatically be turned off at release time (by --disable-debug). In case you want the message to still be there during releases, because it's a warning or an error, use kdWarning() or kdError().

+

−

+

−

Components and libraries are advised to use a debug area number, as in kdDebug(1234). For this, the number must be registered in kdelibs/kdecore/kdebug.areas. Debug areas make it possible to turn off or on the debug output for specific area numbers, using the "kdebugdialog" program, which is part of kdebase. "kdebugdialog --fullmode" also permits to control where to log debug output. It is usually not necessary to register area numbers for standalone applications, unless it's so complex that you want to divide the output into several areas.

+

−

+

−

To make it clear: do NOT use qDebug(), this one doesn't get disabled at releases. Also avoid using assert() or kdFatal() which lead to a crash when something goes wrong, never nice for the user. Better detect the error, output a kdWarning or kdError, and recover if possible.

+

−

+

−

==What tools are available to debug my application?==

+

kdDebug() calls are a simple but efficient way to debug an application.

kdDebug() calls are a simple but efficient way to debug an application.

gdb, the GNU debugger, is the quickest way to execute step-by-step and investigate variables (prefer the 5.0 version, it is really better than the 4.1.x).

gdb, the GNU debugger, is the quickest way to execute step-by-step and investigate variables (prefer the 5.0 version, it is really better than the 4.1.x).

Line 32:

Line 27:

Memory leak tracer : See kdesdk/kmtrace. The README explains it all.

Memory leak tracer : See kdesdk/kmtrace. The README explains it all.

kdcop and dcop allow to browse the dcop interface and to easily make dcop calls.

kdcop and dcop allow to browse the dcop interface and to easily make dcop calls.

−

Check this page and kdesdk, there are a bunch of useful scripts there.

+

Check this page and kdesdk, there are a bunch of useful scripts there.

−

==How do I print a QString in gdb?==

+

===How do I print a QString in gdb?===

Check out kdesdk, and add this line to your ~/.gdbinit :

Check out kdesdk, and add this line to your ~/.gdbinit :

source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb

source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb

Line 43:

Line 38:

$1 = "content"

$1 = "content"

−

See the kde-devel-gdb file for the other macros it defines.

+

See the kde-devel-gdb file for the other macros it defines.

−

==I have no symbol when I debug an app that uses kpart, what should I do?==

+

===I have no symbol when I debug an app that uses kpart, what should I do?===

You must stop just after the main to load the debugging symbols of the shared library. After that, you can debug normally.

You must stop just after the main to load the debugging symbols of the shared library. After that, you can debug normally.

One can go as far as creating a gdb macro, to stop right after the part was loaded. For kword, by example, I use :

One can go as far as creating a gdb macro, to stop right after the part was loaded. For kword, by example, I use :

Line 55:

Line 50:

QObject *, char const *, bool)' cont

QObject *, char const *, bool)' cont

−

==How do I debug an ioslave?==

+

===How do I debug an ioslave?===

See kdebase/kioslave/DEBUG.howto

See kdebase/kioslave/DEBUG.howto

+

+

==KDE 3 specific==

+

===Is there a preferred way to print debug output on stderr?===

+

Yes, you must use kdDebug():

+

+

<code cppqt>

+

#include <kdebug.h>

+

kdDebug() << "KMyApp just started" << endl;

+

</code>

+

+

The syntax is much like cout, you can use many native types between the "<<". This will print out a debugging message, which will automatically be turned off at release time (by --disable-debug). In case you want the message to still be there during releases, because it's a warning or an error, use kdWarning() or kdError().

+

+

Components and libraries are advised to use a debug area number, as in kdDebug(1234). For this, the number must be registered in kdelibs/kdecore/kdebug.areas. Debug areas make it possible to turn off or on the debug output for specific area numbers, using the "kdebugdialog" program, which is part of kdebase. "kdebugdialog --fullmode" also permits to control where to log debug output. It is usually not necessary to register area numbers for standalone applications, unless it's so complex that you want to divide the output into several areas.

+

+

To make it clear: do NOT use qDebug(), this one doesn't get disabled at releases. Also avoid using assert() or kdFatal() which lead to a crash when something goes wrong, never nice for the user. Better detect the error, output a kdWarning or kdError, and recover if possible.

+

+

==KDE 4 specific==

+

===Is there a preferred way to print debug output on stderr?===

+

Yes, you must use kDebug():

+

+

<code cppqt>

+

#include <kdebug.h>

+

kDebug() << "KMyApp just started" << endl;

+

</code>

+

+

The syntax is much like cout, you can use many native types between the "<<". This will print out a debugging message, which will automatically be turned off at release time (by --disable-debug). In case you want the message to still be there during releases, because it's a warning or an error, use kWarning() or kError().

+

+

Components and libraries are advised to use a debug area number, as in kDebug(1234). For this, the number must be registered in kdelibs/kdecore/kdebug.areas. Debug areas make it possible to turn off or on the debug output for specific area numbers, using the "kdebugdialog" program, which is part of kdebase. "kdebugdialog --fullmode" also permits to control where to log debug output. It is usually not necessary to register area numbers for standalone applications, unless it's so complex that you want to divide the output into several areas.

+

+

To make it clear: do NOT use qDebug(), this one doesn't get disabled at releases. Also avoid using assert() or kFatal() which lead to a crash when something goes wrong and that is not a nice experience for the user. Better detect the error, output a kWarning or kError, and recover if possible.

General

How do I avoid Dr Konqi?

You must set the environment variable KDE_DEBUG (to 1 or whatever you want in fact).

To get Dr Konqi back, unset the KDE_DEBUG environment variable.

Example:

To avoid Dr Konqi:

export KDE_DEBUG=1

To see Dr Konqi:

unset KDE_DEBUG

What is a core file? How do I get a core file?

A core file is an image of the memory when your application crashed. Using the core file, you can now which variables were set and where your application crashed.

Some distributions disable the generation of core files. To re-enable them, use "ulimit -c unlimited".

Once you have a core file for a crash, you can examine it with gdb appname core . This will open gdb on the core file for the given application. Once at the gdb prompt, the most useful command is "bt" which generates a backtrace of the crash.
For more information about how to use gdb, see this page.

What tools are available to debug my application?

kdDebug() calls are a simple but efficient way to debug an application.
gdb, the GNU debugger, is the quickest way to execute step-by-step and investigate variables (prefer the 5.0 version, it is really better than the 4.1.x).
Valgrind
kdbg is a nice graphical frontend to gdb with a KDE GUI. It has support for many Qt types (including QString).
Memory leak tracer : See kdesdk/kmtrace. The README explains it all.
kdcop and dcop allow to browse the dcop interface and to easily make dcop calls.
Check this page and kdesdk, there are a bunch of useful scripts there.

How do I print a QString in gdb?

Check out kdesdk, and add this line to your ~/.gdbinit :

source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb

Then in gdb you can do printqstring myqstring to see its contents.
For instance, QString myqstring = QString::fromLatin1("contents"); can be examined using

(gdb) printqstring myqstring
$1 = "content"

See the kde-devel-gdb file for the other macros it defines.

I have no symbol when I debug an app that uses kpart, what should I do?

You must stop just after the main to load the debugging symbols of the shared library. After that, you can debug normally.
One can go as far as creating a gdb macro, to stop right after the part was loaded. For kword, by example, I use :

How do I debug an ioslave?

See kdebase/kioslave/DEBUG.howto

KDE 3 specific

Is there a preferred way to print debug output on stderr?

Yes, you must use kdDebug():

include <kdebug.h>

kdDebug() << "KMyApp just started" << endl;

The syntax is much like cout, you can use many native types between the "<<". This will print out a debugging message, which will automatically be turned off at release time (by --disable-debug). In case you want the message to still be there during releases, because it's a warning or an error, use kdWarning() or kdError().

Components and libraries are advised to use a debug area number, as in kdDebug(1234). For this, the number must be registered in kdelibs/kdecore/kdebug.areas. Debug areas make it possible to turn off or on the debug output for specific area numbers, using the "kdebugdialog" program, which is part of kdebase. "kdebugdialog --fullmode" also permits to control where to log debug output. It is usually not necessary to register area numbers for standalone applications, unless it's so complex that you want to divide the output into several areas.

To make it clear: do NOT use qDebug(), this one doesn't get disabled at releases. Also avoid using assert() or kdFatal() which lead to a crash when something goes wrong, never nice for the user. Better detect the error, output a kdWarning or kdError, and recover if possible.

KDE 4 specific

Is there a preferred way to print debug output on stderr?

Yes, you must use kDebug():

include <kdebug.h>

kDebug() << "KMyApp just started" << endl;

The syntax is much like cout, you can use many native types between the "<<". This will print out a debugging message, which will automatically be turned off at release time (by --disable-debug). In case you want the message to still be there during releases, because it's a warning or an error, use kWarning() or kError().

Components and libraries are advised to use a debug area number, as in kDebug(1234). For this, the number must be registered in kdelibs/kdecore/kdebug.areas. Debug areas make it possible to turn off or on the debug output for specific area numbers, using the "kdebugdialog" program, which is part of kdebase. "kdebugdialog --fullmode" also permits to control where to log debug output. It is usually not necessary to register area numbers for standalone applications, unless it's so complex that you want to divide the output into several areas.

To make it clear: do NOT use qDebug(), this one doesn't get disabled at releases. Also avoid using assert() or kFatal() which lead to a crash when something goes wrong and that is not a nice experience for the user. Better detect the error, output a kWarning or kError, and recover if possible.