-finstrument-functions范例

今天,我们要解释的参数是:-finstrument-functions
其详细的用法:gcc -finstrument-functions hello.c -o hello
其作用是,在每次进入函数的时候都调用:__cyg_profile_func_enter
在函数return之前,调用__cyg_profile_func_exit
而这两个函数需要用户在使用此参数前提前定义
下面举例说明之:

#include “stdio.h“
#define DUMP(func, call) \
        printf(“%s: func = %p, called by = %p\n“, __FUNCTION__, func, call)

void __attribute__((__no_instrument_function__))
__cyg_profile_func_enter(void *this_func, void *call_site)
{
        DUMP(this_func, call_site);
}
void __attribute__((__no_instrument_function__))
__cyg_profile_func_exit(void *this_func, void *call_site)
{
        DUMP(this_func, call_site);
}

int cc(int c)
{
    return c+c;
}

int bb(int b)
{
    return b*b;
}

int aa(int a)
{
    return a+1;
}

main()
{
    printf(“The %d \n“, aa(bb(cc(2))));
}

 使用该参数编译后的运行结果为:__cyg_profile_func_enter: func = 0×80485c3, called by = 0×481e23
__cyg_profile_func_enter: func = 0×8048510, called by = 0×8048600
__cyg_profile_func_exit: func […]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值