19

I am trying to understand an existing pass in LLVM and thus trying to print the nicely written debug messages in the pass. I am doing so by using clang -debug -some-other-flags. However while compiling it says:

clang: warning: argument unused during compilation: '-debug'

How to enable the debug output?

shrm
  • 1,112
  • 2
  • 8
  • 20

2 Answers2

24

Clang does not have a "debug" command-line option; you need to either build the IR from clang and then run opt -debug separately, or run clang -mllvm -debug.

In general, the -mllvm flag passes whatever appears afterwards on to LLVM itself. Use multiple -mllvm flags if you want to pass multiple options onwards.

Oak
  • 26,231
  • 8
  • 93
  • 152
  • 2
    That seems to work. Thanks. May I ask what is the role of `-mllvm` flag ? – shrm Mar 25 '13 at 14:08
  • 2
    @mishr It passes whatever appears afterwards on to LLVM itself. – Oak Mar 25 '13 at 14:11
  • 4
    If you run passes using Clang, there are likely many of them. In this case, something like `-mllvm -debug-only=simplifycfg` might be helpful. – Sjlver Aug 24 '16 at 09:56
8

In case the accepted answer does not work for you: apart from adding -mllvm -debug, you need clang which is built with debug assertions enabled, which is done by adding -DLLVM_ENABLE_ASSERTIONS=On to cmake options when compiling clang (ref).

gluk47
  • 1,812
  • 20
  • 31