Main Content

Run Polyspace Bug Finder on Desktop

Polyspace® Bug Finder™ identifies run-time errors, concurrency issues, security vulnerabilities, and other defects in C and C++ embedded software. Using static analysis, including semantic analysis, Bug Finder analyzes control flow, data flow, and interprocedural behavior. By highlighting defects as soon as they are detected, Bug Finder lets you triage and fix bugs early in the development process.

You can run Bug Finder on complete C/C++ projects from the Polyspace user interface or using scripts. See:

  • Run Polyspace in User Interface

    If this is your first time using Polyspace, you might want to start from the Polyspace user interface. You can get help from features such as a project setup wizard, assisted configuration and summarized analysis log.

  • Run Polyspace on Windows or Linux Command Line

    Once you set up a project in the Polyspace user interface and complete a few trial runs, you can export the configuration to scripts that you run automatically or on-demand. You can also run a Polyspace analysis directly from the command line in your operating system. You can then save the commands in batch files (Windows) or shell scripts (Linux) for later runs. If you are running Polyspace Server products using continuous integration tools such as Jenkins, you can reuse your scripts from the Polyspace desktop products.

  • Run Polyspace in MATLAB

    If you have a MATLAB installation, it is particularly easy to write scripts to run a Polyspace analysis. You get all the benefits of scripting in the MATLAB environment, for instance, automatic help on function syntaxes. After analysis, you can create your own visualization of the results using MATLAB graphics and visualization tools.

Example Files

To follow the steps in this tutorial, copy the files from polyspaceroot\polyspace\examples\cxx\Bug_Finder_Example\sources to another folder. Here, polyspaceroot is the Polyspace installation folder, for instance, C:\Program Files\Polyspace\R2024b.

Run Polyspace in User Interface

Open Polyspace User Interface

Double-click the polyspace executable in polyspaceroot\polyspace\bin. Here, polyspaceroot is the Polyspace installation folder, for instance, C:\Program Files\Polyspace\R2024b. See also Installation Folder.

If you set up a shortcut to Polyspace on your desktop or the Start menu in Windows®, double-click the shortcut.

Add Source Files

To run an analysis, you have to create a new Polyspace project. A Polyspace project points to source and include folders on your file system.

On the left of the Start Page pane, click Start a new project. Alternatively, select File > New Project.

After you provide a project name, on the next screens, add your source and include folders (both folders can be the same). In this tutorial, add the path to the folder in which you saved the source and include files.

After you finish adding your source and include folders, you see a new project on the Project Browser pane. Your source folders are copied to the first module in the project. You can right-click a project to add more folders later. If you add folders later, you must explicitly copy them to a module.

Configure and Run Polyspace

You can change the default options associated with a Polyspace analysis.

Click the Configuration node in your project module. On the Configuration pane, change options as needed. For instance, on the Coding Rules & Code Metrics node, select Check MISRA C:2004.

For more information, see the tooltip on each option. Click the More help link for context-sensitive help on the options.

To start analysis, click Run Bug Finder in the top toolbar. If the button indicates Code Prover, click the arrow beside the button to switch to Bug Finder.

Follow the progress of analysis on the Output Summary window. After the analysis, the results open automatically.

Additional Information

See:

Run Polyspace on Windows or Linux Command Line

You can run Bug Finder from the Windows or Linux® command line with batch (.bat) files or shell (.sh) scripts.

To run a Bug Finder analysis, use the polyspace-bug-finder command.

To save typing the full path to the command, add the path polyspaceroot\polyspace\bin to the Path environment variable on your operating system. Here, polyspaceroot is the Polyspace installation folder, for instance, C:\Program Files\Polyspace\R2024b.

Navigate to the folder where you saved the files (using cd). Enter the following:

polyspace-bug-finder -sources numerical.c,dataflow.c -I . -results-dir .
Here, . indicates the current folder. The options used are:

  • -sources: Specify comma-separated source files.

  • -I: Specify path to include folder. Use the -I flag each time you want to add a separate include folder.

  • -results-dir: Specify the path to the folder where Polyspace Bug Finder results will be saved.

    Note that the results folder is cleaned up and repopulated at each run. To avoid accidental removal of files during the cleanup, instead of using an existing folder that contains other files, specify a dedicated folder for the Polyspace results.

After analysis, the results are saved in the file ps_results.psbf. You can open this file from the Polyspace user interface. For instance, enter the following:

polyspace ps_results.psbf

Instead of specifying comma-separated sources directly on the command line, you can list the sources in a text file (one file per line). Use the option -sources-list-file to specify this text file.

Additional Information

See:

Run Polyspace in MATLAB

Before you run Polyspace from MATLAB®, you must link your Polyspace and MATLAB installations. See Integrate Polyspace with MATLAB and Simulink.

To run an analysis, use a polyspace.Project object. The object has two properties:

  • Configuration: Specify the analysis options such as sources, includes, compiler and results folder using this property.

  • Results: After analysis, read the analysis results to a MATLAB table using this property.

To run the analysis, use the run method of this object.

To run Polyspace on the example file numerical.c in polyspaceroot\polyspace\examples\cxx\Bug_Finder_Examples\sources, enter the following at the MATLAB command prompt.

proj = polyspace.Project

% Configure analysis
proj.Configuration.Sources = {fullfile(polyspaceroot, 'polyspace', ... 
    'examples', 'cxx', 'Bug_Finder_Example', 'sources', 'numerical.c')};
proj.Configuration.TargetCompiler.Compiler = 'gnu4.9';
proj.Configuration.EnvironmentSettings.IncludeFolders = {fullfile(polyspaceroot, ...
'polyspace', 'examples', 'cxx', 'Bug_Finder_Example', 'sources')}
proj.Configuration.ResultsDir = fullfile(pwd,'results');

% Run analysis
bfStatus = proj.run('bugFinder');

% Read results
resObj = proj.Results;
bfSummary = getSummary(resObj, 'defects');
bfResults = getResults(resObj, 'readable');

After analysis, the results are saved in the file ps_results.psbf. You can open this file from the Polyspace user interface. For instance, enter the following:

resultsFile = fullfile(proj.Configuration.ResultsDir,'ps_results.psbf');
polyspaceBugFinder(resultsFile)

Additional Information

See:

Related Topics