用Clang进行动态检测 [英] Dynamic instrumentation with Clang

查看:80
本文介绍了用Clang进行动态检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用C(可能是C ++)进行一些动态代码检测来加速使用Clang,在该过程中我将获取源文件并生成检测输出。我想在任何代码块的开头添加一个函数调用,并更改所有布尔表达式以调用某个函数,以便我也可以跟踪它。例如:

  foo = a&& (b || c); 

将变成类似以下内容:

  foo = EXPR_AND(a,EXPR_OR(b,c)); 

因此,我可以跟踪发生的所有条件组合。



我认为使用RecursiveASTVisitor是最好的方法,但是是否有一种简单的方法来输出我访问的每个节点的C代码?



任何



注意:经过进一步的研究,我才发现libclang看起来可能是我最好的选择。



朋友再加上重写器,我可能会满足我的需求。任何指向好的示例的指针(我刚刚发现出色的Apple开发人员在libclang上观看视频)都很棒。

解决方案

示例,请参见此项目



它使用clang为了检测调用函数的进入和退出,还检查传递参数的类型。


I'm trying to get up to speed on using Clang by doing a bit of dynamic code instrumentation with C (and maybe C++) where I take a source file and generate an instrumented output. I'd like to add a function call at the beginning of any block and also change all boolean expressions to call some function so I can track that too. For example:

foo = a && (b || c);

would become something like:

foo = EXPR_AND(a, EXPR_OR(b, c));

and thus I can track all combinations of conditions that occur.

I assume using a RecursiveASTVisitor would be the best approach, but is there an easy way to output the C code for each node I visit?

Any suggestions of what to look at to accomplish something like this would be most appreciated!

Note: After some further investigation, I just discovered libclang which looks like it could be my best friend. Coupled with a rewriter, I might just have what I need. Any pointers to good examples (I just found the excellent Apple developers meeting video on libclang) would be great.

解决方案

For a good example see this project.

It uses clang in order to instrument call function entering and exit, and it also inspects types of passed arguments.

这篇关于用Clang进行动态检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆