Valgrind with dynamically linked GCC plugin

I have been using valgrind's profiling tool for a long time. This requires an executable, i.e.

$    valgrind ./a.out

      

I want to use it in a dynamically connected GCC plugin and specify the time and number of calls for each function used in the plugin. I run the GCC plugin like this:

$    gcc -fplugin=./plugin.so myfile.c

      

When I run the following command, valgrind reports a memory leak for gcc only, not plugin.so. I need a way to run valgrind exclusively on my plugin, which is a .so file.

$    valgrind gcc -fplugin=./plugin.so myfile.c

$    gcc -fplugin=./plugin.so myfile.c -wrapper valgrind

      

Can this be done? I searched a lot but couldn't find a specific answer.

+3


source to share


1 answer


I posted this question on the valgrind-users mailing list and got a solution.

http://sourceforge.net/p/valgrind/mailman/message/34174148/

The plugin is not loaded by GCC itself, but by a child of GCC. Therefore, we need to run valgrind with the --trace-childen = yes option



 $valgrind –trace-children=yes --leak-check=full g++ -fplugin=./plugin.so test0.o

      

Next, we need to find the valgrind output for our function name and define the child process that was responsible for loading and executing the plugin. Try to inject a deliberate memory leak into your plugin and search for a function in the exit to identify the process.

+2


source







All Articles