Skip to content

ahueck/llvm-meta-meetup

Repository files navigation

llvm-meta-meetup · License

Example project for the LLVM Social Darmstadt meetup talk Opaque pointers, the need for debug information and how to use them. The talk is attached with the initial release of this project, see Releases.

Scope

Finds the corresponding debug intrinsic of allocas and prints their DIType structure to console.

Under lib/pass, the analysis pass to find allocas and their debug intrinsics can be found. The printing of DIType nodes is done with a visitor, see DIVisitor.h.

Example

Given the code:

struct BasicStruct {
  int a;
};
int foo() {
  struct BasicStruct b_struct;
}

The pass will emit the following to console:

  %b_struct = alloca %struct.BasicStruct, align 4:

!14 = !DILocalVariable(name: "b_struct", scope: !9, file: !1, line: 5, type: !15)
!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "BasicStruct", file: !1, line: 1, size: 32, elements: !16)
  !17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 2, baseType: !12, size: 32)
      !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)

The visitor calls traverse and visit for each relevant DINode type. Users of the visitor should override relevant visit functions, e.g., bool visitBasicType(const llvm::DIBasicType* basic_type).

Building llvm-meta-meetup

llvm-meta-meetup requires LLVM >= 10 (tested only with 14 & 15) and CMake version >= 3.20. For testing, llvm-lit is used. Use CMake presets develop or release to build. Refer to the CI file for a complete recipe.

2.1 Build

llvm-meta-meetup uses CMake to build. Example build recipe (release build, installs to default prefix ${llvm-meta-meetup_SOURCE_DIR}/install/meta)

$> cd llvm-meta-meetup
$> cmake --preset release
$> cmake --build build --target install --parallel

2.2 Test

Assuming build as described above. Execute the lit test suite:

$> cmake --build build --target check-meta

2.3 Apply

In build/script the script apply.sh is generated to analyze single translation units, see apply.tmpl. It is installed to install-prefix/bin. For debug builds, the script name includes ${CMAKE_DEBUG_POSTFIX} as a postfix.

Example:

$> cd llvm-meta-meetup
$> $install-prefix/bin/apply.sh test/pass/stack_basic_int.c