Adding debug metadata
To allow source-level debugging, we have to add debug information. Support for debug information in LLVM uses debug metadata to describe the types of the source language and other static information, and intrinsics to track variable values. The LLVM core libraries generate debug information in the DWARF format on Unix systems and in PDB format for Windows. We’ll look at the general structure in the next section.
Understanding the general structure of debug metadata
To describe the general structure, LLVM uses metadata similar to the metadata for type-based analysis. The static structure describes the file, the compilation unit, functions and lexical blocks, and the used data types.
The main class we use is llvm::DIBuilder
, and we need to use the llvm/IR/DIBuilder
header file to get the class declaration. This builder class provides an easy-to-use interface to create the debug metadata. Later, the metadata is either added to LLVM objects such as...