Development/Tutorials/Debugging/Using Error Messages: Difference between revisions

    From KDE TechBase
    No edit summary
    (11 intermediate revisions by 7 users not shown)
    Line 1: Line 1:
    When you start a konsole and type the commands to start an application you
    When you start a konsole and type the commands to start an application you
    will see all sorts of statements are printed in the konsole while the  
    will see all sorts of statements are printed in the konsole while the  
    Line 5: Line 7:
    compiled with the debugging enabled. So using a precompiled package from a distribution
    compiled with the debugging enabled. So using a precompiled package from a distribution
    probably will not give you this information. If you compiled the application  
    probably will not give you this information. If you compiled the application  
    yourself, make sure the configure option "<tt>--disable-debug</tt>" was not used.
    yourself, make sure the configure option <tt>--disable-debug</tt> was not used.


    In KDE all debugging text-output can be switched on or off based on so
    In KDE all debugging text-output can be switched on or off based on so
    called 'sections'. One application can be one section. One part of the kde
    called '''areas'''. One application can be one or more area. One part of the kde base libraries can be another area. Enabling/disabling these areas from being printed can be done using the '''kdebugdialog''' application. For simple debugging selecting all
    base libraries can be another section.
    Enable/disabling these sections from being printed can be done using the
    '''kdebugdialog''' application. For simple debugging selecting all
    sections is probably wise.
    sections is probably wise.


    When you are debugging it is best to simply start a konsole and start the
    When you are debugging it is best to simply start a konsole and start the
    application from there. In a konsole you could simply type:
    application from there. In a konsole you could simply type:
     
    <pre>
    kicker
    kicker
     
    </pre>
    and in the konsole kicker could return a message like:
    and in the konsole kicker could return a message like:
     
    <pre>
    ERROR: kicker is already running!
    ERROR: kicker is already running!
     
    </pre>
    When a lot of output is written to the konsole it might go out of view before
    When a lot of output is written to the konsole it might go out of view before
    you could read it, therefor it is easy to create a text file which contains
    you could read it, therefor it is easy to create a text file which contains
    all this information, to do so type the following:
    all this information, to do so type the following:
     
    <pre>
    application 2&gt;&amp;1 | tee debug.log
    application 2&gt;&amp;1 | tee debug.log
     
    </pre>
    where 'application' can be replaced with the application you are debugging.
    where 'application' can be replaced with the application you are debugging.
    Afterwards you could open the file 'debug.log' to look at the messages again.
    Afterwards you could open the file 'debug.log' to look at the messages again.
    Line 40: Line 39:
    not just the application you are debugging!
    not just the application you are debugging!


    '''Case 1: Graphical login (i.e. kdm, gdm, xdm, etc.'''
    '''Case 1: Graphical login (i.e. kdm, gdm, xdm, etc.)'''


    The debug messages get redirected into the file {{path|~/.xsession-errors}} or
    The debug messages get redirected into the file {{path|~/.xsession-errors}} or
    Line 49: Line 48:


    Use the following command to restart your session:
    Use the following command to restart your session:
      startx 2&gt;&amp;1 | tee startx.log</pre>
      startx 2&gt;&amp;1 | tee startx.log


    so that all the debug messages of applications started at KDE's startup (and
    so that all the debug messages of applications started at KDE's startup (and
    Line 56: Line 55:
    == Links ==
    == Links ==


    The debug messages are usually printed in C++ with the kDebug statement. Example:
    The debug messages are usually printed in C++ with the kDebug or kWarning statement. Example:
    kDebug(1210) << "arbitrary message" << endl;
    <pre>
    The number 1210 in this case represents kicker.
    kDebug(1210) << "arbitrary message";
    kWarning(1210) << "this rather should not happen";
    </pre>
    The number 1210 (so called ''debug area'') in this case represents kicker.  You can omit the number.


    * [http://api.kde.org/4.0-api/kdelibs-apidocs/kdecore/html/group__kdebug.html kDebug API documentation]
    See also: [http://api.kde.org/4.0-api/kdelibs-apidocs/kdecore/html/group__kdebug.html kDebug/kWarning API documentation] and [http://websvn.kde.org/trunk/KDE/kdelibs/kdecore/kdebug.areas?view=markup kdebug.areas] for list of debug areas numbers.
    Note that you can use ''add_definition(-DKDE_DEFAULT_DEBUG_AREA=<number>)'' in CMakeLists.txt to specify default debug area.


    ''Initial Author:'' [mailto:[email protected] Thomas Zander]
    ''Initial Author:'' [mailto:[email protected] Thomas Zander]

    Revision as of 12:44, 13 July 2012


    When you start a konsole and type the commands to start an application you will see all sorts of statements are printed in the konsole while the application is running. All applications print these messages, to look at them you have to know where to look. The application will have to be compiled with the debugging enabled. So using a precompiled package from a distribution probably will not give you this information. If you compiled the application yourself, make sure the configure option --disable-debug was not used.

    In KDE all debugging text-output can be switched on or off based on so called areas. One application can be one or more area. One part of the kde base libraries can be another area. Enabling/disabling these areas from being printed can be done using the kdebugdialog application. For simple debugging selecting all sections is probably wise.

    When you are debugging it is best to simply start a konsole and start the application from there. In a konsole you could simply type:

    kicker
    

    and in the konsole kicker could return a message like:

    ERROR: kicker is already running!
    

    When a lot of output is written to the konsole it might go out of view before you could read it, therefor it is easy to create a text file which contains all this information, to do so type the following:

    application 2>&1 | tee debug.log
    

    where 'application' can be replaced with the application you are debugging. Afterwards you could open the file 'debug.log' to look at the messages again.

    If you are NOT starting the application from a konsole the messages will be logged somewhere else, or they could have been discarded by the program that started your application.

    If your application is started by clicking on an icon your best bet is to check the following log files. Beware; they contain logs for a lot of applications, not just the application you are debugging!

    Case 1: Graphical login (i.e. kdm, gdm, xdm, etc.)

    The debug messages get redirected into the file ~/.xsession-errors or ~/.X.err in your home directory (that is with a leading dot '.' also watch the Capital).

    Case 2: You are using startx:

    Use the following command to restart your session:

    startx 2>&1 | tee startx.log
    

    so that all the debug messages of applications started at KDE's startup (and any application launched from the panel etc.) go to the file "startx.log"

    Links

    The debug messages are usually printed in C++ with the kDebug or kWarning statement. Example:

    kDebug(1210) << "arbitrary message";
    kWarning(1210) << "this rather should not happen";
    

    The number 1210 (so called debug area) in this case represents kicker. You can omit the number.

    See also: kDebug/kWarning API documentation and kdebug.areas for list of debug areas numbers. Note that you can use add_definition(-DKDE_DEFAULT_DEBUG_AREA=<number>) in CMakeLists.txt to specify default debug area.

    Initial Author: Thomas Zander