NOTE: I realise my question was not clear. I have modified it now, and apologise for making the mistake in the first place.
I have a large C project that is to be run on an embedded system. I use the ARM compiler. The code is spread across multiple sub-folders, and consists of .c and .h files.
I wish to take stock of what function is called how many times, so that I can identify dead code and also speed up the most frequently used functions. The ARM compiler has a few options for removing unreachable code, it fails when function pointers come into play So, I'd like to go through every branch of the code and keep a count of number of calls to a function.
For example (this is a very simple program to demonstrate what I am looking for, not the original code):
void foo1(void)
{
printf("Number is divisible by 5");
}
void foo2(void)
{
printf("Number is divisible by 10");
}
void foo3(void)
{
printf("Number is divisible by neither 10 nor 5");
}
void foo4(void)
{
printf("foo4 called");
}
int main (void)
{
int x;
x = rand (11);
if (! x%10)
{
foo2();
foo1();
}
else if (! x%5) foo1();
else foo3();
return 0;
}
I'd like to run through the ENTIRE code so as to access all sections of the if branch (i.e foo1, foo2, and foo3). This will help me identify which function is called how many times. In the above example foo1() is called more frequently than foo2(), and foo4() is never called. Thus it would make sense to identify and remove foo4() and optimise foo1().
Any ideas/tools to run the ENTIRE code ?
One of the ways I thought was to modify the main function like so:
int main (void)
{
int x ;
x = rand (11);
//*************************************************
//starting modification
int a = 1; //added by me
if_1: //added by me
if (a == 1)
{
foo1(); //original code
foo2(); //original code
a=2; //added by me
goto if_1; //added by me
}
else if (a==2)
{
foo2(); //original code
a=3; //added by me
goto if_1: //added by me
}
else foo3(); //original code
//end of modification
//********************************************************
return 0;
}
This way it runs through the original code. Any idea how to this type of modification?