ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Valgrind and GDB on same roslaunch File

asked 2016-10-05 16:42:03 -0500

Pototo gravatar image


How can I launch both valgrind and gdb on the same launch file? It seems that I can only add one "launch-prefix" attribute on my lunch file. This is what I tried:

launch-prefix="valgrind --vgdb=yes --vgdb-error=0" launch-prefix="xterm -e gdb --args set non-stop off target remote | vgdb run"

but I get that "duplicate attribute" error.

Or is there another way to look for ALL possible errors that can be happening in my program? Can GDB be enough to catch all the program errors, including memory leaks?

edit retag flag offensive close merge delete


I don't think this kind of combination was considered when launch-prefix was designed and implemented. vgdb support in Vagrind is relatively new (~2014?).

gvdhoorn gravatar image gvdhoorn  ( 2016-10-06 01:34:07 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-10-06 01:45:46 -0500

gvdhoorn gravatar image

updated 2016-10-06 01:47:02 -0500

I don't think it would be possible to use the launch-prefix route to get what you want. For vgdb to work, your node needs to be loaded into Valgrind, which will then start its own gdb server. The gdb session would then connect to that server. launch-prefix just takes the full path to the node roslaunch would normally start, prefixes it with your set prefix (ie: gdb ..), appends some parameters and the starts the entire command.

In your case it would seem Valgrind should be started with your node, with gdb connecting after that. Problem is that launch-prefix does not support that scenario. Valgrind could perhaps run in the background, but that is not how launch-prefix is supposed to work.

A work-around (for now, until someone comes up with a better way) could be to not launch your node through a launch file, but separately from the command line. The rest of your system could still be configured and setup using a launch file of course.

Another approach which might work is to use a wrapper bash script. That script would take care of starting Valgrind and gdb, and you'd use the wrapper script as a launch-prefix. That would allow you to start your entire system using a launch file. But without starting Valgrind as a background task, I'm not sure how this is going to be different.

edit flag offensive delete link more

answered 2016-10-05 17:26:58 -0500

jorge gravatar image

Hi, I'm not expert at all on these two tools, but for me it doesn't make sense to run together, as they help in different steps of the development cycle.

  • I first use gdb when I want to understand what my program does, specially if it crashes.
  • And I use valgrind once my program works to detect memory leaks and performance bottlenecks.
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-10-05 16:42:03 -0500

Seen: 1,370 times

Last updated: Oct 06 '16