Hi, I tried using -finstrument-functions and -Os flags at the same time but the compiled test program segfaults due to recursive calls:
$> gcc -g -Os -finstrument-functions ptrace.c && ./a.out Segmentation fault (core dumped) $> gdb a.out core #0 0x080485b7 in __cyg_profile_func_enter (this_fn=0x80485a2, call_site=0x80485bc) at ptrace.c:15 #1 0x080485bc in __cyg_profile_func_enter (this_fn=0x80485a2, call_site=0x80485bc) at ptrace.c:15 #2 0x080485bc in __cyg_profile_func_enter (this_fn=0x80485a2, call_site=0x80485bc) at ptrace.c:15 #3 0x080485bc in __cyg_profile_func_enter (this_fn=0x80485a2, call_site=0x80485bc) at ptrace.c:15 #4 0x080485bc in __cyg_profile_func_enter (this_fn=0x80485a2, call_site=0x80485bc) at ptrace.c:15 I disabled function instrumentation for __cyg_profile_func_enter using __attribute__ ((no_instrument_function)) but it looks like it's ignored. Does -Os behavior specifically ignores the 'no_instrument_function' attribute ? Taking -Os out makes it work: $> gcc -g -finstrument-functions ptrace.c && ./a.out enter 0x8048552 enter 0x804851f enter 0x80484ec enter 0x80484be exit 0x80484be exit 0x80484ec exit 0x804851f enter 0x80484be exit 0x80484be exit 0x8048552 -- Regards! http://groleo.wordpress.com/
#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #ifdef __cplusplus extern "C" { #endif /* called upon function entry */ void __attribute__ ((no_instrument_function)) __cyg_profile_func_enter(void *this_fn, void *call_site) { fprintf(stdout, "enter %p\n", this_fn); } /* called upon function exit */ void __attribute__ ((no_instrument_function)) __cyg_profile_func_exit(void *this_fn, void *call_site) { fprintf(stdout, "exit %p\n", this_fn); } void func_c( void ) { return; } void func_b( void ) { func_c(); } void func_a( void ) { func_b(); } #ifdef __cplusplus } #endif int main() { func_a(); func_c(); }