How to debug clang for learning?

I cloned the llvm-project and compiled the clang by:

-DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm

Then using gdb or lldb to debug clang, setting the breakpoint and runing:

lldb bin/clang++
(lldb) b DiagnoseUninstantiableTemplate
Breakpoint 1: where = clang++`clang::Sema::DiagnoseUninstantiableTemplate(clang::SourceLocation, clang::NamedDecl*, bool, clang::NamedDecl const*, clang::NamedDecl const*, clang::TemplateSpecializationKind, bool) + 59 at SemaTemplate.cpp:790:3, address = 0x00000000075869eb
(lldb) r test.cpp

but it doesn’t break on breakpoint, test.cpp code as below:

template<typename ...>
struct dump;
int main() {
    dump<int> x;
}

Why it does’n break on? I tried break on driver.cpp:main it will success.

The clang driver will fork itself into a subprocess. You have two ways to achieve what you want:

  1. Disable the forking behavior by adding -fintegrated-cc1 on the command line

  2. Invoke clang cc1 yourself directly (this is what the driver will invoke). To see the cc1 invocation, add -### to your clang command line.