聘我网

新概念招聘3.0

-finstrument-functions无效?

vote up0vote downstar
[root@ xx]# cat test.c
#include <stdio.h>

int test(void)
{  
  return 1;
}
int main(void)
{
  test();
  return 0;
}
[root@ xx]# gcc -Wall test.c -o test -finstrument-functions
[root@ xx]# ./test 
[root@ xx]# gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
Copyright (C) 2006 Free Software Foundation, Inc.

理应有

进入xxx函数,退出xxx函数

的信息,为何却没有呢?

 

1 个答复

vote up0vote downcheck

方案1

在代码中加上这几行:

void __cyg_profile_func_enter( void *func_address, void *call_site )
                                __attribute__ ((no_instrument_function));

void __cyg_profile_func_exit ( void *func_address, void *call_site )
                                __attribute__ ((no_instrument_function));

void __cyg_profile_func_enter (void *this_fn, void *call_site)  {
    printf( "entering %p\n", (int *)this_fn );
}

void __cyg_profile_func_exit (void *this_fn, void *call_site) {
    printf( "leaving %p\n", (int *)this_fn );
}

再重新编译执行即可。(gcc -Wall test.c -o test -finstrument-functions;./test

方案2

将以下代码放在单独文件,如instrument.c

#include  <stdio.h>

void __cyg_profile_func_enter (void *this_fn, void *call_site) {
    printf( "entering %p\n", this_fn );
}

void __cyg_profile_func_exit (void *this_fn, void *call_site) {
    printf( "leaving %p\n", this_fn );
}

然后gcc -c instrument.c -o instrument.o;gcc -finstrument-functions test.c profile.o -o test;./test

链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.