-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[lldb] Fix lookup of types in anonymous namespaces with -gsimple-template-names #123054
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| #include "llvm/ADT/iterator.h" | ||
| #include "llvm/BinaryFormat/Dwarf.h" | ||
| #include "llvm/DebugInfo/DWARF/DWARFAddressRange.h" | ||
| #include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
|
|
||
| using namespace lldb_private; | ||
| using namespace lldb_private::dwarf; | ||
|
|
@@ -376,7 +378,8 @@ lldb_private::Type *DWARFDIE::ResolveTypeUID(const DWARFDIE &die) const { | |
| return nullptr; | ||
| } | ||
|
|
||
| static CompilerContext GetContextEntry(DWARFDIE die) { | ||
| static CompilerContext GetContextEntry(DWARFDIE die, | ||
| bool complete_template_names) { | ||
| auto ctx = [die](CompilerContextKind kind) { | ||
| return CompilerContext(kind, ConstString(die.GetName())); | ||
| }; | ||
|
|
@@ -386,11 +389,6 @@ static CompilerContext GetContextEntry(DWARFDIE die) { | |
| return ctx(CompilerContextKind::Module); | ||
| case DW_TAG_namespace: | ||
| return ctx(CompilerContextKind::Namespace); | ||
| case DW_TAG_class_type: | ||
| case DW_TAG_structure_type: | ||
| return ctx(CompilerContextKind::ClassOrStruct); | ||
| case DW_TAG_union_type: | ||
| return ctx(CompilerContextKind::Union); | ||
| case DW_TAG_enumeration_type: | ||
| return ctx(CompilerContextKind::Enum); | ||
| case DW_TAG_subprogram: | ||
|
|
@@ -401,12 +399,28 @@ static CompilerContext GetContextEntry(DWARFDIE die) { | |
| return ctx(CompilerContextKind::Typedef); | ||
| case DW_TAG_base_type: | ||
| return ctx(CompilerContextKind::Builtin); | ||
| case DW_TAG_class_type: | ||
| case DW_TAG_structure_type: | ||
| case DW_TAG_union_type: { | ||
| CompilerContextKind kind = die.Tag() == DW_TAG_union_type | ||
| ? CompilerContextKind::Union | ||
| : CompilerContextKind::ClassOrStruct; | ||
| llvm::StringRef name = die.GetName(); | ||
| if (!complete_template_names || name.contains('<')) | ||
|
||
| return CompilerContext(kind, ConstString(name)); | ||
|
|
||
| std::string name_storage = name.str(); | ||
| llvm::raw_string_ostream os(name_storage); | ||
| llvm::DWARFTypePrinter<DWARFDIE>(os).appendAndTerminateTemplateParameters( | ||
| die); | ||
| return CompilerContext(kind, ConstString(os.str())); | ||
| } | ||
| default: | ||
| llvm_unreachable("Check tag type in the caller!"); | ||
| } | ||
| } | ||
|
|
||
| static void GetDeclContextImpl(DWARFDIE die, | ||
| static void GetDeclContextImpl(DWARFDIE die, bool complete_template_names, | ||
| llvm::SmallSet<lldb::user_id_t, 4> &seen, | ||
| std::vector<CompilerContext> &context) { | ||
| // Stop if we hit a cycle. | ||
|
|
@@ -428,7 +442,7 @@ static void GetDeclContextImpl(DWARFDIE die, | |
| case DW_TAG_subprogram: | ||
| case DW_TAG_variable: | ||
| case DW_TAG_typedef: | ||
| context.push_back(GetContextEntry(die)); | ||
| context.push_back(GetContextEntry(die, complete_template_names)); | ||
| break; | ||
| default: | ||
| break; | ||
|
|
@@ -438,15 +452,16 @@ static void GetDeclContextImpl(DWARFDIE die, | |
| } | ||
| } | ||
|
|
||
| std::vector<CompilerContext> DWARFDIE::GetDeclContext() const { | ||
| std::vector<CompilerContext> | ||
| DWARFDIE::GetDeclContext(bool complete_template_names) const { | ||
| llvm::SmallSet<lldb::user_id_t, 4> seen; | ||
| std::vector<CompilerContext> context; | ||
| GetDeclContextImpl(*this, seen, context); | ||
| GetDeclContextImpl(*this, complete_template_names, seen, context); | ||
| std::reverse(context.begin(), context.end()); | ||
| return context; | ||
| } | ||
|
|
||
| static void GetTypeLookupContextImpl(DWARFDIE die, | ||
| static void GetTypeLookupContextImpl(DWARFDIE die, bool complete_template_names, | ||
| llvm::SmallSet<lldb::user_id_t, 4> &seen, | ||
| std::vector<CompilerContext> &context) { | ||
| // Stop if we hit a cycle. | ||
|
|
@@ -461,7 +476,7 @@ static void GetTypeLookupContextImpl(DWARFDIE die, | |
| case DW_TAG_variable: | ||
| case DW_TAG_typedef: | ||
| case DW_TAG_base_type: | ||
| context.push_back(GetContextEntry(die)); | ||
| context.push_back(GetContextEntry(die, complete_template_names)); | ||
| break; | ||
|
|
||
| // If any of the tags below appear in the parent chain, stop the decl | ||
|
|
@@ -484,10 +499,11 @@ static void GetTypeLookupContextImpl(DWARFDIE die, | |
| } | ||
| } | ||
|
|
||
| std::vector<CompilerContext> DWARFDIE::GetTypeLookupContext() const { | ||
| std::vector<CompilerContext> | ||
| DWARFDIE::GetTypeLookupContext(bool complete_template_names) const { | ||
| llvm::SmallSet<lldb::user_id_t, 4> seen; | ||
| std::vector<CompilerContext> context; | ||
| GetTypeLookupContextImpl(*this, seen, context); | ||
| GetTypeLookupContextImpl(*this, complete_template_names, seen, context); | ||
| std::reverse(context.begin(), context.end()); | ||
| return context; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,8 @@ | |
| #include "llvm/ADT/STLExtras.h" | ||
| #include "llvm/DebugInfo/DWARF/DWARFAddressRange.h" | ||
| #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" | ||
| #include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h" | ||
| #include "llvm/Support/Casting.h" | ||
| #include "llvm/Support/FileUtilities.h" | ||
| #include "llvm/Support/Format.h" | ||
| #include "llvm/Support/FormatAdapters.h" | ||
| #include "llvm/Support/Threading.h" | ||
|
|
||
|
|
@@ -2740,18 +2738,11 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, TypeResults &results) { | |
| // Copy our match's context and update the basename we are looking for | ||
| // so we can use this only to compare the context correctly. | ||
| m_index->GetTypesWithQuery(query_simple, [&](DWARFDIE die) { | ||
| // Check the language, but only if we have a language filter. | ||
| if (query.HasLanguage()) { | ||
| if (!query.LanguageMatches(GetLanguageFamily(*die.GetCU()))) | ||
| return true; // Keep iterating over index types, language mismatch. | ||
| } | ||
|
Comment on lines
-2743
to
-2747
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already checked in the caller. |
||
|
|
||
| std::string qualified_name; | ||
| llvm::raw_string_ostream os(qualified_name); | ||
| llvm::DWARFTypePrinter<DWARFDIE> type_printer(os); | ||
| type_printer.appendQualifiedName(die); | ||
| TypeQuery die_query(qualified_name, e_exact_match); | ||
| if (query.ContextMatches(die_query.GetContextRef())) | ||
| std::vector<CompilerContext> qualified_context = | ||
| query.GetModuleSearch() | ||
| ? die.GetDeclContext(/*complete_template_names=*/true) | ||
| : die.GetTypeLookupContext(/*complete_template_names=*/true); | ||
| if (query.ContextMatches(qualified_context)) | ||
| if (Type *matching_type = ResolveType(die, true, true)) | ||
| results.InsertUnique(matching_type->shared_from_this()); | ||
| return !results.Done(query); // Keep iterating if we aren't done. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.