Friday, January 26, 2018

Call Graph for User space program

Call Graph for User space program 


root@embsys-VirtualBox:~/github/intx/usrc/gcc_inst_func# cat gcc_profiling_a2l.c
#include

void __cyg_profile_func_enter (void *this_fn, void *call_site) __attribute__((no_instrument_function));
void __cyg_profile_func_exit  (void *this_fn, void *call_site) __attribute__((no_instrument_function));

int foo()
{
        //printf("Inside foo!\n");
}

int boo()
{
        //printf("Inside boo!\n");
}

void __cyg_profile_func_enter (void *this_fn, void *call_site)
{
        char cmd[80];
        //printf("Function Entry : %p %p \n", this_fn, call_site);
        //sprintf(cmd,"addr2line -e a.out %p",this_fn);
        printf("\n--->Enter\n");
        sprintf(cmd,"nm a.out | grep %llx",this_fn);
        system(cmd);
}

void __cyg_profile_func_exit (void *this_fn, void *call_site)
{
        //printf("Function Exit : %p %p \n", this_fn, call_site);
        char cmd[80];

        printf("\n--->Exit\n");
        sprintf(cmd,"nm a.out | grep %llx",this_fn);
        system(cmd);
}

int main()
{
        foo();
        boo();
        return 0;
}

 gcc  -g -finstrument-functions  gcc_profiling_a2l.c

 ./a.out

--->Enter
00000000004007be T main

--->Enter
0000000000400696 T foo

--->Exit
0000000000400696 T foo

--->Enter
00000000004006bf T boo

--->Exit
00000000004006bf T boo

--->Exit
00000000004007be T main

No comments:

Post a Comment

Featured Post

XDP - Getting Started with XDP (Linux)