finstrument-functions
2017-12-03 23:59:16
参考 如何快速地在每个函数入口处加入相同的语句?
https://www.zhihu.com/question/56132218
做个存档
scj@scjComputer:~/THpro/func_trace$ tree .
.
├── func_trace.c
├── func_trace.sh
├── imple
│ ├── bar.c
│ └── bar.h
├── main.c
└── 步骤
func_trace.c
#include <stdio.h>
static FILE *fp_trace;
void __attribute__((constructor)) traceBegin(void) {
fp_trace = fopen("func_trace.out", "w");
}
void __attribute__((destructor)) traceEnd(void) {
if (fp_trace != NULL) {
fclose(fp_trace);
}
}
void __cyg_profile_func_enter(void *func, void *caller) {
if (fp_trace != NULL) {
fprintf(fp_trace, "entry %p %p\n", func, caller);
}
}
void __cyg_profile_func_exit(void *func, void *caller) {
if (fp_trace != NULL) {
fprintf(fp_trace, "exit %p %p\n", func, caller);
}
}
func_trace.sh
#!/bin/bash
EXECUTABLE="$1"
TRACELOG="$2" while read TRACEFLAG FADDR CADDR; do
FNAME="$(addr2line -f -e ${EXECUTABLE} ${FADDR}|head -1)" if test "${TRACEFLAG}" = "entry"
then
CNAME="$(addr2line -f -e ${EXECUTABLE} ${CADDR}|head -1)"
CLINE="$(addr2line -s -e ${EXECUTABLE} ${CADDR})"
echo "Enter ${FNAME} called from ${CNAME} (${CLINE})"
fi if test "${TRACEFLAG}" = "exit"
then
echo "Exit ${FNAME}"
fi done < "${TRACELOG}"
bar.c
#include "bar.h"
int bar(void) {
zoo();
return ;
}
int foo(void) {
return ;
}
void zoo(void) {
foo();
}
bar.h
#ifndef bar_h
#define bar_h int bar(void);
int foo(void);
void zoo(void); #endif
main.c
#include <stdio.h>
#include "./imple/bar.h" int main(int argc, char **argv) {
bar();
}
然后按照如下顺序执行:
gcc func_trace.c -c
gcc main.c ./imple/*.c func_trace.o -finstrument-functions
./a.out
./func_trace.sh a.out func_trace.out
可以直接编译好多源文件的程序了。
直接把main.c以外的文件放进imple文件夹里头就可以 如果第二步有问题,用
gcc main.c ./source/*.c func_trace.o -finstrument-functions 2>trace_log.txt
导出编译信息 imple文件夹里头的东西封装成so后反而看不到调用过程。
finstrument-functions的更多相关文章
- asp.net MVC helper 和自定义函数@functions小结
asp.net Razor 视图具有.cshtml后缀,可以轻松的实现c#代码和html标签的切换,大大提升了我们的开发效率.但是Razor语法还是有一些棉花糖值得我们了解一下,可以更加强劲的提升我们 ...
- 【跟着子迟品 underscore】Array Functions 相关源码拾遗 & 小结
Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...
- 【跟着子迟品 underscore】Object Functions 相关源码拾遗 & 小结
Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...
- ajax的使用:(ajaxReturn[ajax的返回方法]),(eval返回字符串);分页;第三方类(page.class.php)如何载入;自动加载函数库(functions);session如何防止跳过登录访问(构造函数说明)
一.ajax例子:ajaxReturn("ok","eval")->thinkphp中ajax的返回值的方法,返回参数为ok,返回类型为eval(字符串) ...
- QM模块包含主数据(Master data)和功能(functions)
QM模块包含主数据(Master data)和功能(functions) QM主数据 QM主数据 1 Material Master MM01/MM02/MM50待测 物料主数据 2 Sa ...
- jQuery String Functions
In today's post, I have put together all jQuery String Functions. Well, I should say that these are ...
- 2-4. Using auto with Functions
在C++14中允许使用type deduction用于函数参数和函数返回值 Return Type Deduction in C++11 #include <iostream> using ...
- [Python] Pitfalls: About Default Parameter Values in Functions
Today an interesting bug (pitfall) is found when I was trying debug someone's code. There is a funct ...
- Kernel Functions for Machine Learning Applications
In recent years, Kernel methods have received major attention, particularly due to the increased pop ...
- Execution Order of Event Functions
In Unity scripting, there are a number of event functions that get executed in a predetermined order ...
随机推荐
- Win10系列:C#应用控件基础19
ScrollViewer控件 ScrollViewer控件包含一个水平和一个竖直滚动条以及一个可滚动的内容显示区域,在显示区域内可以放置其他可见控件.ScrollViewer控件的水平和垂直滚动条两端 ...
- Win10系列:C#应用控件基础17
Popup控件 在应用程序中使用Popup控件时,通常会先将其设置为隐藏状态,当用户触发应用中已定义的事件时,Popup控件将以弹出窗口的方式显示相关信息来提示用户操作. 在XAML文件中,Popup ...
- python xml文件解析
参考链接:http://www.runoob.com/python/python-xml.html
- 最简单的操作 jetty IDEA 【debug】热加载
[博客园cnblogs笔者m-yb原创,转载请加本文博客链接,笔者github: https://github.com/mayangbo666,公众号aandb7,QQ群927113708] http ...
- ln 链接命令 简要说明 软硬链接关系说明
ln [选项] 目标 -s 创建符号链接(软链接) -f 强制创建链接 -i 覆盖前先询问 -v 显示创建链接过程 ln命令不能对目录创建硬链接,但可以创建软链接,对目录的软链接经常被用到 删除软链接 ...
- python笔记12-字典
1.定义字典#定义字典--字典里面的key是不能重复的info = { 'name':'xiaoming', 'sex':'nan', 'age':20, 'id':1,}2.字典取值 #取值:方法1 ...
- 使用GraphHttpClient调用Microsoft Graph接口 - PATCH
博客地址:http://blog.csdn.net/FoxDave 通过前两讲的阐述我们应该大致了解了使用GraphHttpClient调用Microsoft Graph接口的模式,并介绍了使用get ...
- Alpha冲刺8
前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/10023260.html 作业博客:https://edu.cnblogs.com/campus ...
- 1.Python
一.Python基础:1.第一句python文件后缀名:文件后缀名是.py2.两种执行方式:(1)把文件地址交给python解释器,python解释器去找到这个文件读到内存执行(2)进入解释器:解释器 ...
- web-msg-send 学习 http://www.workerman.net/web-sender
WEB消息推送框架 web-msg-sender是一款web长连接推送框架,采用PHPSocket.IO开发,基于WebSocket长连接通讯,如果浏览器不支持WebSocket则自动转用comet推 ...