How to debug passes

Hi,

Could you please confirm the following steps for debugging a pass?

  1. copy your pass into llvm/lib/Transforms/Hello/Hello.cpp

  2. name you pass Hello

  3. insert debug messages like:

errs() << "Vis­iting func­tion " << F.get­Name();

``4. get LLVM bitcode:
`

    clang -O3 -emit-llvm hello.c -c -o hello.bc

`

Hi Iulia,

You can skip step 5 - it's not required. opt will happily work with *.ll
as well as *.bc files. Since textual form _is_ much easier to read for
humans, you can generate it directly in step 4:

clang -O3 -emit-llvm -S hello.c -c -o hello.ll

Otherwise your steps look correct (assuming that when registering your
pass with RegisterPass<> you used 'dummypass' as the name for your
pass). Did you verify that hello.ll contains any functions? And have you
tried similar steps with the Hello pass?

-Andrzej

Hi,

Actually I copy-pasted step 5 from the article in which I found the solution, in the text of the mail so that is why dummypass appears instead of hello. I used hello instead of dummypass in my tries, but it still doesn’t display nothing after recompiling the pass. The hello.c file contains several functions, so the module pass should display something (I placed a message at the verry beginning of the runOnModule funtion of the pass). I am compiling all the code once with ninja on Linux and I have seen that the hello pass is compiled as well. I have not compiled it separatelly.

Do you have any ideas why is this?

Thank you,
Iulia

Trimis de pe smartphone-ul meu Samsung Galaxy.

-------- Mesaj original --------
De la: Andrzej Warzynski Andrzej.Warzynski@arm.com
Către: Iulia Stirb iulia_s24@yahoo.com, via Llvm-dev llvm-dev@lists.llvm.org, nd nd@arm.com
Subiect: Re: [llvm-dev] How to debug passes

Hi Iulia,

You can skip step 5 - it’s not required. opt will happily work with *.ll
as well as *.bc files. Since textual form is much easier to read for
humans, you can generate it directly in step 4:

clang -O3 -emit-llvm -S hello.c -c -o hello.ll

Otherwise your steps look correct (assuming that when registering your
pass with RegisterPass<> you used ‘dummypass’ as the name for your
pass). Did you verify that hello.ll contains any functions? And have you
tried similar steps with the Hello pass?

-Andrzej