Skip to content

Commit

Permalink
[lldb][NFC] Modernize for-loops in ModuleList
Browse files Browse the repository at this point in the history
Reviewed By: mib

Differential Revision: https://reviews.llvm.org/D112379
  • Loading branch information
Teemperor committed Oct 30, 2021
1 parent 85bcc1e commit 4cf9d1e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 65 deletions.
2 changes: 1 addition & 1 deletion lldb/include/lldb/Core/ModuleList.h
Expand Up @@ -159,7 +159,7 @@ class ModuleList {
/// ModulesDidLoad may be deferred when adding multiple Modules
/// to the Target, but it must be called at the end,
/// before resuming execution.
bool AppendIfNeeded(const lldb::ModuleSP &module_sp, bool notify = true);
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify = true);

void Append(const ModuleList &module_list);

Expand Down
107 changes: 43 additions & 64 deletions lldb/source/Core/ModuleList.cpp
Expand Up @@ -200,16 +200,15 @@ void ModuleList::ReplaceEquivalent(
}
}

bool ModuleList::AppendIfNeeded(const ModuleSP &module_sp, bool notify) {
if (module_sp) {
bool ModuleList::AppendIfNeeded(const ModuleSP &new_module, bool notify) {
if (new_module) {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
collection::iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos) {
if (pos->get() == module_sp.get())
for (const ModuleSP &module_sp : m_modules) {
if (module_sp.get() == new_module.get())
return false; // Already in the list
}
// Only push module_sp on the list if it wasn't already in there.
Append(module_sp, notify);
Append(new_module, notify);
return true;
}
return false;
Expand Down Expand Up @@ -372,10 +371,10 @@ void ModuleList::FindFunctions(ConstString name,
Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);

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(lookup_info.GetLookupName(), CompilerDeclContext(),
lookup_info.GetNameTypeMask(), options, sc_list);
for (const ModuleSP &module_sp : m_modules) {
module_sp->FindFunctions(lookup_info.GetLookupName(),
CompilerDeclContext(),
lookup_info.GetNameTypeMask(), options, sc_list);
}

const size_t new_size = sc_list.GetSize();
Expand All @@ -384,10 +383,9 @@ void ModuleList::FindFunctions(ConstString name,
lookup_info.Prune(sc_list, old_size);
} else {
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, CompilerDeclContext(), name_type_mask,
options, sc_list);
for (const ModuleSP &module_sp : m_modules) {
module_sp->FindFunctions(name, CompilerDeclContext(), name_type_mask,
options, sc_list);
}
}
}
Expand All @@ -401,10 +399,9 @@ void ModuleList::FindFunctionSymbols(ConstString name,
Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);

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)->FindFunctionSymbols(lookup_info.GetLookupName(),
lookup_info.GetNameTypeMask(), sc_list);
for (const ModuleSP &module_sp : m_modules) {
module_sp->FindFunctionSymbols(lookup_info.GetLookupName(),
lookup_info.GetNameTypeMask(), sc_list);
}

const size_t new_size = sc_list.GetSize();
Expand All @@ -413,9 +410,8 @@ void ModuleList::FindFunctionSymbols(ConstString name,
lookup_info.Prune(sc_list, old_size);
} else {
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)->FindFunctionSymbols(name, name_type_mask, sc_list);
for (const ModuleSP &module_sp : m_modules) {
module_sp->FindFunctionSymbols(name, name_type_mask, sc_list);
}
}
}
Expand All @@ -424,65 +420,54 @@ void ModuleList::FindFunctions(const RegularExpression &name,
const ModuleFunctionSearchOptions &options,
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, options, sc_list);
}
for (const ModuleSP &module_sp : m_modules)
module_sp->FindFunctions(name, options, sc_list);
}

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, sc_list);
}
for (const ModuleSP &module_sp : m_modules)
module_sp->FindCompileUnits(path, sc_list);
}

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, CompilerDeclContext(), max_matches,
variable_list);
for (const ModuleSP &module_sp : m_modules) {
module_sp->FindGlobalVariables(name, CompilerDeclContext(), max_matches,
variable_list);
}
}

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);
}
for (const ModuleSP &module_sp : m_modules)
module_sp->FindGlobalVariables(regex, max_matches, variable_list);
}

void ModuleList::FindSymbolsWithNameAndType(ConstString name,
SymbolType symbol_type,
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)->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
for (const ModuleSP &module_sp : m_modules)
module_sp->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
}

void ModuleList::FindSymbolsMatchingRegExAndType(
const RegularExpression &regex, lldb::SymbolType symbol_type,
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)->FindSymbolsMatchingRegExAndType(regex, symbol_type, sc_list);
for (const ModuleSP &module_sp : m_modules)
module_sp->FindSymbolsMatchingRegExAndType(regex, symbol_type, sc_list);
}

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) {
ModuleSP module_sp(*pos);
for (const ModuleSP &module_sp : m_modules) {
if (module_sp->MatchesModuleSpec(module_spec))
matching_module_list.Append(module_sp);
}
Expand Down Expand Up @@ -558,9 +543,8 @@ void ModuleList::FindTypes(Module *search_first, ConstString name,
bool ModuleList::FindSourceFile(const FileSpec &orig_spec,
FileSpec &new_spec) 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) {
if ((*pos)->FindSourceFile(orig_spec, new_spec))
for (const ModuleSP &module_sp : m_modules) {
if (module_sp->FindSourceFile(orig_spec, new_spec))
return true;
}
return false;
Expand All @@ -572,10 +556,9 @@ void ModuleList::FindAddressesForLine(const lldb::TargetSP target_sp,
std::vector<Address> &output_local,
std::vector<Address> &output_extern) {
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)->FindAddressesForLine(target_sp, file, line, function, output_local,
output_extern);
for (const ModuleSP &module_sp : m_modules) {
module_sp->FindAddressesForLine(target_sp, file, line, function,
output_local, output_extern);
}
}

Expand All @@ -602,10 +585,8 @@ size_t ModuleList::GetSize() const {

void ModuleList::Dump(Stream *s) 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)->Dump(s);
}
for (const ModuleSP &module_sp : m_modules)
module_sp->Dump(s);
}

void ModuleList::LogUUIDAndPaths(Log *log, const char *prefix_cstr) {
Expand All @@ -628,9 +609,8 @@ void ModuleList::LogUUIDAndPaths(Log *log, const char *prefix_cstr) {
bool ModuleList::ResolveFileAddress(lldb::addr_t vm_addr,
Address &so_addr) 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) {
if ((*pos)->ResolveFileAddress(vm_addr, so_addr))
for (const ModuleSP &module_sp : m_modules) {
if (module_sp->ResolveFileAddress(vm_addr, so_addr))
return true;
}

Expand Down Expand Up @@ -673,10 +653,9 @@ uint32_t ModuleList::ResolveSymbolContextsForFileSpec(
const FileSpec &file_spec, uint32_t line, bool check_inlines,
SymbolContextItem resolve_scope, 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)->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
resolve_scope, sc_list);
for (const ModuleSP &module_sp : m_modules) {
module_sp->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
resolve_scope, sc_list);
}

return sc_list.GetSize();
Expand Down

0 comments on commit 4cf9d1e

Please sign in to comment.