Run Polyspace as You Code in Eclipse and Review Results
You can configure Polyspace® as You Code to run on each save in your Eclipse™-based IDE, or you can start the analysis manually. The analysis runs on the file that is currently active in the IDE. After analysis, you see bugs and coding standard violations as source code markers or in a separate list.
Check Installation and Start Plugin
To confirm that the Polyspace as You Code plugin is installed in your Eclipse-based IDE, check the list of installed plugins.
Select Help > About Eclipse IDE.
Click Installation Details and type
polyspace
in the search bar on the Plug-ins tab.
To start the Polyspace as You Code plugin, open a C or C++ file in the editor. The plugin does not start automatically when you open the Eclipse IDE if no C or C+ file is open in the editor. You can confirm that the extension starts as expected in the Console view. To open this view, select Window > Show View > Console. If the plugin starts without errors, you see a message similar to this:
[2023-01-26 00:43:42.68] [Information] No setting set for the port. Trying to find a free port. [2023-01-26 00:43:49.539] [Information] Connector was successfully started on port 56041
You can also open the Console view by pressing Alt+Shift+Q and then Q again, and start typing console in the search bar.
The Polyspace as You Code plugin establishes an internal connection with the analysis engine on the selected port. If you do not specify a port, Polyspace queries your system for an open port and uses the port that your system returns.
Open Polyspace as You Code Perspective
The Polyspace as You Code plugin has a dedicated perspective in the Eclipse IDE that groups all the relevant Polyspace views.
To open the Polyspace as You Code perspective, click on the far right of the toolbar. If the perspective is already open but a different perspective is active, click to return to the Polyspace perspective.
The different views in the Polyspace as You Code perspective show information about the state of your configuration and about the files that you select for analysis. For more information, click in each view (when available) to open the documentation.
Quality Monitoring View
The Quality Monitoring view shows all the files that you have selected for analysis, along with the status of the analysis and the number of findings for each file.
To analyze a file, select that file and click . You can also start a sequential file-by-file analysis by clicking .
Open the settings on the Analysis node by clicking to configure adding files to this view on save. See Configure Polyspace as You Code Plugin in Eclipse. To add a file manually, right-click the file in the editor or in the Project Explorer.
Headers View
When you analyze a file, Polyspace also analyzes the header files that are included by and that are in the same folder as the analyzed file. If Polyspace reports findings in a header file, you see an H next to the analyzed file in the Quality Monitoring view. Click the analyzed file in that view to list the headers file in the Headers view.
You see header files in the list only if they contain findings. Click the file in the Headers view to open its findings in the Polyspace Problems view.
Polyspace Problems View
The Polyspace Problems view shows the all the analysis findings listed as one finding per line. Each line shows additional information,such as:
The rule name, family, and description.
Name of the file containing the finding. If this file is a header, the Header columns show the name of the source file containing this header file.
Review information
The findings are grouped by results family. To change the grouping or view a flat list, click the three vertical dots and select Grouping options.
Click a column header to sort findings by the content of that column. For instance, you can sort findings by files.
The results that show in the Polyspace Problems view represent the results for the files that you select in the Quality Monitoring view. The number of results in the Polyspace Problems view can change and does not represent results for all analyzed files.
When you select a file in the Quality Monitoring view, in the Polyspace Problems view you see results from:
Each file listed in the Quality Monitoring view including the selected file.
The header files of the file you select in the Quality Monitoring view.
If you select a different file in the Quality Monitoring view:
Polyspace removes the previously selected file's header file results from the Polyspace Problems pane.
The newly selected file's header file results show in the Polyspace Problems pane.
Result Details View
When you select a finding in the Polyspace Problems view or in the editor, the Result Details view shows additional information about the finding, including (when available) the traceback and the review information imported from the baseline.
If you select multiple lines of code, this view shows the result details for all the findings in the selection. Click to view contextual help about the selected finding.
To lock this view while you browse findings in the source code or the Polyspace Problems view, click . The view does not update when you select a different finding. Click the icon again to unlock the view.
Configuration View
The Configuration view shows the current analysis settings and the status of the generated build options, if applicable.
Click to generate a build options file. This button is available only if you configure the plugin to extract build options from your build command, from your Eclipse C/C++ project, or from a JSON compilation database. See Generate Build Options for Polyspace as You Code Analysis in Eclipse.
Click to open the settings on the Analysis node. See Configure Analysis Settings.
Click to open the Checkers selection interface. See Configure Checkers for Polyspace as You Code in Eclipse.
Baseline View
View whether you are using the baseline or not and the status of the baseline download if applicable. If you configure the baseline settings, you see information about the Polyspace Access server and the project you use as a baseline. See Set Baseline Polyspace as You Code Results in Eclipse.
In the Baseline view, you can:
Click to download or update a baseline.
Click to open the baseline settings.
If the results from the baseline run are generated with a Polyspace product version that is older than your Polyspace as You Code version, the view shows a warning.
Run Analysis
Polyspace analyzes only files that are part of the Eclipse workspace. To add a file to a workspace, you add it to a project in that workspace. Files that are not in the workspace are not analyzed even if you add them to the Quality Monitoring list. If a file that you analyze includes a file that is not in the workspace, the Polyspace as You Code analysis runs but does not report any findings in the included file.
On Save
By default, the Polyspace as You Code plugin adds the current file to the Quality Monitoring view on save but does not start the analysis.
To enable the analysis of the current file on save, click in the Quality Monitoring view and select Start analysis on save in the Preferences window. You can also open the preferences by pressing Alt+W+P.
After analysis, findings appear as source code markers. You also see the finding locations as red marks on the scroll bar. Click a finding location to navigate to the corresponding source code. If the analysis fails, check the messages in the Console view to diagnose the cause of the failure.
If results do not appear, see Troubleshoot Failed Analysis or Unexpected Results in Polyspace as You Code.
On Demand
To disable starting an analysis on save, go to the Polyspace as You Code preferences and clear the Start analysis on save checkbox. To start an analysis manually, do one of the following:
Click in the Quality Monitoring view.
Right-click the file in the editor and click Run Polyspace Analysis.
Review Results
After analysis, you see the results in two forms:
As source code markers. You can point to a source code marker to view more details about the finding and view options to justify that finding.
In a list on the Polyspace Problems view. If you select a finding in the Polyspace Problems view or in the editor, you see additional details about the finding in the Result Details view. Click to open the contextual help for the currently selected finding.
Apply Suggested Fix for Common Defects or Coding Rule Violations
If Polyspace reports certain common defects or coding rule violations in your code, the Polyspace as You Code plugin proposes one or more fixes that you can apply to these findings.
To apply a quick fix, hover over a finding in the editor and then, from the
light bulb menu, click the appropriate option. The quick fix options have the
format Fix checkerName
:
proposedFix
. Here,
checkerName
is the name of the selected defect
checker or coding rule, and proposedFix
is the fix
that Polyspace applies to your code. Polyspace edits your code and fixes the issue or all instances of the issue
in the currently active file, depending on the option that you select. If there
is more than one proposed fix, you see all available fixes in the menu.
This table lists the common defects and coding rule violations for which Polyspace proposes a fix, along with the Polyspace checkers that report these issues.
Common Defect or Coding Rule Violation | Polyspace Checkers That Report the Issue |
---|---|
Function that could be evaluated a compile time missing
constexpr specifier |
|
Inefficient use of std::any_cast to
cast object by value |
|
Inefficient use of std::string
operator+() |
|
Inefficient use of the [] operator to
insert or assign a value to a key in a
std::map or
std::unordered_map (C++ 17 and later
only) |
|
Parameter passed by value results in expensive copy |
|
Unmodified expensive-to-copy parameter passed by value |
|
Unmodified local variable is created by expensive copy
from a const reference |
|
Unmodified variable not declared
const |
|
Unnecessary call to std::move in a
return statement |
|
Unused include |
|
Unused parameter |
|
Use of std::endl |
|
Justify Results Using Code Annotations
If you decide not to fix a result, you can justify the result by adding code annotations. If the annotations follow a specific syntax, subsequent Polyspace as You Code runs can read these annotations and suppress the corresponding result.
To add a code annotation, right-click a finding in the Polyspace Problems view and select Polyspace > Justify the current result. The annotation is entered on the same line as the finding. You can also apply an annotation by pointing to the code marker for that result.
To mass-justify findings of the same defect or coding rule violation in the current file, right-click a finding in the Polyspace Problems view and select Polyspace > Justify all instances of the selected finding. Polyspace inserts an annotation in your code on each line that contains this finding.
If you import review information from a baseline run, any status, severity, or comment from the baseline run is automatically applied to the corresponding Polyspace as You Code finding.
Findings with an imported status of
Not a defect
,Justified
, orNo action planned
are removed from the Polyspace Problems view and in those findings are suppressed in subsequent analyses.
If you select multiple lines of code and then right-click in the Polyspace Problems view, you can select the Polyspace > Justify the current result option to justify each result in the selected code.
Polyspace as You Code inserts code annotations as comments enclosed in
"/* */
" for C files and prefixed with "//
"
in C++ files (C++ style). The comment format in C files complies with MISRA C:2004
rule 2.2. See MISRA C:2004 and MISRA AC AGC Rules (Polyspace Bug Finder).
See also:
View Context-Sensitive Help for Result
You can see more information on a type of result by visiting the context-sensitive help page for the result.
To open the context-sensitive help for a finding, select that finding in your code or in the Polyspace Problems view, and then click in the Result Details view.
You can also open the full searchable documentation for the Polyspace as You Code plugin in your system browser by clicking in the Baseline, Configuration, or Quality Monitoring view.
Configure Checkers and Other Settings
Polyspace as You Code checks for a default subset of defects, but you can expand the set of checkers and perform other configuration through the Polyspace as You Code plugin settings in Eclipse. To open the settings, press Alt+W+P and go to the Polyspace as You Code node in the Preferences window.
For instance, you might want to:
Enable or disable certain checkers. See Configure Checkers for Polyspace as You Code in Eclipse.
Review only new results. See Set Baseline Polyspace as You Code Results in Eclipse.
For the full list of settings, see Configure Polyspace as You Code Plugin in Eclipse.