Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
You can now use PVS-Studio with Visual …

You can now use PVS-Studio with Visual Studio absent; just give it the preprocessed files generated by any preprocessor

Oct 11 2013

The new version of the static code analyzer PVS-Studio 5.10 comes with a small utility PVS-Studio Standalone which you may even miss at first. I'd say that's one small step for mankind but one big leap for PVS-Studio :).

Analysis based on pre-generated preprocessed files is no longer supported. Please consider using the Compiler Monitoring mode instead. This mode allows a generation and analysis of preprocessed files automatically during regular build process.

0219_Standalone/image1.png

You can use the current version of this utility in two (for now) ways:

  • View analysis results (the .plog file) saved on another computer without running the Visual Studio IDE.
  • Analyze preprocessed files (generated by any preprocessor beforehand) without a preprocessor and project files or makefiles.

At the same time, the tool supports complete code navigation, all the usual PVS-Studio's settings, and also the table representation of analysis results, which I told you about the other day. This method of analysis result representation allows you to use message filtering and sorting mechanisms to the full extent so that you can comfortably handle large lists of diagnostic messages.

In this article, I'm going to show you two scenarios of using this utility with the highest efficiency.

Scenario One - opening the .plog file on a computer without Visual Studio

Suppose that for some reason you don't have Visual Studio installed on your computer. But you've learned from articles that PVS-Studio is a very cool product and want to get analysis results for your project. Since you don't have any of the IDEs supported by PVS-Studio on your computer, you may ask your colleague to check the project on another computer with Visual Studio, save the analysis results into a .plog file and copy it to your computer (better if you also copy the project source codes so that you can navigate through the code and fix bugs). What do you need to do that?

Preparations for project analysis on a computer with an IDE installed

  • Open PVS-Studio on a computer where you have an IDE with PVS-Studio integrated.
  • Set the variable SourceTreeRoot in PVS-Studio's settings so that it contains the path to the root folder with the project source code files you want to check. You need this for the .plog file to contain relative paths instead of absolute paths.
  • Run analysis of the project and save the analysis report file.

Viewing the log on a computer without an IDE

1. Install PVS-Studio Standalone (make sure to select this option in the setup window).

0219_Standalone/image2.png

2. Run PVS-Studio Standalone from the Start menu.

0219_Standalone/image1.png

3. After the program starts, open the .plog file.

0219_Standalone/image3.png

4. Here it is:

0219_Standalone/image4.png

5. You can start examining the log right away, but before that try clicking on any message - you will be asked to specify the folder with the source codes:

0219_Standalone/image5.png

6. Here we go:

0219_Standalone/image6.png

7. Now you can view the log, perform message filtering and sorting and even edit and correct the source code!

0219_Standalone/image7.png

We hope you won't demand too much from this "environment" of ours: though it is built on Scientilla (like Notepad++), it's incredibly far from a full-blown IDE like Visual Studio. The most serious trouble is the absence of IntelliSence. We try to make up for it by the search dialog. However, you still have the following capabilities:

  • You can view the analyzer's diagnostic messages and navigate through the code.
  • You can open messages, filter them or disable individual diagnostics WITHOUT having to relaunch the analysis.
  • You can mark messages as false positives.
  • To sum it up, it's almost as complete as the original PVS-Studio save the incremental analysis mode.

But I guess many of you will find the second scenario more interesting; so, go on reading.

Scenario Two - checking preprocessed files

The coolest thing about PVS-Studio Standalone is not the option that allows you to handle ready logs, but the ability to check preprocessed files. What is the most difficult aspect of PVS-Studio's integration into a customer's project? You see, the analyzer needs to generate preprocessed files to be able to perform analysis. If you have a project file .vcproj/.vcxproj (i.e. you work in the Visual Studio environment) PVS-Studio creates preprocessed files automatically once you click on the "Start" button. But if you happen to work in a different mode (say, you use a makefile), you'll have to integrate a PVS-Studio call into the build system, which may be troublesome for certain reasons.

This mode is reasonable to use because it is easy, above all. Our experience tells us that with most build systems it's easier to add one more flag in the compilation parameters for all files rather than integrate an analyzer call "in parallel" with the compiler. Although direct integration of an analyzer into the build process is certainly a better solution from the "ideological" viewpoint, this practice is sometimes not very suitable when you want just to give the analyzer a quick try on your project.

This is where our new tool PVS-Studio Standalone comes in handy. You can feed it with preprocessed files for it to analyze them and even map them to the source codes. That is, you'll get diagnostic messages on the source codes, not the preprocessed files. Let's see how it is actually done.

I'm going to test PVS-Studio Standalone on... let it be zlib. No, no, it's not another report article about errors found in zlib. There will be very few warnings on it, so don't be surprised. The library is clear. Besides, PVS-Studio checked zlib's code for a number of times when checking other projects, so all the false alarms on zlib were eliminated long ago. This article is meant to demonstrate usage of the new tool, not to tell you about bugs found in some project. That's why I've chosen a relatively simple project, so that everyone understands what we are doing.

Building zlib

  • Download the zip-file, unpack it into zlib-1.2.8, and put the win32\Makefile.msc file into the root folder (i.e. into zlib-1.2.8).
  • Set up the building environment of the command line with VS2012 x86 Native Tools Command Prompt (or any other tool).
  • Run nmake -f Makefile.msc.
  • Make sure it's been compiled right.

Getting preprocessed .i files

1. Open the Makefile.msc to edit it.

2. Add the switch /P to generate the preprocessed files. That is, instead of the command

CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)

we have

CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" /P $(LOC)

3. Generate the preprocessed files:

nmake -f Makefile.msc clean

nmake -f Makefile.msc

4. Make sure that our .i files are in the necessary folder.

Checking projects in PVS-Studio Standalone

1. Run PVS-Studio Standalone.

2. Select the Tools menu, then the Verify Preprocessed Files... command.

0219_Standalone/image8.png

3. Fill in the fields as shown below:

0219_Standalone/image9.png

What you should be especially careful about is the paths to your source codes and to the .i files (these paths coincide in our case); the paths to the system include-folders (so that you don't get error messages on them), and some other parameters.

You may want to view the list of supported preprocessors:

0219_Standalone/image10.png

Those readers who have been following our articles for a long time may ask in surprise: "So, you guys support gcc now?!" Yes, we do! We support it in case of MinGW and Cygwin and (God, they've done it at last!) Linux.

So, now you can check even linux-projects, though this is a freshly added functionality and it hasn't been properly tested yet, to be honest. Those who feel like experimenting with it please report any troubles that may occur to us; we'll try to fix them as quickly as possible.

4. Having filled in the dialog window, click on the Start button. A bit later we get a window with the analysis results and navigation options:

0219_Standalone/image11.png

You can check and CORRECT the code right in PVS-Studio Standalone!

We've created a very cool app which extends PVS-Studio's scope of use in a way very convenient to users.

What next?

Now everyone who wanted us to support MinGW, Cygwin and gcc or for some reasons faced troubles when trying to check their code with PVS-Studio, go download the new version and experiment with PVS-Studio Standalone.

P.S. By the way, it's the first article about PVS-Studio with so many screenshots :-)

Popular related articles


Comments (0)

Next comments next comments
close comment form
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam