通过LLVM在c / c ++程序中找到所有可能的路径 [英] Finding all possible paths in a c/c++ program by LLVM

查看:176
本文介绍了通过LLVM在c / c ++程序中找到所有可能的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过LLVM在我的程序中找到任何可能的路径。现在我可以找到我的代码中所有函数的入口到出口BB的路径。但这不是我需要的。我需要的是扩展CFG(也许通过内联函数调用?!)有一个CFG的整个源代码和查找路径在这个扩展的CFG。
我想使用-inline pass首先内联所有函数,然后运行我的pathfinder pass但是我观察到-inline只适用于在代码(cpp文件)中明确提到的内联函数。我不能通过几百个功能,并添加到所有的内联。我还需要保证所有呼叫都是内联的,不会丢失任何呼叫。我不知道内联是我唯一的选择,甚至这是一个选项。任何想法,这是赞赏。

I am trying to find any possible path in my program by LLVM. Right now I can find paths from entry to exit BB of all functions in my code. However that's not what I need. What I need is extending CFG (maybe by inlining function calls?!) to have a CFG for entire source code and find paths in this extended CFG. I was thinking of using -inline pass first to inline all functions first and then run my pathfinder pass but as I observed -inline works only for functions which are explicitly mentioned inline in code(cpp file). I can't go through hundreds of functions and add inline to all of them. I also need to guarantee that all calls are inlined and no call is missed. I'm not sure that inlining is my only option or even that is an option. Any thought on this is appreciated.

**显然我的源代码中没有递归调用。

**obviously there is no recursive call in my source code.

推荐答案

不完全确定您要的是什么,但是您可以使用任何程序语言来解析source.cpp和source .h来查找函数声明/定义,并根据一些规则添加 inline

Not entirely sure what you are asking, however you could use just about any program language to parse the source.cpp and source.h to find function declaration/definition and add the inline based on some rule.

基本上你会将source.cpp视为一个.txt文件,并使用你喜欢的任何api来获取 char * 。搜索,然后搜索参数和结束

Basically you will treat the source.cpp as a .txt and use any api of your preference to get the files as a char *. Have it search for ( then search for parameters and a closing ).

// FindFunctions.cpp
#include "..."
...

char * AddFuncDecChars( _In_ char * file, char * stringToBeInserted)
{
    //Find possible functions with `()`.
    int[] PossFuncs = FindParenths(File);
    // Check to see if space delimited block followed by another block or
    // multiple space delimited blocks with commas.
    int[] VerifiedParens HasSpaceDelimWithPossibleCommas( PossFuncs, 
    File);
    char * Change InsertStringToFunc( File, VerifiedParen,
    stringToBeInserted);
    return Change;
} 

还有 inline 在头中的定义不是cpp所以可能需要通过接收 .h .cpp 对。

Also inline has to have definition in the header not cpp so might have to add that to headers by taking in a .h and .cpp pair.

这篇关于通过LLVM在c / c ++程序中找到所有可能的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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