gcc –finstrument-functions特性的应用

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

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值