1 gcc –finstrument-functions特性的应用
这几天看了一下nginx的源码,分析过程中发现nginx模块加载、初始化这部分利用了函数指针的方式挂在的,通过阅读源码的方式寻找函数调用关系比较吃力。所以想起了通过gcc的–finstrument-functions特性,打印出函数调用栈。参照这个调用栈,再来分析代码,容易多了。gcc这个特性最大的魅力就是不需要修改源代码,只需要重新编译、连接。即可。
1.1 gcc特性介绍
1.1.1 -finstrument-functions
Generateinstrumentation calls for entry and exit to functions. Just after functionentry and just before function exit, the following profiling functions will becalled with the address of the current function and its call site. (On someplatforms, __builtin_return_address does not work beyond the current function, so the call site informationmay not be available to the profiling functions otherwise.)
void __cyg_profile_func_enter (void *this_fn,
void*call_site);
void __cyg_profile_func_exit (void *this_fn,
void*call_site);
The first argumentis the address of the start of the current function, which may be looked upexactly in the symbol table.
Thisinstrumentation is also done for functions expanded inline in other functions.The profiling calls will indicate where, conceptually, the inline function isentered and exited. This means that addressable versions of such functions mustbe available. If all your uses of a function are expanded inline, this may meanan additional expansion of code size. If you use `extern inline' in your C code,an addressable version of such functions must be provided. (This is normallythe case anyways, but if you get lucky and the optimizer always expands thefunctions inline, you might have gotten away without providing static copies.)
A function may b