I have a large application written in C + POSIX there are many functions which are never called inside it. However, due to the size of the code it is difficult to track them manually.
Some people have suggested to use gcc with-Wunused
and lto, but it didn't returned any used functions, whereas I continue to find and remove some manually.
So I think I need a code coverage tool for analysing the program at run-time. Peoples suggested me gcov or valgrind, but I was unable to find how to use them to print a list of dead functions. gcov alone revealed only 68% of the functions compiled are used, but I don't have any way to list them.
So does someone know a good tool, and if so tell me how exactly I can use it for that purpose (a command line example would be welcome)?
I removed all functions which are not used in the source code. Only functions like this remain inside the source code :
if(conditional statement) {
some stuff;
dead_function();
some_stuff;
}
Whereconditional statement
is never true at run time, and the removal ofdead_function()
would lead to the removal of the statement to avoid undefined errors.
dead_function
is used) but dead code. That requires completely different techniques! Beware that runtime analysis will only find code that doesn't happen to have been run in a particular execution of the program — that code may be live under different circumstances.