Antithesis logomark
DOCS

C/C++ Instrumentation

Prerequisites

Instrumentation for C and C++ is packaged with the C++ SDK. Instrumentation is supported by the header file antithesis_instrumentation.h. This file must be included in one, and only one translation unit at link time. Coverage instrumentation requires Clang 13 or higher, and either C++ 11 or higher or C89 or higher.

We recommended that you include the instrumentation header in the file where you define the main function, as follows:

#include "antithesis_instrumentation.h"

Build Requirements

Your instrumented binary must be built with libraries and dependencies that it will use at runtime.

Add the following compile flag:

-fsanitize-coverage=trace-pc-guard -g

And add the following link flag:

--build-id

If your build process includes a single compile/link step, then add both compile and link flags with the following:

-fsanitize-coverage=trace-pc-guard -g -Wl,--build-id

Validation

To confirm that the instrumentation process was successful, you can run the command nm to list all the symbols in a binary, and then grep the string “antithesis_load_libvoidstar”.

$ nm client_binary | grep "antithesis_load_libvoidstar"
T antithesis_load_libvoidstar

Notice the “T” character in the previous code block: it means the symbol is in the text (code) section.

If this does not work you probably failed to include the header file.

Symbolization

The LLVM compiler infrastructure will output debug symbols in the DWARF format. Antithesis needs either the original unstripped binary, or the binary together with its debug info (as produced by objcopy --only-keep-debug and --add-gnu-debuglink). Symlink (or move) these files into a directory named /symbols in the root of the appropriate container image.

Antithesis labels the coverage it reports for each binary with the binary’s file name.

Help

Contact us if you need help with this.