如何正确地将 pvs-studio 集成到内核模块 makefile 中?

How to properly integrate the pvs-studio into the kernel module makefile?

我打算使用 pvc-studio 检查简单的开源驱动程序,但到目前为止还没有成功。我的系统是 Debian 4.6.0-amd64。我使用原生 x86_64 gcc 编译器。

运行 命令

pvs-studio-analyzer trace -- make; pvs-studio-analyzer analyze -o ./app.log

打印出 No compilation units found.

我尝试将调用嵌入到 makefile 中,如下所示:

CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
DEST = /lib/modules/$(CURRENT)/misc

PARAMS = -I/usr/src/linux-headers-4.6.0-1-common/include -I/usr/src/linux-headers-4.6.0-1-amd64/include

TARGET1 = file1
TARGET2 = file2

obj-m   := $(TARGET1).o $(TARGET2).o

all: default clean
default: file1.c file2.c
    pvs-studio --cfg ~/pvs.cfg --source-file $< --cl-params $(CFLAGS) $(PARAMS) $<
    $(MAKE) -C $(KDIR) M=$(PWD) modules

...

因此,我收到了很多类似“没有与内核头文件相关的文件或目录”的错误消息。

我的 .cfg 文件:

exclude-path = /usr/include/
exclude-path = /usr/src/linux-headers-4.6.0-1-amd64/include
exclude-path = /usr/src/linux-headers-4.6.0-1-common/include
platform = linux64
preprocessor = gcc
analysis-mode=4
language = C

我做错了什么?如何正确操作?

要检查项目,可以使用 pvs-studio-analyzer 实用程序或 intergarte 分析器 (pvs-studio)直接进入构建系统,但不能同时使用两个选项。

  1. pvs-studio-analyzer

No compilation units found

执行跟踪命令后,会在当前目录中创建一个 strace_out 文件。你必须确保在这个文件中有文件编译的命令。如果找到需要的命令,编译器名称有不寻常的标题,可以用参数--compiler指向:

pvs-studio-analyzer analyze ... --compiler COMPILER_NAME ...

如果要跟踪的文件中没有编译命令,是否需要检查工程是否正在编译。或许,需要先执行一个命令make clean.

  1. 当集成到 Makefile 中时,分析器还需要有关编译器的信息。

默认情况下,编译器取自环境变量CC/CXX。在给定的示例中,它们没有声明,正如我所见。

如果找不到某些 header 文件,需要将它们的路径添加到 --cl-params 参数中。

配置文件排列正确。尝试考虑我的建议和 运行 再分析一次。

link 提供完整文档:“How to run PVS-Studio on Linux”。