How to use LLDB to single-step debug clang for crash issue?

Greetings! I was trying to use LLDB to single-step debug clang, but couldn’t stop at the breakpoint I added.
The command I executed and the outputs are as follows:

$ lldb ./build/bin/clang test.cc
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'lldb.embedded_interpreter'
(lldb) target create "./build/bin/clang"
Current executable set to '/home/ubuntu/llvm-project/build/bin/clang' (x86_64).
(lldb) settings set -- target.run-args  "test.cc"
(lldb) breakpoint set --method Parser::ParseDeclGroup
Breakpoint 1: where = clang`clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 97 at ParseDecl.cpp:2258:31, address = 0x000000000976e745
(lldb) run
Process 108173 launched: '/home/ubuntu/llvm-project/build/bin/clang' (x86_64)
clang-19: /home/ubuntu/llvm-project/clang/lib/AST/ExprClassification.cpp:72: Cl clang::Expr::ClassifyImpl(clang::ASTContext&, clang::SourceLocation*) const: Assertion `isPRValue()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /home/ubuntu/llvm-project/build/bin/clang-19 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name test.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/ubuntu/llvm-project -fcoverage-compilation-dir=/home/ubuntu/llvm-project -resource-dir /home/ubuntu/llvm-project/build/lib/clang/19 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward -internal-isystem /home/ubuntu/llvm-project/build/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-d2363e.o -x c++ test.cc
1.      test.cc:6:10: at annotation token
2.      test.cc:6:1: parsing function body 'operator*'
3.      test.cc:6:1: in compound statement ('{}')
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang-19  0x000055555ab36086 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 88
1  clang-19  0x000055555ab364a7
2  clang-19  0x000055555ab338f7 llvm::sys::RunSignalHandlers() + 150
3  clang-19  0x000055555ab3591e
4  libc.so.6 0x00007ffff7a49520
5  libc.so.6 0x00007ffff7a9d9fc pthread_kill + 300
6  libc.so.6 0x00007ffff7a49476 raise + 22
7  libc.so.6 0x00007ffff7a2f7f3 abort + 211
8  libc.so.6 0x00007ffff7a2f71b
9  libc.so.6 0x00007ffff7a40e96
10 clang-19  0x0000555560d069bb clang::Expr::ClassifyImpl(clang::ASTContext&, clang::SourceLocation*) const + 561
11 clang-19  0x000055555f44f7f6
12 clang-19  0x000055555fef4ba5 clang::Sema::DeduceAutoType(clang::TypeLoc, clang::Expr*, clang::QualType&, clang::sema::TemplateDeductionInfo&, bool, bool, clang::TemplateSpecCandidateSet*) + 3493
13 clang-19  0x000055555fcc1251 clang::Sema::CheckTemplateArgument(clang::NonTypeTemplateParmDecl*, clang::QualType, clang::Expr*, clang::TemplateArgument&, clang::TemplateArgument&, clang::Sema::CheckTemplateArgumentKind) + 1035
14 clang-19  0x000055555fcbaaa3 clang::Sema::CheckTemplateArgument(clang::NamedDecl*, clang::TemplateArgumentLoc&, clang::NamedDecl*, clang::SourceLocation, clang::SourceLocation, unsigned int, llvm::SmallVectorImpl<clang::TemplateArgument>&, llvm::SmallVectorImpl<clang::TemplateArgument>&, clang::Sema::CheckTemplateArgumentKind) + 1341
15 clang-19  0x000055555fcbba82 clang::Sema::CheckTemplateArgumentList(clang::TemplateDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo&, bool, llvm::SmallVectorImpl<clang::TemplateArgument>&, llvm::SmallVectorImpl<clang::TemplateArgument>&, bool, bool*, bool) + 1164
16 clang-19  0x000055555fcb2d24 clang::Sema::CheckTemplateIdType(clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&) + 842
17 clang-19  0x000055555fcb4868 clang::Sema::ActOnTemplateIdType(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::OpaquePtr<clang::TemplateName>, clang::IdentifierInfo const*, clang::SourceLocation, clang::SourceLocation, llvm::MutableArrayRef<clang::ParsedTemplateArgument>, clang::SourceLocation, bool, bool, clang::ImplicitTypenameContext) + 2176
18 clang-19  0x000055555edc6650 clang::Parser::AnnotateTemplateIdTokenAsType(clang::CXXScopeSpec&, clang::ImplicitTypenameContext, bool) + 378
19 clang-19  0x000055555ec945e5 clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(clang::CXXScopeSpec&, bool, clang::ImplicitTypenameContext) + 1407
20 clang-19  0x000055555ec94036 clang::Parser::TryAnnotateTypeOrScopeToken(clang::ImplicitTypenameContext) + 2438
21 clang-19  0x000055555ed24ce9 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) + 10831
22 clang-19  0x000055555ed21fd0 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) + 98
23 clang-19  0x000055555ed1f5ae clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 288
24 clang-19  0x000055555ed1f2e3 clang::Parser::ParseExpression(clang::Parser::TypeCastState) + 51
25 clang-19  0x000055555edb63ed clang::Parser::ParseReturnStatement() + 679
26 clang-19  0x000055555edad7f2 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) + 2634
27 clang-19  0x000055555edac9b7 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) + 293
28 clang-19  0x000055555edb13ef clang::Parser::ParseCompoundStatementBody(bool) + 1205
29 clang-19  0x000055555edb6900 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) + 356
30 clang-19  0x000055555ec919d1 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) + 4483
31 clang-19  0x000055555ecc31ec clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 2824
32 clang-19  0x000055555edc26ac clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) + 1476
33 clang-19  0x000055555edc2081 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) + 1359
34 clang-19  0x000055555edc1b05 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) + 243
35 clang-19  0x000055555ecc18de clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) + 384
36 clang-19  0x000055555ec8f4bf clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 3095
37 clang-19  0x000055555ec8e7e2 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) + 2184
38 clang-19  0x000055555ec8981c clang::ParseAST(clang::Sema&, bool, bool) + 749
39 clang-19  0x000055555bc7a866 clang::ASTFrontendAction::ExecuteAction() + 332
40 clang-19  0x000055555b946330 clang::CodeGenAction::ExecuteAction() + 106
41 clang-19  0x000055555bc7a110 clang::FrontendAction::Execute() + 158
42 clang-19  0x000055555bb8570b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1047
43 clang-19  0x000055555be3149d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 931
44 clang-19  0x00005555569e82f3 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 1725
45 clang-19  0x00005555569d90d6
46 clang-19  0x00005555569d962b clang_main(int, char**, llvm::ToolContext const&) + 820
47 clang-19  0x0000555556a14dcc main + 143
48 libc.so.6 0x00007ffff7a30d90
49 libc.so.6 0x00007ffff7a30e40 __libc_start_main + 128
50 clang-19  0x00005555569d8465 _start + 37
Process 108173 stopped and restarted: thread 1 received signal: SIGCHLD
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 19.0.0git (git@github.com:simonzgx/llvm-project.git cd9bab2e2acbdc22943703d5649dede72b09cad7)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/ubuntu/llvm-project/build/bin
Build config: +unoptimized, +assertions
Process 108173 stopped and restarted: thread 1 received signal: SIGCHLD
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/test-97899f.cpp
clang: note: diagnostic msg: /tmp/test-97899f.sh
clang: note: diagnostic msg: 

********************
Process 108173 exited with status = 1 (0x00000001)

It would be great if someone could help.

Is it possible you were starting with clang-the-driver and it spawned a subprocess which crashed?

(lldb) run

Process 108173 launched: '/home/ubuntu/llvm-project/build/bin/clang' (x86_64)

Process 108173 stopped and restarted: thread 1 received signal: SIGCHLD

Process 108173 exited with status = 1 (0x00000001)

This makes me suspicious.

minor aside, br s -M Parser::ParseDeclGroup idk the name rules, but I would have probably used br s -n Parser::ParseDeclGroup because it’s not a method name. but it clearly resolved to the intended method. You could have prob also just don b Parser::ParseDeclGroup and that would work; b is a series of regular expressions that rewrite to the most likely breakpoint set options, it usually does exactly what the user expected.

1 Like

don’t the people working on clang pass like -### on the compile line to see what the driver executes, and then run the printed line instead? I’ve never worked on clang, that’s just a vague memory.

1 Like

Thanks for your reply! I will try your suggestions and update here if any progress is made.

Yes, you should debug frontend invocation, i.e. clang -cc1. You can use -### to get the arguments. There’s going to be a lot of them, but it typically boils down to just few, e.g. -std=c++20.

1 Like

Yes, once I execute clang test.cc -### to get the full arguments and append them to the LLDB debug command, it works fine. Thank you both very much.

These days, also, clang doesn’t use a subprocess if it’s /only/ launching the driver.

So if you’re interested in only a clang crash, you would probably be able to hit your breakpoint if you’d run clang test.cpp -c rather than clang test.cpp (in the latter case, the driver needs to run clang, then lld - so the driver uses subprocesses for both - but in the former, the driver’s only going to run clang, so it skips the subprocess and reuses the driver process for the cc1 work too)

1 Like