简体   繁体   English

静态分析工具应编译代码

[英]Should static analysis tool compile code

Does there exist static analysis tool (C/C++) which analyzes code without being able to compile it? 是否存在静态分析工具(C / C ++),其无法编译代码来分析代码? (The reason I ask is my code may have some functions from external SDK) (我问的原因是我的代码可能具有外部SDK的某些功能)

Most static analysis tools (eg frama-C ) don't compile C code, but often requires its preprocessed form. 大多数静态分析工具(例如frama-C )不编译C代码,但通常需要其预处理形式。 So they require the availability of header files used by your code. 因此,它们需要您的代码使用的头文件的可用性。 Often, they fork the compiler just to get the preprocessed form (ie gcc -C -E ) 通常,他们派发编译器只是为了获得预处理形式(即gcc -C -E

Notice that these tools usually don't need or care about the binary form of the libraries you are using, only their header files. 请注意,这些工具通常不需要或不在乎您使用的库的二进制形式,而仅是它们的头文件。

However, I believe that extending a compiler to add much more static analysis abilities is a plus, since the analyzer can take advantage of all the work done (and the infrastructure provided) by the compiler. 但是,我相信扩展编译器以添加更多的静态分析功能是一个加号,因为分析器可以利用编译器完成的所有工作(以及提供的基础结构)。 This is the main motivation for my (free software, obsolete in 2019) GCC MELT tool (which you can use to extend GCC to do some particular static analysis). 这是我(免费软件,于2019年过时)GCC MELT工具(可用于扩展GCC进行某些特定静态分析)的主要动力。

Some few static analyzers -eg coccinelle - are able to handle unpreprocessed C code (using macros). 有的几个静态分析仪-例如COCCINELLE -能够处理unpreprocessed C代码(使用宏)。 But then, they need some way to understand the macros which your code is using (otherwise they cannot check much: a macro invocation can expand to many thousands statements!). 但是,然后,他们需要某种方式来理解您的代码正在使用的宏(否则它们将无法进行大量检查:宏调用可以扩展为成千上万的语句!)。

NB all the analyzers mentioned above are free software. 注意:上述所有分析仪均为免费软件。

我已经使用了很多年了: FlexeLint

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM