QP-nano 6.8.1
PC-Lint-Plus

The QP-nano distribution contains a "port" to PC-Lint-Plus static analysis tool from Gimpel Software, which is a static analysis tool for C and C++ with one of the longest track records and best value of the money in the industry. The "PC-Lint-Plus port" allows you to statically analyze the QP-nano source code and facilitates static analysis of your application code based on QP-nano.

The QP-nano "port" to PC-Lint-Plus is located in the directory qpn/ports/lint-plus and includes also lint configuration files, as well as an example of "linting" application code in the directory qpn/examples/arm-cm/dpp_ek-tm4c123gxl/lint-plus. The following listing describes the most important files in these three directories.

qpn\ - QP-nano installation directory
|
| +-ports/ - QP-nano ports directory
| | +-lint-plus/ - QP-nano "port" to PC-Lint-Plus
| | | +-qkn/ - QP-nano port with the QK-nano kernel
| | | +-qvn/ - QP-nano port with the QV-nano kernel
| | | +-au-ds.lnt - Dan Saks recommendations
| | | +-au-misra3.lnt - MISRA-C:2012 compliance checks
| | | +-au-misra3-amd1.lnt - MISRA-C:2012-Amendment-1 additional checks
| | | +-qpn.lnt - PC-Lint-Plus options for QP-nano applications
| | | +-std.lnt - Standard PC-Lint-Plus settings recommended by Quantum Leaps
| | | +-lin.bat - Batch file to invoke PC-Lint-Plus to run analysis of QP-nano code
| | | +-options.lnt - PC/Lint-Plus options for "linting" QP-nano source code
| | | +-lint_qfn.log - PC/Lint-Plus output for the QEP/QF-nano components of QP-nano
| | | +-lint_qvn.log - PC/Lint-Plus output for the QV-nano component of QP-nano
| | | +-lint_qkn.log - PC/Lint-Plus output for the QK-nano component of QP-nano
| | | +-qpn_conf.h - QP-nano config file for a "generic C compiler"
| | | +-stdbool.h - Standard Boolean type and constants for a "generic C compiler"
| | | +-stdint.h - Standard exact-width integers for a "generic C compiler"
| |
| +-examples\ - QP-nano examples directory (application)
| | +-arm-cm\ - QP-nano examples for ARM Cortex-M
| | | +-dpp_ek-tm4c123gxl\ - DPP example on the EK-TM4C123GLX board
| | | | +-lint-plus\ - directory for linting the application
| | | | | +-lin.bat - Batch to run PC-Lint-Plus analysis of application code
| | | | | +-options.lnt - PC-Lint-Plus options for "linting" of application code

Linting the QP-nano Source Code

The directory qpn/ports/lint-plus (see listing above) contains also the lin.bat batch file for "linting" the QP-nano source code. The lin.bat batch file invokes PC-Lint-Plus and generates the lint output files. As shown in the listing above, the lint output is collected into four text files lint_qfn.log, lint_qkn.log<tt>, andlint_qvn.log`, for QEP/QF-nano, QK-nano, and QV-nano components of the QP-nano framework, respectively.

Note
In order to execute the lin.bat file on your system, you might need to adjust the symbol PCLP_DIR at the top of the batch file, to the PC-Lint-Plus installation directory on your computer.

According to the PC-Lint-Plus guidelines, the lin.bat uses two option files: the qpn.lnt configuration file discussed before and the options.lnt configuration file that covers all deviations from the MISRA-C rules within the QP-nano source code. These deviations are intentionally localized to QP-nano code and are independent from your application-level code. In other words, a MISRA-C deviation present in the QP-nano code does not mean that such deviation is somehow allowed or its detection is somehow suppressed in the application-level code. This is because the the options.lnt configuration file for internals of QP-nano is not used to "lint" the application-level code.

Linting QP-nano Application Code

The QP-nano baseline code contains an example of MISRA-C compliance checking with PC-Lint-Plus: the DPP example for the EK-TM4C123GLX Cortex-M4F board, located in the directory qpn/examples/arm-cm/dpp_ek-tm4c123gxl/lint-plus. The PC-Lint-Plus analysis is very simple and requires invoking the lin.bat file.

Note
In order to execute the lin.bat file on your system, you might need to adjust the symbol PCLP_DIR at the top of the batch file, to the PC-Lint-Plus installation directory on your computer. You

The lint-plus subdirectory contains also the options.lnt with the PC-Lint-Plus options specific to linting the application. Here, you might include linting options for your specific compiler, as described in the "PC-Lint-Plus Manual", Chapter 2 "Installation and Configuration".

Structure of PC-Lint-Plus Options for QP-nano

PC-Lint-Plus has several places where it reads its currently valid options:

  • From special PC-Lint-Plus option files (usually called *.lnt)
  • From the command line
  • From within the special lint-comments in the source code modules (not recommended)

The QP-nano source code and example application code has been "linted" only by means of the first alternative (option files) with possibility of adding options via command line. The third alternative–lint comments–is not used and Quantum Leaps does not recommend this alternative.

Note
The QP-nano source code is completely free of lint comments, which are viewed as a contamination of the source code.

The structure of the PC-Lint-Plus option files used for "linting" QP-nano follows exactly the Gimpel Software guidelines for configuring PC-Lint-Plus (See Section 2 "Configuration" in the PC-Lint-Plus Manual). The design and grouping of the lint options also reflects the fact that static code analysis of a software framework, such as QP-nano, has really two major aspects. First, the source code of the framework itself has to be analyzed. But even more important and helpful to the users of the framework is providing the infrastructure to effectively analyze the application-level code based on the framework. With this in mind, the PC-Lint-Plus options for static analysis of QP-nano are divided into two groups, located in directories qpn/include and qpn/ports/lint. These two groups are for analyzing QP-nano applications and QP-nano source code, respectively.

As shown in the PC-Lint-Plus "port" files description, the directory qpn/include, contains the PC-Lint-Plus options for "linting" the application code along with all platform-independent QP-nano header files required by the applications. This collocation of lint options with header files simplifies "linting", because specifying just -iqpn/include include directory to PC-Lint-Plus accomplishes both inclusion of QP-nano header files and PC-Lint-Plus options. Note that the qpn/include directory contains all PC-Lint-Plus option files used in "linting" the code, including the standard MISRA-C:2012 au-misr3.lnt option file as well as Dan Saks' recommendations au-ds.lnt, which are copied from the PC-Lint-Plus distribution. This design freezes the lint options for which the compliance has been checked.

The std.lnt option file

According to the Gimpel Software PC-Lint-Plus Configuration Guidelines, the file qpn/ports/lint-plus/std.lnt file, contains the top-level options, which Quantum Leaps recommends for all projects. These options include the formatting of the PC-Lint-Plus messages and making two passes to perform better cross-module analysis. However, the most important option is -restore_at_end, which has the effect of surrounding each source file with options -save and -restore. This precaution prevents options from "bleeding" from one file to another.

Top-level option file std.lnt

// message formatting options...
-hF1 // output: a single line
+ffn // use full path names
//-"format=%(\q%f\q %l %C%) %t %n: %m"
//-width(0,0) // do not break lines
-width(120,4) // break lines after 99 characters with 4 characters indent
+flm // make sure no foreign includes change the format
// language standard...
-std=c89
-d__STDC_VERSION__=199409L // C89 Standard last ammended 1994-04
//-std=c99
//-d__STDC_VERSION__=199901L // C99 Standard 1999-01
+rw(inline, entry)
-zero(99) // don't stop because of warnings
-passes(2) // make two passes (for better error messages)
-restore_at_end // don't let -e<nn> options bleed to other files
-summary() // produce a summary of all produced messages
// globally supress the following warning:
-e546 // explicitly taking address of function
-e717 // monocarpic do-while used to group statements

The qpn.lnt option file

The most important file for "linting" QP-nano applications is the qpn.lnt option file. This file handles all deviations from the MISRA-C:2012 rules, which might arise at the application-level code from the use of the QP-nano framework. In other words, the qpn.lnt option file allows completely clean "linting" of the application-level code, as long as the application code does not violate any of the MISRA-C:2012 rules.

At the same time, the qpn.lnt option file has been very carefully designed not to suppress any MISRA-C:2012 rule checking outside the very specific context of the QP-nano API. In other words, the qpn.lnt option file still supports 100% of the MISRA-C:2012 rule checks that PC-Lint-Plus is capable of performing.

Remarks
For example, for reasons explained in Section 5.10 of the "QP-nano MISRA Compliance Matrix", QP-nano extensively uses function-like macros, which deviates from the MISRA-C:2012 advisory Rule 4.9 and which PC-Lint-Plus checks with the warning 9026. However, instead of suppressing this warning globally (with the -e9096 directive), the qpn.lnt option file suppresses warning 9096 only for the specific QP function-like macros that are visible to the application level. So specifically, the qpn.lnt file contains directives -esym(9026, Q_TRAN, Q_SUPER, ...), which suppresses the warning only for the specified macros, but does not disable checking of any other macros in the application-level code.

NEXT : ARM Cortex-M