aboutsummaryrefslogtreecommitdiffstats
path: root/source/Core/ModuleList.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Core/ModuleList.cpp')
-rw-r--r--source/Core/ModuleList.cpp207
1 files changed, 76 insertions, 131 deletions
diff --git a/source/Core/ModuleList.cpp b/source/Core/ModuleList.cpp
index 9d795f9e5586..b0567a902fd7 100644
--- a/source/Core/ModuleList.cpp
+++ b/source/Core/ModuleList.cpp
@@ -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,40 +57,26 @@ class SymbolFile;
namespace lldb_private {
class Target;
}
-namespace lldb_private {
-class TypeList;
-}
using namespace lldb;
using namespace lldb_private;
namespace {
-static constexpr PropertyDefinition g_properties[] = {
- {"enable-external-lookup", OptionValue::eTypeBoolean, true, true, nullptr,
- {},
- "Control the use of external tools and repositories to locate symbol "
- "files. Directories listed in target.debug-file-search-paths and "
- "directory of the executable are always checked first for separate debug "
- "info files. Then depending on this setting: "
- "On macOS, Spotlight would be also used to locate a matching .dSYM "
- "bundle based on the UUID of the executable. "
- "On NetBSD, directory /usr/libdata/debug would be also searched. "
- "On platforms other than NetBSD directory /usr/lib/debug would be "
- "also searched."
- },
- {"clang-modules-cache-path", OptionValue::eTypeFileSpec, true, 0, nullptr,
- {},
- "The path to the clang modules cache directory (-fmodules-cache-path)."}};
-
-enum { ePropertyEnableExternalLookup, ePropertyClangModulesCachePath };
+#define LLDB_PROPERTIES_modulelist
+#include "CoreProperties.inc"
+
+enum {
+#define LLDB_PROPERTIES_modulelist
+#include "CorePropertiesEnum.inc"
+};
} // namespace
ModuleListProperties::ModuleListProperties() {
m_collection_sp =
std::make_shared<OptionValueProperties>(ConstString("symbols"));
- m_collection_sp->Initialize(g_properties);
+ m_collection_sp->Initialize(g_modulelist_properties);
llvm::SmallString<128> path;
clang::driver::Driver::getDefaultModuleCachePath(path);
@@ -99,7 +86,7 @@ ModuleListProperties::ModuleListProperties() {
bool ModuleListProperties::GetEnableExternalLookup() const {
const uint32_t idx = ePropertyEnableExternalLookup;
return m_collection_sp->GetPropertyAtIndexAsBoolean(
- nullptr, idx, g_properties[idx].default_uint_value != 0);
+ nullptr, idx, g_modulelist_properties[idx].default_uint_value != 0);
}
bool ModuleListProperties::SetEnableExternalLookup(bool new_value) {
@@ -135,9 +122,9 @@ ModuleList::ModuleList(ModuleList::Notifier *notifier)
const ModuleList &ModuleList::operator=(const ModuleList &rhs) {
if (this != &rhs) {
std::lock(m_modules_mutex, rhs.m_modules_mutex);
- std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex,
+ std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex,
std::adopt_lock);
- std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex,
+ std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex,
std::adopt_lock);
m_modules = rhs.m_modules;
}
@@ -155,8 +142,8 @@ void ModuleList::AppendImpl(const ModuleSP &module_sp, bool use_notifier) {
}
}
-void ModuleList::Append(const ModuleSP &module_sp, bool notify) {
- AppendImpl(module_sp, notify);
+void ModuleList::Append(const ModuleSP &module_sp, bool notify) {
+ AppendImpl(module_sp, notify);
}
void ModuleList::ReplaceEquivalent(const ModuleSP &module_sp) {
@@ -339,14 +326,10 @@ ModuleSP ModuleList::GetModuleAtIndexUnlocked(size_t idx) const {
return module_sp;
}
-size_t ModuleList::FindFunctions(ConstString name,
- FunctionNameType name_type_mask,
- bool include_symbols, bool include_inlines,
- bool append,
- SymbolContextList &sc_list) const {
- if (!append)
- sc_list.Clear();
-
+void ModuleList::FindFunctions(ConstString name,
+ FunctionNameType name_type_mask,
+ bool include_symbols, bool include_inlines,
+ SymbolContextList &sc_list) const {
const size_t old_size = sc_list.GetSize();
if (name_type_mask & eFunctionNameTypeAuto) {
@@ -357,7 +340,7 @@ size_t ModuleList::FindFunctions(ConstString name,
for (pos = m_modules.begin(); pos != end; ++pos) {
(*pos)->FindFunctions(lookup_info.GetLookupName(), nullptr,
lookup_info.GetNameTypeMask(), include_symbols,
- include_inlines, true, sc_list);
+ include_inlines, sc_list);
}
const size_t new_size = sc_list.GetSize();
@@ -369,15 +352,14 @@ size_t ModuleList::FindFunctions(ConstString name,
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos) {
(*pos)->FindFunctions(name, nullptr, name_type_mask, include_symbols,
- include_inlines, true, sc_list);
+ include_inlines, sc_list);
}
}
- return sc_list.GetSize() - old_size;
}
-size_t ModuleList::FindFunctionSymbols(ConstString name,
- lldb::FunctionNameType name_type_mask,
- SymbolContextList &sc_list) {
+void ModuleList::FindFunctionSymbols(ConstString name,
+ lldb::FunctionNameType name_type_mask,
+ SymbolContextList &sc_list) {
const size_t old_size = sc_list.GetSize();
if (name_type_mask & eFunctionNameTypeAuto) {
@@ -401,96 +383,66 @@ size_t ModuleList::FindFunctionSymbols(ConstString name,
(*pos)->FindFunctionSymbols(name, name_type_mask, sc_list);
}
}
-
- return sc_list.GetSize() - old_size;
}
-size_t ModuleList::FindFunctions(const RegularExpression &name,
- bool include_symbols, bool include_inlines,
- bool append, SymbolContextList &sc_list) {
- const size_t old_size = sc_list.GetSize();
-
+void ModuleList::FindFunctions(const RegularExpression &name,
+ bool include_symbols, bool include_inlines,
+ SymbolContextList &sc_list) {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos) {
- (*pos)->FindFunctions(name, include_symbols, include_inlines, append,
- sc_list);
+ (*pos)->FindFunctions(name, include_symbols, include_inlines, sc_list);
}
-
- return sc_list.GetSize() - old_size;
}
-size_t ModuleList::FindCompileUnits(const FileSpec &path, bool append,
- SymbolContextList &sc_list) const {
- if (!append)
- sc_list.Clear();
-
+void ModuleList::FindCompileUnits(const FileSpec &path,
+ SymbolContextList &sc_list) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos) {
- (*pos)->FindCompileUnits(path, true, sc_list);
+ (*pos)->FindCompileUnits(path, sc_list);
}
-
- return sc_list.GetSize();
}
-size_t ModuleList::FindGlobalVariables(ConstString name,
- size_t max_matches,
- VariableList &variable_list) const {
- size_t initial_size = variable_list.GetSize();
+void ModuleList::FindGlobalVariables(ConstString name, size_t max_matches,
+ VariableList &variable_list) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos) {
(*pos)->FindGlobalVariables(name, nullptr, max_matches, variable_list);
}
- return variable_list.GetSize() - initial_size;
}
-size_t ModuleList::FindGlobalVariables(const RegularExpression &regex,
- size_t max_matches,
- VariableList &variable_list) const {
- size_t initial_size = variable_list.GetSize();
+void ModuleList::FindGlobalVariables(const RegularExpression &regex,
+ size_t max_matches,
+ VariableList &variable_list) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos) {
(*pos)->FindGlobalVariables(regex, max_matches, variable_list);
}
- return variable_list.GetSize() - initial_size;
}
-size_t ModuleList::FindSymbolsWithNameAndType(ConstString name,
- SymbolType symbol_type,
- SymbolContextList &sc_list,
- bool append) const {
+void ModuleList::FindSymbolsWithNameAndType(ConstString name,
+ SymbolType symbol_type,
+ SymbolContextList &sc_list) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- if (!append)
- sc_list.Clear();
- size_t initial_size = sc_list.GetSize();
-
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos)
(*pos)->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
- return sc_list.GetSize() - initial_size;
}
-size_t ModuleList::FindSymbolsMatchingRegExAndType(
+void ModuleList::FindSymbolsMatchingRegExAndType(
const RegularExpression &regex, lldb::SymbolType symbol_type,
- SymbolContextList &sc_list, bool append) const {
+ SymbolContextList &sc_list) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- if (!append)
- sc_list.Clear();
- size_t initial_size = sc_list.GetSize();
-
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos)
(*pos)->FindSymbolsMatchingRegExAndType(regex, symbol_type, sc_list);
- return sc_list.GetSize() - initial_size;
}
-size_t ModuleList::FindModules(const ModuleSpec &module_spec,
- ModuleList &matching_module_list) const {
- size_t existing_matches = matching_module_list.GetSize();
-
+void ModuleList::FindModules(const ModuleSpec &module_spec,
+ ModuleList &matching_module_list) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos) {
@@ -498,7 +450,6 @@ size_t ModuleList::FindModules(const ModuleSpec &module_spec,
if (module_sp->MatchesModuleSpec(module_spec))
matching_module_list.Append(module_sp);
}
- return matching_module_list.GetSize() - existing_matches;
}
ModuleSP ModuleList::FindModule(const Module *module_ptr) const {
@@ -536,44 +487,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);
-
- if (total_matches >= max_matches)
- break;
- }
- }
+ 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);
- return total_matches;
+ if (types.GetSize() >= max_matches)
+ return;
+ }
}
bool ModuleList::FindSourceFile(const FileSpec &orig_spec,
@@ -641,11 +584,11 @@ void ModuleList::LogUUIDAndPaths(Log *log, const char *prefix_cstr) {
for (pos = begin; pos != end; ++pos) {
Module *module = pos->get();
const FileSpec &module_file_spec = module->GetFileSpec();
- log->Printf("%s[%u] %s (%s) \"%s\"", prefix_cstr ? prefix_cstr : "",
- (uint32_t)std::distance(begin, pos),
- module->GetUUID().GetAsString().c_str(),
- module->GetArchitecture().GetArchitectureName(),
- module_file_spec.GetPath().c_str());
+ LLDB_LOGF(log, "%s[%u] %s (%s) \"%s\"", prefix_cstr ? prefix_cstr : "",
+ (uint32_t)std::distance(begin, pos),
+ module->GetUUID().GetAsString().c_str(),
+ module->GetArchitecture().GetArchitectureName(),
+ module_file_spec.GetPath().c_str());
}
}
}
@@ -757,9 +700,9 @@ bool ModuleList::ModuleIsInCache(const Module *module_ptr) {
return false;
}
-size_t ModuleList::FindSharedModules(const ModuleSpec &module_spec,
- ModuleList &matching_module_list) {
- return GetSharedModuleList().FindModules(module_spec, matching_module_list);
+void ModuleList::FindSharedModules(const ModuleSpec &module_spec,
+ ModuleList &matching_module_list) {
+ GetSharedModuleList().FindModules(module_spec, matching_module_list);
}
size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) {
@@ -794,8 +737,9 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec,
// mutex list.
if (!always_create) {
ModuleList matching_module_list;
- const size_t num_matching_modules =
- shared_module_list.FindModules(module_spec, matching_module_list);
+ shared_module_list.FindModules(module_spec, matching_module_list);
+ const size_t num_matching_modules = matching_module_list.GetSize();
+
if (num_matching_modules > 0) {
for (size_t module_idx = 0; module_idx < num_matching_modules;
++module_idx) {
@@ -808,8 +752,9 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec,
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES));
if (log != nullptr)
- log->Printf("module changed: %p, removing from global module list",
- static_cast<void *>(module_sp.get()));
+ LLDB_LOGF(log,
+ "module changed: %p, removing from global module list",
+ static_cast<void *>(module_sp.get()));
shared_module_list.Remove(module_sp);
module_sp.reset();
@@ -945,8 +890,8 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec,
platform_module_spec.GetSymbolFileSpec() =
located_binary_modulespec.GetSymbolFileSpec();
ModuleList matching_module_list;
- if (shared_module_list.FindModules(platform_module_spec,
- matching_module_list) > 0) {
+ shared_module_list.FindModules(platform_module_spec, matching_module_list);
+ if (!matching_module_list.IsEmpty()) {
module_sp = matching_module_list.GetModuleAtIndex(0);
// If we didn't have a UUID in mind when looking for the object file,