c - gcc: how to only trace specific functions calls -
options -pg, -mfentry , -finstrument-functions affects functions in .c file, how can insert trace call specific functions, not all?
i checked gcc function attributes seems there's no counterparts -pg, -mfentry , -finstrument-functions can used decorate specific functions.
no_instrument_function excludes functions want opposite, i.e., includes functions.
you can backtraces in c. method you'll have add code function want trace.
here's simple example :
#include <execinfo.h> #include <stdio.h> #include <stdlib.h> /* obtain backtrace , print stdout. */ void print_trace (void) { void *array[10]; size_t size; char **strings; size_t i; size = backtrace (array, 10); strings = backtrace_symbols (array, size); printf ("obtained %zd stack frames.\n", size); (i = 0; < size; i++) printf ("%s\n", strings[i]); free (strings); } /* dummy function make backtrace more interesting. */ void dummy_function (void) { print_trace (); } int main (void) { dummy_function (); return 0; } in compilation add -g -rdynamic flag linker :
gcc -g -rdynamic example.c -o example
Comments
Post a Comment