Development/FAQs/Debugging FAQ/ja: Difference between revisions

    From KDE TechBase
    (Created page with "===アプリケーションのデバッグツールにはどのようなものがありますか?===")
    (Updating to match new version of source page)
     
    (11 intermediate revisions by 2 users not shown)
    Line 10: Line 10:
    Example:<br />
    Example:<br />
    *To avoid Dr Konqi:
    *To avoid Dr Konqi:
    ::<code>export KDE_DEBUG=1</code>
    ::<syntaxhighlight lang="bash">export KDE_DEBUG=1</syntaxhighlight>
    *To see Dr Konqi:
    *To see Dr Konqi:
    ::<code>unset KDE_DEBUG</code>
    ::<syntaxhighlight lang="bash">unset KDE_DEBUG</syntaxhighlight>


    ===How do I switch Dr Konqi to developer mode?===
    ===How do I switch Dr Konqi to developer mode?===
    Line 37: Line 37:
    *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.
    *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.
    *qdbus and dbusviewer from Qt allow to browse DBus interfaces and to easily make DBus calls.


    Check [[Special:myLanguage/Development/Tools|this page]] and kdesdk, there are a bunch of useful scripts there.
    [[Special:myLanguage/Development/Tools|このページ]]kdesdk をチェックして下さい。便利なスクリプトが集まっています。


    ===How do I print a QString in gdb?===
    ===QString の文字列を gdb で出力するにはどうしたら良いですか?===


    Check out kdesdk, and add this line to your ~/.gdbinit :
    kdesdk をチェックアウトし ~/.gdbinit に以下の行を加えて下さい。{{Input|1=source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb}}
    {{Input|1=source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb}}
    そうすれば、gdb で <code>printqstring myqstring</code> とすることで内容を見ることができます。
    Then in gdb you can do <code>printqstring myqstring</code> to see its contents.
    たとえば、<code>QString myqstring=QString::fromLatin1("contents")</code> は次のマクロで調べることができます。
    For instance, <code>QString myqstring = QString::fromLatin1("contents");</code> can be examined using


    {{Input|1=
    {{Input|1=
    Line 52: Line 51:
    $1 = "content"}}
    $1 = "content"}}


    See the <tt>kde-devel-gdb</tt> file for the other macros it defines.
    定義されている他のマクロを知るには <tt>kde-devel-gdb</tt> を見て下さい。


    ===I have no symbol when I debug an app that uses kpart, what should I do?===
    ===KPart を使っているアプリケーションをデバッグしているとき、デバッグシンボルがありません。どうするべきですか?===


    You must stop just after the main to load the debugging symbols of the shared library. After that, you can debug normally.
    main が共有ライブラリーのデバッグシンボルをロードした直後に止める必要があります。そうすれば後は普通にデバッグできます。
    One can go as far as creating a gdb macro, to stop right after the part was loaded. For kword, by example, I use:
    kpart がロードされた直度に止めるために、gdb のマクロを作ることだってできます。KWord を例にすると、わたしは以下のマクロの定義を使っています。
    {{Input|1=
    {{Input|1=
    define startkword
    define startkword
    Line 65: Line 64:
                           QObject *, char const *, bool)' cont}}
                           QObject *, char const *, bool)' cont}}


    ===How do I debug an ioslave?===
    ===ioslave をデバッグするにはどうすればよいですか?===


    See [[Development/Tutorials/Debugging/Debugging IOSlaves|debugging ioslaves]]
    [[Development/Tutorials/Debugging/Debugging IOSlaves|ioslave のデバッグ]]を参照してください。


    === Why isn't my signal and slot connection working? ===
    === Why isn't my signal and slot connection working? ===
    Line 81: Line 80:
    3) Verify that the receiver isn't already deleted at that time
    3) Verify that the receiver isn't already deleted at that time
    4) Verify that emitter->signalsBlocked() returns false
    4) Verify that emitter->signalsBlocked() returns false
    ==KDE 4 specific==


    ===デバッグ用の出力を標準エラー (stderr) に出したいのですが、おすすめの方法は何ですか?===
    ===デバッグ用の出力を標準エラー (stderr) に出したいのですが、おすすめの方法は何ですか?===


    kDebug() を使うとよいでしょう。
    Yes; see [[Special:myLanguage/Development/Tutorials/Debugging/Using_Error_Messages|this tutorial]].
     
    <syntaxhighlight lang="cpp-qt">
    #include <kdebug.h>
    kDebug() << "KMyApp just started";  
    </syntaxhighlight>
     
    文法は cout とほとんど同じで、多くのネイティブな型を "<<" の間に使えます。これはデバッグメッセージを出力しますが、リリース時に(<tt>--disable-debug</tt> で)自動的に無効にすることができます。もし、メッセージをリリース中も出力したいならば、それらは警告やエラーなので <tt>kWarning()</tt> や <tt>kError()</tt> を使って下さい。
     
    コンポーネントやライブラリなどは kDebug(1234) などのようにデバッグエリアナンバーを使うようにアドバイスされています。このためには、kdelibs/kdecore/kdebug.area にその数字が登録されていなければいけません。デバッグエリアのお陰で、特定のエリアナンバーのデバッグ出力を無効にすることができます。そのためには {{program|kdebugdialog}} という kdebase の一部であるプログラムを使います。<tt>kdebugdialog --fullmode</tt> によってまた、デバッグ出力のログをどこに取るか制御することもできます。普段、スタンドアローンなアプリケーションのためにエリアナンバーを登録することは、そのアプリケーションが複雑で出力をいくつかのエリアに分割したいと思うことが無ければ、必要ありません。
     
    It is possible to omit the debug area number when calling kDebug by adding the following code to your top-level CMakeLists.txt:
     
    <code>
    add_definitions(-DKDE_DEFAULT_DEBUG_AREA=XXXX)
    </code>
     
    For more information, about this, see [http://www.kdedevelopers.org/node/3171 Allen Winter's blog post].
     
    <tt>qDebug()</tt> を使ってはいけないということだけははっきり覚えておいて下さい。それはリリース時に無効になりません。また、<tt>assert()</tt> や <tt>kFatal()</tt> を使うことも避けて下さい。それらは何かアプリケーションないでまずいことが起きた場合、アプリをクラッシュさせてしまいます。決してユーザーにとって良いものではないのです。エラーを発見する良い方法は <tt>kWarning()</tt> や <tt>kError()</tt> を使って下さい。そして、できる限りそのエラーから回復させて下さい。
     
    To get timestamps with your debug output, which are useful for debugging multi-threaded, networked and asynchronous operations, <tt>export KDE_DEBUG_TIMESTAMP=1</tt> before running your app. Since KDE SC 4.5.


    [[Category:FAQs]]
    [[Category:FAQs]]
    [[Category:Programming]]
    [[Category:Programming]]

    Latest revision as of 10:25, 11 March 2016

    一般

    Dr Konqi が出ないようにするにはどうしたら良いですか?

    KDE_DEBUG 環境変数を1に設定してください。

    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
    

    core ファイルって何ですか? どうすれば core ファイルを得ることができますか?

    core ファイルとはアプリケーションがクラッシュしたときのメモリイメージです。これを使うことによって、どの変数がセットされていたり、どこでアプリがクラッシュしたかを知ることができます。

    いくつかのディストリビューションでは core ファイルの生成を不可にしています。生成できるようにするには ulimit -c unlimited を実行してください。

    いったん core ファイルが手に入ったら、"gdb appname core" で調べることができます。これで gdb は与えられたアプリケーション用に core ファイル上でオープンできます。gdb のプロンプトが出たら、bt というコマンドが役に立ちます。これはクラッシュのバックトレースを生成することができます。gdb の使い方についてもっと情報がほしいなら、こちらのページを見て下さい。

    アプリケーションのデバッグツールにはどのようなものがありますか?

    • 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 dbusviewer from Qt allow to browse DBus interfaces and to easily make DBus calls.

    このページや kdesdk をチェックして下さい。便利なスクリプトが集まっています。

    QString の文字列を gdb で出力するにはどうしたら良いですか?

    kdesdk をチェックアウトし ~/.gdbinit に以下の行を加えて下さい。

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

    そうすれば、gdb で printqstring myqstring とすることで内容を見ることができます。 たとえば、QString myqstring=QString::fromLatin1("contents") は次のマクロで調べることができます。

    (gdb) printqstring myqstring
    $1 = "content"

    定義されている他のマクロを知るには kde-devel-gdb を見て下さい。

    KPart を使っているアプリケーションをデバッグしているとき、デバッグシンボルがありません。どうするべきですか?

    main が共有ライブラリーのデバッグシンボルをロードした直後に止める必要があります。そうすれば後は普通にデバッグできます。 kpart がロードされた直度に止めるために、gdb のマクロを作ることだってできます。KWord を例にすると、わたしは以下のマクロの定義を使っています。

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

    ioslave をデバッグするにはどうすればよいですか?

    ioslave のデバッグを参照してください。

    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

    デバッグ用の出力を標準エラー (stderr) に出したいのですが、おすすめの方法は何ですか?

    Yes; see this tutorial.