PC-lint Plugin in the MPLAB® X IDE
Contents
Introduction
The Gimpel PC-lint/Motor Industry Software Reliability Association (MISRA) plugin provides a Language Interpreter (LINT) and MISRA standard check on C source files created in MPLAB® X IDE. This plugin has various settings, which include a PC-lint installation path, compiler configuration, command-line argument, log file creation, and selection of source files.
PC-lint will check your C/C++ source code and find bugs, glitches, inconsistencies, non-portable constructs, redundant code, and much more using the Kernighan & Ritchie (K&R) and American National Standards Institute (ANSI) standards for C (style of coding). The purpose of linting your program is to determine potential problems prior to integration or porting or to reveal unusual constructs that may be a source of subtle errors. The C compiler cannot always detect each and every potential problem in your source files; this is where PC-lint comes in. PC-lint can be configured to suit your needs, it can either complain a lot or a little.
To check the source code, the plugin will invoke the Gimpel PC-lint/MISRA executable file with the appropriate command-line argument. The output of the Gimpel PC-lint/MISRA analysis will be redirected to the MPLAB X IDE Output window. The output will contain the file name(s) and line number(s) where linting found inconsistencies. Double-clicking an output line will open the corresponding file at the line number in the MPLAB X IDE Editor window.
Gimpel PC-lint/MISRA Installation
To be able to use the MPLAB X PC-lint plugin, you will need to install the Gimpel PC-lint Software. Go to the Gimpel website to acquire this product.
On Microsoft® Windows, running the setup program will copy the PC-lint files onto your hard drive. Running the configuration wizard (config.exe) will configure PC-lint (lint-nt.exe) for your compiler, libraries, editors, and IDEs. It may be run multiple times if you have multiple configurations for which you need support. It will build a batch file for calling PC-lint (lin.bat) and will invoke the appropriate PC-lint configuration files (*.lnt) for your environment. Note that PC-lint error messages may be found in the file msg.txt.
Some important Gimpel PC-lint/Motor Industry Software Reliability Association (MISRA) plugin files are:
lin.bat
The batch file for invoking lint-nt.exe is lin.bat.
lint-nt.exe
The lint-nt.exe file is the PC-lint executable to process the C source file(s) for linting.
config.exe
The config.exe file is the configuration wizard for PC-lint. This wizard creates a file that contains options to allow PC-lint to process the source code, i.e., using this utility you will be able to select your desired Microchip C compiler.
co-xxxx.lnt
The co-xxxx.lnt files are included with PC-lint and contain options for using the respective MPLAB XC C compiler with PC-lint.
The following is taken from co-xc8.lnt.
msg.txt
The msg.txt file is an ASCII rendition of PC-lint messages for MPLAB X IDE use. PC-lint message types are shown in the following table:
Type | C | C++ | Warning Level |
---|---|---|---|
Syntax Errors | 1 - 199 | 1001 - 1199 | 1 |
Internal Errors | 200 - 299 | 0 | |
Fatal Errors | 300 - 399 | 0 | |
Warnings | 400 - 699 | 1400 - 1699 | 2 |
Informational | 700 - 899 | 1700 - 1899 | 3 |
Elective Notes | 900 - 999 | 1900 - 1999 | 4 |
Installing the PC-lint Plugin on MPLAB X IDE
To install the plugin into MPLAB X IDE, follow the instructions in the "Installing Microchip Supplied Plugins" section of the "Plugins Window: Available Plugins Tab".
PC-lint Instructions For Use
Objective
The following step-by-step instructions will show you how to set up PC-lint for a project in MPLAB X IDE. To start, make sure you have the following installed:
- PC-lint from the Gimpel Software website
For this specific example we are running a MISRA C 2012 (TM) check.
Procedure
To be able to run a MISRA12 check for example, you need the following config-files:
- au-misra3.lnt - MISRA checks to run
- co-xc8.lnt - XC8 compiler config-files
Create an UserOption file that contains the following:
- path to check-config-file = “au-misra3.lnt”
- path to compiler-config-file = “co-xc8.lnt”
- path to compiler header files
This is an example of how it looks for this specific tutorial:
// Standard lint options
// -SL-3.3.16: Based on input, setup this configuration
C:\lint\configSL\au-misra3.lnt
C:\lint\configSL\co-xc8.lnt
// C:\lint\options.lnt -si4 -sp4
-i"C:\Program Files (x86)\Microchip\xc8\v1.36\include"
As we can see from above, this option file includes the path to the lnt file that needs to be run for the MISRA standard, the path to the lnt file specific to the XC8 compiler, and the path to include compiler header files.
Configure PC-lint in MPLAB X by going to Tools > Options > Embedded > PCLint:
- Location - path to your PC-lint installation “lint-nt.exe”
- Options - select UserOptionFile
- User Option File - select the UserOption file you created in the previous step
- Standards - MISRA2012
You also need to create two more config-files “include-path.lnt” and “lint-cmac.h” as described in the header of the “co-xc8.lnt” file.
Both files contain the information that is usually passed via compiler-options “-i xxx” in include-path.lnt and "-D xxx“ in lint-cmac.h.
For MPLAB XC Compilers, PC-lint requires include-path.lnt and lint-cmac.h for linting. These two files can be generated from the MPLAB X IDE project context menu item Generate PCLint Dependency Files. Selecting this item will add both dependency files to the c:\pclint\lint\lnt folder.
Finally, right-click on the project in the MPLAB X and select Lint this Project.
Results
You will then see an output like this:
The output will contain the file name(s) and line number(s) in which linting found inconsistencies. Double clicking an output line will open the corresponding file at the line number in the MPLAB X IDE editor window.
Using PCLint with MPLAB X IDE
Step-by-Step
Create a user option file, named myOptions.lnt, in the folder C:\lint, containing these instructions:
au-misra3.lnt
co-xc8.lnt
Inside MPLAB X IDE, select the created user option file by navigating to Tools > Options > Embedded > PCLint > Options > UserOptionFile.
Get the co-xc8.lnt file (modified 22Jul2015) from the the Gimpel website.
File
co-xc8.lnt
To do the above steps run xc8 —CHIP=16F1619 -v -v test.c > out.txt from the command prompt and then create lint-cmac.h and include-path.lnt.
Add the following two lines to co-xc8.lnt:
include-path.lnt
Click on the project, then click on Lint this project.