Skip to content

Commit f50fff2

Browse files
committed
fixup! move to new FindModule API; make module UID atomic
1 parent 222afb1 commit f50fff2

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class Module : public std::enable_shared_from_this<Module>,
9898
// using the "--global" (-g for short).
9999
static size_t GetNumberAllocatedModules();
100100

101-
static Module *GetAllocatedModuleWithUID(lldb::user_id_t uid);
102101
static Module *GetAllocatedModuleAtIndex(size_t idx);
103102

104103
static std::recursive_mutex &GetAllocationModuleCollectionMutex();

lldb/include/lldb/Core/ModuleList.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ class ModuleList {
351351
// UUID values is very efficient and accurate.
352352
lldb::ModuleSP FindModule(const UUID &uuid) const;
353353

354+
/// Find a module by LLDB-specific unique identifier.
355+
///
356+
/// \param[in] uid The UID of the module assigned to it on construction.
357+
///
358+
/// \returns ModuleSP of module with \c uid. Returns nullptr if no such
359+
/// module could be found.
360+
lldb::ModuleSP FindModule(lldb::user_id_t uid) const;
361+
354362
/// Finds the first module whose file specification matches \a module_spec.
355363
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const;
356364

lldb/source/Core/Module.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,6 @@ size_t Module::GetNumberAllocatedModules() {
121121
return GetModuleCollection().size();
122122
}
123123

124-
Module *Module::GetAllocatedModuleWithUID(lldb::user_id_t uid) {
125-
std::lock_guard<std::recursive_mutex> guard(
126-
GetAllocationModuleCollectionMutex());
127-
for (Module *mod : GetModuleCollection())
128-
if (mod->GetID() == uid)
129-
return mod;
130-
return nullptr;
131-
}
132-
133124
Module *Module::GetAllocatedModuleAtIndex(size_t idx) {
134125
std::lock_guard<std::recursive_mutex> guard(
135126
GetAllocationModuleCollectionMutex());
@@ -139,8 +130,7 @@ Module *Module::GetAllocatedModuleAtIndex(size_t idx) {
139130
return nullptr;
140131
}
141132

142-
// TODO: needs a mutex
143-
static lldb::user_id_t g_unique_id = 1;
133+
static std::atomic<lldb::user_id_t> g_unique_id = 1;
144134

145135
Module::Module(const ModuleSpec &module_spec)
146136
: UserID(g_unique_id++), m_unwind_table(*this), m_file_has_changed(false),

lldb/source/Core/ModuleList.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,20 @@ ModuleSP ModuleList::FindModule(const UUID &uuid) const {
584584
return module_sp;
585585
}
586586

587+
ModuleSP ModuleList::FindModule(lldb::user_id_t uid) const {
588+
ModuleSP module_sp;
589+
ForEach([&](const ModuleSP &m) {
590+
if (m->GetID() == uid) {
591+
module_sp = m;
592+
return true;
593+
}
594+
595+
return false;
596+
});
597+
598+
return module_sp;
599+
}
600+
587601
void ModuleList::FindTypes(Module *search_first, const TypeQuery &query,
588602
TypeResults &results) const {
589603
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -809,16 +809,16 @@ ResolveFunctionCallLabel(llvm::StringRef name,
809809

810810
const auto &label = *label_or_err;
811811

812-
Module *module = Module::GetAllocatedModuleWithUID(label.m_module_id);
812+
auto module_sp = sc.target_sp->GetImages().FindModule(label.m_module_id);
813813

814-
if (!module)
814+
if (!module_sp)
815815
return llvm::createStringError(
816816
llvm::formatv("failed to find module by UID {0}", label.m_module_id));
817817

818-
auto *symbol_file = module->GetSymbolFile();
818+
auto *symbol_file = module_sp->GetSymbolFile();
819819
if (!symbol_file)
820820
return llvm::createStringError(
821-
llvm::formatv("no SymbolFile found on module {0:x}.", module));
821+
llvm::formatv("no SymbolFile found on module {0:x}.", module_sp.get()));
822822

823823
SymbolContextList sc_list;
824824
if (auto err =

0 commit comments

Comments
 (0)