tags:

views:

165

answers:

1

Hello,

I am running a daemon in Linux and I want to run this daemon under valgrind to find memory related errors. Since it is a daemon , I need to use trace-children = yes option. But this spawns many processes later on during its life time and I dont want them to run under valgrind. Is there a way to exclude certain children from running under valgrind?

Any help is appreciated.

+2  A: 

The currently released version (valgrind 3.5.0) has no option to trace some but not all children. However if you are willing to use the latest code from the SVN repository, it contains a new option --trace-children-skip for this purpose:

--trace-children-skip=patt1,patt2

This option only has an effect when --trace-children=yes is specified. It allows for some children to be skipped. The option takes a comma separated list of patterns for the names of child executables that Valgrind should not trace into. Patterns may include the metacharacters ? and *, which have the usual meaning.

This can be useful for pruning uninteresting branches from a tree of processes being run on Valgrind. But you should be careful when using it. When Valgrind skips tracing into an executable, it doesn't just skip tracing that executable, it also skips tracing any of that executable's child processes. In other words, the flag doesn't merely cause tracing to stop at the specified executables -- it skips tracing of entire process subtrees rooted at any of the specified executables.

The older method is to omit --trace-children=yes, and for the children that you do want to trace, replace them with a trivial script that runs the real program under valgrind:

#!/bin/sh
exec valgrind --log-file=myprog.vg.%p myprog-real "$@"

Even with the new option, this kind of script can be useful if you have e.g. a grandchild that you want to trace under valgrind but want to skip its parent.

mark4o
Mark, thanks for the answer. But I found an easier way! There is an option --trace-children-skip which does exactly what I wanted. It is only available in svn trunk, not any release version. "--trace-children-skip=*/sed,*/expr,*/xgcc,*/cat,*/rm,*/stty"
kumar
Cool! I've been using the other way for years; it is nice to see this is being added. I've added this info to the answer.
mark4o