Local build processes failing in kwinject-enabled builds

Occasionally, kwinject's process interception/monitoring mechanism can interfere with the process itself.

You can use the attach and detach keywords to specify a list of commands which kwinject should not intercept when monitoring your build. kwinject will detach from the specified processes as soon as they are started.

On Linux, the top-level process when running kwinject is ignored. You can detach kwinject in a child process.

To define a set of commands that kwinject should detach from, you edit the compiler mapping file, located at <klocwork_install>/config/kwfilter.conf.

When the list of commands to detach from is short, add a single detach line to kwfilter.conf.

When the list of commands becomes long, use the detach keyword to specify patterns (such as "detach from all programs within this directory" or "detach from all programs with a specific prefix"). Use the attach keyword to add exceptions to the detach rules (for example, "detach from all programs, except compiler and linker").

The attach and detach lines should be added underneath the filter binding line for the applicable compiler, and should have the following syntax:

detach <prog_name>[, <prog_name> ...]

where<prog_name> is one or more executables that you do not want kwinject to intercept

attach <prog_name>[, <prog_name> ...]

where<prog_name> is one or more exceptions to the rule specified with the detach keyword

Use one of the following formats for <prog_name>:

  • the short name of the command (for example, cl.exe)
  • the absolute path to the command
  • a partial path (for example, sdk\bin\cl.exe)

<prog_name> is a glob-like pattern, so it can contain:

  • * wildcard (any sequence of characters) - for example,sdk\bin\*.exe
  • ? wildcard (any character)

Example 1: Using the detach keyword (Windows)

filter mscompile cl
...
detach bad1.exe, bad2.exe

Example 2: Using both the attach and detach keywords (Windows)

filter mscompile cl
...
attach build.exe, nmake.exe
detach public\common\bin\*.exe, sdk\bin\*.exe
detach msbuild.exe 

Example 3: Detaching kwinject using a child process (Linux)

To detach a process called 'child', consider the following steps:

  1. Create a child process called 'child', with the contents:

    #!/bin/sh
    gcc test.c
  2. Add the following line to kwfilter.conf:

    detach child
    As the child process contains the compilation, we can still create a build spec by calling it directly with kwinject. In this example, the detach is not applied:
    kwinject ./child
  3. Create a parent process called 'parent', with the contents to call the child process:

    #!/bin/sh
    ./child
  4. To detach the child process, we need to call the parent process with kwinject. This will apply the detach to the child process and thus, no compilation will be traced, resulting in an empty build spec:

    kwinject ./parent