Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unused functions detection utility for c

I am trying to measure my code coverage utilization on a C project consist of several libraries, and main program.

Is there a utility that can help me find which function I dont use from both libraries and main program.

I want to build list of functions (public functions) that are not used by my main program, in order to ignore them in my code coverage report.

like image 343
dk7 Avatar asked Feb 19 '23 00:02

dk7


2 Answers

If you are using gcc you compile your code with option:

-Wunused-function

Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.

like image 68
Alok Save Avatar answered Feb 27 '23 23:02

Alok Save


cflow can create a call graph for the program, but it doesn't work well with pointers to functions in some cases.

for eaxample:

#include <stdio.h>

static int f1(){
        return 1;
}

int (*p_f1)() = f1;

int main() {
        p_f1();
        return 0;
}
like image 38
dk7 Avatar answered Feb 27 '23 23:02

dk7