Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,12 @@ class ModuleList {
/// Atomically swaps the contents of this module list with \a other.
void Swap(ModuleList &other);

/// For each module in this ModuleList, preload its symbols.
///
/// \param[in] parallelize
/// If true, all modules will be preloaded in parallel.
void PreloadSymbols(bool parallelize) const;

protected:
// Class typedefs.
typedef std::vector<lldb::ModuleSP>
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/DynamicLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class DynamicLoader : public PluginInterface {
/// resulting module at the virtual base address \p base_addr.
/// Note that this calls Target::GetOrCreateModule with notify being false,
/// so it is necessary to call Target::ModulesDidLoad afterwards.
///
virtual lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file,
lldb::addr_t link_map_addr,
lldb::addr_t base_addr,
Expand Down Expand Up @@ -352,6 +353,7 @@ class DynamicLoader : public PluginInterface {
protected:
// Utility methods for derived classes

/// Find a module in the target that matches the given file.
lldb::ModuleSP FindModuleViaTarget(const FileSpec &file);

/// Checks to see if the target module has changed, updates the target
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Core/DynamicLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
if (ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec))
return module_sp;

if (ModuleSP module_sp = target.GetOrCreateModule(module_spec, false))
if (ModuleSP module_sp = target.GetOrCreateModule(
module_spec, false /* notify */, nullptr /* error_ptr */))
return module_sp;

return nullptr;
Expand Down
21 changes: 21 additions & 0 deletions lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "lldb/Core/ModuleList.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
Expand All @@ -28,6 +29,7 @@
#include "lldb/Utility/Log.h"
#include "lldb/Utility/UUID.h"
#include "lldb/lldb-defines.h"
#include "llvm/Support/ThreadPool.h"

#if defined(_WIN32)
#include "lldb/Host/windows/PosixApi.h"
Expand Down Expand Up @@ -1381,3 +1383,22 @@ void ModuleList::Swap(ModuleList &other) {
m_modules_mutex, other.m_modules_mutex);
m_modules.swap(other.m_modules);
}

void ModuleList::PreloadSymbols(bool parallelize) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);

if (!parallelize) {
for (const ModuleSP &module_sp : m_modules)
module_sp->PreloadSymbols();
return;
}

// parallelize
llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
for (const ModuleSP &module_sp : m_modules)
task_group.async([module_sp] {
if (module_sp)
module_sp->PreloadSymbols();
});
// task group destructor waits for all tasks to complete
}
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
}

ModuleSP module_sp = LoadModuleAtAddress(
so_entry.file_spec, so_entry.link_addr, so_entry.base_addr, true);
so_entry.file_spec, so_entry.link_addr, so_entry.base_addr,
true /* base_addr_is_offset */);
if (!module_sp.get())
return;

Expand Down Expand Up @@ -510,6 +511,10 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
load_module_fn(*I);
}

if (m_process->GetTarget().GetPreloadSymbols())
new_modules.PreloadSymbols(
m_process->GetTarget().GetParallelModuleLoad());

m_process->GetTarget().ModulesDidLoad(new_modules);
}

Expand Down Expand Up @@ -725,11 +730,12 @@ void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() {
for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I)
task_group.async(load_module_fn, *I);
task_group.wait();
} else {
for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) {
} else
for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I)
load_module_fn(*I);
}
}

if (m_process->GetTarget().GetPreloadSymbols())
module_list.PreloadSymbols(m_process->GetTarget().GetParallelModuleLoad());

m_process->GetTarget().ModulesDidLoad(module_list);
m_initial_modules_added = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ lldb::ModuleSP DynamicLoaderWasmDYLD::LoadModuleAtAddress(
const lldb_private::FileSpec &file, lldb::addr_t link_map_addr,
lldb::addr_t base_addr, bool base_addr_is_offset) {
if (ModuleSP module_sp = DynamicLoader::LoadModuleAtAddress(
file, link_map_addr, base_addr, base_addr_is_offset))
file, link_map_addr, base_addr, base_addr_is_offset)) {
if (m_process->GetTarget().GetPreloadSymbols())
module_sp->PreloadSymbols();
return module_sp;
}

if (ModuleSP module_sp = m_process->ReadModuleFromMemory(file, base_addr)) {
UpdateLoadedSections(module_sp, link_map_addr, base_addr, false);
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2509,10 +2509,6 @@ ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec,
if (symbol_file_spec)
module_sp->SetSymbolFileFileSpec(symbol_file_spec);

// Preload symbols outside of any lock, so hopefully we can do this for
// each library in parallel.
if (GetPreloadSymbols())
module_sp->PreloadSymbols();
llvm::SmallVector<ModuleSP, 1> replaced_modules;
for (ModuleSP &old_module_sp : old_modules) {
if (m_images.GetIndexForModule(old_module_sp.get()) !=
Expand Down
Loading