Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell valgrind to follow only a particular child process?

Tags:

valgrind

I used the "--trace-children=yes" option, I also used "--trace-children-skip=patt1,patt2,..." option (to filter out the noise processes). But it is still very slow for me, my multi-process app times out, and the "--trace-children-skip=" option gets very long.
I need something like "--trace-children-only=patt1,patt2,..." option that will allow me to specify a particular child process to follow. I fail to find anything like that.
How to tell valgrind to follow only a particular child process?

like image 808
Robin Kuzmin Avatar asked Oct 17 '25 07:10

Robin Kuzmin


1 Answers

When you start valgrind on a program, child processes must necessarily "start to run" under valgrind. More precisely, when a parent starts a child, it will first fork. The 'real' executable that is running when using valgrind is valgrind itself. So, forking valgrind gives a copy of valgrind, and the child process necessarily "starts" in valgrind mode. Then when the child calls exec, valgrind checks the --trace-children* options to decide to either exec the exec-ed program, or rather exec itself (valgrind).

So, if you have a process A that launches child B, that launches child C, there is no way for valgrind to only be activated for C.

The solution is to put in the PATH a C script that hides the real C executable. In this script, do something like: valgrind ... valgrind args ... /path/to/the/real/C .... C args ... (of course C args can be recuperated from the script arguments).

like image 200
phd Avatar answered Oct 22 '25 01:10

phd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!