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 an intrinsic to track variable values. The LLVM core libraries generate debug information in DWARF format on Unix systems and in Protein Data Bank (PDB) format for Windows. We take a look at the general structure in the next section.
Understanding the general structure of debug metadata
To describe the static structure, LLVM uses metadata in a similar way to the metadata for type-based analysis. The static structure describes the file, the compilation unit, functions, lexical blocks, and the used data types.
The main class we use is llvm::DIBuilder
, and we need to use the llvm/IR/DIBuilder
include file to get the class declaration. This builder class provides an easy-to-use interface to create the debug metadata. The metadata is later either added to...