aprantl created this revision. aprantl added reviewers: friss, JDevlieghere, jasonmolenda. Herald added a project: LLDB.
In r368345 I accidentally introduced a regression that would over-report the number of matches found by FIndTypes if the DeclContext Filter was hit. This patch fixes this issue and adds test coverage for it in the form of an assertion in lldb-test (which does trigger this code). rdar://problem/55500457 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D68169 Files: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/tools/lldb-test/lldb-test.cpp
Index: lldb/tools/lldb-test/lldb-test.cpp =================================================================== --- lldb/tools/lldb-test/lldb-test.cpp +++ lldb/tools/lldb-test/lldb-test.cpp @@ -518,11 +518,12 @@ DenseSet<SymbolFile *> SearchedFiles; TypeMap Map; - if (!Name.empty()) - Symfile.FindTypes(ConstString(Name), ContextPtr, true, UINT32_MAX, - SearchedFiles, Map); - else - Module.FindTypes(parseCompilerContext(), languages, true, Map); + unsigned num_matches = + !Name.empty() + ? Symfile.FindTypes(ConstString(Name), ContextPtr, true, UINT32_MAX, + SearchedFiles, Map) + : Module.FindTypes(parseCompilerContext(), languages, true, Map); + assert(num_matches == Map.GetSize()); outs() << formatv("Found {0} types:\n", Map.GetSize()); StreamString Stream; Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2427,46 +2427,25 @@ DIEArray die_offsets; m_index->GetTypes(name, die_offsets); const size_t num_die_matches = die_offsets.size(); + const uint32_t initial_types_size = types.GetSize(); - if (num_die_matches) { - const uint32_t initial_types_size = types.GetSize(); - for (size_t i = 0; i < num_die_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + for (size_t i = 0; i < num_die_matches; ++i) { + const DIERef &die_ref = die_offsets[i]; + DWARFDIE die = GetDIE(die_ref); + if (die) { + if (!DIEInDeclContext(parent_decl_ctx, die)) + continue; // The containing decl contexts don't match - if (die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) - continue; // The containing decl contexts don't match - - Type *matching_type = ResolveType(die, true, true); - if (matching_type) { - // We found a type pointer, now find the shared pointer form our type - // list - types.InsertUnique(matching_type->shared_from_this()); - if (types.GetSize() >= max_matches) - break; - } - } else { - m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); - } - } - const uint32_t num_matches = types.GetSize() - initial_types_size; - if (log && num_matches) { - if (parent_decl_ctx) { - GetObjectFile()->GetModule()->LogMessage( - log, - "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx " - "= %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u", - name.GetCString(), static_cast<const void *>(parent_decl_ctx), - parent_decl_ctx->GetName().AsCString("<NULL>"), append, max_matches, - num_matches); - } else { - GetObjectFile()->GetModule()->LogMessage( - log, - "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx " - "= NULL, append=%u, max_matches=%u, type_list) => %u", - name.GetCString(), append, max_matches, num_matches); + Type *matching_type = ResolveType(die, true, true); + if (matching_type) { + // We found a type pointer, now find the shared pointer form our type + // list + types.InsertUnique(matching_type->shared_from_this()); + if (types.GetSize() >= max_matches) + break; } + } else { + m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); } } @@ -2476,22 +2455,33 @@ if (num_die_matches < max_matches) { UpdateExternalModuleListIfNeeded(); - for (const auto &pair : m_external_type_modules) { - ModuleSP external_module_sp = pair.second; - if (external_module_sp) { - SymbolFile *sym_file = external_module_sp->GetSymbolFile(); - if (sym_file) { - const uint32_t num_external_matches = - sym_file->FindTypes(name, parent_decl_ctx, append, max_matches, - searched_symbol_files, types); - if (num_external_matches) - return num_external_matches; - } - } + for (const auto &pair : m_external_type_modules) + if (ModuleSP external_module_sp = pair.second) + if (SymbolFile *sym_file = external_module_sp->GetSymbolFile()) + sym_file->FindTypes(name, parent_decl_ctx, append, max_matches, + searched_symbol_files, types); + } + + uint32_t num_matches = types.GetSize() - initial_types_size; + if (log && num_matches) { + if (parent_decl_ctx) { + GetObjectFile()->GetModule()->LogMessage( + log, + "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx " + "= %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u", + name.GetCString(), static_cast<const void *>(parent_decl_ctx), + parent_decl_ctx->GetName().AsCString("<NULL>"), append, max_matches, + num_matches); + } else { + GetObjectFile()->GetModule()->LogMessage( + log, + "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx " + "= NULL, append=%u, max_matches=%u, type_list) => %u", + name.GetCString(), append, max_matches, num_matches); } } - return num_die_matches; + return num_matches; } size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits