KDE/FAQs/Debugging FAQ: Difference between revisions

From KDE Community Wiki
< KDE‎ | FAQs
m (kDebug() is dead, use qDebug())
(No pages are in category)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<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:
Line 18: Line 11:
::<syntaxhighlight lang="bash">unset KDE_DEBUG</syntaxhighlight>
::<syntaxhighlight lang="bash">unset KDE_DEBUG</syntaxhighlight>


===How do I switch Dr Konqi to developer mode?=== <!--T:6-->
==How do I switch Dr Konqi to developer mode?==
 
<!--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 27: Line 18:
</syntaxhighlight>
</syntaxhighlight>


===What is a core file? How do I get a core file?=== <!--T:8-->
==What is a core file? How do I get a core file?==


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


<!--T:10-->
Some distributions disable the generation of core files. To re-enable them, use <code>ulimit -c unlimited</code>.
Some distributions disable the generation of core files. To re-enable them, use <code>ulimit -c unlimited</code>.


<!--T:11-->
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.
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]]
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?=== <!--T:12-->
==What tools are available to debug my application?==


<!--T:13-->
* KDE5 uses <code>qCDebug()</code> calls to control debugging output. See [[Guidelines and HOWTOs/Debugging/Using Error Messages#Controlling Messages]] to learn how to enable output from these calls.
*qDebug() calls are a simple yet efficient way to debug an application; simply add a qDebug() call in the code to print e.g. the value of some variable, compile the application, then run it from a terminal emulator; note that the application needs to be built with debugging symbols (CMAKE_BUILD_TYPE=debug or CMAKE_BUILD_TYPE=RelWithDebInfo, if the build type is "release", qDebug() calls won't output anything)
*<code>qDebug()</code> calls are a simple yet efficient way to debug an application; simply add a <code>qDebug()</code> call in the code to print e.g. the value of some variable, compile the application, then run it from a terminal emulator. The application needs to be built with debugging symbols (CMAKE_BUILD_TYPE=debug or CMAKE_BUILD_TYPE=RelWithDebInfo); if the build type is "release", <code>qDebug()</code> calls won't output anything
*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.
*Valgrind
*Valgrind
*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.
*qdbus and dbusviewer 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.


<!--T:14-->
Check [[Guidelines_and_HOWTOs/Debugging|this page]] and kdesdk, there are a bunch of useful scripts there.
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?=== <!--T:15-->
==How do I print a QString in gdb?==


<!--T:16-->
Check out <tt>sdk/kde-dev-scripts</tt>, and add this line to your ~/.gdbinit :
Check out kdesdk, and add this line to your ~/.gdbinit :
{{Input|1=source /path/to/kde/sources/kde/sdk/kde-dev-scripts/kde-devel-gdb}}
{{Input|1=source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb}}
Then in gdb you can enter <code>qs myqstring</code> to see its contents.
Then in gdb you can do <code>printqstring myqstring</code> to see its contents.
For instance, <code>QString myqstring = QString::fromLatin1("contents");</code> can be examined using
For instance, <code>QString myqstring = QString::fromLatin1("contents");</code> can be examined using


<!--T:17-->
{{Input|1=
{{Input|1=
(gdb) printqstring myqstring
(gdb) qs myqstring
$1 = "content"}}
$1 = "contents"}}


<!--T:18-->
Look in the <tt>[https://invent.kde.org/sdk/kde-dev-scripts/-/blob/master/kde-devel-gdb kde-devel-gdb]</tt> file for other useful 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?=== <!--T:19-->
==I have no symbol when I debug an app that uses kpart, what should I do?==


<!--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:
Line 80: Line 62:
                       QObject *, char const *, bool)' cont}}
                       QObject *, char const *, bool)' cont}}


===How do I debug an ioslave?=== <!--T:21-->
== Why isn't my signal and slot connection working? ==


<!--T:22-->
See [[Guidelines and HOWTOs/Debugging/Debugging IOSlaves|debugging ioslaves]]
=== 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 102: Line 75:
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-->
==Is there a preferred way to print debug output on stderr?==
 
<!--T:40-->
Yes; see [[Special:myLanguage/Guidelines_and_HOWTOs/Debugging/Using_Error_Messages|this tutorial]].


<!--T:39-->
Yes; see [[Guidelines_and_HOWTOs/Debugging/Using_Error_Messages|this tutorial]].
[[Category:FAQs]]
[[Category:Programming]]
</translate>

Latest revision as of 13:31, 2 February 2023

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

How do I switch Dr Konqi to developer mode?

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

[drkonqi]
ConfigName=developer

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

What tools are available to debug my application?

  • KDE5 uses qCDebug() calls to control debugging output. See Guidelines and HOWTOs/Debugging/Using Error Messages#Controlling Messages to learn how to enable output from these calls.
  • qDebug() calls are a simple yet efficient way to debug an application; simply add a qDebug() call in the code to print e.g. the value of some variable, compile the application, then run it from a terminal emulator. The application needs to be built with debugging symbols (CMAKE_BUILD_TYPE=debug or CMAKE_BUILD_TYPE=RelWithDebInfo); if the build type is "release", qDebug() calls won't output anything
  • gdb, the GNU debugger, is the quickest way to execute step-by-step and investigate variables.
  • Valgrind
  • kdbg is a nice graphical frontend to gdb with a KDE GUI. It has support for many Qt types (including QString).
  • 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.

How do I print a QString in gdb?

Check out sdk/kde-dev-scripts, and add this line to your ~/.gdbinit :

source /path/to/kde/sources/kde/sdk/kde-dev-scripts/kde-devel-gdb

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

(gdb) qs myqstring
$1 = "contents"

Look in the kde-devel-gdb file for other useful 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:

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

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

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

Yes; see this tutorial.