Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable --debug-only in LLVM build with cmake?

I am building LLVM with cmake and Ninja build generator as following:

cmake path/to/llvm/ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=1 -DLLVM_ENABLE_CXX1Y=1 -DLLVM_ENABLE_RTTI=1 -DLLVM_TARGETS_TO_BUILD="X86" -G Ninja

Now I a am trying to use the -debug-only=mytype option of opt to print some debug information about my own passes: using the following in my passes code:

define DEBUG_TYPE "mytype"
DEBUG(errs() << "My debug message\n");

Running opt as following doesn't generate any output messages:

opt < a.bc > /dev/null -mypass -debug-only=mytype

According to LLVM documentation:

For performance reasons, -debug-only is not available in optimized build (--enable-optimized) of LLVM.

I suspect this to be the root of my issue, but I can't find how to turn on/off this option when using cmake to build llvm.

like image 258
Manuel Selva Avatar asked Feb 06 '23 22:02

Manuel Selva


1 Answers

It is controlled by enabling assertions. cmake -DLLVM_ENABLE_ASSERTIONS=ON is enough to turn it on. If you don't see your debug output, then your code is not executed.

like image 179
Joky Avatar answered Feb 08 '23 10:02

Joky