Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
4 changes: 4 additions & 0 deletions lldb/include/lldb/API/SBModuleSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class LLDB_API SBModuleSpec {

bool GetDescription(lldb::SBStream &description);

lldb::SBTarget GetTarget();

void SetTarget(lldb::SBTarget target);

private:
friend class SBModuleSpecList;
friend class SBModule;
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@ class LLDB_API SBTarget {
friend class SBValue;
friend class SBVariablesOptions;

friend class SBModuleSpec;

friend class lldb_private::python::SWIGBridge;

// Constructors are private, use static Target::Create function to create an
Expand Down
4 changes: 2 additions & 2 deletions lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ class ModuleList {

static Status
GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
bool *did_create_ptr, bool always_create = false);
bool *did_create_ptr, bool always_create = false,
bool invoke_locate_callback = true);

static bool RemoveSharedModule(lldb::ModuleSP &module_sp);

Expand Down
12 changes: 12 additions & 0 deletions lldb/include/lldb/Core/ModuleSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#include "lldb/Utility/Iterable.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/UUID.h"
#include "lldb/lldb-forward.h"

#include "llvm/Support/Chrono.h"

#include <memory>
#include <mutex>
#include <vector>

Expand Down Expand Up @@ -126,6 +128,12 @@ class ModuleSpec {

lldb::DataBufferSP GetData() const { return m_data; }

lldb::TargetSP GetTargetSP() { return m_target_wp.lock(); }

lldb::TargetSP GetTargetSP() const { return m_target_wp.lock(); }

void SetTarget(std::shared_ptr<Target> target) { m_target_wp = target; }

void Clear() {
m_file.Clear();
m_platform_file.Clear();
Expand All @@ -137,6 +145,7 @@ class ModuleSpec {
m_object_size = 0;
m_source_mappings.Clear(false);
m_object_mod_time = llvm::sys::TimePoint<>();
m_target_wp.reset();
}

explicit operator bool() const {
Expand Down Expand Up @@ -265,6 +274,9 @@ class ModuleSpec {
ArchSpec m_arch;
UUID m_uuid;
ConstString m_object_name;
/// This is set to take advantage of the target's search path and platform's
/// locate module callback
std::weak_ptr<Target> m_target_wp;
uint64_t m_object_offset = 0;
uint64_t m_object_size = 0;
llvm::sys::TimePoint<> m_object_mod_time;
Expand Down
16 changes: 8 additions & 8 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ class Platform : public PluginInterface {
/// Returns \b true if this Platform plug-in was able to find
/// a suitable executable, \b false otherwise.
virtual Status ResolveExecutable(const ModuleSpec &module_spec,
lldb::ModuleSP &exe_module_sp,
const FileSpecList *module_search_paths_ptr);
lldb::ModuleSP &exe_module_sp);

/// Find a symbol file given a symbol file module specification.
///
Expand Down Expand Up @@ -304,10 +303,11 @@ class Platform : public PluginInterface {
/// \return
/// The Status object for any errors found while searching for
/// the binary.
virtual Status GetSharedModule(
const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
virtual Status
GetSharedModule(const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
bool *did_create_ptr);

void CallLocateModuleCallbackIfSet(const ModuleSpec &module_spec,
lldb::ModuleSP &module_sp,
Expand Down Expand Up @@ -1039,8 +1039,8 @@ class Platform : public PluginInterface {
/// predefined trap handlers, this method may be a no-op.
virtual void CalculateTrapHandlerSymbolNames() = 0;

Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr);
Status GetCachedExecutable(ModuleSpec &module_spec,
lldb::ModuleSP &module_sp);

virtual Status DownloadModuleSlice(const FileSpec &src_file_spec,
const uint64_t src_offset,
Expand Down
6 changes: 2 additions & 4 deletions lldb/include/lldb/Target/RemoteAwarePlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class RemoteAwarePlatform : public Platform {
public:
using Platform::Platform;

virtual Status
ResolveExecutable(const ModuleSpec &module_spec,
lldb::ModuleSP &exe_module_sp,
const FileSpecList *module_search_paths_ptr) override;
virtual Status ResolveExecutable(const ModuleSpec &module_spec,
lldb::ModuleSP &exe_module_sp) override;

bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
ModuleSpec &module_spec) override;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/API/SBModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ SBModule::SBModule(const SBModuleSpec &module_spec) {
LLDB_INSTRUMENT_VA(this, module_spec);

ModuleSP module_sp;
Status error = ModuleList::GetSharedModule(
*module_spec.m_opaque_up, module_sp, nullptr, nullptr, nullptr);
Status error = ModuleList::GetSharedModule(*module_spec.m_opaque_up,
module_sp, nullptr, nullptr);
if (module_sp)
SetSP(module_sp);
}
Expand Down
13 changes: 13 additions & 0 deletions lldb/source/API/SBModuleSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "lldb/API/SBModuleSpec.h"
#include "Utils.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBTarget.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/Host.h"
Expand Down Expand Up @@ -174,6 +175,18 @@ void SBModuleSpec::SetObjectSize(uint64_t object_size) {
m_opaque_up->SetObjectSize(object_size);
}

SBTarget SBModuleSpec::GetTarget() {
LLDB_INSTRUMENT_VA(this);

return SBTarget(m_opaque_up->GetTargetSP());
}

void SBModuleSpec::SetTarget(SBTarget target) {
LLDB_INSTRUMENT_VA(this, target);

m_opaque_up->SetTarget(target.GetSP());
}

SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {
LLDB_INSTRUMENT_VA(this);
}
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Core/DynamicLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
}
}
ModuleSpec module_spec;
module_spec.SetTarget(target.shared_from_this());
module_spec.GetUUID() = uuid;
FileSpec name_filespec(name);
if (FileSystem::Instance().Exists(name_filespec))
Expand All @@ -238,8 +239,8 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
// Has lldb already seen a module with this UUID?
// Or have external lookup enabled in DebugSymbols on macOS.
if (!module_sp)
error = ModuleList::GetSharedModule(module_spec, module_sp, nullptr,
nullptr, nullptr);
error =
ModuleList::GetSharedModule(module_spec, module_sp, nullptr, nullptr);

// Can lldb's symbol/executable location schemes
// find an executable and symbol file.
Expand Down
35 changes: 30 additions & 5 deletions lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/TypeList.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpecList.h"
Expand Down Expand Up @@ -1038,9 +1040,9 @@ size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) {

Status
ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
bool *did_create_ptr, bool always_create) {
bool *did_create_ptr, bool always_create,
bool invoke_locate_callback) {
SharedModuleList &shared_module_list = GetSharedModuleList();
std::lock_guard<std::recursive_mutex> guard(shared_module_list.GetMutex());
char path[PATH_MAX];
Expand Down Expand Up @@ -1095,6 +1097,22 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
if (module_sp)
return error;

// Try target's platform locate module callback before second attempt.
if (invoke_locate_callback) {
TargetSP target_sp = module_spec.GetTargetSP();
if (target_sp && target_sp->IsValid()) {
if (PlatformSP platform_sp = target_sp->GetPlatform()) {
FileSpec symbol_file_spec;
platform_sp->CallLocateModuleCallbackIfSet(
module_spec, module_sp, symbol_file_spec, did_create_ptr);
if (module_sp) {
// The callback found a module.
return error;
}
}
}
}

module_sp = std::make_shared<Module>(module_spec);
// Make sure there are a module and an object file since we can specify a
// valid file path with an architecture that might not be in that file. By
Expand Down Expand Up @@ -1122,10 +1140,17 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
module_sp.reset();
}

if (module_search_paths_ptr) {
const auto num_directories = module_search_paths_ptr->GetSize();
// Get module search paths from the target if available.
lldb::TargetSP target_sp = module_spec.GetTargetSP();
FileSpecList module_search_paths;
if (target_sp) {
module_search_paths = target_sp->GetExecutableSearchPaths();
}

if (!module_search_paths.IsEmpty()) {
const auto num_directories = module_search_paths.GetSize();
for (size_t idx = 0; idx < num_directories; ++idx) {
auto search_path_spec = module_search_paths_ptr->GetFileSpecAtIndex(idx);
auto search_path_spec = module_search_paths.GetFileSpecAtIndex(idx);
FileSystem::Instance().Resolve(search_path_spec);
namespace fs = llvm::sys::fs;
if (!FileSystem::Instance().IsDirectory(search_path_spec))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
// Search for the kext on the local filesystem via the UUID
if (!m_module_sp && m_uuid.IsValid()) {
ModuleSpec module_spec;
module_spec.SetTarget(target.shared_from_this());
module_spec.GetUUID() = m_uuid;
if (!m_uuid.IsValid())
module_spec.GetArchitecture() = target.GetArchitecture();
Expand All @@ -801,9 +802,8 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
// system.
PlatformSP platform_sp(target.GetPlatform());
if (platform_sp) {
FileSpecList search_paths = target.GetExecutableSearchPaths();
platform_sp->GetSharedModule(module_spec, process, m_module_sp,
&search_paths, nullptr, nullptr);
platform_sp->GetSharedModule(module_spec, process, m_module_sp, nullptr,
nullptr);
}

// Ask the Target to find this file on the local system, if possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,9 @@ void DynamicLoaderPOSIXDYLD::ResolveExecutableModule(
if (module_sp && module_sp->MatchesModuleSpec(module_spec))
return;

module_spec.SetTarget(target.shared_from_this());
const auto executable_search_paths(Target::GetDefaultExecutableSearchPaths());
auto error = platform_sp->ResolveExecutable(
module_spec, module_sp,
!executable_search_paths.IsEmpty() ? &executable_search_paths : nullptr);
auto error = platform_sp->ResolveExecutable(module_spec, module_sp);
if (error.Fail()) {
StreamString stream;
module_spec.Dump(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ Status PlatformAppleSimulator::GetSymbolFile(const FileSpec &platform_file,

Status PlatformAppleSimulator::GetSharedModule(
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr) {
// For iOS/tvOS/watchOS, the SDK files are all cached locally on the
// host system. So first we ask for the file in the cached SDK, then
Expand All @@ -432,12 +431,10 @@ Status PlatformAppleSimulator::GetSharedModule(
error = GetSymbolFile(platform_file, module_spec.GetUUIDPtr(),
platform_module_spec.GetFileSpec());
if (error.Success()) {
error = ResolveExecutable(platform_module_spec, module_sp,
module_search_paths_ptr);
error = ResolveExecutable(platform_module_spec, module_sp);
} else {
const bool always_create = false;
error = ModuleList::GetSharedModule(module_spec, module_sp,
module_search_paths_ptr, old_modules,
error = ModuleList::GetSharedModule(module_spec, module_sp, old_modules,
did_create_ptr, always_create);
}
if (module_sp)
Expand Down Expand Up @@ -660,4 +657,3 @@ void PlatformAppleSimulator::Terminate() {
PlatformDarwin::Terminate();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class PlatformAppleSimulator : public PlatformDarwin {

Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
bool *did_create_ptr) override;

Expand Down
Loading
Loading