Valgrind with dynamically linked GCC plugin

259 views Asked by At

I've been using the profiling tool valgrind for a while now. It requires an executable to run, i.e.

$    valgrind ./a.out

I want to use it on a dynamically linked GCC plugin, and list the time taken and the number of calls by each function used in the plugin. I am running the GCC plugin as follows:

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

When I run the following command, valgrind reports the memory leaks for only gcc and not for 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

Is it even possible to do that? I've searched up on this a lot but haven't found any concrete answer on it.

1

There are 1 answers

0
Suryansh On BEST ANSWER

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

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

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

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

We then need to search the valgrind output for the name of our function and identify the child process which was responsible for loading and executing the plugin.Try introducing some memory leaks intentionally in your plugin and search for the function in the output, to identify the process.