Note: This tutorial assumes that you have completed the previous tutorials: Using rxconsole and roslaunch.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Valgrind か GDBでnodeをroslaunchする方法

Description: roslaunchから立ち上げたroscpp nodesのデバッグを行いたいとき、付属のデバッグツールの変わりにgdb や valgrindのようなデバッグツールでnodeをlaunchしたいと思うかもしれない。これを実現するのは実に簡単である。

Keywords: roslaunch, valgrind, gdb, pdb

Tutorial Level: INTERMEDIATE

<node> タグのattributeのひとつであるlaunch-prefixはROSのnodeがデバッグするのを簡単にしてくれます。以下に幾らかの便利な例を紹介します。

  • launch-prefix="xterm -e gdb --args" : 分かれたxtremウィンドウでgdbの中にnodeを実行します。始めるには、runと打って開始します。

  • launch-prefix="gdb -ex run --args" : launchしたxtremウィンドウと同じウィンドウ上でgdbの中にnodeを実行します。runと打たずに開始されます。

  • launch-prefix="valgrind" : valgrindの中で実行します。

  • launch-prefix="xterm -e" : 分割されたxtremウィンドウの中でnodeを実行します。

  • launch-prefix="nice" : プロセスのCPUの使用率をさげます。

  • launch-prefix="screen -d -m gdb --args" : 他のマシンでnodeが実行されているときに利用できます。そのとき、sshでログインし、screen -D -Rと打つとgdbのセッションが見れます。

  • launch-prefix="xterm -e python -m pdb" : デバッグのために分割されたxtermウィンドウ上のpdbの中でpythonのnodeを実行します。始めるにはrunと打つと開始します。

コアダンプを取得する

クラッシュを処理する際にコアダンプを取得するには、まず、コアファイルのサイズ制限をセットします。制限を調べるには、以下のコマンドを実行します。:

$ ulimit -a
core file size          (blocks, -c) 0           #  <-- Prevents core dumps
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 20
file size               (blocks, -f) unlimited
pending signals                 (-i) 16382
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

コアサイズをunlimitedに設定します。:

ulimit -c unlimited

クラッシュするプロセスは、コアファイルを作ろうとします。しかし、現在 (2010-07-02)、デフォルトのroslaunchのワーキングディレクトリである$ROS_HOMEが"core"という名前のディレクトリを含んでいるため、ファイルを作るのに失敗します。

これを解決するには、コアファイルの名前をデフォルトでプロセスpidを使うようにセットします。以下をrootになって実行してください:

echo 1 > /proc/sys/kernel/core_uses_pid

これで$ROS_HOME/core.PIDとして、コアダンプが現れるようになります。


Wiki: ja/roslaunch/Tutorials/Roslaunch Nodes in Valgrind or GDB (last edited 2013-03-08 00:13:17 by Yuto Inagaki)