This is an archive of the discontinued LLVM Phabricator instance.

Don't index the skeleton CU when we have a fission compile unit.
ClosedPublic

Authored by clayborg on Aug 8 2022, 1:51 PM.

Details

Summary

When fission is enabled, we were indexing the skeleton CU _and_ the .dwo CU. Issues arise when users enable compiler options that add extra data to the skeleton CU (like -fsplit-dwarf-inlining) and there can end up being types in the skeleton CU due to template parameters. We never want to index this information since the .dwo file has the real definition, and we really don't want function prototypes from this info since all parameters are removed. The index doesn't work correctly if it does index the skeleton CU as the DIE offset will assume it is from the .dwo file, so even if we do index the skeleton CU, the index entries will try and grab information from the .dwo file using the wrong DIE offset which can cause errors to be displayed or even worse, if the DIE offsets is valid in the .dwo CU, the wrong DIE will be used.

Diff Detail

Event Timeline

clayborg created this revision.Aug 8 2022, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 1:51 PM
Herald added a subscriber: arphaman. · View Herald Transcript
clayborg requested review of this revision.Aug 8 2022, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 1:51 PM
labath added a comment.Aug 9 2022, 8:15 AM

Seems reasonable, but could use a test case, though I'm not sure what would be the best way to approach that. I suppose one could dump the index of one of these dwo-less files, and then make sure it's contents are right (empty?).

The m_dwo_id change also looks like its fixing a bug where we could end up mistakenly associating a regular unit (from the main exe file) with a split unit from a dwp file if that split unit happens to have a dwo id of zero. That might be another test vector.

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
339

What's the relationship of this field and the m_is_dwo flag? Do we need both?

Seems reasonable, but could use a test case, though I'm not sure what would be the best way to approach that. I suppose one could dump the index of one of these dwo-less files, and then make sure it's contents are right (empty?).

That is what I was struggling with. I might be able to use lldb-test to dump a type lookup on a name that used to appear in both the DWO file and in the skeleton compile unit and make sure no error string from the parsing gets emitted? I haven't used lldb-test much, but is this possible to expect output and make sure the error that detected this issue is not emitted once it is fixed? The test would create a binary with -fsplit-dwarf-inlining enabled and make sure that the skeleton compile unit ends up having a type from a type template that _could_ be found if this fix wasn't there, then make sure when we do a type lookup we don't see the error message. Let me know if you have any other ideas on how to do this.

The m_dwo_id change also looks like its fixing a bug where we could end up mistakenly associating a regular unit (from the main exe file) with a split unit from a dwp file if that split unit happens to have a dwo id of zero. That might be another test vector.

yeah, I guess we would test this by making a DWO ID of zero and making sure it works. Doesn't matter if it is in a .dwo file in a .dwp file right? Just a test with a "a.out" binary that contains a skeleton compile unit that has a DWO ID of zero and a corresponding .dwo file that has this same ID inside of it right?

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
339

I think the "m_is_dwo" is set to true if this is a DWO file, where m_dwo_id is for the skeleton compile unit. So they are different and can't be derived from each other if I understand the code correctly.

Seems reasonable, but could use a test case, though I'm not sure what would be the best way to approach that. I suppose one could dump the index of one of these dwo-less files, and then make sure it's contents are right (empty?).

That is what I was struggling with. I might be able to use lldb-test to dump a type lookup on a name that used to appear in both the DWO file and in the skeleton compile unit and make sure no error string from the parsing gets emitted? I haven't used lldb-test much, but is this possible to expect output and make sure the error that detected this issue is not emitted once it is fixed? The test would create a binary with -fsplit-dwarf-inlining enabled and make sure that the skeleton compile unit ends up having a type from a type template that _could_ be found if this fix wasn't there, then make sure when we do a type lookup we don't see the error message. Let me know if you have any other ideas on how to do this.

Yeah, that's pretty much what I had in mind. I think it should be sufficient to run lldb-test symbols on this binary. Among other things, that will dump the contents of the dwarf index, and we can verify that it is empty. A good way to that is to use CHECK/CHECK-NEXT/EMPTY to match the lines before after the place where the output should appear. So, something like this might work:

# CHECK: Function basenames:
## if the next line is empty then no entries have been printed
# CHECK-EMPTY:

So I can't get -fsplit-dwarf-inlining to emit anything when I try to cross with clang. I add the flag but no extra function info gets emitted in the dwarf in the main executable. I tried:

clang++ -gdwarf-5 -gsplit-dwarf -fsplit-dwarf-inlining -c main.cpp -o main2.o

I also tried to create an simple a.out program with a DWO_ID of zero. If it obj2yaml and then to yaml2obj, something gets messed up in the binary, so not sure if ojb2yaml + yaml2obj can handle fission binaries correctly.

Any ideas?

clayborg updated this revision to Diff 454695.Aug 22 2022, 9:50 PM

Added a test case that tests that we can load a .dwo file with a DWO ID of zero.
Was unable to get clang to emit extra stuff in the skeleton compile unit even with -fsplit-dwarf-inlining.

labath accepted this revision.Aug 24 2022, 3:18 AM

So I can't get -fsplit-dwarf-inlining to emit anything when I try to cross with clang. I add the flag but no extra function info gets emitted in the dwarf in the main executable. I tried:

clang++ -gdwarf-5 -gsplit-dwarf -fsplit-dwarf-inlining -c main.cpp -o main2.o

You probably also need to enable optimizations for any inlining to happen (maybe not if you use always_inline). And you need to make the source sufficiently nontrivial so that there is some debug info to produce. For example, this code worked for me:

$ cat main.cpp 
int use(int);

int inlined(int x) { return 1 + use(x); }

int main() { return 2*inlined(57); }
$ clang++ -gdwarf-5 -gsplit-dwarf -fsplit-dwarf-inlining -c main.cpp -O1

I also tried to create an simple a.out program with a DWO_ID of zero. If it obj2yaml and then to yaml2obj, something gets messed up in the binary, so not sure if ojb2yaml + yaml2obj can handle fission binaries correctly.

I'm not surprised that fails, but possible the problem was not with fission. obj2yaml is not good at round-tripping fully linked binaries (with program headers and stuff). Things work much better for .o files (which should be sufficient for your needs here).

I also often find it easier to take the assembly output (clang -s) and tweak that, instead of going all the way to object code and then back to yaml.

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
339

ok. makes sense.

This revision is now accepted and ready to land.Aug 24 2022, 3:18 AM

This seems to trigger a use after free in lldb-api :: functionalities/thread/create_after_attach/TestCreateAfterAttach.py

asan log:

==4741==ERROR: AddressSanitizer: heap-use-after-free on address 0x62f00023bf58 at pc 0x563639db88f1 bp 0x7ffd942412f0 sp 0x7ffd942412e8
READ of size 4 at 0x62f00023bf58 thread T0
    #0 0x563639db88f0 in HasChildren lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h:124:37
    #1 0x563639db88f0 in GetFirstChild lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h:148:12
    #2 0x563639db88f0 in GetFirstChild lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp:101:34
    #3 0x563639db88f0 in child_iterator lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h:107:57
    #4 0x563639db88f0 in DWARFDIE::children() const lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp:466:27
    #5 0x563639d9f4e1 in DWARFASTParserClang::EnsureAllDIEsInDeclContextHaveBeenParsed(lldb_private::CompilerDeclContext) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2203:37
    #6 0x563639f1ab62 in lldb_private::TypeSystemClang::DeclContextFindDeclByName(void*, lldb_private::ConstString, bool) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:9494:22
    #7 0x563639f489fd in lldb_private::CompilerDeclContext::FindDeclByName(lldb_private::ConstString, bool) lldb/source/Symbol/CompilerDeclContext.cpp:20:27
    #8 0x563639b6113c in lldb_private::ClangExpressionDeclMap::LookupLocalVariable(lldb_private::NameSearchContext&, lldb_private::ConstString, lldb_private::SymbolContext&, lldb_private::CompilerDeclContext const&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1084:20
    #9 0x563639b5d7cf in lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&, std::__u::shared_ptr<lldb_private::Module>, lldb_private::CompilerDeclContext const&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1434:9
    #10 0x563639b5c9df in lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:728:5
    #11 0x563639b3df83 in lldb_private::ClangASTSource::FindExternalVisibleDeclsByName(clang::DeclContext const*, clang::DeclarationName) lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp:180:3
    #12 0x56363d02aa30 in clang::DeclContext::lookup(clang::DeclarationName) const clang/lib/AST/DeclBase.cpp:1706:17
    #13 0x56363c2bca5b in LookupDirect(clang::Sema&, clang::LookupResult&, clang::DeclContext const*) clang/lib/Sema/SemaLookup.cpp:1108:39
    #14 0x56363c2b67f5 in CppNamespaceLookup(clang::Sema&, clang::LookupResult&, clang::ASTContext&, clang::DeclContext*, (anonymous namespace)::UnqualUsingDirectiveSet&) clang/lib/Sema/SemaLookup.cpp:1207:16
    #15 0x56363c2b5a1e in clang::Sema::CppLookupName(clang::LookupResult&, clang::Scope*) clang/lib/Sema/SemaLookup.cpp:1495:15
    #16 0x56363c2bc0f2 in clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool, bool) clang/lib/Sema/SemaLookup.cpp:2259:9
    #17 0x56363bdb50b8 in clang::Sema::BuildUsingDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, bool, clang::SourceLocation, clang::CXXScopeSpec&, clang::DeclarationNameInfo, clang::SourceLocation, clang::ParsedAttributesView const&, bool, bool) clang/lib/Sema/SemaDeclCXX.cpp:12329:5
    #18 0x56363bdb49f3 in clang::Sema::ActOnUsingDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec&, clang::UnqualifiedId&, clang::SourceLocation, clang::ParsedAttributesView const&) clang/lib/Sema/SemaDeclCXX.cpp:11833:7
    #19 0x56363b49df12 in clang::Parser::ParseUsingDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) clang/lib/Parse/ParseDeclCXX.cpp:803:26
    #20 0x56363b49c27d in clang::Parser::ParseUsingDirectiveOrDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation&, clang::ParsedAttributes&) clang/lib/Parse/ParseDeclCXX.cpp:512:10
    #21 0x56363b46c161 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) clang/lib/Parse/ParseDecl.cpp:1797:12
    #22 0x56363b55fb99 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) clang/lib/Parse/ParseStmt.cpp:247:16
    #23 0x56363b55cfb6 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) clang/lib/Parse/ParseStmt.cpp:115:20
    #24 0x56363b56c048 in clang::Parser::ParseCompoundStatementBody(bool) clang/lib/Parse/ParseStmt.cpp:1171:11
    #25 0x56363b56e32d in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) clang/lib/Parse/ParseStmt.cpp:2442:21
    #26 0x56363b5988a8 in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) clang/lib/Parse/Parser.cpp:1428:10
    #27 0x56363b47493a in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) clang/lib/Parse/ParseDecl.cpp:2117:27
    #28 0x56363b5971c9 in clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) clang/lib/Parse/Parser.cpp:1179:10
    #29 0x56363b596633 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) clang/lib/Parse/Parser.cpp:1193:12
    #30 0x56363b594dbc in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) clang/lib/Parse/Parser.cpp:1019:12
    #31 0x56363b592079 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) clang/lib/Parse/Parser.cpp:737:12
    #32 0x56363b453bbe in clang::ParseAST(clang::Sema&, bool, bool) clang/lib/Parse/ParseAST.cpp:162:20
    #33 0x563639b7608c in lldb_private::ClangExpressionParser::ParseInternal(lldb_private::DiagnosticManager&, clang::CodeCompleteConsumer*, unsigned int, unsigned int) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp:1176:5
    #34 0x563639b9e617 in lldb_private::ClangUserExpression::TryParse(lldb_private::DiagnosticManager&, lldb_private::ExecutionContextScope*, lldb_private::ExecutionContext&, lldb_private::ExecutionPolicy, bool, bool) lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp:580:35
    #35 0x563639b9ecff in lldb_private::ClangUserExpression::Parse(lldb_private::DiagnosticManager&, lldb_private::ExecutionContext&, lldb_private::ExecutionPolicy, bool, bool) lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp:679:24
    #36 0x563639aa5039 in lldb_private::UserExpression::Evaluate(lldb_private::ExecutionContext&, lldb_private::EvaluateExpressionOptions const&, llvm::StringRef, llvm::StringRef, std::__u::shared_ptr<lldb_private::ValueObject>&, lldb_private::Status&, std::__u::basic_string<char, std::__u::char_traits<char>, std::__u::allocator<char>>*, lldb_private::ValueObject*) lldb/source/Expression/UserExpression.cpp:271:27
    #37 0x56363a090e07 in lldb_private::Target::EvaluateExpression(llvm::StringRef, lldb_private::ExecutionContextScope*, std::__u::shared_ptr<lldb_private::ValueObject>&, lldb_private::EvaluateExpressionOptions const&, std::__u::basic_string<char, std::__u::char_traits<char>, std::__u::allocator<char>>*, lldb_private::ValueObject*) lldb/source/Target/Target.cpp:2520:25
    #38 0x56363980c17d in lldb_private::CommandObjectExpression::EvaluateExpression(llvm::StringRef, lldb_private::Stream&, lldb_private::Stream&, lldb_private::CommandReturnObject&) lldb/source/Commands/CommandObjectExpression.cpp:402:38
    #39 0x56363980d703 in lldb_private::CommandObjectExpression::DoExecute(llvm::StringRef, lldb_private::CommandReturnObject&) lldb/source/Commands/CommandObjectExpression.cpp:626:7
    #40 0x563639ad9301 in lldb_private::CommandObjectRaw::Execute(char const*, lldb_private::CommandReturnObject&) lldb/source/Interpreter/CommandObject.cpp:769:17
    #41 0x563639ac357c in lldb_private::CommandInterpreter::HandleCommand(char const*, lldb_private::LazyBool, lldb_private::CommandReturnObject&) lldb/source/Interpreter/CommandInterpreter.cpp:1988:14

0x62f00023bf58 is located 47960 bytes inside of 53152-byte region [0x62f000230400,0x62f00023d3a0)
freed by thread T0 here:
    #0 0x563639384022 in operator delete(void*, unsigned long) compiler-rt/lib/asan/asan_new_delete.cpp:164:3
    #1 0x563639ddb422 in __libcpp_operator_delete<void *, unsigned long> include/c++/v1/new:256:3
    #2 0x563639ddb422 in __do_deallocate_handle_size<> include/c++/v1/new:282:10
    #3 0x563639ddb422 in __libcpp_deallocate include/c++/v1/new:296:14
    #4 0x563639ddb422 in deallocate include/c++/v1/__memory/allocator.h:128:13
    #5 0x563639ddb422 in deallocate include/c++/v1/__memory/allocator_traits.h:282:13
    #6 0x563639ddb422 in ~__split_buffer include/c++/v1/__split_buffer:355:9
    #7 0x563639ddb422 in std::__u::vector<DWARFDebugInfoEntry, std::__u::allocator<DWARFDebugInfoEntry>>::shrink_to_fit() include/c++/v1/vector:1525:5
    #8 0x563639dd4f07 in DWARFUnit::ClearDIEsRWLocked() lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:599:15
    #9 0x563639dd4e6a in DWARFUnit::ScopedExtractDIEs::~ScopedExtractDIEs() lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:183:9
    #10 0x563639df0f2c in reset llvm/include/llvm/ADT/Optional.h:88:12
    #11 0x563639df0f2c in ~OptionalStorage llvm/include/llvm/ADT/Optional.h:67:24
    #12 0x563639df0f2c in ~Optional llvm/include/llvm/ADT/APInt.h:33:29
    #13 0x563639df0f2c in destroy include/c++/v1/__memory/allocator.h:170:15
    #14 0x563639df0f2c in destroy<llvm::Optional<DWARFUnit::ScopedExtractDIEs>, void> include/c++/v1/__memory/allocator_traits.h:309:13
    #15 0x563639df0f2c in __base_destruct_at_end include/c++/v1/vector:833:9
    #16 0x563639df0f2c in __clear include/c++/v1/vector:827:29
    #17 0x563639df0f2c in std::__u::vector<llvm::Optional<DWARFUnit::ScopedExtractDIEs>, std::__u::allocator<llvm::Optional<DWARFUnit::ScopedExtractDIEs>>>::~vector() include/c++/v1/vector:436:9
    #18 0x563639debf7d in lldb_private::ManualDWARFIndex::Index() lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp:137:1
    #19 0x563639dedbf3 in lldb_private::ManualDWARFIndex::GetGlobalVariables(DWARFUnit&, llvm::function_ref<bool (DWARFDIE)>) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp:390:3
    #20 0x563639e12633 in SymbolFileDWARF::ParseVariablesForContext(lldb_private::SymbolContext const&) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:3131:18
    #21 0x563639f44425 in lldb_private::CompileUnit::GetVariableList(bool) lldb/source/Symbol/CompileUnit.cpp:213:36
    #22 0x56363a04799f in lldb_private::StackFrame::GetInScopeVariableList(bool, bool) lldb/source/Target/StackFrame.cpp:487:25
    #23 0x563639b6100e in lldb_private::ClangExpressionDeclMap::LookupLocalVariable(lldb_private::NameSearchContext&, lldb_private::ConstString, lldb_private::SymbolContext&, lldb_private::CompilerDeclContext const&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1076:32
    #24 0x563639b5d7cf in lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&, std::__u::shared_ptr<lldb_private::Module>, lldb_private::CompilerDeclContext const&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1434:9
    #25 0x563639b5c9df in lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:728:5
    #26 0x563639b3df83 in lldb_private::ClangASTSource::FindExternalVisibleDeclsByName(clang::DeclContext const*, clang::DeclarationName) lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp:180:3
    #27 0x56363d02aa30 in clang::DeclContext::lookup(clang::DeclarationName) const clang/lib/AST/DeclBase.cpp:1706:17
    #28 0x56363c2bca5b in LookupDirect(clang::Sema&, clang::LookupResult&, clang::DeclContext const*) clang/lib/Sema/SemaLookup.cpp:1108:39
    #29 0x56363c2b67f5 in CppNamespaceLookup(clang::Sema&, clang::LookupResult&, clang::ASTContext&, clang::DeclContext*, (anonymous namespace)::UnqualUsingDirectiveSet&) clang/lib/Sema/SemaLookup.cpp:1207:16
    #30 0x56363c2b5a1e in clang::Sema::CppLookupName(clang::LookupResult&, clang::Scope*) clang/lib/Sema/SemaLookup.cpp:1495:15
    #31 0x56363c2bc0f2 in clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool, bool) clang/lib/Sema/SemaLookup.cpp:2259:9
    #32 0x56363bdb50b8 in clang::Sema::BuildUsingDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, bool, clang::SourceLocation, clang::CXXScopeSpec&, clang::DeclarationNameInfo, clang::SourceLocation, clang::ParsedAttributesView const&, bool, bool) clang/lib/Sema/SemaDeclCXX.cpp:12329:5
    #33 0x56363bdb49f3 in clang::Sema::ActOnUsingDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec&, clang::UnqualifiedId&, clang::SourceLocation, clang::ParsedAttributesView const&) clang/lib/Sema/SemaDeclCXX.cpp:11833:7
    #34 0x56363b49df12 in clang::Parser::ParseUsingDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) clang/lib/Parse/ParseDeclCXX.cpp:803:26
    #35 0x56363b49c27d in clang::Parser::ParseUsingDirectiveOrDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation&, clang::ParsedAttributes&) clang/lib/Parse/ParseDeclCXX.cpp:512:10
    #36 0x56363b46c161 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) clang/lib/Parse/ParseDecl.cpp:1797:12
    #37 0x56363b55fb99 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) clang/lib/Parse/ParseStmt.cpp:247:16
    #38 0x56363b55cfb6 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) clang/lib/Parse/ParseStmt.cpp:115:20
    #39 0x56363b56c048 in clang::Parser::ParseCompoundStatementBody(bool) clang/lib/Parse/ParseStmt.cpp:1171:11
    #40 0x56363b56e32d in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) clang/lib/Parse/ParseStmt.cpp:2442:21
    #41 0x56363b5988a8 in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) clang/lib/Parse/Parser.cpp:1428:10
    #42 0x56363b47493a in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) clang/lib/Parse/ParseDecl.cpp:2117:27
jgorbe added a subscriber: jgorbe.Aug 30 2022, 4:41 PM

This seems to trigger a use after free in lldb-api :: functionalities/thread/create_after_attach/TestCreateAfterAttach.py

asan log:

==4741==ERROR: AddressSanitizer: heap-use-after-free on address 0x62f00023bf58 at pc 0x563639db88f1 bp 0x7ffd942412f0 sp 0x7ffd942412e8
READ of size 4 at 0x62f00023bf58 thread T0
    #0 0x563639db88f0 in HasChildren lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h:124:37
    #1 0x563639db88f0 in GetFirstChild lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h:148:12
    #2 0x563639db88f0 in GetFirstChild lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp:101:34
    #3 0x563639db88f0 in child_iterator lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h:107:57
    #4 0x563639db88f0 in DWARFDIE::children() const lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp:466:27
    #5 0x563639d9f4e1 in DWARFASTParserClang::EnsureAllDIEsInDeclContextHaveBeenParsed(lldb_private::CompilerDeclContext) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2203:37
    #6 0x563639f1ab62 in lldb_private::TypeSystemClang::DeclContextFindDeclByName(void*, lldb_private::ConstString, bool) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:9494:22
    #7 0x563639f489fd in lldb_private::CompilerDeclContext::FindDeclByName(lldb_private::ConstString, bool) lldb/source/Symbol/CompilerDeclContext.cpp:20:27
    #8 0x563639b6113c in lldb_private::ClangExpressionDeclMap::LookupLocalVariable(lldb_private::NameSearchContext&, lldb_private::ConstString, lldb_private::SymbolContext&, lldb_private::CompilerDeclContext const&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1084:20
    #9 0x563639b5d7cf in lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&, std::__u::shared_ptr<lldb_private::Module>, lldb_private::CompilerDeclContext const&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1434:9
    #10 0x563639b5c9df in lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:728:5
    #11 0x563639b3df83 in lldb_private::ClangASTSource::FindExternalVisibleDeclsByName(clang::DeclContext const*, clang::DeclarationName) lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp:180:3
    #12 0x56363d02aa30 in clang::DeclContext::lookup(clang::DeclarationName) const clang/lib/AST/DeclBase.cpp:1706:17
    #13 0x56363c2bca5b in LookupDirect(clang::Sema&, clang::LookupResult&, clang::DeclContext const*) clang/lib/Sema/SemaLookup.cpp:1108:39
    #14 0x56363c2b67f5 in CppNamespaceLookup(clang::Sema&, clang::LookupResult&, clang::ASTContext&, clang::DeclContext*, (anonymous namespace)::UnqualUsingDirectiveSet&) clang/lib/Sema/SemaLookup.cpp:1207:16
    #15 0x56363c2b5a1e in clang::Sema::CppLookupName(clang::LookupResult&, clang::Scope*) clang/lib/Sema/SemaLookup.cpp:1495:15
    #16 0x56363c2bc0f2 in clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool, bool) clang/lib/Sema/SemaLookup.cpp:2259:9
    #17 0x56363bdb50b8 in clang::Sema::BuildUsingDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, bool, clang::SourceLocation, clang::CXXScopeSpec&, clang::DeclarationNameInfo, clang::SourceLocation, clang::ParsedAttributesView const&, bool, bool) clang/lib/Sema/SemaDeclCXX.cpp:12329:5
    #18 0x56363bdb49f3 in clang::Sema::ActOnUsingDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec&, clang::UnqualifiedId&, clang::SourceLocation, clang::ParsedAttributesView const&) clang/lib/Sema/SemaDeclCXX.cpp:11833:7
    #19 0x56363b49df12 in clang::Parser::ParseUsingDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) clang/lib/Parse/ParseDeclCXX.cpp:803:26
    #20 0x56363b49c27d in clang::Parser::ParseUsingDirectiveOrDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation&, clang::ParsedAttributes&) clang/lib/Parse/ParseDeclCXX.cpp:512:10
    #21 0x56363b46c161 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) clang/lib/Parse/ParseDecl.cpp:1797:12
    #22 0x56363b55fb99 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) clang/lib/Parse/ParseStmt.cpp:247:16
    #23 0x56363b55cfb6 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) clang/lib/Parse/ParseStmt.cpp:115:20
    #24 0x56363b56c048 in clang::Parser::ParseCompoundStatementBody(bool) clang/lib/Parse/ParseStmt.cpp:1171:11
    #25 0x56363b56e32d in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) clang/lib/Parse/ParseStmt.cpp:2442:21
    #26 0x56363b5988a8 in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) clang/lib/Parse/Parser.cpp:1428:10
    #27 0x56363b47493a in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) clang/lib/Parse/ParseDecl.cpp:2117:27
    #28 0x56363b5971c9 in clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) clang/lib/Parse/Parser.cpp:1179:10
    #29 0x56363b596633 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) clang/lib/Parse/Parser.cpp:1193:12
    #30 0x56363b594dbc in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) clang/lib/Parse/Parser.cpp:1019:12
    #31 0x56363b592079 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) clang/lib/Parse/Parser.cpp:737:12
    #32 0x56363b453bbe in clang::ParseAST(clang::Sema&, bool, bool) clang/lib/Parse/ParseAST.cpp:162:20
    #33 0x563639b7608c in lldb_private::ClangExpressionParser::ParseInternal(lldb_private::DiagnosticManager&, clang::CodeCompleteConsumer*, unsigned int, unsigned int) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp:1176:5
    #34 0x563639b9e617 in lldb_private::ClangUserExpression::TryParse(lldb_private::DiagnosticManager&, lldb_private::ExecutionContextScope*, lldb_private::ExecutionContext&, lldb_private::ExecutionPolicy, bool, bool) lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp:580:35
    #35 0x563639b9ecff in lldb_private::ClangUserExpression::Parse(lldb_private::DiagnosticManager&, lldb_private::ExecutionContext&, lldb_private::ExecutionPolicy, bool, bool) lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp:679:24
    #36 0x563639aa5039 in lldb_private::UserExpression::Evaluate(lldb_private::ExecutionContext&, lldb_private::EvaluateExpressionOptions const&, llvm::StringRef, llvm::StringRef, std::__u::shared_ptr<lldb_private::ValueObject>&, lldb_private::Status&, std::__u::basic_string<char, std::__u::char_traits<char>, std::__u::allocator<char>>*, lldb_private::ValueObject*) lldb/source/Expression/UserExpression.cpp:271:27
    #37 0x56363a090e07 in lldb_private::Target::EvaluateExpression(llvm::StringRef, lldb_private::ExecutionContextScope*, std::__u::shared_ptr<lldb_private::ValueObject>&, lldb_private::EvaluateExpressionOptions const&, std::__u::basic_string<char, std::__u::char_traits<char>, std::__u::allocator<char>>*, lldb_private::ValueObject*) lldb/source/Target/Target.cpp:2520:25
    #38 0x56363980c17d in lldb_private::CommandObjectExpression::EvaluateExpression(llvm::StringRef, lldb_private::Stream&, lldb_private::Stream&, lldb_private::CommandReturnObject&) lldb/source/Commands/CommandObjectExpression.cpp:402:38
    #39 0x56363980d703 in lldb_private::CommandObjectExpression::DoExecute(llvm::StringRef, lldb_private::CommandReturnObject&) lldb/source/Commands/CommandObjectExpression.cpp:626:7
    #40 0x563639ad9301 in lldb_private::CommandObjectRaw::Execute(char const*, lldb_private::CommandReturnObject&) lldb/source/Interpreter/CommandObject.cpp:769:17
    #41 0x563639ac357c in lldb_private::CommandInterpreter::HandleCommand(char const*, lldb_private::LazyBool, lldb_private::CommandReturnObject&) lldb/source/Interpreter/CommandInterpreter.cpp:1988:14

0x62f00023bf58 is located 47960 bytes inside of 53152-byte region [0x62f000230400,0x62f00023d3a0)
freed by thread T0 here:
    #0 0x563639384022 in operator delete(void*, unsigned long) compiler-rt/lib/asan/asan_new_delete.cpp:164:3
    #1 0x563639ddb422 in __libcpp_operator_delete<void *, unsigned long> include/c++/v1/new:256:3
    #2 0x563639ddb422 in __do_deallocate_handle_size<> include/c++/v1/new:282:10
    #3 0x563639ddb422 in __libcpp_deallocate include/c++/v1/new:296:14
    #4 0x563639ddb422 in deallocate include/c++/v1/__memory/allocator.h:128:13
    #5 0x563639ddb422 in deallocate include/c++/v1/__memory/allocator_traits.h:282:13
    #6 0x563639ddb422 in ~__split_buffer include/c++/v1/__split_buffer:355:9
    #7 0x563639ddb422 in std::__u::vector<DWARFDebugInfoEntry, std::__u::allocator<DWARFDebugInfoEntry>>::shrink_to_fit() include/c++/v1/vector:1525:5
    #8 0x563639dd4f07 in DWARFUnit::ClearDIEsRWLocked() lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:599:15
    #9 0x563639dd4e6a in DWARFUnit::ScopedExtractDIEs::~ScopedExtractDIEs() lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:183:9
    #10 0x563639df0f2c in reset llvm/include/llvm/ADT/Optional.h:88:12
    #11 0x563639df0f2c in ~OptionalStorage llvm/include/llvm/ADT/Optional.h:67:24
    #12 0x563639df0f2c in ~Optional llvm/include/llvm/ADT/APInt.h:33:29
    #13 0x563639df0f2c in destroy include/c++/v1/__memory/allocator.h:170:15
    #14 0x563639df0f2c in destroy<llvm::Optional<DWARFUnit::ScopedExtractDIEs>, void> include/c++/v1/__memory/allocator_traits.h:309:13
    #15 0x563639df0f2c in __base_destruct_at_end include/c++/v1/vector:833:9
    #16 0x563639df0f2c in __clear include/c++/v1/vector:827:29
    #17 0x563639df0f2c in std::__u::vector<llvm::Optional<DWARFUnit::ScopedExtractDIEs>, std::__u::allocator<llvm::Optional<DWARFUnit::ScopedExtractDIEs>>>::~vector() include/c++/v1/vector:436:9
    #18 0x563639debf7d in lldb_private::ManualDWARFIndex::Index() lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp:137:1
    #19 0x563639dedbf3 in lldb_private::ManualDWARFIndex::GetGlobalVariables(DWARFUnit&, llvm::function_ref<bool (DWARFDIE)>) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp:390:3
    #20 0x563639e12633 in SymbolFileDWARF::ParseVariablesForContext(lldb_private::SymbolContext const&) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:3131:18
    #21 0x563639f44425 in lldb_private::CompileUnit::GetVariableList(bool) lldb/source/Symbol/CompileUnit.cpp:213:36
    #22 0x56363a04799f in lldb_private::StackFrame::GetInScopeVariableList(bool, bool) lldb/source/Target/StackFrame.cpp:487:25
    #23 0x563639b6100e in lldb_private::ClangExpressionDeclMap::LookupLocalVariable(lldb_private::NameSearchContext&, lldb_private::ConstString, lldb_private::SymbolContext&, lldb_private::CompilerDeclContext const&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1076:32
    #24 0x563639b5d7cf in lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&, std::__u::shared_ptr<lldb_private::Module>, lldb_private::CompilerDeclContext const&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1434:9
    #25 0x563639b5c9df in lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:728:5
    #26 0x563639b3df83 in lldb_private::ClangASTSource::FindExternalVisibleDeclsByName(clang::DeclContext const*, clang::DeclarationName) lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp:180:3
    #27 0x56363d02aa30 in clang::DeclContext::lookup(clang::DeclarationName) const clang/lib/AST/DeclBase.cpp:1706:17
    #28 0x56363c2bca5b in LookupDirect(clang::Sema&, clang::LookupResult&, clang::DeclContext const*) clang/lib/Sema/SemaLookup.cpp:1108:39
    #29 0x56363c2b67f5 in CppNamespaceLookup(clang::Sema&, clang::LookupResult&, clang::ASTContext&, clang::DeclContext*, (anonymous namespace)::UnqualUsingDirectiveSet&) clang/lib/Sema/SemaLookup.cpp:1207:16
    #30 0x56363c2b5a1e in clang::Sema::CppLookupName(clang::LookupResult&, clang::Scope*) clang/lib/Sema/SemaLookup.cpp:1495:15
    #31 0x56363c2bc0f2 in clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool, bool) clang/lib/Sema/SemaLookup.cpp:2259:9
    #32 0x56363bdb50b8 in clang::Sema::BuildUsingDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, bool, clang::SourceLocation, clang::CXXScopeSpec&, clang::DeclarationNameInfo, clang::SourceLocation, clang::ParsedAttributesView const&, bool, bool) clang/lib/Sema/SemaDeclCXX.cpp:12329:5
    #33 0x56363bdb49f3 in clang::Sema::ActOnUsingDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec&, clang::UnqualifiedId&, clang::SourceLocation, clang::ParsedAttributesView const&) clang/lib/Sema/SemaDeclCXX.cpp:11833:7
    #34 0x56363b49df12 in clang::Parser::ParseUsingDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) clang/lib/Parse/ParseDeclCXX.cpp:803:26
    #35 0x56363b49c27d in clang::Parser::ParseUsingDirectiveOrDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation&, clang::ParsedAttributes&) clang/lib/Parse/ParseDeclCXX.cpp:512:10
    #36 0x56363b46c161 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) clang/lib/Parse/ParseDecl.cpp:1797:12
    #37 0x56363b55fb99 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) clang/lib/Parse/ParseStmt.cpp:247:16
    #38 0x56363b55cfb6 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) clang/lib/Parse/ParseStmt.cpp:115:20
    #39 0x56363b56c048 in clang::Parser::ParseCompoundStatementBody(bool) clang/lib/Parse/ParseStmt.cpp:1171:11
    #40 0x56363b56e32d in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) clang/lib/Parse/ParseStmt.cpp:2442:21
    #41 0x56363b5988a8 in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) clang/lib/Parse/Parser.cpp:1428:10
    #42 0x56363b47493a in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) clang/lib/Parse/ParseDecl.cpp:2117:27

D133790