45

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!

Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319

1 Answers1

57
  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
  • 63,317
  • 21
  • 138
  • 197
  • 7
    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 Jan 17 '09 at 06:36
  • 1
    when using trace-childen, dont you also need to specify --depth otherwise it will stop monitoring forks of forks? – DEzra Jul 02 '09 at 08:13
  • 4
    There is no `--depth` option; `--trace-children=yes` will trace forks of forks and all other descendants. – mark4o Jan 27 '10 at 07:58
  • 4
    According to the man page, this option does not cause valgrind to trace into forks, it causes it to trace into execs. Valgrind always follows forks, but won't follow an exec unless you add this option (is my understanding of the man page). – Ziggy Feb 24 '12 at 21:20