>
>
Is it possible to run PVS-Studio in Lin…

Evgenii Ryzhkov
Articles: 125

Is it possible to run PVS-Studio in Linux?

Sometimes our customers wonder if it is possible to run PVS-Studio in Linux. Today we are ready to tell you about our research regarding this issue.

Good news, friends! Launching PVS-Studio for Linux is possible since October, 2016! You can use the analyzer in Ubuntu, Debian, OpenSUSE, CentOS, Fedora, Gentoo and many other distribution kits, based on the Linux kernel. The analyzer can be installed with the help of a package or unpacked from the archive. You may find more details about the news of PVS-Studio for Linux release by the link. An article describing the development of the analyzer under this platform is available here.

Introduction, or PVS-Studio's anatomy in brief

So, the PVS-Studio code analyzer consists of the following parts:

  • analyzer kernel presented by the PVS-Studio.exe file;
  • a handful of plugins for Visual Studio in the form of a dll set for VS 2012, 2010, 2008 and 2005;
  • external preprocessor cl.exe (from Visual C++), clang.exe (from Clang) or some other preprocessor like gcc.exe (from MinGW).

The preprocessor is required to parse all the #define's and #include's. The results of the preprocessor's work are received by the analyzer kernel (a console application). The analyzer builds the code tree and traverses it to find error patterns it is familiar with. The results of the analyzer's operation are arranged in the form of a set of diagnostic messages and sent to the Visual Studio plugin. It is the plugin that performs additional message filtering, provides you with easy and convenient navigation and many other things.

To launch the tool in another system (that is Linux), you should have at least a preprocessor and the analyzer kernel (the PVS-Studio.exe file) there. So what have we done?

Towards Linux?

Well, we don't have plans to create a native Linux-version of PVS-Studio for now due to commercial reasons first of all. Few people are lucky enough to build up a business on selling tools for Linux developers, and our company is obviously not the one to rush into this pool. However, users sometimes ask us about it, and we have finally decided to investigate this issue.

So, we obviously took the Linux-native gcc as the preprocessor. We were lucky to have had an experience of running the tool under MinGW earlier, which allowed us to make almost no modifications this time. At last, we learned quite quickly to get preprocessed files.

Then we needed to "feed" the preprocessed files to PVS-Studio.exe. This task appeared rather easy to accomplish on a Windows-machine. Of course, there were some issues with file paths and other subtle things, but we managed that in general. Then we found it interesting to run PVS-Studio in the Linux environment itself to easily integrate into Makefile.

We felt reluctant to port the PVS-Studio's code to Linux, as it is a very big and unrewarding task. That's why we took Wine. It allowed us to run the analyzer quite easily and pass several internal tests. After that we started at once to integrate the PVS-Studio call into Makefile of one of the open source projects.

Note that we did all that to a special version of PVS-Studio where we had disabled some features and modified others. That is, you will hardly succeed if you just take PVS-Studio.exe from the distribution pack. In the future, though, the pack will perhaps include the tool version capable of running under Wine right away.

So, we managed to run the tool under Wine in the native Linux environment, having modified the PVS-Studio's code and given it some crutches. At the same time, it was a successful integration into Makefile of a real project, just as we had wished! To know more about how to integrate PVS-Studio into any Makefile and build system, please see the documentation.

After this launch we got a test log-file that can be opened in Visual Studio with PVS-Studio to get a processed plog-file with messages output into the PVS-Studio Output Window. Of course, navigation doesn't work in a Windows system in this case, since the file paths are written in the Unix-format, but you can convert them into the Windows-format manually.

It's the other point which is important: there is a fundamental possibility to launch PVS-Studio under Linux in the native build environment! Moreover, you can actually realize (as a separate task) some UI to handle the text analysis log in Linux - that is, make an analogue of the PVS-Studio Output Window for Linux.

Address to our users

If there are those among our users interested in developing a Linux-oriented version of PVS-Studio and public release of this functionality, please let us know. But don't forget that it will require a large internal development on our side. Because it's just one thing to launch PVS-Studio.exe and pass a couple of projects, and quite another thing to provide full-blown operation of this version and test it on a large number of projects.