GCC 的 __cyg_profile_func_enter

Landlord 2009-11-26 04:08:35
想要做一些性能测试,通过 GCC 的 -finstrument-functions 在函数的进入跟出口出加入对 __cyg_profile_func_enter 及 __cyg_profile_func_exit 的调用。
上面两个函数在另一个库中实现,现在我需要对另一个库进行分析,于是我用 -finstrument-functions 对库的所有实现文件及连接都使用这个参数进行编译。但是奇怪的是一直无法实现上面两个接口的调用。也就是在函数的进入及出口没有调用上面两个函数。
用 nm 取得被分析的库,其中有符号:
U __cyg_profile_func_enter
U __cyg_profile_func_exit
并且在实现这两个接口的库使用 nm,得到:
0006a35e T __cyg_profile_func_enter
0006a1b2 T __cyg_profile_func_exit
也就是说被分析的库中有对上面函数的引用。但是我使用 objdump 将目标文件的汇编输出,并提取一个较简单的函数如下:
00000320 <_Z19getCatalogSetStreamv>:
320: 55 push %ebp
321: 89 e5 mov %esp,%ebp
323: 56 push %esi
324: 53 push %ebx
325: 83 ec 10 sub $0x10,%esp
328: e8 fc ff ff ff call 329 <_Z19getCatalogSetStreamv+0x9>
32d: 81 c3 02 00 00 00 add $0x2,%ebx
333: 8b 45 04 mov 0x4(%ebp),%eax
336: 89 44 24 04 mov %eax,0x4(%esp)
33a: 8b 83 00 00 00 00 mov 0x0(%ebx),%eax
340: 89 04 24 mov %eax,(%esp)
343: e8 fc ff ff ff call 344 <_Z19getCatalogSetStreamv+0x24>
348: 8d b3 04 00 00 00 lea 0x4(%ebx),%esi
34e: 8b 45 04 mov 0x4(%ebp),%eax
351: 89 44 24 04 mov %eax,0x4(%esp)
355: 8b 83 00 00 00 00 mov 0x0(%ebx),%eax
35b: 89 04 24 mov %eax,(%esp)
35e: e8 fc ff ff ff call 35f <_Z19getCatalogSetStreamv+0x3f>
363: 89 f0 mov %esi,%eax
365: 83 c4 10 add $0x10,%esp
368: 5b pop %ebx
369: 5e pop %esi
36a: 5d pop %ebp
36b: c3 ret
在上面的代码中,并没有找到对 __cyg_profile_func_enter 及 __cyg_profile_func_exit 的调用。奇怪的是我也自己写过测试文件,测试的接口及__cyg_profile_func_enter 及 __cyg_profile_func_exit的实现都写在同一个文件中生成一个可执行文件是可以调用得到的,用objdump也能看到相应的Call指令。

但是为什么我上面所述的方式就是没有成功呢。在网上找了一些相关的例子,也没有发现什么特别之处。不知道哪位遇到过这样的问题。这里有一个例子:http://groups.google.com/group/gnu.gcc.help/browse_thread/thread/6be86f82ea9ed742

我使用的平台是 Redhat Linux Enterprise Advanced Server 5.2 i386_32,编译器4.1.2。
...全文
490 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jazzelan 2009-11-27
  • 打赏
  • 举报
回复
学习老!顶
ProgrammerNO1 2009-11-27
  • 打赏
  • 举报
回复
牛X,,顶!!
平凡的思想者 2009-11-27
  • 打赏
  • 举报
回复
举个例子:
#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);
}

main()
{
puts("Hello World!");
return 0;
}

编译并执行:
$ gcc -finstrument-functions hello.c -o hello
$ ./hello
__cyg_profile_func_enter: func = 0x8048468, called by = 0xb7e36ebc
Hello World!
__cyg_profile_func_exit: func = 0x8048468, called by = 0xb7e36ebc

23,107

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧