views:

225

answers:

2

Hi All,

how do i do a valgrind memcheck on every instance of Process without starting it via valgrind command options.

Is there a way to keep the monitoring options saved on a process rather than starting up the process every-time with valgrind command?

In Microsoft Application Verifier if an application is specified to be monitored, then any number of instances of that application gets monitored, whether its a child process or started otherwise.

Any ideas to do same in Valgrind?

I have tried --trace-children=yes option of valgrind memcheck ...but my application xyz signals another application zzz to start a new intance of xyz(process), which i want to analyze. in this case, valgrind exits when xyz finishes signalling zzz. it does not follow up on what process zzz started.

Thanks, Vijay

+4  A: 

IIRC, Valgrind must execute the application because it alters the read-only symbols to replace common library functions like malloc and so on.

This means you can't attach memcheck to an already running process because it can't alter that section of the program in memory (and it would probably corrupt running state).

There are probably other reasons too. A quick google suggests that you can't attach memcheck to a running process too. As suggested, you can wrap your executables in a bash script such as. So if program myprog creates new processes of newprog then do:

]$ mv /path/to/myprog /path/to/newprog

then

#!/bin/bash
valgrind (options) /path/to/newprog $@

and call it myprog the $@ ensures arguments are passed. Then when your program creates a new process, using myprog -a b -c d then it is wrapped in valgrind.

This only applies to certain C calls like execve() and others, whereas other obscure ways of creating processes may not take advantage of the wrapping.

If I am wrong, it would be a good thing to know :)

Aiden Bell
Thanks Aiden, thats a good idea. i will try to wrap the executable to create another instance of process with parameters passing, as suggested and see if that helps. thanks, Vijay
+1  A: 

Can you wrap xyz either in a batch file or another executable that launches it within valgrind?

In other words, rename xyz to run_me_under_valgrind, then create a new xyz that launches the original run_me_under_valgrind under valgrind.

Adam Liss