PC-lint Plugin in the MPLAB® X IDE

Last modified by Microchip on 2023/11/09 09:12

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.​

Currently, for PC-lint to support MPLAB XC C compilers, you will need to follow the instructions in the co-xc8.lnt, co-xc16.lnt, and co-xc32.lnt files for editing lint-cmac.h and include-path.lnt files.

The following is taken from co-xc8.lnt.

Before you start using this file, please perform these simple steps:
1) Include the path(s) to your header files.

  • Run MPLAB XC8 to compile the empty.c file with -v option. Copy any -I argument from the output to include-path.lnt (in the same directory where co-xc8.lnt exists).
  • Don't forget to use the -i lint option. ex: -i"include-path".
  • Note that any other include directories should be added explicitly.

2) Next, include the preprocessor macro definitions specific to the chip you are using.

  • From the output you get in step one, copy all arguments starting with -D to lint-cmac.h in the same directory as co-xc8.lnt.
  • Edit the file to have the form: #define macro_name value // each definition on a separate line

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:

TypeCC++Warning Level
Syntax Errors1 - 1991001 - 11991
Internal Errors200 - 299 0
Fatal Errors300 - 399 0
Warnings400 - 6991400 - 16992
Informational700 - 8991700 - 18993
Elective Notes900 - 9991900 - 19994

Back to Top

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:

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

Make sure you have the latest version of these configuration 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:

// Microchip MPLAB XC8 C-si4 -sp4,
// Standard lint options
// -SL-3.3.16Based 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
    PCLint Configuration

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.

See the header of co-xc8.lnt for a more detailed explanation of how to create these two files.


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.
Generate PCLint Dependency Files


Finally, right-click on the project in the MPLAB X and select Lint this Project.

Start Lint Process

Back to Top


Results

You will then see an output like this:

example output of the pc-lint plugin

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.

Back to Top

Using PCLint with MPLAB X IDE

Complete before executing PCLint.

Step-by-Step

Create a user option file, named myOptions.lnt, in the folder C:\lint, containing these instructions:

-i"C:\lint"
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

Before you start using this file, please perform these simple steps:
1) Include the path(s) to your header files.

  • Run MPLAB XC8 to compile the empty.c file with -v option. Copy any -I argument from the output to include-path.lnt (in the same directory where co-xc8.lnt exists).
  • Don't forget to use the -i lint option. ex: -i"include-path".
  • Note that any other include directories should be added explicitly.

2) Next, include the preprocessor macro definitions specific to the chip you are using.

  • From the output you get in step one, copy all arguments starting with -D to lint-cmac.h in the same directory as co-xc8.lnt.
  • Edit the file to have the form: #define macro_name value  each definition on a separate line

​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.

These steps must be done every time the project configuration is changed.


 Add the following two lines to co-xc8.lnt:

-header(lint-cmac.h)  //preprocessor macro definitions
include-path.lnt

Click on the project, then click on Lint this project.

Anytime anything in the project properties is changed (e.g., include path, change of device, compiler version, etc.), these steps must be repeated.

Back to Top