Difference between revisions of "Development/FAQs/Debugging FAQ"

Jump to: navigation, search
(Delete kde3-specific instructions.)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==General==
+
<languages />
===How do I avoid Dr Konqi?===
+
<translate>
 +
==General== <!--T:1-->
 +
 
 +
===How do I avoid Dr Konqi?=== <!--T:2-->
 +
 
 +
<!--T:3-->
 
You must set the environment variable KDE_DEBUG (to 1 or whatever you want in fact).
 
You must set the environment variable KDE_DEBUG (to 1 or whatever you want in fact).
  
 +
<!--T:4-->
 
To get Dr Konqi back, unset the KDE_DEBUG environment variable.
 
To get Dr Konqi back, unset the KDE_DEBUG environment variable.
  
 +
<!--T:5-->
 
Example:<br />
 
Example:<br />
 
*To avoid Dr Konqi:
 
*To avoid Dr Konqi:
::<pre>export KDE_DEBUG=1</pre>
+
::<code>export KDE_DEBUG=1</code>
 
*To see Dr Konqi:
 
*To see Dr Konqi:
::<pre>unset KDE_DEBUG</pre>
+
::<code>unset KDE_DEBUG</code>
  
===How do I switch Dr Konqi to developer mode?===
+
===How do I switch Dr Konqi to developer mode?=== <!--T:6-->
  
 +
<!--T:7-->
 
Edit file $KDEHOME/share/config/drkonqirc and add the following:
 
Edit file $KDEHOME/share/config/drkonqirc and add the following:
 
<syntaxhighlight lang="ini">
 
<syntaxhighlight lang="ini">
Line 19: Line 27:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===What is a core file? How do I get a core file?===
+
===What is a core file? How do I get a core file?=== <!--T:8-->
  
 +
<!--T:9-->
 
A core file is an image of the memory when your application crashed. Using the core file, you can know 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 know 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".
+
<!--T:10-->
 +
Some distributions disable the generation of core files. To re-enable them, use <code>ulimit -c unlimited</code>.
  
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.
+
<!--T:11-->
For more information about how to use gdb, see [[Development/Tutorials/Debugging/Debugging_with_GDB|this page]]
+
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 <code>bt</code> which generates a backtrace of the crash.
 +
For more information about how to use gdb, see [[Special:myLanguage/Development/Tutorials/Debugging/Debugging_with_GDB|this page]]
  
===What tools are available to debug my application?===
+
===What tools are available to debug my application?=== <!--T:12-->
 +
 
 +
<!--T:13-->
 
*kDebug() (kdDebug() in KDE3) calls are a simple but efficient way to debug an application.
 
*kDebug() (kdDebug() in KDE3) 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 (recommended versions are gdb >= 6.x)
 
*gdb, the GNU debugger, is the quickest way to execute step-by-step and investigate variables (recommended versions are gdb >= 6.x)
Line 34: Line 47:
 
*kdbg is a nice graphical frontend to gdb with a KDE GUI. It has support for many Qt types (including QString).
 
*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.
 
*Memory leak tracer : See kdesdk/kmtrace. The README explains it all.
*qdbus and dbus-viewer from Qt allow to browse DBus interfaces and to easily make DBus calls.
+
*qdbus and dbusviewer from Qt allow to browse DBus interfaces and to easily make DBus calls.
  
Check [[Development/Tools|this page]] and kdesdk, there are a bunch of useful scripts there.
+
<!--T:14-->
 +
Check [[Special:myLanguage/Development/Tools|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?=== <!--T:15-->
 +
 
 +
<!--T:16-->
 
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  
+
{{Input|1=source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb}}
Then in gdb you can do printqstring myqstring to see its contents.
+
Then in gdb you can do <code>printqstring myqstring</code> to see its contents.
For instance, QString myqstring = QString::fromLatin1("contents"); can be examined using
+
For instance, <code>QString myqstring = QString::fromLatin1("contents");</code> can be examined using
  
<pre>
+
<!--T:17-->
 +
{{Input|1=
 
(gdb) printqstring myqstring
 
(gdb) printqstring myqstring
$1 = "content"
+
$1 = "content"}}
</pre>
+
  
 +
<!--T:18-->
 
See the <tt>kde-devel-gdb</tt> file for the other macros it defines.  
 
See the <tt>kde-devel-gdb</tt> 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?=== <!--T:19-->
 +
 
 +
<!--T:20-->
 
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:
<pre>
+
{{Input|1=
 
define startkword
 
define startkword
 
break main
 
break main
 
run
 
run
 
break 'KoDocument::KoDocument(int, QWidget *, char const *,  
 
break 'KoDocument::KoDocument(int, QWidget *, char const *,  
                       QObject *, char const *, bool)' cont
+
                       QObject *, char const *, bool)' cont}}
</pre>
+
===How do I debug an ioslave?===
+
  
 +
===How do I debug an ioslave?=== <!--T:21-->
 +
 +
<!--T:22-->
 
See [[Development/Tutorials/Debugging/Debugging IOSlaves|debugging ioslaves]]
 
See [[Development/Tutorials/Debugging/Debugging IOSlaves|debugging ioslaves]]
  
=== Why isn't my signal and slot connection working? ===
+
=== Why isn't my signal and slot connection working? === <!--T:23-->
  
 +
<!--T:24-->
 
Here are some steps that you can use to troubleshoot why your signal/slot connection is not working (your slot does not get called for some reason).
 
Here are some steps that you can use to troubleshoot why your signal/slot connection is not working (your slot does not get called for some reason).
  
 +
<!--T:25-->
 
1) Verify that the connect() doesn't print a warning to the console at runtime.
 
1) Verify that the connect() doesn't print a warning to the console at runtime.
  
 +
<!--T:26-->
 
If it does, check that you wrote Q_OBJECT, that the parameter names are not in the connect, that the parameter types are compatible, and that the slot is defined, and that the moc was compiled.
 
If it does, check that you wrote Q_OBJECT, that the parameter names are not in the connect, that the parameter types are compatible, and that the slot is defined, and that the moc was compiled.
  
 +
<!--T:27-->
 
1b) Or you can just check to see what connect() returns as a bool. Although this won't give you the error message.
 
1b) Or you can just check to see what connect() returns as a bool. Although this won't give you the error message.
 
2) Verify that the signal is indeed emitted
 
2) Verify that the signal is indeed emitted
Line 78: Line 102:
 
4) Verify that emitter->signalsBlocked() returns false
 
4) Verify that emitter->signalsBlocked() returns false
  
 +
===Is there a preferred way to print debug output on stderr?=== <!--T:29-->
  
==KDE 4 specific==
+
Yes; see [[Special:myLanguage/Development/Tutorials/Debugging/Using_Error_Messages|this tutorial]].
===Is there a preferred way to print debug output on stderr?===
+
Yes, you must use kDebug():
+
 
+
<syntaxhighlight lang="cpp-qt">
+
#include <kdebug.h>
+
kDebug() << "KMyApp just started";  
+
</syntaxhighlight>
+
 
+
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 <tt>--disable-debug</tt>). In case you want the message to still be there during releases, because it's a warning or an error, use <tt>kWarning()</tt> or <tt>kError()</tt>.
+
 
+
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 {{program|kdebugdialog}} program, which is part of kdebase. <tt>kdebugdialog --fullmode</tt> 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.
+
 
+
It is possible to omit the debug area number when calling kDebug by adding the following code to your top-level CMakeLists.txt:
+
 
+
<pre>
+
add_definitions(-DKDE_DEFAULT_DEBUG_AREA=XXXX)
+
</pre>
+
 
+
For more information, about this, see [http://www.kdedevelopers.org/node/3171 Allen Winter's blog post].
+
 
+
To make it clear: do NOT use <tt>qDebug()</tt>, this one does not get disabled at releases. Also avoid using <tt>assert()</tt> or <tt>kFatal()</tt> 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 <tt>kWarning()</tt> or <tt>kError()</tt>, and recover if possible.
+
 
+
To get timestamps with your debug output, which are useful for debugging multi-threaded, networked and asynchronous operations, <tt>export KDE_DEBUG_TIMESTAMP=1</tt> before running your app. Since KDE SC 4.5.
+
  
 +
<!--T:39-->
 
[[Category:FAQs]]
 
[[Category:FAQs]]
 
[[Category:Programming]]
 
[[Category:Programming]]
 +
</translate>

Latest revision as of 19:35, 25 November 2013

Other languages:Greek 10% • ‎English 100% • ‎Japanese 56% • ‎Polish 98% • ‎Brazilian Portuguese 98% • ‎Turkish 5%

Contents

[edit] General

[edit] 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

[edit] How do I switch Dr Konqi to developer mode?

Edit file $KDEHOME/share/config/drkonqirc and add the following:

[drkonqi]
ConfigName=developer

[edit] 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 know 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

[edit] What tools are available to debug my application?

  • kDebug() (kdDebug() in KDE3) 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 (recommended versions are gdb >= 6.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.
  • qdbus and dbusviewer from Qt allow to browse DBus interfaces and to easily make DBus calls.

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

[edit] 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.

[edit] 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:

define startkword
break main
run
break 'KoDocument::KoDocument(int, QWidget *, char const *, 
                       QObject *, char const *, bool)' cont

[edit] How do I debug an ioslave?

See debugging ioslaves

[edit] Why isn't my signal and slot connection working?

Here are some steps that you can use to troubleshoot why your signal/slot connection is not working (your slot does not get called for some reason).

1) Verify that the connect() doesn't print a warning to the console at runtime.

If it does, check that you wrote Q_OBJECT, that the parameter names are not in the connect, that the parameter types are compatible, and that the slot is defined, and that the moc was compiled.

1b) Or you can just check to see what connect() returns as a bool. Although this won't give you the error message. 2) Verify that the signal is indeed emitted 3) Verify that the receiver isn't already deleted at that time 4) Verify that emitter->signalsBlocked() returns false

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

Yes; see this tutorial.


This page was last modified on 25 November 2013, at 19:35. This page has been accessed 17,616 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal