Skip to content
Open
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
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 allow_locate_callback = true);

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

Expand Down
17 changes: 17 additions & 0 deletions lldb/include/lldb/Core/ModuleSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "llvm/Support/Chrono.h"

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

Expand Down Expand Up @@ -126,6 +127,18 @@ class ModuleSpec {

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

Target *GetTargetPtr() {
auto locked = m_target.lock();
return locked.get();
}

const Target *GetTargetPtr() const {
auto locked = m_target.lock();
return locked.get();
}

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

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

explicit operator bool() const {
Expand Down Expand Up @@ -265,6 +279,9 @@ class ModuleSpec {
ArchSpec m_arch;
UUID m_uuid;
ConstString m_object_name;
std::weak_ptr<Target>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put comment above with ///

m_target; // This is set to take advantage of the target's search path
// and platform's locate module callback
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
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
34 changes: 32 additions & 2 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 @@ -1029,9 +1031,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 allow_locate_callback) {
ModuleList &shared_module_list = GetSharedModuleList();
std::lock_guard<std::recursive_mutex> guard(
shared_module_list.m_modules_mutex);
Expand Down Expand Up @@ -1087,6 +1089,24 @@ 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 (allow_locate_callback) {
ModuleSpec module_spec_copy(module_spec);
Target *target = module_spec_copy.GetTargetPtr();
if (target && target->IsValid()) {
Platform *platform = target->GetPlatform().get();
if (platform) {
FileSpec symbol_file_spec;
platform->CallLocateModuleCallbackIfSet(
module_spec, module_sp, symbol_file_spec, did_create_ptr);
if (module_sp) {
// Success! 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 @@ -1114,6 +1134,16 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
module_sp.reset();
}

// Get module search paths from the target if available
ModuleSpec module_spec_copy(module_spec);
Target *target = module_spec_copy.GetTargetPtr();
FileSpecList module_search_paths;
FileSpecList *module_search_paths_ptr = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this pointer, just use module_search_paths everywhere in this function.

if (target && target->IsValid()) {
module_search_paths = target->GetExecutableSearchPaths();
module_search_paths_ptr = &module_search_paths;
}

if (module_search_paths_ptr) {
const auto num_directories = module_search_paths_ptr->GetSize();
for (size_t idx = 0; idx < num_directories; ++idx) {
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
39 changes: 26 additions & 13 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ Status PlatformDarwin::ResolveSymbolFile(Target &target,

Status PlatformDarwin::GetSharedModule(
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
Status error;
module_sp.reset();
Expand All @@ -341,18 +340,25 @@ Status PlatformDarwin::GetSharedModule(
// module first.
if (m_remote_platform_sp) {
error = m_remote_platform_sp->GetSharedModule(
module_spec, process, module_sp, module_search_paths_ptr, old_modules,
did_create_ptr);
module_spec, process, module_sp, old_modules, did_create_ptr);
}
}

if (!module_sp) {
// Fall back to the local platform and find the file locally
error = Platform::GetSharedModule(module_spec, process, module_sp,
module_search_paths_ptr, old_modules,
did_create_ptr);
old_modules, did_create_ptr);

const FileSpec &platform_file = module_spec.GetFileSpec();
// Get module search paths from the target if available
ModuleSpec module_spec_copy(module_spec);
Target *target = module_spec_copy.GetTargetPtr();
FileSpecList module_search_paths;
FileSpecList *module_search_paths_ptr = nullptr;
if (target) {
module_search_paths = target->GetExecutableSearchPaths();
module_search_paths_ptr = &module_search_paths;
}
if (!module_sp && module_search_paths_ptr && platform_file) {
// We can try to pull off part of the file path up to the bundle
// directory level and try any module search paths...
Expand All @@ -362,9 +368,9 @@ Status PlatformDarwin::GetSharedModule(
ModuleSpec new_module_spec(module_spec);
new_module_spec.GetFileSpec() = bundle_directory;
if (Host::ResolveExecutableInBundle(new_module_spec.GetFileSpec())) {
Status new_error(Platform::GetSharedModule(
new_module_spec, process, module_sp, nullptr, old_modules,
did_create_ptr));
Status new_error(Platform::GetSharedModule(new_module_spec, process,
module_sp, old_modules,
did_create_ptr));

if (module_sp)
return new_error;
Expand All @@ -390,7 +396,7 @@ Status PlatformDarwin::GetSharedModule(
ModuleSpec new_module_spec(module_spec);
new_module_spec.GetFileSpec() = new_file_spec;
Status new_error(Platform::GetSharedModule(
new_module_spec, process, module_sp, nullptr, old_modules,
new_module_spec, process, module_sp, old_modules,
did_create_ptr));

if (module_sp) {
Expand Down Expand Up @@ -1303,9 +1309,16 @@ PlatformDarwin::LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) {

lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths(
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
const FileSpec &platform_file = module_spec.GetFileSpec();
ModuleSpec module_spec_copy(module_spec);
Target *target = module_spec_copy.GetTargetPtr();
FileSpecList module_search_paths;
FileSpecList *module_search_paths_ptr = nullptr;
if (target) {
module_search_paths = target->GetExecutableSearchPaths();
module_search_paths_ptr = &module_search_paths;
}
// See if the file is present in any of the module_search_paths_ptr
// directories.
if (!module_sp && module_search_paths_ptr && platform_file) {
Expand Down Expand Up @@ -1356,9 +1369,9 @@ lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths(
if (FileSystem::Instance().Exists(path_to_try)) {
ModuleSpec new_module_spec(module_spec);
new_module_spec.GetFileSpec() = path_to_try;
Status new_error(
Platform::GetSharedModule(new_module_spec, process, module_sp,
nullptr, old_modules, did_create_ptr));
Status new_error(Platform::GetSharedModule(new_module_spec, process,
module_sp, old_modules,
did_create_ptr));

if (module_sp) {
module_sp->SetPlatformFileSpec(path_to_try);
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class PlatformDarwin : public PlatformPOSIX {

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 Expand Up @@ -189,7 +188,7 @@ class PlatformDarwin : public PlatformPOSIX {

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

// The OSType where lldb is running.
Expand Down
Loading
Loading