Development/FAQs/Debugging FAQ/pt-br: Difference between revisions

    From KDE TechBase
    (Created page with "Veja o arquivo <tt>kde-devel-gdb</tt> para descobrir outras macros definidas.")
    (Created page with "===Eu não tenho nenhum símbolo quando depuro uma aplicação que utiliza uma kpart, o que devo fazer?===")
    Line 55: Line 55:
    Veja o arquivo <tt>kde-devel-gdb</tt> para descobrir outras macros definidas.  
    Veja o arquivo <tt>kde-devel-gdb</tt> para descobrir outras macros definidas.  


    ===I have no symbol when I debug an app that uses kpart, what should I do?===
    ===Eu não tenho nenhum símbolo quando depuro uma aplicação que utiliza uma kpart, o que devo fazer?===


    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.  

    Revision as of 21:41, 29 April 2012

    Geral

    Como evitar o Dr. Konqi?

    Você deve configurar a variável de ambiente KDE_DEBUG (para 1 ou qualquer outro valor).

    Para restaurar o Dr. Konqi, remova a variável de ambiente KDE_DEBUG.

    Exemplo:

    • Para evitar o Dr. Konqi:
    export KDE_DEBUG=1
    • Para ver o Dr. Konqi:
    unset KDE_DEBUG

    Como mudar o Dr. Konqi para o modo de desenvolvedor?

    Edite o arquivo $KDEHOME/share/config/drkonqirc e adicione o seguinte:

    [drkonqi]
    ConfigName=developer
    

    O que é um core file? Como obtê-lo?

    Um core file é uma imagem da memória no momento em que sua aplicação quebrou. Utilizando este arquivo, você pode determinar quais variáveis estavam configuradas e em que ponto a aplicação quebrou.

    Algumas distribuições desativam a produção de core files. Para ativa-los novamente, utilize o comando ulimit -c unlimited.

    Após obter o core file de um crash, você pode examina-lo com o comando gdb nomeapp core. Isso fará o gdb abrir o core file para a aplicação fornecida. Um vez no prompt do gdb, o comando mais útil é bt, que produz um backtrace do crash. Para mais informações sobre o uso do gdb, veja esta página

    Quais ferramentas estão disponíveis para depurar minha aplicação?

    • 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 dbus-viewer 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.

    Como faço para exibir um QString no 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"

    Veja o arquivo kde-devel-gdb para descobrir outras macros definidas.

    Eu não tenho nenhum símbolo quando depuro uma aplicação que utiliza uma kpart, o que devo fazer?

    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

    How do I debug an ioslave?

    See debugging ioslaves

    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


    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";
    

    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.

    It is possible to omit the debug area number when calling kDebug by adding the following code to your top-level CMakeLists.txt:

    add_definitions(-DKDE_DEFAULT_DEBUG_AREA=XXXX)

    For more information, about this, see Allen Winter's blog post.

    To make it clear: do NOT use qDebug(), this one does not 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.

    To get timestamps with your debug output, which are useful for debugging multi-threaded, networked and asynchronous operations, export KDE_DEBUG_TIMESTAMP=1 before running your app. Since KDE SC 4.5.