参考链接:
https://www.cnblogs.com/zhaohongtian/p/6801310.html
-finstrument-functions:
一、多个文件同时编译:
[mjj@hadoop-senior test]$ gcc -g -finstrument-functions test.c main.c instrument.c -o main
可直接生成带有hook(进入与退出函数的桩点)的可执行文件main
instrument.c 相当于复写void __cyg_profile_func_enter( void *, void * ),void __cyg_profile_func_exit( void *, void * ) 这两个函数,使运行地址输出到指定为文件中。所以在没有-finstrument-functions选项的情况下,instrument.c的内容不会被调用;
-g保留源代码的符号信息,如果没有-g,对记录下的地址进行addr2line操作不能解析出该地址对应的函数名和所在的文件函数;
[mjj@hadoop-senior test]$ gcc -g -c -finstrument-functions test.c main.c instrument.c
[mjj@hadoop-senior test]$ gcc test.o main.o instrument.o -o main
分开编译多次测试发现只有将-g和-finstrument-functions选项全部加在汇编过程才能发挥作用,因此可以推测这种插桩方式是在源代码等级进行的;
问题:
[mjj@hadoop-senio

本文记录了一次使用GCC的-finstrument-functions选项进行源码插桩的实验,详细介绍了如何通过该选项在编译时生成带有hook的可执行文件,并探讨了在多文件编译时遇到的问题及-g选项的重要性。实验结果显示,只有在汇编阶段同时包含-g和-finstrument-functions,插桩才能生效。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



