C++ (with Klocwork)#

The Klocwork module reads data generated by Klocwork’s kwbuildproject utility. Klocwork Version 10 and higher stores its data in the kwtables directory. Earlier versions of Klocwork stored the data in a MySql database. Lattix can read in data from both sources.

Model Generation from kwtables Directory (for Klocwork Version 10+)#

Introduction#

As of Klocwork version 10, Klocwork no longer stores its entity / relational data in MySql databases. The current release of Lattix Architect supports extracting Klocwork entity / relational from the kwtables directory generated by the kwbuildproject Klocwork Utility.

Run the Klockwork command:

kwinject --output specfile.out <build_command>
which creates the specfile.out file.
For instance, if you build with the make command, run:
kwinject ---output specfile.out make

Then you can run:

kwbuildproject.exe --url URL-to-klockwork-project --tables-directory output-kwtables-dir specfile.out
Which creates the output-kwtables-dir.
More information can be found on the Klocwork site here.

Creating a model#

image5

  • Select New Project from the File menu

  • Set Module Type to “C/C++ Klocwork”

  • Select your kwtables directory in the Input Sources

  • Press “Add Directory”

  • Press “Create Project”

Model Generation from MySql (for Klocwork Version 9 and earlier)#

Configuring Lattix to Work with Klocwork#

In order to work with Klocwork data, you will need to obtain and install a MySql JDBC driver.

  • Download the JDBC driver from http://dev.mysql.com/downloads/connector/j/5.1.htm. The driver can also be found in Server/class/mysql-connector.jar in your Klocwork server installation.

  • Install the JAR file (called mysql-connector-java-5.1.10-bin.jar as of this writing) containing the JDBC driver into the libplugins directory of your Lattix installation (typically c:\Program Files\Lattix9.0\lib\plugins in your Lattix installation)

Creating a Lattix Project with the Klocwork Module#

Creating a Lattix Project with the Klocwork module is a fairly straightforward process:

  • Start Lattix and select New Project from the File menu

  • Set the module type of project to C++ (Klocwork)

  • Press the Add button

Lattix displays a dialog box that looks something like this:

image6

  • Enter information about the server containing the Klocwork database. The username for a Klocwork database is usually kw - case sensitive. Typically there is no password.

  • Once the host, port, username and password is filled out, you can expand the Project drop down list box to display the list of Klocwork projects available in the database. Select the desired project.

  • Please note that Klocwork has changed the default port from 3313 to 3306. If you are unable to connect to the Klocwork MySql database from one port, please try using the other port to connect.

  • Once the project is selected, you can select the desired build. Selecting <Newest> or not selecting a build will use the latest build as input.

  • Press OK to add the connection to the project.

  • Press Create Project to create the project.

Atom and Dependency Kinds#

Atom Kinds#

This module creates atoms of these kinds:

  • Header File

  • Source File

  • Macro

  • Abstract Class

  • Class - class, struct

  • Class Field

  • Class Method

  • Constant

  • Global Function

  • Global Variable

  • Template Class

  • Template Class Method

  • Template Function

Dependency Kinds#

This module creates dependencies between atoms of the following kinds:

  • Data

    • Read Global - Read a global variable.

    • Read Field - Read a class member field.

    • References - Data reference to a non-scalar value (i.e. a struct).

    • Modify Global - Write to a global variable

    • Modify Field - Write to a class field.

  • Class

    • Reference - Reference to a class

    • Inherit - Reference from a derived class to a base class

    • Weak Type - This dependency kind is a type reference that does not require the full definition. For example struct MyStruct *mystructp generates a Week Type reference that mystructp uses struct MyStruct. Similarly, class MyClass; MyClass *myclassp; produces a Weak Type reference that myclassp uses MyClass. The Weak Type dependency kind is filtered by default.

  • Method

    • Override - Reference from a method in a derived class to the method it overrides in a base class

    • Invoke - Call a function

    • Invoke Declaration - Reference to the forward declaration used to compile a function call.

    • Call Function Pointer - Reference to a variable containing a function pointer used for an indirect function call

  • Declaration

  • Macro

    • Use Macro

    • Configuration Macro

Klocwork Module Project Options#

There are several project options that control the behavior of the Klocwork module. The options can be specified at project creation time by selecting the Options tab in the Create New Project dialog or by selecting Project Properties from the Project menu and clicking on Options under C++ (Klocwork). Here are the options for the Klocwork plug-in:

  • Member Level Processing - This tells the module whether it should create atoms for the contents of the files in your Klocwork project. By default, the Klocwork module aggregates file contents dependencies to the file.

  • Dependencies for Members - This tells the module whether dependencies should be aggregated to the file or should be attached to the contents (members) of the file.

  • Show New Members Atoms - When creating atoms for members, the default behavior is to aggregate the created member atoms to their containing file in the DSM. Select Show New Members Atoms causes Lattix to expand the members and make them visible in the DSM.

  • Enable Line Number Processing - In order to reduce memory requirements, the Klocwork plug-in does not preserve line number information for atom definitions and dependencies. Enabling this option preserves line number information. This line number information can be quite useful when used in conjunction with the View Source functionality.

  • Skip symbols matching these patterns (regexp) - This option contains a list of patterns that the Klocwork module uses to exclude atoms with particular names from the DSM. Dependencies on these external atoms appear as externals in the Usage panel. The default set of skipped symbols is configured to remove dependency information for Windows header files.

Command Line Support#

ldcupdate and ldcreport are command line utilities that can be used to update Lattix Projects and to generate generate reports from them. This functionality can be used to automatically update the Lattix Project as part a build procedure. This section provides some examples of using these tools with the Klocwork module.

Examples#

ldcupdate unittests.ldz -module:klc klc:/work/CppConstructs/kwtables

Update project, unittests.ldz, created from the kwtables directory for a Klocwork 10.* project.

ldcupdate unittests.ldz -module:klc klocworkdatabase:host=localhost,port=3313,user=kw,project=unittest

Create new Lattix project, unittests.ldz from the latest build of the unittest project in the Klocwork 9.* repository. The command line assumes that the MySQL for the repository is running on the local machine, at the typical port, with the user name kw.

ldcupdate unittests.ldz -report:html

Update the project and generate an html report in unittests.html.

ldcreport unittests.ldz -report:html -cycles -violations

Creates a cycles and violations report for unittests.ldz in html format.