roslaunch + gdb debug

    xiaoxiao2023-03-24  7

    Recently I found gdb is really good. Before when I met some crash, I just guess where the problem might be and then try to put some print inside the code to find the problem. It always take many days to figure out the problem. Now I think I am so stupid why even I didn't consider to find the debug tool. Just this time I can't find the reason, so I did some search, then find gdb is really good. I just take several hours to find where the problem exactly is. Let's give my resolution.

    My program is developed under the ROS platform. I need set some parameters to control my program, so I use roslaunch to appoint the specific yaml file. Use gdb in roslauch:

    add launch-prefix="gdb -ex run --args" to the <node /> tag

    and then roslaunch to run. When program met some problem like memory error , gdb will stop program running and tell me the problem (If I don't set gdb, it often crashes without telling me any reason). Sometime it gives which line. If don't give this, I use bt (backtrace) to see why it exactly it crashes. During this debug I just use two gdb commands:  bt and  print. 更多使用方式见 http://wiki.ros.org/roslaunch/Tutorials/Roslaunch%20Nodes%20in%20Valgrind%20or%20GDB

    launch-prefix="xterm -e gdb --args" : run your node in a gdb in a separate xterm window, manually type run to start it

    launch-prefix="gdb -ex run --args" : run your node in gdb in the same xterm as your launch without having to type runto start it

    launch-prefix="valgrind" : run your node in valgrind

    launch-prefix="xterm -e" : run your node in a separate xterm window

    launch-prefix="nice" : nice your process to lower its CPU usage

    launch-prefix="screen -d -m gdb --args" : useful if the node is being run on another machine; you can then ssh to that machine and do screen -D -R to see the gdb session

    launch-prefix="xterm -e python -m pdb" : run your python node a separate xterm window in pdb for debugging; manually type run to start it

    launch-prefix="yappi -b -f pstat -o <filename>": run your rospy node in a multi-thread profiler such as yappi.

    launch-prefix="/path/to/run_tmux": run your node in a new tmux window; you'll need to create /path/to/run_tmuxwith the contents:

    #!/bin/sh tmux new-window "gdb --args $*"
    转载请注明原文地址: https://ju.6miu.com/read-1202409.html
    最新回复(0)