Run Analysis and Review Results in Eclipse
R2026bAfter you configure the Polyspace®
as You Code™ plugin, you are ready to run an analysis and fix or justify any results.
Before continuing this tutorial, verify that you have added
example.hpp and example_source.cpp to the
Quality Monitoring list. See Configure Polyspace as You Code in Eclipse.
Run Polyspace as You Code Analysis in Eclipse
Run an analysis on example_source.cpp by using one of these methods.
If you set Start analysis on save, save your edited file.
Right-click the file and select Run Polyspace Analysis.
In the Quality Monitoring list, click the analyze all files icon
.
View, Fix, or Justify Findings
After Polyspace runs the analysis, the filename in the Quality Monitoring pane is green if there are no results and red if there are results. A number to the right of the filename indicates the number of results. View your results in the Polyspace Problems pane. Open the Polyspace Problems pane by clicking the filename in the Quality Monitoring list. If the Polyspace Problems pane is not open, reset the perspective by clicking Window > Perspective > Reset Perspective.
The Polyspace Problems pane shows all results in a list. Use the filter in the Polyspace Problems pane to search for specific results. Each result contains a filename and line number that indicate the location in the code where Polyspace found the defect or coding rule violation.
Click a result to view more information about the result in the Result Details pane. Click the expander for the result in the Result Details pane to show potential fixes or justifications to apply to the result.
After Polyspace
as You Code completes its analysis on example_source.cpp, open
the results in the Polyspace Problems pane. Use the filter to search
for 6.5.1. Polyspace finds a violation of MISRA C++:2023: 6.5.1 on line
9.
Click the result in the Polyspace Problems pane to open the file where the rule violation occurs. Each result is noted in the file with a red underline. Hover over the underlined sections of code to see a list of each result associated with the underlined section.
In example.h, add this line of code on line 9 after the class
definition:
int getDenominator(bool triggerError);MISRA C++:2023:
6.5.1 in example_source.cpp is no longer
present.With automatic analysis active, you can find and justify or fix results during the code authoring process. Each time you save changes, a Polyspace analysis begins in the background and displays any new results or removes fixed results from the list.
Justify Individual Findings
You can justify a result from the Polyspace Problems pane or from the location of the result in the code.
To add a justification to a result, right-click a result in the Polyspace Problems pane and select Polyspace > Justify the current result. This adds an amendable comment to your code at the location where the code violation occurs.
Adding a justification removes the result from the Polyspace Problems pane. To show the result again, remove the justification comment from the file and perform a new Polyspace analysis.
For this tutorial, after running an analysis:
Locate the result for the defect integer division by zero on line 6 in the Polyspace Problems pane.
Right-click the result and select Polyspace > Justify the current result.
Provide Justification Catalog
You can add a catalog of predefined justifications to Polyspace as You Code. If you use a catalog of predefined justifications, you can select a comment from the catalog to append to the justification instead of manually typing a justification comment.
Click the configure settings icon
in the Configuration pane
and select the Polyspace as You Code tab. Enter the path to
your justification catalog in the text box relative to the install location. The
catalog must be in JSON format. See Create and Edit Justification Catalog.
In this tutorial, use the example JSON file
example_catalog.json to create a justification
catalog:
{
"justifications": [
{
"family": "Defect",
"acronym": "INT_ZERO_DIV",
"comment": "This is my justification for division"
},
{
"family": "Defect",
"acronym": "INT_ZERO_DIV",
"comment": "Alternative justification for division"
}
]
}Provide the location of the catalog in the Eclipse™ preferences.
After running an analysis:
Locate the result for the defect integer division by zero on line 6 in the Polyspace Problems pane.
Right-click the result and select Polyspace > Justify the current result.
Eclipse displays options from your justification catalog in the file editor. Select one of the options from the list to add it to your justification annotation.
View Header Findings
When you analyze source files, Polyspace as You Code shows any header file results in the Polyspace Problems pane. If a header contains a result, it is noted with a red H next to the source file in the Quality Monitoring list.
Double-click a header result in the Polyspace Problems pane to go to the header file that contains the result. To find which source file analysis caused the header result, click the expander in the Result Details pane for the result.
After you run an analysis on the example code, open the results in the
Polyspace Problems pane. Use the filter to search for
19.2.1. There is a violation of MISRA C++:2023 Rule 19.2.1 in
the file example.h.
Replace the example header file with this code:
#ifndef CALCULATOR_H
#define CALCULATOR_H
class Calculator {
public:
int divide(int numerator, int denominator);
Calculator() = default;
};
#endif // CALCULATOR_H
Save the file and run another analysis. The violation of MISRA
C++:2023 19.2.1 is no longer in the results list.
Compare Results Against a Baseline
For more efficient bug fixing, compare your Polyspace as You Code single-file analysis results against a set of baseline results so you can focus on new or unreviewed results only. You can create a local baseline or download a Polyspace Bug Finder™ analysis from Polyspace Access™ to use as a baseline.
For more information on creating or downloading a baseline in Eclipse, see Eclipse: Configure Baseline Results in Polyspace as You Code.