Skip to content

LLDB crashes when printing a clang::TemplateDecl object #66335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kasuga-fj opened this issue Sep 14, 2023 · 6 comments
Open

LLDB crashes when printing a clang::TemplateDecl object #66335

kasuga-fj opened this issue Sep 14, 2023 · 6 comments
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] lldb

Comments

@kasuga-fj
Copy link
Contributor

LLDB crashed when I tried printing an object while debugging clang++.

Here is the stack trace.

$ /path/to/lldb /path/to/clang++
(lldb) target create "/path/to/clang++"
Current executable set to '/path/to/clang++' (x87_64).
(lldb) b Sema::DeclareImplicitDeductionGuides
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) run -cc1 main.cpp
Process 3231335 launched: '/path/to/clang++' (x86_64)
1 location added to breakpoint 1
Process 3231335 stopped
* thread #1, name = 'clang++', stop reason = breakpoint 1.1
    frame #0: 0x00007ffff05c5ce3 libclang-cpp.so.18git`clang::Sema::DeclareImplicitDeductionGuides(this=0x000055555569fd10, Template=0x00005555556b34d0, Loc=(ID = 76)) at SemaTemplate.cpp:2617:75
   2614 void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
   2615                                           SourceLocation Loc) {
   2616   if (CXXRecordDecl *DefRecord =
-> 2617           cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) {
   2618     if (TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate())
   2619       Template = DescribedTemplate;
   2620   }
(lldb) p *Template
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /path/to/lldb /path/to/clang++
1.      HandleCommand(command = "p *Template")
2.      <eof> parser at end of file
3.      <lldb wrapper prefix>:43:16: Generating code for declaration 'clang::Sema::$__lldb_expr'
  #0 0x00007f76d0569c40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/path/to/libLLVM-18git.so+0x7f5c40)
  #1 0x00007f76d056720e SignalHandler(int) Signals.cpp:0:0
  #2 0x00007f76cf954520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
  #3 0x00007f76cc9da68b clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb368b)
  #4 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #5 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #6 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #7 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #8 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #9 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #10 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #11 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #12 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 ...... (omitted since the stack frame is the same)
#245 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#246 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#247 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#248 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#249 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#250 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#251 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#252 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#253 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#254 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#255 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
LLDB diagnostics will be written to /tmp/diagnostics-f465ea
Please include the directory content when filing a bug report
Segmentation fault (core dumped)

LLDB diagnostics is as follows.

$ ls /tmp/diagnostics-f465ea/
diagnostics.log
$ cat /tmp/diagnostics-f465ea/diagnostics.log
$

The main.cpp I passed to clang++ is as follows.

struct X {
  X(const T&);
};

void f() {
  auto x = X(42);
}

The versions of lldb/clang++ are

$ /path/to/lldb --version
lldb version 18.0.0git (${upstream url} revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a)
  clang revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a
  llvm revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a

$ /path/to/clang++ --version
clang version 18.0.0 (${upstream url} f8f934e22c4a9dc7abaaddf422c8725bacf2048a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to 

GDB prints the object correctly.

...
(gdb) p *Template
$1 = {<clang::NamedDecl> = {<clang::Decl> = {_vptr.Decl = 0x7ffff7f47df0 <vtable for clang::ClassTemplateDecl+16>, NextInContextAndBits = {Value = {Data = "h:kUUU\000"}},
      DeclCtx = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 0, clang::DeclContext*, clang::Decl::MultipleDC*>> = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 1, clang::Decl::MultipleDC*>> = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 2>> = {Val = {Value = {Data = "p\243fUUU\000"}}}, <No data fields>}, <No data fields>}, <No data fields>}, Loc = {ID = 31}, DeclKind = 30, InvalidDecl = 0, HasAttrs = 0, Implicit = 0, Used = 0,
      Referenced = 0, TopLevelDeclInObjCContainer = 0, static StatisticsEnabled = false, Access = 3, FromASTFile = 0, IdentifierNamespace = 38, CacheValidAndLinkage = 0}, Name = {Ptr = 93824993767936}},
  TemplatedDecl = 0x5555556b3440, TemplateParams = 0x5555556b3428}
@github-actions github-actions bot added clang Clang issues not falling into any other category new issue labels Sep 14, 2023
@kasuga-fj
Copy link
Contributor Author

The clang has been added, but I think it's a bug of lldb (I can't edit the labels, sorry)

@Michael137 Michael137 added lldb and removed clang Clang issues not falling into any other category labels Sep 14, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 14, 2023

@llvm/issue-subscribers-lldb

LLDB crashed when I tried printing an object while debugging clang++.

Here is the stack trace.

$ /path/to/lldb /path/to/clang++
(lldb) target create "/path/to/clang++"
Current executable set to '/path/to/clang++' (x87_64).
(lldb) b Sema::DeclareImplicitDeductionGuides
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) run -cc1 main.cpp
Process 3231335 launched: '/path/to/clang++' (x86_64)
1 location added to breakpoint 1
Process 3231335 stopped
* thread #1, name = 'clang++', stop reason = breakpoint 1.1
    frame #0: 0x00007ffff05c5ce3 libclang-cpp.so.18git`clang::Sema::DeclareImplicitDeductionGuides(this=0x000055555569fd10, Template=0x00005555556b34d0, Loc=(ID = 76)) at SemaTemplate.cpp:2617:75
   2614 void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
   2615                                           SourceLocation Loc) {
   2616   if (CXXRecordDecl *DefRecord =
-> 2617           cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) {
   2618     if (TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate())
   2619       Template = DescribedTemplate;
   2620   }
(lldb) p *Template
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /path/to/lldb /path/to/clang++
1.      HandleCommand(command = "p *Template")
2.      <eof> parser at end of file
3.      <lldb wrapper prefix>:43:16: Generating code for declaration 'clang::Sema::$__lldb_expr'
  #0 0x00007f76d0569c40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/path/to/libLLVM-18git.so+0x7f5c40)
  #1 0x00007f76d056720e SignalHandler(int) Signals.cpp:0:0
  #2 0x00007f76cf954520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
  #3 0x00007f76cc9da68b clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb368b)
  #4 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #5 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #6 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #7 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #8 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #9 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #10 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #11 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #12 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 ...... (omitted since the stack frame is the same)
#245 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#246 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#247 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#248 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#249 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#250 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#251 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#252 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#253 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#254 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#255 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
LLDB diagnostics will be written to /tmp/diagnostics-f465ea
Please include the directory content when filing a bug report
Segmentation fault (core dumped)

LLDB diagnostics is as follows.

$ ls /tmp/diagnostics-f465ea/
diagnostics.log
$ cat /tmp/diagnostics-f465ea/diagnostics.log
$

The main.cpp I passed to clang++ is as follows.

struct X {
  X(const T&);
};

void f() {
  auto x = X(42);
}

The versions of lldb/clang++ are

$ /path/to/lldb --version
lldb version 18.0.0git (${upstream url} revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a)
  clang revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a
  llvm revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a

$ /path/to/clang++ --version
clang version 18.0.0 (${upstream url} f8f934e22c4a9dc7abaaddf422c8725bacf2048a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to 

GDB prints the object correctly.

...
(gdb) p *Template
$1 = {<clang::NamedDecl> = {<clang::Decl> = {_vptr.Decl = 0x7ffff7f47df0 <vtable for clang::ClassTemplateDecl+16>, NextInContextAndBits = {Value = {Data = "h:kUUU\000"}},
      DeclCtx = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 0, clang::DeclContext*, clang::Decl::MultipleDC*>> = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 1, clang::Decl::MultipleDC*>> = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 2>> = {Val = {Value = {Data = "p\243fUUU\000"}}}, <No data fields>}, <No data fields>}, <No data fields>}, Loc = {ID = 31}, DeclKind = 30, InvalidDecl = 0, HasAttrs = 0, Implicit = 0, Used = 0,
      Referenced = 0, TopLevelDeclInObjCContainer = 0, static StatisticsEnabled = false, Access = 3, FromASTFile = 0, IdentifierNamespace = 38, CacheValidAndLinkage = 0}, Name = {Ptr = 93824993767936}},
  TemplatedDecl = 0x5555556b3440, TemplateParams = 0x5555556b3428}

@Michael137
Copy link
Member

Doesn't repro for me on my M1 Mac. I'll check on my Linux x86 machine

What does your ~/.lldbinit look like? Also, if this still reproduces, could you do the following:

  1. put log enable lldb expr types -f /tmp/lldb.log into your ~/.lldbinit
  2. reproduce the crash
  3. Attach /tmp/lldb.log here

@EugeneZelenko EugeneZelenko added crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Sep 15, 2023
@kasuga-fj
Copy link
Contributor Author

~/.lldbinit didn't exist on my machine. I created ~/.lldbinit as you mentioned and the issue was still reproduced. /tmp/lldb.log is attached (the file is zipped because it's too large).
lldb.log.zip

@Michael137
Copy link
Member

Couldn't reproduce on my Ubuntu x86_64 machine either with top-of-tree clang/lldb

How are you building clang/lldb? Could you provide your cmake and build invocations please?

@kasuga-fj
Copy link
Contributor Author

I built lldb by with the following commands (there are unrelated components, but there is a no problem).

$ cmake \
  -G Ninja \
  -DCMAKE_INSTALL_PREFIX=/path/to/install \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_LINK_LLVM_DYLIB=ON \
  -DLLVM_TARGETS_TO_BUILD=host \
  -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
  -DLLVM_ENABLE_PROJECTS="clang;flang;mlir;lldb" \
  -DLLVM_ENABLE_RUNTIMES="compiler-rt;openmp;libcxx;libcxxabi" \
  /path/to/llvm
$ ninja
$ ninja install

Then I built clang in debug mode.

$ cmake \
  -G Ninja \
  -DCMAKE_INSTALL_PREFIX=/path/to/install-clang \
  -DCMAKE_BUILD_TYPE=Debug \
  -DLLVM_LINK_LLVM_DYLIB=ON \
  -DLLVM_TARGETS_TO_BUILD=host \
  -DLLVM_ENABLE_PROJECTS="clang" \
  ../../llvm
$ ninja
$ ninja install

This is my first time building and using lldb, so I may have made some odd mistakes...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] lldb
Projects
None yet
Development

No branches or pull requests

4 participants