Skip to content

Commit c8a091e

Browse files
authored
[lldb][NFC] Use IterationAction for ModuleList::ForEach callbacks (#150930)
1 parent a63bbf2 commit c8a091e

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
@@ -17,6 +17,7 @@
1717
#include "lldb/Utility/Status.h"
1818
#include "lldb/lldb-enumerations.h"
1919
#include "lldb/lldb-forward.h"
20+
#include "lldb/lldb-private-enumerations.h"
2021
#include "lldb/lldb-types.h"
2122

2223
#include "llvm/ADT/DenseSet.h"
@@ -488,8 +489,9 @@ class ModuleList {
488489
/// be non-null.
489490
///
490491
/// This function is thread-safe.
491-
void ForEach(std::function<bool(const lldb::ModuleSP &module_sp)> const
492-
&callback) const;
492+
void
493+
ForEach(std::function<IterationAction(const lldb::ModuleSP &module_sp)> const
494+
&callback) const;
493495

494496
/// Returns true if 'callback' returns true for one of the modules
495497
/// in this ModuleList.

lldb/source/Commands/CommandCompletions.cpp

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

lldb/source/Core/ModuleList.cpp

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

10791079
void ModuleList::ForEach(
1080-
std::function<bool(const ModuleSP &module_sp)> const &callback) const {
1080+
std::function<IterationAction(const ModuleSP &module_sp)> const &callback)
1081+
const {
10811082
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
10821083
for (const auto &module_sp : m_modules) {
10831084
assert(module_sp != nullptr);
1084-
// If the callback returns false, then stop iterating and break out
1085-
if (!callback(module_sp))
1085+
if (callback(module_sp) == IterationAction::Stop)
10861086
break;
10871087
}
10881088
}

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
@@ -5260,17 +5260,17 @@ llvm::Error ProcessGDBRemote::LoadModules() {
52605260
loaded_modules.Remove(removed_modules);
52615261
m_process->GetTarget().ModulesDidUnload(removed_modules, false);
52625262

5263-
new_modules.ForEach([&target](const lldb::ModuleSP module_sp) -> bool {
5263+
new_modules.ForEach([&target](const lldb::ModuleSP module_sp) {
52645264
lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
52655265
if (!obj)
5266-
return true;
5266+
return IterationAction::Continue;
52675267

52685268
if (obj->GetType() != ObjectFile::Type::eTypeExecutable)
5269-
return true;
5269+
return IterationAction::Continue;
52705270

52715271
lldb::ModuleSP module_copy_sp = module_sp;
52725272
target.SetExecutableModule(module_copy_sp, eLoadDependentsNo);
5273-
return false;
5273+
return IterationAction::Stop;
52745274
});
52755275

52765276
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
@@ -408,7 +408,7 @@ void ProcessMinidump::BuildMemoryRegions() {
408408
to_add.back().SetName(module_sp->GetFileSpec().GetPath().c_str());
409409
}
410410
}
411-
return true;
411+
return IterationAction::Continue;
412412
});
413413
m_memory_regions->insert(m_memory_regions->end(), to_add.begin(),
414414
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
@@ -2487,9 +2487,9 @@ ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec,
24872487

24882488
ModuleList found_modules;
24892489
m_images.FindModules(module_spec_copy, found_modules);
2490-
found_modules.ForEach([&](const ModuleSP &found_module) -> bool {
2490+
found_modules.ForEach([&](const ModuleSP &found_module) {
24912491
old_modules.push_back(found_module);
2492-
return true;
2492+
return IterationAction::Continue;
24932493
});
24942494
}
24952495

0 commit comments

Comments
 (0)