instrumentation - How to instrument gcc? -
i have instrument gcc purposes. goal able track gcc functions called during particularly compile. unfortunately i'm not familiar architecture of gcc need little help. tried following steps:
1) hacking gcc/makefile.in , adding "-finstrument-functions" flag t_cflags.
2) have implemented , tested version of start_test , end_test functions. called gcc/main.c, before , after toplev_main() call. containing file linked gcc (the object added objs-common , dependency defined later in gcc/makefile.in)
3) downloading prerequisites contrib/download_prerequisites.
4) executing configuration clean build directory (on same level source dir): ./../gcc-4.6.2/configure --prefix="/opt/gcc-4.6.2/" --enable-languages="c,c++"
5) starting build "make all"
this way runned out of memory, although had 28g.
next tried remove t_cflags settings makefile , give -finstrument-functions make command: make cflags="-finstrument-functions". build successful way when tried compile resulted empty output files. (theoretically end_test should have written result given file.)
what make wrong? in advance!
unless exclude being instrumented, main subject instrumentation, placing calls start_test , end_test inside main not how want it. 'correct' way ensure file opened , closed @ right times define 'constructor' , 'destructor', , gcc automatically generates calls them before , after main:
void start_test (void) __attribute__ ( (no_instrument_function, constructor)); void end_test (void) __attribute__ ( (no_instrument_function, destructor)); /* file write profiling information. */ static file *profiler_out; void start_test (void) { profiler_out = fopen ("profiler.out", "w"); if (profiler_out == null) exit (-1); } void end_test (void) { fclose (profiler_out); } footnotes:
- read more
constructor,destructor,no_instrument_functionattributes here. function attributes gcc understands. - read excellent guide instrumentation, on ibm website.
Comments
Post a Comment