According to this answer,it should print all function names:
[root@ test]# cat hw.c
#include <stdio.h>
int func(void)
{
return 1;
}
int main(void)
{
func();
printf("%d",6);
return 6;
}
[root@ test]# gcc -Wall hw.c -o hw -finstrument-functions
[root@ test]# ./hw
6
[root@ test]# gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
Copyright (C) 2006 Free Software Foundation, Inc.
But why it’s not working for me?
This is from the gcc manual:
Unless somthing implements those functions, you will get linker errors (which is what happens with MinGW). Conceivably, your GCC version is providing empty implementations.
I got it to work with MinGW GCC by providing this implementation:
but this only gives the function addresses. I’d have thought there should be a GCC default implementation of this, but there doesn’t seem to be.
People may also be interested in this visualisation of the call tree, which uses the -fintrument-functions flag – caveat, I haven’t tried it myself.