Skip to content

Commit 6ad1930

Browse files
committed
[lldb][NFC] Use IterationAction for ModuleList::ForEach callbacks (llvm#150930)
(cherry picked from commit c8a091e)
1 parent a3a03fd commit 6ad1930

File tree

8 files changed

+21
-19
lines changed

8 files changed

+21
-19
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Utility/Status.h"
1919
#include "lldb/lldb-enumerations.h"
2020
#include "lldb/lldb-forward.h"
21+
#include "lldb/lldb-private-enumerations.h"
2122
#include "lldb/lldb-types.h"
2223

2324
#include "llvm/ADT/DenseSet.h"
@@ -530,8 +531,9 @@ class ModuleList {
530531
/// be non-null.
531532
///
532533
/// This function is thread-safe.
533-
void ForEach(std::function<bool(const lldb::ModuleSP &module_sp)> const
534-
&callback) const;
534+
void
535+
ForEach(std::function<IterationAction(const lldb::ModuleSP &module_sp)> const
536+
&callback) const;
535537

536538
void ClearModuleDependentCaches();
537539

lldb/source/Commands/CommandCompletions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void CommandCompletions::ModuleUUIDs(CommandInterpreter &interpreter,
570570
lldb::eDescriptionLevelInitial);
571571
request.TryCompleteCurrentArg(module->GetUUID().GetAsString(),
572572
strm.GetString());
573-
return true;
573+
return IterationAction::Continue;
574574
});
575575
}
576576

lldb/source/Core/ModuleList.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,12 +1343,12 @@ bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
13431343
}
13441344

13451345
void ModuleList::ForEach(
1346-
std::function<bool(const ModuleSP &module_sp)> const &callback) const {
1346+
std::function<IterationAction(const ModuleSP &module_sp)> const &callback)
1347+
const {
13471348
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
13481349
for (const auto &module_sp : m_modules) {
13491350
assert(module_sp != nullptr);
1350-
// If the callback returns false, then stop iterating and break out
1351-
if (!callback(module_sp))
1351+
if (callback(module_sp) == IterationAction::Stop)
13521352
break;
13531353
}
13541354
}

lldb/source/Plugins/InstrumentationRuntime/Utility/Utility.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ lldb::ModuleSP GetPreferredAsanModule(const Target &target) {
2323
target.GetImages().ForEach([&](const lldb::ModuleSP &m) {
2424
if (pattern.match(m->GetFileSpec().GetFilename().GetStringRef())) {
2525
module = m;
26-
return false;
26+
return IterationAction::Stop;
2727
}
2828

29-
return true;
29+
return IterationAction::Continue;
3030
});
3131

3232
return module;

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5265,17 +5265,17 @@ llvm::Error ProcessGDBRemote::LoadModules() {
52655265
loaded_modules.Remove(removed_modules);
52665266
m_process->GetTarget().ModulesDidUnload(removed_modules, false);
52675267

5268-
new_modules.ForEach([&target](const lldb::ModuleSP module_sp) -> bool {
5268+
new_modules.ForEach([&target](const lldb::ModuleSP module_sp) {
52695269
lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
52705270
if (!obj)
5271-
return true;
5271+
return IterationAction::Continue;
52725272

52735273
if (obj->GetType() != ObjectFile::Type::eTypeExecutable)
5274-
return true;
5274+
return IterationAction::Continue;
52755275

52765276
lldb::ModuleSP module_copy_sp = module_sp;
52775277
target.SetExecutableModule(module_copy_sp, eLoadDependentsNo);
5278-
return false;
5278+
return IterationAction::Stop;
52795279
});
52805280

52815281
loaded_modules.AppendIfNeeded(new_modules);

lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void ProcessMinidump::BuildMemoryRegions() {
405405
to_add.back().SetName(module_sp->GetFileSpec().GetPath().c_str());
406406
}
407407
}
408-
return true;
408+
return IterationAction::Continue;
409409
});
410410
m_memory_regions->insert(m_memory_regions->end(), to_add.begin(),
411411
to_add.end());

lldb/source/Target/InstrumentationRuntime.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ void InstrumentationRuntime::ModulesDidLoad(
4949
return;
5050
}
5151

52-
module_list.ForEach([this](const lldb::ModuleSP module_sp) -> bool {
52+
module_list.ForEach([this](const lldb::ModuleSP module_sp) {
5353
const FileSpec &file_spec = module_sp->GetFileSpec();
5454
if (!file_spec)
55-
return true; // Keep iterating.
55+
return IterationAction::Continue;
5656

5757
const RegularExpression &runtime_regex = GetPatternForRuntimeLibrary();
5858
if (runtime_regex.Execute(file_spec.GetFilename().GetCString()) ||
@@ -62,11 +62,11 @@ void InstrumentationRuntime::ModulesDidLoad(
6262
Activate();
6363
if (!IsActive())
6464
SetRuntimeModuleSP({}); // Don't cache module if activation failed.
65-
return false; // Stop iterating, we're done.
65+
return IterationAction::Stop;
6666
}
6767
}
6868

69-
return true;
69+
return IterationAction::Continue;
7070
});
7171
}
7272

lldb/source/Target/Target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,9 +2523,9 @@ ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec,
25232523

25242524
ModuleList found_modules;
25252525
m_images.FindModules(module_spec_copy, found_modules);
2526-
found_modules.ForEach([&](const ModuleSP &found_module) -> bool {
2526+
found_modules.ForEach([&](const ModuleSP &found_module) {
25272527
old_modules.push_back(found_module);
2528-
return true;
2528+
return IterationAction::Continue;
25292529
});
25302530
}
25312531

0 commit comments

Comments
 (0)