Skip to content

Cherry-pick FindTypes API modernization #235

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

Merged
merged 13 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions lldb/include/lldb/Core/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,7 @@ class Module : public std::enable_shared_from_this<Module>,
/// \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);
Expand All @@ -459,8 +457,8 @@ class Module : public std::enable_shared_from_this<Module>,
/// 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, bool append, TypeMap &types);
void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
TypeMap &types);

lldb::TypeSP FindFirstType(const SymbolContext &sc,
ConstString type_name, bool exact_match);
Expand All @@ -479,11 +477,9 @@ class Module : public std::enable_shared_from_this<Module>,
/// \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.
///
Expand Down Expand Up @@ -1074,9 +1070,9 @@ class Module : public std::enable_shared_from_this<Module>,
private:
Module(); // Only used internally by CreateJITModule ()

size_t FindTypes_Impl(
void FindTypes_Impl(
ConstString name, const CompilerDeclContext *parent_decl_ctx,
bool append, size_t max_matches,
size_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types);

Expand Down
10 changes: 4 additions & 6 deletions lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,10 @@ class ModuleList {
/// \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;

Expand Down
15 changes: 7 additions & 8 deletions lldb/include/lldb/Symbol/SymbolFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,24 @@ class SymbolFile : public PluginInterface {
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,
bool append, uint32_t max_matches,
uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types);

/// Find types specified by a CompilerContextPattern.
/// \param languages Only return results in these languages.
virtual size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages, bool append,
TypeMap &types);
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();

Expand Down
5 changes: 2 additions & 3 deletions lldb/include/lldb/Symbol/TypeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ class TypeList {

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;
Expand Down
19 changes: 9 additions & 10 deletions lldb/source/API/SBModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}

Expand Down
15 changes: 6 additions & 9 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
116 changes: 57 additions & 59 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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;
}
module->FindTypes(name, name_is_fully_qualified, max_num_matches,
searched_symbol_files, type_list);

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;
if (type_list.Empty())
return 0;

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
Expand All @@ -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,
Expand Down
Loading