[Lldb-commits] [lldb] f2e0585 - [lldb] Access the ModuleList through iterators where possible (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 7 21:06:45 PST 2021
Author: Jonas Devlieghere
Date: 2021-01-07T21:06:36-08:00
New Revision: f2e05855deb39125a30a67b63a5e524792805768
URL: https://github.com/llvm/llvm-project/commit/f2e05855deb39125a30a67b63a5e524792805768
DIFF: https://github.com/llvm/llvm-project/commit/f2e05855deb39125a30a67b63a5e524792805768.diff
LOG: [lldb] Access the ModuleList through iterators where possible (NFC)
Replace uses of GetModuleAtIndexUnlocked and
GetModulePointerAtIndexUnlocked with the ModuleIterable and
ModuleIterableNoLocking where applicable.
Differential revision: https://reviews.llvm.org/D94271
Added:
Modified:
lldb/include/lldb/Core/ModuleList.h
lldb/include/lldb/Utility/Iterable.h
lldb/source/Breakpoint/Breakpoint.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Core/ModuleList.cpp
lldb/source/Core/SearchFilter.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
lldb/source/Target/Process.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h
index 1609f0f77c56..46a718f08f04 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -237,20 +237,6 @@ class ModuleList {
/// \see ModuleList::GetSize()
Module *GetModulePointerAtIndex(size_t idx) const;
- /// Get the module pointer for the module at index \a idx without acquiring
- /// the ModuleList mutex. This MUST already have been acquired with
- /// ModuleList::GetMutex and locked for this call to be safe.
- ///
- /// \param[in] idx
- /// An index into this module collection.
- ///
- /// \return
- /// A pointer to a Module which can by nullptr if \a idx is out
- /// of range.
- ///
- /// \see ModuleList::GetSize()
- Module *GetModulePointerAtIndexUnlocked(size_t idx) const;
-
/// Find compile units by partial or full path.
///
/// Finds all compile units that match \a path in all of the modules and
@@ -491,11 +477,13 @@ class ModuleList {
typedef LockingAdaptedIterable<collection, lldb::ModuleSP, vector_adapter,
std::recursive_mutex>
ModuleIterable;
- ModuleIterable Modules() { return ModuleIterable(m_modules, GetMutex()); }
+ ModuleIterable Modules() const {
+ return ModuleIterable(m_modules, GetMutex());
+ }
typedef AdaptedIterable<collection, lldb::ModuleSP, vector_adapter>
ModuleIterableNoLocking;
- ModuleIterableNoLocking ModulesNoLocking() {
+ ModuleIterableNoLocking ModulesNoLocking() const {
return ModuleIterableNoLocking(m_modules);
}
};
diff --git a/lldb/include/lldb/Utility/Iterable.h b/lldb/include/lldb/Utility/Iterable.h
index 3f9b8b1e4c57..5c38e46feb92 100644
--- a/lldb/include/lldb/Utility/Iterable.h
+++ b/lldb/include/lldb/Utility/Iterable.h
@@ -170,7 +170,7 @@ template <typename C, typename E, E (*A)(typename C::const_iterator &),
typename MutexType>
class LockingAdaptedIterable : public AdaptedIterable<C, E, A> {
public:
- LockingAdaptedIterable(C &container, MutexType &mutex)
+ LockingAdaptedIterable(const C &container, MutexType &mutex)
: AdaptedIterable<C, E, A>(container), m_mutex(&mutex) {
m_mutex->lock();
}
diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp
index 06d08ecdb3eb..d7bca308ca99 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -508,7 +508,6 @@ void Breakpoint::ModulesChanged(ModuleList &module_list, bool load,
"delete_locations: %i\n",
module_list.GetSize(), load, delete_locations);
- std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
if (load) {
// The logic for handling new modules is:
// 1) If the filter rejects this module, then skip it. 2) Run through the
@@ -525,7 +524,7 @@ void Breakpoint::ModulesChanged(ModuleList &module_list, bool load,
// them after the locations pass. Have to do it this way because resolving
// breakpoints will add new locations potentially.
- for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
+ for (ModuleSP module_sp : module_list.Modules()) {
bool seen = false;
if (!m_filter_sp->ModulePasses(module_sp))
continue;
@@ -589,9 +588,7 @@ void Breakpoint::ModulesChanged(ModuleList &module_list, bool load,
else
removed_locations_event = nullptr;
- size_t num_modules = module_list.GetSize();
- for (size_t i = 0; i < num_modules; i++) {
- ModuleSP module_sp(module_list.GetModuleAtIndexUnlocked(i));
+ for (ModuleSP module_sp : module_list.Modules()) {
if (m_filter_sp->ModulePasses(module_sp)) {
size_t loc_idx = 0;
size_t num_locations = m_locations.GetSize();
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 4bce4e7e0734..1cb21384fd2a 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1399,31 +1399,30 @@ static void DumpBasename(Stream &strm, const FileSpec *file_spec_ptr,
}
static size_t DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list) {
- size_t num_dumped = 0;
std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
const size_t num_modules = module_list.GetSize();
- if (num_modules > 0) {
- strm.Printf("Dumping headers for %" PRIu64 " module(s).\n",
- static_cast<uint64_t>(num_modules));
- strm.IndentMore();
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
- Module *module = module_list.GetModulePointerAtIndexUnlocked(image_idx);
- if (module) {
- if (num_dumped++ > 0) {
- strm.EOL();
- strm.EOL();
- }
- ObjectFile *objfile = module->GetObjectFile();
- if (objfile)
- objfile->Dump(&strm);
- else {
- strm.Format("No object file for module: {0:F}\n",
- module->GetFileSpec());
- }
+ if (num_modules == 0)
+ return 0;
+
+ size_t num_dumped = 0;
+ strm.Format("Dumping headers for {0} module(s).\n", num_modules);
+ strm.IndentMore();
+ for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
+ if (module_sp) {
+ if (num_dumped++ > 0) {
+ strm.EOL();
+ strm.EOL();
+ }
+ ObjectFile *objfile = module_sp->GetObjectFile();
+ if (objfile)
+ objfile->Dump(&strm);
+ else {
+ strm.Format("No object file for module: {0:F}\n",
+ module_sp->GetFileSpec());
}
}
- strm.IndentLess();
}
+ strm.IndentLess();
return num_dumped;
}
@@ -2025,14 +2024,13 @@ class CommandObjectTargetModulesDumpSymtab
if (command.GetArgumentCount() == 0) {
// Dump all sections for all modules images
- std::lock_guard<std::recursive_mutex> guard(
- target->GetImages().GetMutex());
- const size_t num_modules = target->GetImages().GetSize();
+ const ModuleList &module_list = target->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
+ const size_t num_modules = module_list.GetSize();
if (num_modules > 0) {
- result.GetOutputStream().Printf("Dumping symbol table for %" PRIu64
- " modules.\n",
- (uint64_t)num_modules);
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ result.GetOutputStream().Format(
+ "Dumping symbol table for {0} modules.\n", num_modules);
+ for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
if (num_dumped > 0) {
result.GetOutputStream().EOL();
result.GetOutputStream().EOL();
@@ -2040,10 +2038,9 @@ class CommandObjectTargetModulesDumpSymtab
if (m_interpreter.WasInterrupted())
break;
num_dumped++;
- DumpModuleSymtab(
- m_interpreter, result.GetOutputStream(),
- target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
- m_options.m_sort_order, name_preference);
+ DumpModuleSymtab(m_interpreter, result.GetOutputStream(),
+ module_sp.get(), m_options.m_sort_order,
+ name_preference);
}
} else {
result.AppendError("the target has no associated executable images");
@@ -2060,9 +2057,8 @@ class CommandObjectTargetModulesDumpSymtab
const size_t num_matches =
FindModulesByName(target, arg_cstr, module_list, true);
if (num_matches > 0) {
- for (size_t i = 0; i < num_matches; ++i) {
- Module *module = module_list.GetModulePointerAtIndex(i);
- if (module) {
+ for (ModuleSP module_sp : module_list.Modules()) {
+ if (module_sp) {
if (num_dumped > 0) {
result.GetOutputStream().EOL();
result.GetOutputStream().EOL();
@@ -2070,8 +2066,9 @@ class CommandObjectTargetModulesDumpSymtab
if (m_interpreter.WasInterrupted())
break;
num_dumped++;
- DumpModuleSymtab(m_interpreter, result.GetOutputStream(), module,
- m_options.m_sort_order, name_preference);
+ DumpModuleSymtab(m_interpreter, result.GetOutputStream(),
+ module_sp.get(), m_options.m_sort_order,
+ name_preference);
}
}
} else
@@ -2120,23 +2117,22 @@ class CommandObjectTargetModulesDumpSections
if (command.GetArgumentCount() == 0) {
// Dump all sections for all modules images
const size_t num_modules = target->GetImages().GetSize();
- if (num_modules > 0) {
- result.GetOutputStream().Printf("Dumping sections for %" PRIu64
- " modules.\n",
- (uint64_t)num_modules);
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
- if (m_interpreter.WasInterrupted())
- break;
- num_dumped++;
- DumpModuleSections(
- m_interpreter, result.GetOutputStream(),
- target->GetImages().GetModulePointerAtIndex(image_idx));
- }
- } else {
+ if (num_modules == 0) {
result.AppendError("the target has no associated executable images");
result.SetStatus(eReturnStatusFailed);
return false;
}
+
+ result.GetOutputStream().Format("Dumping sections for {0} modules.\n",
+ num_modules);
+ for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ if (m_interpreter.WasInterrupted())
+ break;
+ num_dumped++;
+ DumpModuleSections(
+ m_interpreter, result.GetOutputStream(),
+ target->GetImages().GetModulePointerAtIndex(image_idx));
+ }
} else {
// Dump specified images (by basename or fullpath)
const char *arg_cstr;
@@ -2198,7 +2194,8 @@ class CommandObjectTargetModulesDumpClangAST
bool DoExecute(Args &command, CommandReturnObject &result) override {
Target *target = &GetSelectedTarget();
- const size_t num_modules = target->GetImages().GetSize();
+ const ModuleList &module_list = target->GetImages();
+ const size_t num_modules = module_list.GetSize();
if (num_modules == 0) {
result.AppendError("the target has no associated executable images");
result.SetStatus(eReturnStatusFailed);
@@ -2207,14 +2204,12 @@ class CommandObjectTargetModulesDumpClangAST
if (command.GetArgumentCount() == 0) {
// Dump all ASTs for all modules images
- result.GetOutputStream().Printf("Dumping clang ast for %" PRIu64
- " modules.\n",
- (uint64_t)num_modules);
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ result.GetOutputStream().Format("Dumping clang ast for {0} modules.\n",
+ num_modules);
+ for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
if (m_interpreter.WasInterrupted())
break;
- Module *m = target->GetImages().GetModulePointerAtIndex(image_idx);
- if (SymbolFile *sf = m->GetSymbolFile())
+ if (SymbolFile *sf = module_sp->GetSymbolFile())
sf->DumpClangAST(result.GetOutputStream());
}
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -2279,23 +2274,19 @@ class CommandObjectTargetModulesDumpSymfile
const ModuleList &target_modules = target->GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0) {
- result.GetOutputStream().Printf("Dumping debug symbols for %" PRIu64
- " modules.\n",
- (uint64_t)num_modules);
- for (uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
- if (m_interpreter.WasInterrupted())
- break;
- if (DumpModuleSymbolFile(
- result.GetOutputStream(),
- target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
- num_dumped++;
- }
- } else {
+ if (num_modules == 0) {
result.AppendError("the target has no associated executable images");
result.SetStatus(eReturnStatusFailed);
return false;
}
+ result.GetOutputStream().Format(
+ "Dumping debug symbols for {0} modules.\n", num_modules);
+ for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
+ if (m_interpreter.WasInterrupted())
+ break;
+ if (DumpModuleSymbolFile(result.GetOutputStream(), module_sp.get()))
+ num_dumped++;
+ }
} else {
// Dump specified images (by basename or fullpath)
const char *arg_cstr;
@@ -2373,15 +2364,13 @@ class CommandObjectTargetModulesDumpLineTable
const ModuleList &target_modules = target->GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0) {
+ if (target_modules.GetSize() > 0) {
uint32_t num_dumped = 0;
- for (uint32_t i = 0; i < num_modules; ++i) {
+ for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
if (m_interpreter.WasInterrupted())
break;
if (DumpCompileUnitLineTable(
- m_interpreter, result.GetOutputStream(),
- target_modules.GetModulePointerAtIndexUnlocked(i),
+ m_interpreter, result.GetOutputStream(), module_sp.get(),
file_spec,
m_options.m_verbose ? eDescriptionLevelFull
: eDescriptionLevelBrief))
@@ -3903,25 +3892,20 @@ class CommandObjectTargetModulesLookup : public CommandObjectParsed {
const ModuleList &target_modules = target->GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0) {
- for (i = 0; i < num_modules && !syntax_error; ++i) {
- Module *module_pointer =
- target_modules.GetModulePointerAtIndexUnlocked(i);
-
- if (module_pointer != current_module.get() &&
- LookupInModule(m_interpreter,
- target_modules.GetModulePointerAtIndexUnlocked(i),
- result, syntax_error)) {
- result.GetOutputStream().EOL();
- num_successful_lookups++;
- }
- }
- } else {
+ if (target_modules.GetSize() == 0) {
result.AppendError("the target has no associated executable images");
result.SetStatus(eReturnStatusFailed);
return false;
}
+
+ for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
+ if (module_sp != current_module &&
+ LookupInModule(m_interpreter, module_sp.get(), result,
+ syntax_error)) {
+ result.GetOutputStream().EOL();
+ num_successful_lookups++;
+ }
+ }
} else {
// Dump specified images (by basename or fullpath)
const char *arg_cstr;
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index b6e1ceb40889..98f6ae2c62b0 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -346,10 +346,6 @@ void ModuleList::ClearImpl(bool use_notifier) {
Module *ModuleList::GetModulePointerAtIndex(size_t idx) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- return GetModulePointerAtIndexUnlocked(idx);
-}
-
-Module *ModuleList::GetModulePointerAtIndexUnlocked(size_t idx) const {
if (idx < m_modules.size())
return m_modules[idx].get();
return nullptr;
diff --git a/lldb/source/Core/SearchFilter.cpp b/lldb/source/Core/SearchFilter.cpp
index fc1ceff71912..e3327ff5e750 100644
--- a/lldb/source/Core/SearchFilter.cpp
+++ b/lldb/source/Core/SearchFilter.cpp
@@ -228,11 +228,7 @@ void SearchFilter::SearchInModuleList(Searcher &searcher, ModuleList &modules) {
return;
}
- std::lock_guard<std::recursive_mutex> guard(modules.GetMutex());
- const size_t numModules = modules.GetSize();
-
- for (size_t i = 0; i < numModules; i++) {
- ModuleSP module_sp(modules.GetModuleAtIndexUnlocked(i));
+ for (ModuleSP module_sp : modules.Modules()) {
if (!ModulePasses(module_sp))
continue;
if (DoModuleIteration(module_sp, searcher) == Searcher::eCallbackReturnStop)
@@ -262,14 +258,9 @@ SearchFilter::DoModuleIteration(const SymbolContext &context,
return Searcher::eCallbackReturnContinue;
}
- const ModuleList &target_images = m_target_sp->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
-
- size_t n_modules = target_images.GetSize();
- for (size_t i = 0; i < n_modules; i++) {
+ for (ModuleSP module_sp : m_target_sp->GetImages().Modules()) {
// If this is the last level supplied, then call the callback directly,
// otherwise descend.
- ModuleSP module_sp(target_images.GetModuleAtIndexUnlocked(i));
if (!ModulePasses(module_sp))
continue;
@@ -434,11 +425,9 @@ void SearchFilterByModule::Search(Searcher &searcher) {
const ModuleList &target_modules = m_target_sp->GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- for (size_t i = 0; i < num_modules; i++) {
- Module *module = target_modules.GetModulePointerAtIndexUnlocked(i);
- if (FileSpec::Match(m_module_spec, module->GetFileSpec())) {
- SymbolContext matchingContext(m_target_sp, module->shared_from_this());
+ for (ModuleSP module_sp : m_target_sp->GetImages().Modules()) {
+ if (FileSpec::Match(m_module_spec, module_sp->GetFileSpec())) {
+ SymbolContext matchingContext(m_target_sp, module_sp);
Searcher::CallbackReturn shouldContinue;
shouldContinue = DoModuleIteration(matchingContext, searcher);
@@ -550,17 +539,11 @@ void SearchFilterByModuleList::Search(Searcher &searcher) {
// If the module file spec is a full path, then we can just find the one
// filespec that passes. Otherwise, we need to go through all modules and
// find the ones that match the file name.
-
- const ModuleList &target_modules = m_target_sp->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
-
- const size_t num_modules = target_modules.GetSize();
- for (size_t i = 0; i < num_modules; i++) {
- Module *module = target_modules.GetModulePointerAtIndexUnlocked(i);
- if (m_module_spec_list.FindFileIndex(0, module->GetFileSpec(), false) ==
+ for (ModuleSP module_sp : m_target_sp->GetImages().Modules()) {
+ if (m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) ==
UINT32_MAX)
continue;
- SymbolContext matchingContext(m_target_sp, module->shared_from_this());
+ SymbolContext matchingContext(m_target_sp, module_sp);
Searcher::CallbackReturn shouldContinue;
shouldContinue = DoModuleIteration(matchingContext, searcher);
@@ -752,13 +735,9 @@ void SearchFilterByModuleListAndCU::Search(Searcher &searcher) {
// find the ones that match the file name.
ModuleList matching_modules;
- const ModuleList &target_images = m_target_sp->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
- const size_t num_modules = target_images.GetSize();
bool no_modules_in_filter = m_module_spec_list.GetSize() == 0;
- for (size_t i = 0; i < num_modules; i++) {
- lldb::ModuleSP module_sp = target_images.GetModuleAtIndexUnlocked(i);
+ for (ModuleSP module_sp : m_target_sp->GetImages().Modules()) {
if (!no_modules_in_filter &&
m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) ==
UINT32_MAX)
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
index e35e6063a0f1..ddf6f1212a3e 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -216,15 +216,11 @@ void DynamicLoaderDarwin::UnloadAllImages() {
const ModuleList &target_modules = target.GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- size_t num_modules = target_modules.GetSize();
ModuleSP dyld_sp(GetDYLDModule());
-
- for (size_t i = 0; i < num_modules; i++) {
- ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i);
-
+ for (ModuleSP module_sp : target_modules.Modules()) {
// Don't remove dyld - else we'll lose our breakpoint notifying us about
// libraries being re-loaded...
- if (module_sp.get() != nullptr && module_sp.get() != dyld_sp.get()) {
+ if (module_sp && module_sp != dyld_sp) {
UnloadSections(module_sp);
unloaded_modules_list.Append(module_sp);
}
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
index 9fc5e5daeafb..656a5bfe0f52 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
@@ -401,18 +401,16 @@ DynamicLoaderMacOS::GetDyldLockVariableAddressFromModule(Module *module) {
Status DynamicLoaderMacOS::CanLoadImage() {
Status error;
addr_t symbol_address = LLDB_INVALID_ADDRESS;
+ ConstString g_libdyld_name("libdyld.dylib");
Target &target = m_process->GetTarget();
const ModuleList &target_modules = target.GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- ConstString g_libdyld_name("libdyld.dylib");
// Find any modules named "libdyld.dylib" and look for the symbol there first
- for (size_t i = 0; i < num_modules; i++) {
- Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
- if (module_pointer) {
- if (module_pointer->GetFileSpec().GetFilename() == g_libdyld_name) {
- symbol_address = GetDyldLockVariableAddressFromModule(module_pointer);
+ for (ModuleSP module_sp : target.GetImages().ModulesNoLocking()) {
+ if (module_sp) {
+ if (module_sp->GetFileSpec().GetFilename() == g_libdyld_name) {
+ symbol_address = GetDyldLockVariableAddressFromModule(module_sp.get());
if (symbol_address != LLDB_INVALID_ADDRESS)
break;
}
@@ -421,12 +419,10 @@ Status DynamicLoaderMacOS::CanLoadImage() {
// Search through all modules looking for the symbol in them
if (symbol_address == LLDB_INVALID_ADDRESS) {
- for (size_t i = 0; i < num_modules; i++) {
- Module *module_pointer =
- target_modules.GetModulePointerAtIndexUnlocked(i);
- if (module_pointer) {
+ for (ModuleSP module_sp : target.GetImages().Modules()) {
+ if (module_sp) {
addr_t symbol_address =
- GetDyldLockVariableAddressFromModule(module_pointer);
+ GetDyldLockVariableAddressFromModule(module_sp.get());
if (symbol_address != LLDB_INVALID_ADDRESS)
break;
}
@@ -451,9 +447,9 @@ Status DynamicLoaderMacOS::CanLoadImage() {
// _dyld_start) - so we should not allow dlopen calls. But if we found more
// than one module then we are clearly past _dyld_start so in that case
// we'll default to "it's safe".
- if (num_modules <= 1)
- error.SetErrorString("could not find the dyld library or "
- "the dyld lock symbol");
+ if (target.GetImages().GetSize() <= 1)
+ error.SetErrorString("could not find the dyld library or "
+ "the dyld lock symbol");
}
return error;
}
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index 76b4c4811094..5d48273fd8eb 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -728,13 +728,8 @@ bool DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos() {
// DYLD_*_PATH pointed to an equivalent version. We don't want it to stay
// in the target's module list or it will confuse us, so unload it here.
Target &target = m_process->GetTarget();
- const ModuleList &target_modules = target.GetImages();
ModuleList not_loaded_modules;
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
-
- size_t num_modules = target_modules.GetSize();
- for (size_t i = 0; i < num_modules; i++) {
- ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i);
+ for (ModuleSP module_sp : target.GetImages().Modules()) {
if (!module_sp->IsLoadedInTarget(&target)) {
if (log) {
StreamString s;
diff --git a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
index 62b11405a385..c1fceeb1482c 100644
--- a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
@@ -83,11 +83,7 @@ void DynamicLoaderStatic::LoadAllImagesAtFileAddresses() {
// Disable JIT for static dynamic loader targets
m_process->SetCanJIT(false);
- std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
-
- const size_t num_modules = module_list.GetSize();
- for (uint32_t idx = 0; idx < num_modules; ++idx) {
- ModuleSP module_sp(module_list.GetModuleAtIndexUnlocked(idx));
+ for (ModuleSP module_sp : module_list.Modules()) {
if (module_sp) {
bool changed = false;
ObjectFile *image_object_file = module_sp->GetObjectFile();
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 79ee565a3fdd..0f34c48c7e82 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -690,12 +690,7 @@ void ClangASTSource::FillNamespaceMap(
return;
}
- const ModuleList &target_images = m_target->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
-
- for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) {
- lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i);
-
+ for (lldb::ModuleSP image : m_target->GetImages().Modules()) {
if (!image)
continue;
@@ -1667,14 +1662,8 @@ void ClangASTSource::CompleteNamespaceMap(
module_sp->GetFileSpec().GetFilename());
}
} else {
- const ModuleList &target_images = m_target->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
-
CompilerDeclContext null_namespace_decl;
-
- for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) {
- lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i);
-
+ for (lldb::ModuleSP image : m_target->GetImages().Modules()) {
if (!image)
continue;
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index 71cecc0fe8fb..973a5570c06e 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -377,12 +377,7 @@ AppleObjCRuntime::GetObjCVersion(Process *process, ModuleSP &objc_module_sp) {
llvm::Triple::VendorType::Apple)
return ObjCRuntimeVersions::eObjC_VersionUnknown;
- const ModuleList &target_modules = target.GetImages();
- std::lock_guard<std::recursive_mutex> gaurd(target_modules.GetMutex());
-
- size_t num_images = target_modules.GetSize();
- for (size_t i = 0; i < num_images; i++) {
- ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i);
+ for (ModuleSP module_sp : target.GetImages().Modules()) {
// One tricky bit here is that we might get called as part of the initial
// module loading, but before all the pre-run libraries get winnowed from
// the module list. So there might actually be an old and incorrect ObjC
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 4d23443d5d3b..ee84ccd869fc 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -1590,10 +1590,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process);
if (objc_runtime) {
- const ModuleList &images = process->GetTarget().GetImages();
- std::lock_guard<std::recursive_mutex> guard(images.GetMutex());
- for (size_t i = 0; i < images.GetSize(); ++i) {
- lldb::ModuleSP mod_sp = images.GetModuleAtIndexUnlocked(i);
+ for (lldb::ModuleSP mod_sp : process->GetTarget().GetImages().Modules()) {
if (objc_runtime->IsModuleObjCLibrary(mod_sp)) {
const Symbol *symbol =
mod_sp->FindFirstSymbolWithNameAndType(g_class_getNameRaw_symbol_name,
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
index 5c4e3813d517..bcc1f6fd339f 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
@@ -452,15 +452,11 @@ bool AppleObjCTrampolineHandler::AppleObjCVTables::InitializeVTableSymbols() {
if (process_sp) {
Target &target = process_sp->GetTarget();
- const ModuleList &target_modules = target.GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- size_t num_modules = target_modules.GetSize();
if (!m_objc_module_sp) {
- for (size_t i = 0; i < num_modules; i++) {
+ for (ModuleSP module_sp : target.GetImages().Modules()) {
if (ObjCLanguageRuntime::Get(*process_sp)
- ->IsModuleObjCLibrary(
- target_modules.GetModuleAtIndexUnlocked(i))) {
- m_objc_module_sp = target_modules.GetModuleAtIndexUnlocked(i);
+ ->IsModuleObjCLibrary(module_sp)) {
+ m_objc_module_sp = module_sp;
break;
}
}
diff --git a/lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp b/lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
index 333113a0b17a..7d9976285192 100644
--- a/lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
+++ b/lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
@@ -36,13 +36,8 @@ MemoryHistorySP MemoryHistoryASan::CreateInstance(const ProcessSP &process_sp) {
Target &target = process_sp->GetTarget();
- const ModuleList &target_modules = target.GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- for (size_t i = 0; i < num_modules; ++i) {
- Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
-
- const Symbol *symbol = module_pointer->FindFirstSymbolWithNameAndType(
+ for (ModuleSP module_sp : target.GetImages().Modules()) {
+ const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
ConstString("__asan_get_alloc_stack"), lldb::eSymbolTypeAny);
if (symbol != nullptr)
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index a4eab1aa0b41..7580a7c7f388 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -3076,13 +3076,8 @@ void Process::CompleteAttach() {
}
}
// Figure out which one is the executable, and set that in our target:
- const ModuleList &target_modules = GetTarget().GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- size_t num_modules = target_modules.GetSize();
ModuleSP new_executable_module_sp;
-
- for (size_t i = 0; i < num_modules; i++) {
- ModuleSP module_sp(target_modules.GetModuleAtIndexUnlocked(i));
+ for (ModuleSP module_sp : GetTarget().GetImages().Modules()) {
if (module_sp && module_sp->IsExecutable()) {
if (GetTarget().GetExecutableModulePointer() != module_sp.get())
new_executable_module_sp = module_sp;
More information about the lldb-commits
mailing list