开发者

How to exclude certain child processes to run under valgrind?

I am running a daemon in Linux and I w开发者_运维问答ant 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 lifetime and I don't want them to run under valgrind. Is there a way to exclude certain children from running under valgrind?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜