Instrumenting C/C++ codes using LLVM

前端 未结 2 1845
执笔经年
执笔经年 2021-01-30 02:43

I just read about the LLVM project and that it could be used to do static analysis on C/C++ codes using the analyzer Clang which the front end of LLVM. I wanted to know if it is

2条回答
  •  不思量自难忘°
    2021-01-30 03:23

    Since there are no answer to your question after two days, I will offer his one which is slightly but not completely off-topic.

    As an alternative to LLVM, for static analysis of C programs, you may consider writing a Frama-C plug-in.

    The existing plug-in that computes a list of inputs for a C function needs to visit every lvalue in the function's body. This is implemented in file src/inout/inputs.ml. The implementation is short (the complexity is in other plug-ins that provide their results to this one, e.g. resolving pointers) and can be used as a skeleton for your own plug-in.

    A visitor for the Abstract Syntax Tree is provided by the framework. In order to do something special for lvalues, you simply define the corresponding method. The heart of the inputs plug-in is the method definition:

    method vlval lv = ...
    

    Here is an example of what the inputs plug-in does:

    int a, b, c, d, *p;
    
    main(){
      p = &a;
      b = c + *p;
    }
    

    The inputs of main() are computed thus:

    $ frama-c -input t.c
    ...
    [inout] Inputs for function main:
              a; c; p;
    

    More information about writing Frama-C plug-ins in general can be found here.

提交回复
热议问题