Finding all possible paths in a c/c++ program by LLVM

戏子无情 提交于 2020-01-07 02:03:29

问题


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.


回答1:


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.

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;
} 

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.



来源:https://stackoverflow.com/questions/37337703/finding-all-possible-paths-in-a-c-c-program-by-llvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!