Development/Tutorials/Debugging/Debugging symbols: Difference between revisions

From KDE TechBase
No edit summary
No edit summary
Line 5: Line 5:
Depending on your decision, output generated with the command kDebug will also be (debugfull) or not be (release) added to your application.
Depending on your decision, output generated with the command kDebug will also be (debugfull) or not be (release) added to your application.


As an example, let's start with a hello world application.
As an example, let's write an application that crashes:


'''main.cpp'''
'''main.cpp'''
                      
                      
<pre>                                                                                                        
<pre>  
#include <KApplication>                                                                                      
#include <KApplication>
#include <KAboutData>                                                                                          
#include <KAboutData>
#include <KCmdLineArgs>                                                                                      
#include <KCmdLineArgs>
#include <KMessageBox>                                                                                                
#include <KMessageBox>
                                                                                                                                                                   
#include <iostream>
using namespace std;
 
int main (int argc, char *argv[])
int main (int argc, char *argv[])
{
{
     KAboutData aboutData(
     KAboutData aboutData( "tutorial1", 0, ki18n("Tutorial 1"), "1.0",
                        // The program name used internally.
                          ki18n("Displays a KMessageBox popup"),
                        "tutorial1",
                          KAboutData::License_GPL,
                        // The message catalog name
                          ki18n("(c) 2009"), ki18n("Some text..."),
                        // If null, program name is used instead.
                          "http://tutorial.com/",
                        0,
                          "[email protected]");
                        // A displayable program name string.
                        ki18n("Tutorial 1"),
                        // The program version string.
                        "1.0",
                        // Short description of what the app does.
                        ki18n("Displays a KMessageBox popup"),
                        // The license this code is released under
                        KAboutData::License_GPL,
                        // Copyright Statement
                        ki18n("(c) 2007"),
                        // Optional text shown in the About box.
                        // Can contain any information desired.
                        ki18n("Some text..."),
                        // The program homepage string.
                        "http://tutorial.com/",
                        // The bug report email address
                        "[email protected]");
 
     KCmdLineArgs::init( argc, argv, &aboutData );
     KCmdLineArgs::init( argc, argv, &aboutData );
     KApplication app;
     KApplication app;
     KGuiItem yesButton( i18n( "Hello" ), QString(),
 
                        i18n( "This is a tooltip" ),
     KMessageBox::questionYesNo( 0, i18n( "Hello World" ) );
                        i18n( "This is a WhatsThis help text." ) );
    int* i;
     KMessageBox::questionYesNo( 0, i18n( "Hello World" ),
    cout << "i is at " << i << " value " << *i << endl;
                                i18n( "Hello" ), yesButton );
    i=(int*)0x400890;
    cout << "i is at " << i << " value " << *i << endl;
    // We now try to read from memory address 0x400891
    i=(int*)0x400891;
     cout << "i is at " << i << " value " << *i << endl;
 
     return 0;
     return 0;
}
}

Revision as of 16:17, 11 July 2009

Debugging symbols allow you to debug your application better. Debugging symbols are added to your binary by the compiler. You have to decide during the cmake step if you want debugging symbols or not. To compile your application with debugging symbols, use

cmake . -DCMAKE_BUILD_TYPE=debugfull

to compile it without debugging symbols, use

cmake . -DCMAKE_BUILD_TYPE=release

Depending on your decision, output generated with the command kDebug will also be (debugfull) or not be (release) added to your application.

As an example, let's write an application that crashes:

main.cpp

    
#include <KApplication>
#include <KAboutData>
#include <KCmdLineArgs>
#include <KMessageBox>
#include <iostream>
 
using namespace std;

int main (int argc, char *argv[])
{
    KAboutData aboutData( "tutorial1", 0, ki18n("Tutorial 1"), "1.0",
                          ki18n("Displays a KMessageBox popup"),
                          KAboutData::License_GPL,
                          ki18n("(c) 2009"), ki18n("Some text..."),
                          "http://tutorial.com/",
                          "[email protected]");
 
    KCmdLineArgs::init( argc, argv, &aboutData );
    KApplication app;

    KMessageBox::questionYesNo( 0, i18n( "Hello World" ) );
    int* i;
    cout << "i is at " << i << " value " << *i << endl;
    i=(int*)0x400890;
    cout << "i is at " << i << " value " << *i << endl;
    // We now try to read from memory address 0x400891
    i=(int*)0x400891;
    cout << "i is at " << i << " value " << *i << endl;

    return 0;
}

CMakeLists.txt

project (tutorial1)
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories(${KDE4_INCLUDES})
set(tutorial1_SRCS main.cpp)
kde4_add_executable(tutorial1 ${tutorial1_SRCS})
target_link_libraries(tutorial1 ${KDE4_KDEUI_LIBS})
install(TARGETS tutorial1  ${INSTALL_TARGETS_DEFAULT_ARGS})

Now let's compile this without debugging symbols:

cmake . -DCMAKE_BUILD_TYPE=release && make -j4

We see that the resulting file is small:

# ll tutorial1
-rwxr-xr-x 1 root root 18133 Jul 11 18:07 tutorial1

With debugging symbols, the file is bigger:

cmake . -DCMAKE_BUILD_TYPE=debugfull && make
# ll tutorial1
-rwxr-xr-x 1 root root 260256 Jul 11 18:09 tutorial1