【发布时间】:2013-11-08 10:40:08
【问题描述】:
我正在尝试使用 -finstrument-functions 选项分析函数调用。 基本上,我所做的是将以下内容写入任何已编译的源代码中:
static int __stepper=0;
void __cyg_profile_func_enter(void *this_fn, void *call_site)
__attribute__((no_instrument_function));
void __cyg_profile_func_enter(void *this_fn, void *call_site) {
int i=0;
for( ; i<__stepper; i++ ) printf(" ");
printf("E: %p %p\n", this_fn, call_site);
__stepper ++;
} /* __cyg_profile_func_enter */
void __cyg_profile_func_exit(void *this_fn, void *call_site)
__attribute__((no_instrument_function));
void __cyg_profile_func_exit(void *this_fn, void *call_site) {
int i=0;
__stepper --;
for( ; i<__stepper; i++ ) printf(" ");
printf("L: %p %p\n", this_fn, call_site);
} /* __cyg_profile_func_enter */
并得到以下结果:
E: 0xb7597ea0 0xb75987a8
E: 0xb7597de0 0xb7597ef5
L: 0xb7597de0 0xb7597ef5
L: 0xb7597ea0 0xb75987a8
所有函数调用地址都在该区域附近(0xb7.......) 但是,如果我尝试使用“readelf -s”读取函数的符号,它会给出以下信息:
2157: 00101150 361 FUNC LOCAL DEFAULT 13 usb_audio_initfn
2158: 00100940 234 FUNC LOCAL DEFAULT 13 usb_audio_handle_reset
2159: 00100de0 867 FUNC LOCAL DEFAULT 13 usb_audio_handle_control
二进制所有函数的地址区域在0x00左右…… 所以,我无法从函数指针中获取函数名。 看起来像函数指针如何获得偏移量之类的。
有人知道吗?
【问题讨论】:
-
你可以用 GDB 做很多事情。使用指针进行扩展解析是一个有用的功能。你试过了吗?