clang with -emit-llvm


I have just started using llvm. I was trying to debug how clang generates IR for very simple C testcases (few assignments and if-condsitions).
To get a hold on the basic functions, I put some break points on following functions but debugger didn’t stop:

llvm::BinaryOperator::CreateAdd (design has binary op)
llvm::BranchInst::Create (design has if/else)

and quite a few

The command line I used :

clang -S test.c -emit-llvm -o -

Here I could see the entire LLVM code generated and shown in stdout. I am almost sure that I have missed something very basic. Can anyone please help me in setting proper breakpoints so that I can debug through the entire IR generation phase.

Sorry for asking this basic question.


Clang executes itself in a child process to do the actual work. To get working breakpoints you can either tell your debugger to follow child processes, e.g. "set follow-fork-mode child" in GDB, or run clang with the -### argument and use the command line that begins with -cc1 for debugging.

- Ben


Are you attaching debugger to clang? In this case - clang is just a driver, that invokes other executables for each individual step of compilation. Most likely you should debug clang’s cc1:

marcusmae@M17xR4:~/rpmbuild/BUILD/llvm/build$ gdb clang
(gdb) b llvm::BasicBlock::Create
Breakpoint 1 at 0x9f0965: file /home/marcusmae/rpmbuild/BUILD/llvm/build/include/llvm/BasicBlock.h, line 104.
(gdb) r -cc1 -S test.c -emit-llvm -o -
Starting program: /home/marcusmae/rpmbuild/CHROOT/opt/kernelgen/bin/clang -cc1 -S test.c -emit-llvm -o -
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/home/marcusmae/rpmbuild/CHROOT/opt/kernelgen/lib/”.

Breakpoint 1, llvm::BasicBlock::Create (Context=…, Name=…, Parent=0x22df6f0, InsertBefore=0x0)
at /home/marcusmae/rpmbuild/BUILD/llvm/build/include/llvm/BasicBlock.h:104
104 return new BasicBlock(Context, Name, Parent, InsertBefore);

  • D.

2013/1/1 Somenath Chakraborty <>