Development/FAQs/Debugging FAQ/pl

    From KDE TechBase
    Revision as of 21:00, 27 June 2012 by Toudidel (talk | contribs) (Created page with "Pobierz kdesdk i w pliku ~/.gdbinit dodaj linię: {{Input|1=source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb}} W gdb możesz wtedy użyć <code>printqstring myqstring</co...")

    Ogólne

    Jak mogę uniknąć Dr Konqi?

    Należy ustawić zmienną środowiskową KDE_DEBUG (na 1 lub jakąkolwiek inną wartość)

    Aby uzyskać Dr Konqi ponownie, usuń (komendą unset) zmienną środowiskową KDE_DEBUG.

    Przykład:

    • Aby uniknąć Dr Konqi:
    export KDE_DEBUG=1
    • Aby zobaczyć Dr Konqi:
    unset KDE_DEBUG

    Jak mogę przełączyć Dr Konqi do trybu programisty?

    W pliku $KDEHOME/share/config/drkonqirc dodaj:

    [drkonqi]
    ConfigName=developer
    

    Co to jest plik core? Skąd wziąć plik core?

    Plik core to obraz pamięci w momencie zawieszenia aplikacji. Korzystając z pliku core, możesz poznać wartości zmiennych w momencie zawieszenia.

    Niektóre dystrybucje wyłączają generowanie plików core. Aby włączyć ponownie, użyj ulimit -c unlimited.

    Jeśli już masz plik core, możesz przebadać go przy użyciu gdb. Najbardziej przydatną komendą gdb jest bt, generująca zrzut, ślad po zawieszeniu aplikacji. Więcej informacji o gdb znajdziesz na tej stronie.

    Jakich narzędzi można użyć do debuggowania mojej aplikacji?

    • kDebug() (kdDebug() w KDE3) zapewnia prosty, ale efektywny sposób debugowania aplikacji.
    • gdb, the GNU debugger, jest najszybszym sposobem śledzenia aplikacji krok po kroku i badania zmiennych (zalecana wersja gdb 6.x lub wyższa)
    • Valgrind
    • kdbg jest graficznym interfejsem do gdb (z KDE GUI). Wspiera wiele typów Qt (łącznie z QString).
    • Monitor wycieków pamięci : See kdesdk/kmtrace. Plik README dostarczy informacji i wszystko wyjaśni.
    • qdbus i dbusviewer z pakietu Qt pozwala przeglądać interfejsy DBus i w łatwy sposób tworzy odwołania DBus.

    Sprawdź tę stronę i kdesdk, gdzie znajdziesz masę przydatnych skryptów.

    Jak mogę wyświetlić QString w gdb?

    Pobierz kdesdk i w pliku ~/.gdbinit dodaj linię:

    source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb

    W gdb możesz wtedy użyć printqstring myqstring, aby zobaczyć jego zawartość. Na przykład QString myqstring = QString::fromLatin1("contents"); może zostać prześledzony używając

    (gdb) printqstring myqstring
    $1 = "content"

    Zobacz plik kde-devel-gdb z innymi makrami.

    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

    Jak debuggować ioslave?

    Zobacz debuggowanie 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


    Specyficzne dla KDE 4

    Czy istnieje preferowana metoda wyświetlania danych z debuggu w stderr?

    Tak, musisz użyć 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.

    Możliwe jest pominięcie debug area number podczas wywołania kDebug poprzez dodanie następującego kodu do pliku CMakeLists.txt (na najwyższym poziomie):

    add_definitions(-DKDE_DEFAULT_DEBUG_AREA=XXXX)

    Więcej informacji na ten temat znajdziesz w blogu Allena Wintera.

    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.