How can I debug cc1?

I am trying to implement a new C++ OpenMP feature, which is partially working as it should. When I call the clang++ driver, everything works as expected. But when trying to write tests for clang_cc1 the functions that I have modified are not called during LLVM IR code generation.

I have installed the debug version of the compiler, but I don’t know where to put break points since the functions I modified are not called as I thought they would be. Do anybody have tips to how I can find out what functions are called during code generation using gdb?

I’d get full list of cc1 options from clang++ using -### option, and then find the cc1 option that makes breakpoints in your functions work.

2 Likes

You can also to use “b cc1_main”, and then “r -cc1”, for example:

$ gdb --args ./llvm_16.0.6/bin/bin/clang hello.c

Reading symbols from ./llvm_16.0.6/bin/bin/clang…
(gdb) b cc1_main
Breakpoint 1 at 0x2d9234a: file /home/zzy/llvm_16.0.6/llvm-project/clang/tools/driver/cc1_main.cpp, line 185.
(gdb) r -cc1
Starting program: /home/zzy/llvm_16.0.6/bin/bin/clang -cc1
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/lib/x86_64-linux-gnu/libthread_db.so.1”.

Breakpoint 1, cc1_main (Argv=…,
Argv0=0x55555977ba00 std::shared_mutex::unlock()+28 “\220\311Ð\363\017\036\372UH\211\345H\203\354\020H\211}\370H\213E\370H\211\307\350J\377\377\377\220\311Ð\363\017\036\372UH\211\345H\203\354\020H\211}\370H\213E\370H\211\307\350d\377\377\377\220\311Ð\363\017\036\372UH\211\345H\203\354\020H\211}\370H\213E\370H\211\307\350\374\002”, MainAddr=0x7fffffffc410) at /home/zzy/llvm_16.0.6/llvm-project/clang/tools/driver/cc1_main.cpp:185
185 int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
(gdb) bt
#0 cc1_main (Argv=…,
Argv0=0x55555977ba00 std::shared_mutex::unlock()+28 “\220\311Ð\363\017\036\372UH\211\345H\203\354\020H\211}\370H\213E\370H\211\307\350J\377\377\377\220\311Ð\363\017\036\372UH\211\345H\203\354\020H\211}\370H\213E\370H\211\307\350d\377\377\377\220\311Ð\363\017\036\372UH\211\345H\203\354\020H\211}\370H\213E\370H\211\307\350\374\002”, MainAddr=0x7fffffffc410) at /home/zzy/llvm_16.0.6/llvm-project/clang/tools/driver/cc1_main.cpp:185
#1 0x00005555582d39dc in ExecuteCC1Tool (ArgV=…) at /home/zzy/llvm_16.0.6/llvm-project/clang/tools/driver/driver.cpp:360
#2 0x00005555582d41ae in clang_main (Argc=2, Argv=0x7fffffffe398) at /home/zzy/llvm_16.0.6/llvm-project/clang/tools/driver/driver.cpp:435
#3 0x000055555830a35f in main (argc=2, argv=0x7fffffffe398) at tools/clang/tools/driver/clang-driver.cpp:11

3 Likes

Thank you so much! I will definitely try your suggestions.