Working of the valgrind tool suite

342 views Asked by At

I had run valgrind on a sample daemon program. The parent exits after allocating a chunk of 1000B, but the child that runs on the background keeps on allocating 200B of memory on the heap through malloc, after every two seconds.

My question is: does valgrind execute the program on the actual processor, or on a synthetic CPU?

Does it allocate the memory on the actual heap or on a synthetic RAm which doesn't exist?

Since I let the program run for a quite a long duration so much so that the child allocated some 2GB of memory on the heap. On implementing the program on massif, I got one output file for the parent, and on killing the daemon process, I got another massif.out. for the child which showed the allocation of the memory on the heap.

2

There are 2 answers

0
KK. On

If you turn on the memcheck(which is the default), then Valgrind will manage the heap, i.e. all the memory related methods (malloc/free/memmove etc.) will be replaced by Valgrind's version of the corresponding methods.

As already told, your program is running on virtual CPU created and managed by valgrind.

There is no notion of synthetic RAM as far I know. In any case, all this is very transparent to the running process(your daemon) and shoudl not change the behavior of your program in any way.

So the answer is YES for synthetic CPU and no for synthetic RAM.

0
Dmytro Sirenko On

Valgrind run program in its own synthetic CPU, nothing from the program machine code reaches the host CPU.

Memory allocation is hooked with Memcheck, if you use it, otherwise Valgrind calls the libc memory allocation routines.

This facts may complicate Valgrind debugging of system services, indeed.