Remove size_t return parameter from FindTypes

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 simply removes the size_t return parameter altogether —
it's not that useful.

rdar://problem/55500457

Differential Revision: https://reviews.llvm.org/D68169

llvm-svn: 373344
This commit is contained in:
Adrian Prantl 2019-10-01 15:40:41 +00:00
parent 3c912c4abe
commit bf9d84c014
24 changed files with 258 additions and 341 deletions

View File

@ -447,9 +447,7 @@ public:
/// \param[out] type_list
/// A type list gets populated with any matches.
///
/// \return
/// The number of matches added to \a type_list.
size_t
void
FindTypes(ConstString type_name, bool exact_match, size_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeList &types);
@ -459,8 +457,8 @@ public:
/// This behaves like the other FindTypes method but allows to
/// specify a DeclContext and a language for the type being searched
/// for.
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types);
void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
TypeMap &types);
lldb::TypeSP FindFirstType(const SymbolContext &sc,
ConstString type_name, bool exact_match);
@ -479,11 +477,9 @@ public:
/// \param[out] type_list
/// A type list gets populated with any matches.
///
/// \return
/// The number of matches added to \a type_list.
size_t FindTypesInNamespace(ConstString type_name,
const CompilerDeclContext *parent_decl_ctx,
size_t max_matches, TypeList &type_list);
void FindTypesInNamespace(ConstString type_name,
const CompilerDeclContext *parent_decl_ctx,
size_t max_matches, TypeList &type_list);
/// Get const accessor for the module architecture.
///
@ -1074,7 +1070,7 @@ protected:
private:
Module(); // Only used internally by CreateJITModule ()
size_t FindTypes_Impl(
void FindTypes_Impl(
ConstString name, const CompilerDeclContext *parent_decl_ctx,
size_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,

View File

@ -393,12 +393,10 @@ public:
/// \param[out] type_list
/// A type list gets populated with any matches.
///
/// \return
/// The number of matches added to \a type_list.
size_t FindTypes(Module *search_first, ConstString name,
bool name_is_fully_qualified, size_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeList &types) const;
void FindTypes(Module *search_first, ConstString name,
bool name_is_fully_qualified, size_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeList &types) const;
bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const;

View File

@ -188,7 +188,7 @@ public:
virtual uint32_t FindFunctions(const RegularExpression &regex,
bool include_inlines, bool append,
SymbolContextList &sc_list);
virtual uint32_t
virtual void
FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
@ -196,16 +196,16 @@ public:
/// Find types specified by a CompilerContextPattern.
/// \param languages Only return results in these languages.
virtual size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
virtual void FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types);
virtual void
GetMangledNamesForFunction(const std::string &scope_qualified_name,
std::vector<ConstString> &mangled_names);
virtual size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) = 0;
virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) = 0;
virtual void PreloadSymbols();

View File

@ -28,15 +28,14 @@ public:
void Dump(Stream *s, bool show_context);
// lldb::TypeSP
// FindType(lldb::user_id_t uid);
TypeList FindTypes(ConstString name);
void Insert(const lldb::TypeSP &type);
uint32_t GetSize() const;
bool Empty() const { return !GetSize(); }
lldb::TypeSP GetTypeAtIndex(uint32_t idx);
typedef std::vector<lldb::TypeSP> collection;

View File

@ -503,16 +503,10 @@ lldb::SBTypeList SBModule::FindTypes(const char *type) {
const bool exact_match = false;
ConstString name(type);
llvm::DenseSet<SymbolFile *> searched_symbol_files;
const uint32_t num_matches = module_sp->FindTypes(
name, exact_match, UINT32_MAX, searched_symbol_files, type_list);
module_sp->FindTypes(name, exact_match, UINT32_MAX, searched_symbol_files,
type_list);
if (num_matches > 0) {
for (size_t idx = 0; idx < num_matches; idx++) {
TypeSP type_sp(type_list.GetTypeAtIndex(idx));
if (type_sp)
retval.Append(SBType(type_sp));
}
} else {
if (type_list.Empty()) {
auto type_system_or_err =
module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
if (auto err = type_system_or_err.takeError()) {
@ -523,9 +517,14 @@ lldb::SBTypeList SBModule::FindTypes(const char *type) {
if (compiler_type)
retval.Append(SBType(compiler_type));
}
} else {
for (size_t idx = 0; idx < type_list.GetSize(); idx++) {
TypeSP type_sp(type_list.GetTypeAtIndex(idx));
if (type_sp)
retval.Append(SBType(type_sp));
}
}
}
return LLDB_RECORD_RESULT(retval);
}

View File

@ -1891,16 +1891,13 @@ lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
bool exact_match = false;
TypeList type_list;
llvm::DenseSet<SymbolFile *> searched_symbol_files;
uint32_t num_matches =
images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
searched_symbol_files, type_list);
images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
searched_symbol_files, type_list);
if (num_matches > 0) {
for (size_t idx = 0; idx < num_matches; idx++) {
TypeSP type_sp(type_list.GetTypeAtIndex(idx));
if (type_sp)
sb_type_list.Append(SBType(type_sp));
}
for (size_t idx = 0; idx < type_list.GetSize(); idx++) {
TypeSP type_sp(type_list.GetTypeAtIndex(idx));
if (type_sp)
sb_type_list.Append(SBType(type_sp));
}
// Try the loaded language runtimes

View File

@ -1629,75 +1629,30 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter,
static size_t LookupTypeInModule(CommandInterpreter &interpreter, Stream &strm,
Module *module, const char *name_cstr,
bool name_is_regex) {
TypeList type_list;
if (module && name_cstr && name_cstr[0]) {
TypeList type_list;
const uint32_t max_num_matches = UINT32_MAX;
size_t num_matches = 0;
bool name_is_fully_qualified = false;
ConstString name(name_cstr);
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
num_matches =
module->FindTypes(name, name_is_fully_qualified, max_num_matches,
searched_symbol_files, type_list);
module->FindTypes(name, name_is_fully_qualified, max_num_matches,
searched_symbol_files, type_list);
if (num_matches) {
strm.Indent();
strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches,
num_matches > 1 ? "es" : "");
DumpFullpath(strm, &module->GetFileSpec(), 0);
strm.PutCString(":\n");
for (TypeSP type_sp : type_list.Types()) {
if (type_sp) {
// Resolve the clang type so that any forward references to types
// that haven't yet been parsed will get parsed.
type_sp->GetFullCompilerType();
type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
// Print all typedef chains
TypeSP typedef_type_sp(type_sp);
TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
while (typedefed_type_sp) {
strm.EOL();
strm.Printf(" typedef '%s': ",
typedef_type_sp->GetName().GetCString());
typedefed_type_sp->GetFullCompilerType();
typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull,
true);
typedef_type_sp = typedefed_type_sp;
typedefed_type_sp = typedef_type_sp->GetTypedefType();
}
}
strm.EOL();
}
}
return num_matches;
}
return 0;
}
if (type_list.Empty())
return 0;
static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm,
Module &module, const char *name_cstr,
bool name_is_regex) {
TypeList type_list;
const uint32_t max_num_matches = UINT32_MAX;
size_t num_matches = 1;
bool name_is_fully_qualified = false;
ConstString name(name_cstr);
llvm::DenseSet<SymbolFile *> searched_symbol_files;
num_matches = module.FindTypes(name, name_is_fully_qualified, max_num_matches,
searched_symbol_files, type_list);
if (num_matches) {
strm.Indent();
strm.PutCString("Best match found in ");
DumpFullpath(strm, &module.GetFileSpec(), 0);
strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches,
num_matches > 1 ? "es" : "");
DumpFullpath(strm, &module->GetFileSpec(), 0);
strm.PutCString(":\n");
TypeSP type_sp(type_list.GetTypeAtIndex(0));
if (type_sp) {
// Resolve the clang type so that any forward references to types that
// haven't yet been parsed will get parsed.
for (TypeSP type_sp : type_list.Types()) {
if (!type_sp)
continue;
// Resolve the clang type so that any forward references to types
// that haven't yet been parsed will get parsed.
type_sp->GetFullCompilerType();
type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
// Print all typedef chains
@ -1715,7 +1670,50 @@ static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm,
}
strm.EOL();
}
return num_matches;
return type_list.GetSize();
}
static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm,
Module &module, const char *name_cstr,
bool name_is_regex) {
TypeList type_list;
const uint32_t max_num_matches = UINT32_MAX;
bool name_is_fully_qualified = false;
ConstString name(name_cstr);
llvm::DenseSet<SymbolFile *> searched_symbol_files;
module.FindTypes(name, name_is_fully_qualified, max_num_matches,
searched_symbol_files, type_list);
if (type_list.Empty())
return 0;
strm.Indent();
strm.PutCString("Best match found in ");
DumpFullpath(strm, &module.GetFileSpec(), 0);
strm.PutCString(":\n");
TypeSP type_sp(type_list.GetTypeAtIndex(0));
if (type_sp) {
// Resolve the clang type so that any forward references to types that
// haven't yet been parsed will get parsed.
type_sp->GetFullCompilerType();
type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
// Print all typedef chains
TypeSP typedef_type_sp(type_sp);
TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
while (typedefed_type_sp) {
strm.EOL();
strm.Printf(" typedef '%s': ",
typedef_type_sp->GetName().GetCString());
typedefed_type_sp->GetFullCompilerType();
typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
typedef_type_sp = typedefed_type_sp;
typedefed_type_sp = typedef_type_sp->GetTypedefType();
}
}
strm.EOL();
return type_list.GetSize();
}
static uint32_t LookupFileAndLineInModule(CommandInterpreter &interpreter,

View File

@ -939,7 +939,7 @@ void Module::FindAddressesForLine(const lldb::TargetSP target_sp,
}
}
size_t Module::FindTypes_Impl(
void Module::FindTypes_Impl(
ConstString name, const CompilerDeclContext *parent_decl_ctx,
size_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
@ -947,42 +947,38 @@ size_t Module::FindTypes_Impl(
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
if (SymbolFile *symbols = GetSymbolFile())
return symbols->FindTypes(name, parent_decl_ctx, max_matches,
searched_symbol_files, types);
return 0;
symbols->FindTypes(name, parent_decl_ctx, max_matches,
searched_symbol_files, types);
}
size_t Module::FindTypesInNamespace(ConstString type_name,
const CompilerDeclContext *parent_decl_ctx,
size_t max_matches, TypeList &type_list) {
void Module::FindTypesInNamespace(ConstString type_name,
const CompilerDeclContext *parent_decl_ctx,
size_t max_matches, TypeList &type_list) {
TypeMap types_map;
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
size_t num_types = FindTypes_Impl(type_name, parent_decl_ctx, max_matches,
searched_symbol_files, types_map);
if (num_types > 0) {
FindTypes_Impl(type_name, parent_decl_ctx, max_matches, searched_symbol_files,
types_map);
if (types_map.GetSize()) {
SymbolContext sc;
sc.module_sp = shared_from_this();
sc.SortTypeList(types_map, type_list);
}
return num_types;
}
lldb::TypeSP Module::FindFirstType(const SymbolContext &sc,
ConstString name, bool exact_match) {
TypeList type_list;
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
const size_t num_matches =
FindTypes(name, exact_match, 1, searched_symbol_files, type_list);
if (num_matches)
FindTypes(name, exact_match, 1, searched_symbol_files, type_list);
if (type_list.GetSize())
return type_list.GetTypeAtIndex(0);
return TypeSP();
}
size_t Module::FindTypes(
void Module::FindTypes(
ConstString name, bool exact_match, size_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeList &types) {
size_t num_matches = 0;
const char *type_name_cstr = name.GetCString();
llvm::StringRef type_scope;
llvm::StringRef type_basename;
@ -998,12 +994,11 @@ size_t Module::FindTypes(
exact_match = type_scope.consume_front("::");
ConstString type_basename_const_str(type_basename);
if (FindTypes_Impl(type_basename_const_str, nullptr, max_matches,
searched_symbol_files, typesmap)) {
FindTypes_Impl(type_basename_const_str, nullptr, max_matches,
searched_symbol_files, typesmap);
if (typesmap.GetSize())
typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
exact_match);
num_matches = typesmap.GetSize();
}
} else {
// The type is not in a namespace/class scope, just search for it by
// basename
@ -1014,33 +1009,28 @@ size_t Module::FindTypes(
searched_symbol_files, typesmap);
typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
exact_match);
num_matches = typesmap.GetSize();
} else {
num_matches = FindTypes_Impl(name, nullptr, UINT_MAX,
searched_symbol_files, typesmap);
FindTypes_Impl(name, nullptr, UINT_MAX, searched_symbol_files, typesmap);
if (exact_match) {
std::string name_str(name.AsCString(""));
typesmap.RemoveMismatchedTypes(type_scope, name_str, type_class,
exact_match);
num_matches = typesmap.GetSize();
}
}
}
if (num_matches > 0) {
if (typesmap.GetSize()) {
SymbolContext sc;
sc.module_sp = shared_from_this();
sc.SortTypeList(typesmap, types);
}
return num_matches;
}
size_t Module::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {
void Module::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
if (SymbolFile *symbols = GetSymbolFile())
return symbols->FindTypes(pattern, languages, types);
return 0;
symbols->FindTypes(pattern, languages, types);
}
SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {

View File

@ -17,6 +17,7 @@
#include "lldb/Symbol/LocateSymbolFile.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/TypeList.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/ConstString.h"
@ -56,9 +57,6 @@ class SymbolFile;
namespace lldb_private {
class Target;
}
namespace lldb_private {
class TypeList;
}
using namespace lldb;
using namespace lldb_private;
@ -525,44 +523,36 @@ ModuleSP ModuleList::FindModule(const UUID &uuid) const {
return module_sp;
}
size_t
ModuleList::FindTypes(Module *search_first, ConstString name,
bool name_is_fully_qualified, size_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeList &types) const {
void ModuleList::FindTypes(Module *search_first, ConstString name,
bool name_is_fully_qualified, size_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeList &types) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
size_t total_matches = 0;
collection::const_iterator pos, end = m_modules.end();
if (search_first) {
for (pos = m_modules.begin(); pos != end; ++pos) {
if (search_first == pos->get()) {
total_matches +=
search_first->FindTypes(name, name_is_fully_qualified, max_matches,
searched_symbol_files, types);
search_first->FindTypes(name, name_is_fully_qualified, max_matches,
searched_symbol_files, types);
if (total_matches >= max_matches)
break;
if (types.GetSize() >= max_matches)
return;
}
}
}
if (total_matches < max_matches) {
for (pos = m_modules.begin(); pos != end; ++pos) {
// Search the module if the module is not equal to the one in the symbol
// context "sc". If "sc" contains a empty module shared pointer, then the
// comparison will always be true (valid_module_ptr != nullptr).
if (search_first != pos->get())
total_matches +=
(*pos)->FindTypes(name, name_is_fully_qualified, max_matches,
searched_symbol_files, types);
for (pos = m_modules.begin(); pos != end; ++pos) {
// Search the module if the module is not equal to the one in the symbol
// context "sc". If "sc" contains a empty module shared pointer, then the
// comparison will always be true (valid_module_ptr != nullptr).
if (search_first != pos->get())
(*pos)->FindTypes(name, name_is_fully_qualified, max_matches,
searched_symbol_files, types);
if (total_matches >= max_matches)
break;
}
if (types.GetSize() >= max_matches)
return;
}
return total_matches;
}
bool ModuleList::FindSourceFile(const FileSpec &orig_spec,

View File

@ -95,31 +95,27 @@ TypeAndOrName ItaniumABILanguageRuntime::GetTypeInfoFromVTableAddress(
const bool exact_match = true;
TypeList class_types;
uint32_t num_matches = 0;
// First look in the module that the vtable symbol came from and
// look for a single exact match.
llvm::DenseSet<SymbolFile *> searched_symbol_files;
if (sc.module_sp) {
num_matches = sc.module_sp->FindTypes(
ConstString(lookup_name), exact_match, 1,
searched_symbol_files, class_types);
}
if (sc.module_sp)
sc.module_sp->FindTypes(ConstString(lookup_name), exact_match, 1,
searched_symbol_files, class_types);
// If we didn't find a symbol, then move on to the entire module
// list in the target and get as many unique matches as possible
if (num_matches == 0) {
num_matches = target.GetImages().FindTypes(
nullptr, ConstString(lookup_name), exact_match, UINT32_MAX,
searched_symbol_files, class_types);
}
if (class_types.Empty())
target.GetImages().FindTypes(nullptr, ConstString(lookup_name),
exact_match, UINT32_MAX,
searched_symbol_files, class_types);
lldb::TypeSP type_sp;
if (num_matches == 0) {
if (class_types.Empty()) {
LLDB_LOGF(log, "0x%16.16" PRIx64 ": is not dynamic\n",
original_ptr);
return TypeAndOrName();
}
if (num_matches == 1) {
if (class_types.GetSize() == 1) {
type_sp = class_types.GetTypeAtIndex(0);
if (type_sp) {
if (ClangASTContext::IsCXXClassType(
@ -134,10 +130,10 @@ TypeAndOrName ItaniumABILanguageRuntime::GetTypeInfoFromVTableAddress(
type_info.SetTypeSP(type_sp);
}
}
} else if (num_matches > 1) {
} else {
size_t i;
if (log) {
for (i = 0; i < num_matches; i++) {
for (i = 0; i < class_types.GetSize(); i++) {
type_sp = class_types.GetTypeAtIndex(i);
if (type_sp) {
LLDB_LOGF(
@ -151,7 +147,7 @@ TypeAndOrName ItaniumABILanguageRuntime::GetTypeInfoFromVTableAddress(
}
}
for (i = 0; i < num_matches; i++) {
for (i = 0; i < class_types.GetSize(); i++) {
type_sp = class_types.GetTypeAtIndex(i);
if (type_sp) {
if (ClangASTContext::IsCXXClassType(
@ -168,7 +164,7 @@ TypeAndOrName ItaniumABILanguageRuntime::GetTypeInfoFromVTableAddress(
}
}
if (log && i == num_matches) {
if (log) {
LLDB_LOGF(log,
"0x%16.16" PRIx64
": static-type = '%s' has multiple matching dynamic "

View File

@ -121,20 +121,17 @@ ObjCLanguageRuntime::LookupInCompleteClassCache(ConstString &name) {
TypeList types;
llvm::DenseSet<SymbolFile *> searched_symbol_files;
const uint32_t num_types = module_sp->FindTypes(
name, exact_match, max_matches, searched_symbol_files, types);
module_sp->FindTypes(name, exact_match, max_matches, searched_symbol_files,
types);
if (num_types) {
uint32_t i;
for (i = 0; i < num_types; ++i) {
TypeSP type_sp(types.GetTypeAtIndex(i));
for (uint32_t i = 0; i < types.GetSize(); ++i) {
TypeSP type_sp(types.GetTypeAtIndex(i));
if (ClangASTContext::IsObjCObjectOrInterfaceType(
type_sp->GetForwardCompilerType())) {
if (type_sp->IsCompleteObjCClass()) {
m_complete_class_cache[name] = type_sp;
return type_sp;
}
if (ClangASTContext::IsObjCObjectOrInterfaceType(
type_sp->GetForwardCompilerType())) {
if (type_sp->IsCompleteObjCClass()) {
m_complete_class_cache[name] = type_sp;
return type_sp;
}
}
}

View File

@ -308,17 +308,13 @@ uint32_t SymbolFileBreakpad::FindFunctions(const RegularExpression &regex,
return sc_list.GetSize();
}
uint32_t SymbolFileBreakpad::FindTypes(
void SymbolFileBreakpad::FindTypes(
ConstString name, const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) {
return 0;
}
TypeMap &types) {}
size_t SymbolFileBreakpad::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {
return 0;
}
void SymbolFileBreakpad::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {}
void SymbolFileBreakpad::AddSymbols(Symtab &symtab) {
Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS);

View File

@ -97,10 +97,8 @@ public:
lldb::SymbolContextItem resolve_scope,
SymbolContextList &sc_list) override;
size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
TypeList &type_list) override {
return 0;
}
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
TypeList &type_list) override {}
uint32_t FindFunctions(ConstString name,
const CompilerDeclContext *parent_decl_ctx,
@ -111,14 +109,13 @@ public:
uint32_t FindFunctions(const RegularExpression &regex, bool include_inlines,
bool append, SymbolContextList &sc_list) override;
uint32_t FindTypes(ConstString name,
const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) override;
void FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) override;
void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
TypeMap &types) override;
llvm::Expected<TypeSystem &>
GetTypeSystemForLanguage(lldb::LanguageType language) override {

View File

@ -151,8 +151,8 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWO(const DWARFDIE &die, Log *log) {
// The type in the Clang module must have the same langage as the current CU.
LanguageSet languages;
languages.Insert(die.GetCU()->GetLanguageType());
if (!dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages,
dwo_types)) {
dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages, dwo_types);
if (dwo_types.GetSize()) {
if (!IsClangModuleFwdDecl(die))
return TypeSP();
@ -162,8 +162,9 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWO(const DWARFDIE &die, Log *log) {
for (const auto &name_module : sym_file.getExternalTypeModules()) {
if (!name_module.second)
continue;
if (name_module.second->GetSymbolFile()->FindTypes(decl_context,
languages, dwo_types))
name_module.second->GetSymbolFile()->FindTypes(decl_context,
languages, dwo_types);
if (dwo_types.GetSize())
break;
}
}

View File

@ -335,8 +335,8 @@ void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
}
}
size_t SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope,
TypeClass type_mask, TypeList &type_list)
void SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope,
TypeClass type_mask, TypeList &type_list)
{
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
@ -349,8 +349,8 @@ size_t SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope,
if (comp_unit) {
dwarf_cu = GetDWARFCompileUnit(comp_unit);
if (dwarf_cu == nullptr)
return 0;
if (!dwarf_cu)
return;
GetTypes(dwarf_cu->DIE(), dwarf_cu->GetOffset(),
dwarf_cu->GetNextUnitOffset(), type_mask, type_set);
} else {
@ -367,16 +367,13 @@ size_t SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope,
}
std::set<CompilerType> compiler_type_set;
size_t num_types_added = 0;
for (Type *type : type_set) {
CompilerType compiler_type = type->GetForwardCompilerType();
if (compiler_type_set.find(compiler_type) == compiler_type_set.end()) {
compiler_type_set.insert(compiler_type);
type_list.Insert(type->shared_from_this());
++num_types_added;
}
}
return num_types_added;
}
// Gets the first parent that is a lexical block, function or inlined
@ -2383,7 +2380,7 @@ void SymbolFileDWARF::GetMangledNamesForFunction(
}
}
uint32_t SymbolFileDWARF::FindTypes(
void SymbolFileDWARF::FindTypes(
ConstString name, const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
@ -2391,13 +2388,13 @@ uint32_t SymbolFileDWARF::FindTypes(
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
// Make sure we haven't already searched this SymbolFile before...
if (searched_symbol_files.count(this))
return 0;
else
searched_symbol_files.insert(this);
return;
searched_symbol_files.insert(this);
DWARFDebugInfo *info = DebugInfo();
if (info == nullptr)
return 0;
if (!info)
return;
Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
@ -2418,12 +2415,11 @@ uint32_t SymbolFileDWARF::FindTypes(
}
if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
return 0;
return;
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();
for (size_t i = 0; i < num_die_matches; ++i) {
const DIERef &die_ref = die_offsets[i];
@ -2458,8 +2454,7 @@ uint32_t SymbolFileDWARF::FindTypes(
searched_symbol_files, types);
}
uint32_t num_matches = types.GetSize() - initial_types_size;
if (log && num_matches) {
if (log && types.GetSize()) {
if (parent_decl_ctx) {
GetObjectFile()->GetModule()->LogMessage(
log,
@ -2467,60 +2462,53 @@ uint32_t SymbolFileDWARF::FindTypes(
"= %p (\"%s\"), max_matches=%u, type_list) => %u",
name.GetCString(), static_cast<const void *>(parent_decl_ctx),
parent_decl_ctx->GetName().AsCString("<NULL>"), max_matches,
num_matches);
types.GetSize());
} else {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
"= NULL, max_matches=%u, type_list) => %u",
name.GetCString(), max_matches, num_matches);
name.GetCString(), max_matches, types.GetSize());
}
}
return num_matches;
}
size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
void SymbolFileDWARF::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
if (pattern.empty())
return 0;
return;
ConstString name = pattern.back().name;
if (!name)
return 0;
return;
DIEArray die_offsets;
m_index->GetTypes(name, die_offsets);
const size_t num_die_matches = die_offsets.size();
size_t num_matches = 0;
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 (!languages[die.GetCU()->GetLanguageType()])
continue;
llvm::SmallVector<CompilerContext, 4> die_context;
die.GetDeclContext(die_context);
if (!contextMatches(die_context, pattern))
continue;
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());
++num_matches;
}
} else {
if (!die) {
m_index->ReportInvalidDIERef(die_ref, name.GetStringRef());
continue;
}
if (!languages[die.GetCU()->GetLanguageType()])
continue;
llvm::SmallVector<CompilerContext, 4> die_context;
die.GetDeclContext(die_context);
if (!contextMatches(die_context, pattern))
continue;
if (Type *matching_type = ResolveType(die, true, true))
// We found a type pointer, now find the shared pointer form our type
// list.
types.InsertUnique(matching_type->shared_from_this());
}
return num_matches;
}
CompilerDeclContext

View File

@ -181,20 +181,20 @@ public:
const std::string &scope_qualified_name,
std::vector<lldb_private::ConstString> &mangled_names) override;
uint32_t
void
FindTypes(lldb_private::ConstString name,
const lldb_private::CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
lldb_private::TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> pattern,
lldb_private::LanguageSet languages,
lldb_private::TypeMap &types) override;
void FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> pattern,
lldb_private::LanguageSet languages,
lldb_private::TypeMap &types) override;
size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) override;
void GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) override;
llvm::Expected<lldb_private::TypeSystem &>
GetTypeSystemForLanguage(lldb::LanguageType language) override;

View File

@ -1070,16 +1070,15 @@ uint32_t SymbolFileDWARFDebugMap::FindFunctions(const RegularExpression &regex,
return sc_list.GetSize() - initial_size;
}
size_t SymbolFileDWARFDebugMap::GetTypes(SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
TypeList &type_list) {
void SymbolFileDWARFDebugMap::GetTypes(SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
TypeList &type_list) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)",
type_mask);
uint32_t initial_size = type_list.GetSize();
SymbolFileDWARF *oso_dwarf = nullptr;
if (sc_scope) {
SymbolContext sc;
@ -1097,7 +1096,6 @@ size_t SymbolFileDWARFDebugMap::GetTypes(SymbolContextScope *sc_scope,
return false;
});
}
return type_list.GetSize() - initial_size;
}
std::vector<lldb_private::CallEdge>
@ -1199,21 +1197,17 @@ TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
return TypeSP();
}
uint32_t SymbolFileDWARFDebugMap::FindTypes(
void SymbolFileDWARFDebugMap::FindTypes(
ConstString name, const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
const uint32_t initial_types_size = types.GetSize();
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
oso_dwarf->FindTypes(name, parent_decl_ctx, max_matches,
searched_symbol_files, types);
return types.GetSize() >= max_matches;
});
return types.GetSize() - initial_types_size;
}
//

View File

@ -108,7 +108,7 @@ public:
uint32_t FindFunctions(const lldb_private::RegularExpression &regex,
bool include_inlines, bool append,
lldb_private::SymbolContextList &sc_list) override;
uint32_t
void
FindTypes(lldb_private::ConstString name,
const lldb_private::CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
@ -117,9 +117,9 @@ public:
lldb_private::CompilerDeclContext FindNamespace(
lldb_private::ConstString name,
const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) override;
void GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) override;
std::vector<lldb_private::CallEdge>
ParseCallEdgesInFunction(lldb_private::UserID func_id) override;

View File

@ -1250,33 +1250,28 @@ uint32_t SymbolFileNativePDB::FindFunctions(const RegularExpression &regex,
return 0;
}
uint32_t SymbolFileNativePDB::FindTypes(
void SymbolFileNativePDB::FindTypes(
ConstString name, const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files, TypeMap &types) {
uint32_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
if (!name)
return 0;
return;
searched_symbol_files.clear();
searched_symbol_files.insert(this);
// There is an assumption 'name' is not a regex
size_t match_count = FindTypesByName(name.GetStringRef(), max_matches, types);
return match_count;
FindTypesByName(name.GetStringRef(), max_matches, types);
}
size_t SymbolFileNativePDB::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {
return 0;
}
void SymbolFileNativePDB::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {}
size_t SymbolFileNativePDB::FindTypesByName(llvm::StringRef name,
uint32_t max_matches,
TypeMap &types) {
void SymbolFileNativePDB::FindTypesByName(llvm::StringRef name,
uint32_t max_matches,
TypeMap &types) {
size_t match_count = 0;
std::vector<TypeIndex> matches = m_index->tpi().findRecordsByName(name);
if (max_matches > 0 && max_matches < matches.size())
matches.resize(max_matches);
@ -1287,9 +1282,7 @@ size_t SymbolFileNativePDB::FindTypesByName(llvm::StringRef name,
continue;
types.Insert(type);
++match_count;
}
return match_count;
}
size_t SymbolFileNativePDB::ParseTypes(CompileUnit &comp_unit) {
@ -1578,11 +1571,9 @@ bool SymbolFileNativePDB::CompleteType(CompilerType &compiler_type) {
return m_ast->CompleteType(qt);
}
size_t SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
TypeClass type_mask,
lldb_private::TypeList &type_list) {
return 0;
}
void SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
TypeClass type_mask,
lldb_private::TypeList &type_list) {}
CompilerDeclContext
SymbolFileNativePDB::FindNamespace(ConstString name,

View File

@ -116,8 +116,8 @@ public:
lldb::SymbolContextItem resolve_scope,
SymbolContextList &sc_list) override;
size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
TypeList &type_list) override;
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
TypeList &type_list) override;
uint32_t FindFunctions(ConstString name,
const CompilerDeclContext *parent_decl_ctx,
@ -128,14 +128,13 @@ public:
uint32_t FindFunctions(const RegularExpression &regex, bool include_inlines,
bool append, SymbolContextList &sc_list) override;
uint32_t FindTypes(ConstString name,
const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) override;
void FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) override;
void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
TypeMap &types) override;
llvm::Expected<TypeSystem &>
GetTypeSystemForLanguage(lldb::LanguageType language) override;
@ -158,8 +157,8 @@ private:
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
size_t FindTypesByName(llvm::StringRef name, uint32_t max_matches,
TypeMap &types);
void FindTypesByName(llvm::StringRef name, uint32_t max_matches,
TypeMap &types);
lldb::TypeSP CreateModifierType(PdbTypeSymId type_id,
const llvm::codeview::ModifierRecord &mr,

View File

@ -47,11 +47,9 @@ SymbolFile *SymbolFileSymtab::CreateInstance(ObjectFileSP objfile_sp) {
return new SymbolFileSymtab(std::move(objfile_sp));
}
size_t SymbolFileSymtab::GetTypes(SymbolContextScope *sc_scope,
TypeClass type_mask,
lldb_private::TypeList &type_list) {
return 0;
}
void SymbolFileSymtab::GetTypes(SymbolContextScope *sc_scope,
TypeClass type_mask,
lldb_private::TypeList &type_list) {}
SymbolFileSymtab::SymbolFileSymtab(ObjectFileSP objfile_sp)
: SymbolFile(std::move(objfile_sp)), m_source_indexes(), m_func_indexes(),

View File

@ -71,9 +71,9 @@ public:
lldb::SymbolContextItem resolve_scope,
lldb_private::SymbolContext &sc) override;
size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) override;
void GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
lldb_private::TypeList &type_list) override;
// PluginInterface protocol
lldb_private::ConstString GetPluginName() override;

View File

@ -139,18 +139,14 @@ void SymbolFile::GetMangledNamesForFunction(
return;
}
uint32_t SymbolFile::FindTypes(
void SymbolFile::FindTypes(
ConstString name, const CompilerDeclContext *parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types) {
return 0;
}
TypeMap &types) {}
size_t SymbolFile::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {
return 0;
}
void SymbolFile::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, TypeMap &types) {}
void SymbolFile::AssertModuleLock() {
// The code below is too expensive to leave enabled in release builds. It's

View File

@ -355,8 +355,7 @@ TEST_F(SymbolFilePDBTests, TestSimpleClassTypes) {
llvm::pdb::IPDBSession &session = symfile->GetPDBSession();
llvm::DenseSet<SymbolFile *> searched_files;
TypeMap results;
symfile->FindTypes(ConstString("Class"), nullptr, false, 0, searched_files,
results);
symfile->FindTypes(ConstString("Class"), nullptr, 0, searched_files, results);
EXPECT_EQ(1u, results.GetSize());
lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
EXPECT_EQ(ConstString("Class"), udt_type->GetName());
@ -385,8 +384,7 @@ TEST_F(SymbolFilePDBTests, TestNestedClassTypes) {
llvm::dyn_cast_or_null<ClangASTContext>(&clang_ast_ctx_or_err.get());
EXPECT_NE(nullptr, clang_ast_ctx);
symfile->FindTypes(ConstString("Class"), nullptr, false, 0, searched_files,
results);
symfile->FindTypes(ConstString("Class"), nullptr, 0, searched_files, results);
EXPECT_EQ(1u, results.GetSize());
auto Class = results.GetTypeAtIndex(0);
@ -404,8 +402,8 @@ TEST_F(SymbolFilePDBTests, TestNestedClassTypes) {
// compiler type for both, but `FindTypes` may return more than one type
// (with the same compiler type) because the symbols have different IDs.
auto ClassCompilerDeclCtx = CompilerDeclContext(clang_ast_ctx, ClassDeclCtx);
symfile->FindTypes(ConstString("NestedClass"), &ClassCompilerDeclCtx, false,
0, searched_files, results);
symfile->FindTypes(ConstString("NestedClass"), &ClassCompilerDeclCtx, 0,
searched_files, results);
EXPECT_LE(1u, results.GetSize());
lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
@ -449,8 +447,8 @@ TEST_F(SymbolFilePDBTests, TestClassInNamespace) {
auto ns_namespace = symfile->FindNamespace(ConstString("NS"), nullptr);
EXPECT_TRUE(ns_namespace.IsValid());
symfile->FindTypes(ConstString("NSClass"), &ns_namespace, false,
0, searched_files, results);
symfile->FindTypes(ConstString("NSClass"), &ns_namespace, 0, searched_files,
results);
EXPECT_EQ(1u, results.GetSize());
lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
@ -475,8 +473,7 @@ TEST_F(SymbolFilePDBTests, TestEnumTypes) {
const char *EnumsToCheck[] = {"Enum", "ShortEnum"};
for (auto Enum : EnumsToCheck) {
TypeMap results;
symfile->FindTypes(ConstString(Enum), nullptr, false, 0,
searched_files, results);
symfile->FindTypes(ConstString(Enum), nullptr, 0, searched_files, results);
EXPECT_EQ(1u, results.GetSize());
lldb::TypeSP enum_type = results.GetTypeAtIndex(0);
EXPECT_EQ(ConstString(Enum), enum_type->GetName());
@ -524,8 +521,8 @@ TEST_F(SymbolFilePDBTests, TestTypedefs) {
"VariadicFuncPointerTypedef"};
for (auto Typedef : TypedefsToCheck) {
TypeMap results;
symfile->FindTypes(ConstString(Typedef), nullptr, false, 0,
searched_files, results);
symfile->FindTypes(ConstString(Typedef), nullptr, 0, searched_files,
results);
EXPECT_EQ(1u, results.GetSize());
lldb::TypeSP typedef_type = results.GetTypeAtIndex(0);
EXPECT_EQ(ConstString(Typedef), typedef_type->GetName());
@ -570,7 +567,7 @@ TEST_F(SymbolFilePDBTests, TestMaxMatches) {
llvm::DenseSet<SymbolFile *> searched_files;
TypeMap results;
const ConstString name("ClassTypedef");
symfile->FindTypes(name, nullptr, false, 0, searched_files, results);
symfile->FindTypes(name, nullptr, 0, searched_files, results);
// Try to limit ourselves from 1 to 10 results, otherwise we could be doing
// this thousands of times.
// The idea is just to make sure that for a variety of values, the number of
@ -579,7 +576,7 @@ TEST_F(SymbolFilePDBTests, TestMaxMatches) {
uint32_t iterations = std::min(results.GetSize(), 10u);
uint32_t num_results = results.GetSize();
for (uint32_t i = 1; i <= iterations; ++i) {
symfile->FindTypes(name, nullptr, false, i, searched_files, results);
symfile->FindTypes(name, nullptr, i, searched_files, results);
uint32_t num_limited_results = results.GetSize() - num_results);
EXPECT_EQ(i, num_limited_results);
EXPECT_EQ(num_limited_results, results.GetSize());
@ -595,7 +592,7 @@ TEST_F(SymbolFilePDBTests, TestNullName) {
static_cast<SymbolFilePDB *>(module->GetSymbolFile());
llvm::DenseSet<SymbolFile *> searched_files;
TypeMap results;
symfile->FindTypes(ConstString(), nullptr, false, 0, searched_files, results);
symfile->FindTypes(ConstString(), nullptr, 0, searched_files, results);
EXPECT_EQ(0u, results.GetSize());
}