views:

980

answers:

2

I have a process x that I want to check for leaks with valgrind. The problem is that x is run by y, and y in turn is run by z. I can't run x standalone because y and z setup the environment for x, such as environment variables, command line switches, files needed by x etc.

  1. Is there any way I can tell valgrind to run on z but to follow any forks it finds and report them too?
  2. Is there any way I can tell valgrind to follow any forks but only report on the process named x?
  3. Is there any way I can tell valgrind to attach to already-running process, the way I can do with gdb?

I don't know if this matters, but I'm running under Suse64 linux and valgrind-2.4.0.

Thanks!

+6  A: 
  1. Valgrind follows forked processes when given the --trace-children=yes option.
  2. You should be able to achieve this by using suitable filters.
  3. No. Valgrind hooks into the module loading code using LD_PRELOAD, so attaching to a running process is not possible.
JesperE
Valgrind *used* to use LD_PRELOAD, but doesn't do so in current versions. Your answer to 3. is still correct, but the reason has nothing to do with LD_PRELOAD.
Employed Russian
Interesting. Thanks for correcting me.
JesperE
when using trace-childen, dont you also need to specify --depth otherwise it will stop monitoring forks of forks?
DEzra
Maybe, I don't know.
JesperE
There is no `--depth` option; `--trace-children=yes` will trace forks of forks and all other descendants.
mark4o
A: 

Hi All, I tried --trace-children=yes option of valgrind memcheck ...but my application xyz signals another application zzz to start another 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.

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.

The idea 1 is to monitor every instance of a particular Process. Idea 2: is to keep the monitoring options saved on a process rather than starting up the process every-time with valgrind command.

Any ideas if i could it in Valgrind now? Thanks, Vijay

@Vijay: This should be posted as a separate question. It will get more attention from being posted on the main page. You can link back to this question for reference.
Bill the Lizard