Skip to content

Commit 2dc6595

Browse files
author
George Hu
committed
[lldb] Refactor add target into ModuleSpec
1 parent c6534a1 commit 2dc6595

30 files changed

+145
-157
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ class ModuleList {
476476

477477
static Status
478478
GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
479-
const FileSpecList *module_search_paths_ptr,
480479
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
481480
bool *did_create_ptr, bool always_create = false);
482481

lldb/include/lldb/Core/ModuleSpec.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class ModuleSpec {
126126

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

129+
Target *GetTargetPtr() { return m_target; }
130+
131+
const Target *GetTargetPtr() const { return m_target; }
132+
133+
void SetTarget(Target *target) { m_target = target; }
134+
129135
void Clear() {
130136
m_file.Clear();
131137
m_platform_file.Clear();
@@ -137,6 +143,7 @@ class ModuleSpec {
137143
m_object_size = 0;
138144
m_source_mappings.Clear(false);
139145
m_object_mod_time = llvm::sys::TimePoint<>();
146+
m_target = nullptr;
140147
}
141148

142149
explicit operator bool() const {
@@ -265,6 +272,8 @@ class ModuleSpec {
265272
ArchSpec m_arch;
266273
UUID m_uuid;
267274
ConstString m_object_name;
275+
Target *m_target; // This is set to take advantage of the target's search path
276+
// and platform's locate module callback
268277
uint64_t m_object_offset = 0;
269278
uint64_t m_object_size = 0;
270279
llvm::sys::TimePoint<> m_object_mod_time;

lldb/include/lldb/Target/Platform.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ class Platform : public PluginInterface {
127127
/// Returns \b true if this Platform plug-in was able to find
128128
/// a suitable executable, \b false otherwise.
129129
virtual Status ResolveExecutable(const ModuleSpec &module_spec,
130-
lldb::ModuleSP &exe_module_sp,
131-
const FileSpecList *module_search_paths_ptr);
130+
lldb::ModuleSP &exe_module_sp);
132131

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

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

1042-
Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
1043-
const FileSpecList *module_search_paths_ptr);
1042+
Status GetCachedExecutable(ModuleSpec &module_spec,
1043+
lldb::ModuleSP &module_sp);
10441044

10451045
virtual Status DownloadModuleSlice(const FileSpec &src_file_spec,
10461046
const uint64_t src_offset,

lldb/include/lldb/Target/RemoteAwarePlatform.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ class RemoteAwarePlatform : public Platform {
2020
public:
2121
using Platform::Platform;
2222

23-
virtual Status
24-
ResolveExecutable(const ModuleSpec &module_spec,
25-
lldb::ModuleSP &exe_module_sp,
26-
const FileSpecList *module_search_paths_ptr) override;
23+
virtual Status ResolveExecutable(const ModuleSpec &module_spec,
24+
lldb::ModuleSP &exe_module_sp) override;
2725

2826
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
2927
ModuleSpec &module_spec) override;

lldb/source/API/SBModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ SBModule::SBModule(const SBModuleSpec &module_spec) {
3737
LLDB_INSTRUMENT_VA(this, module_spec);
3838

3939
ModuleSP module_sp;
40-
Status error = ModuleList::GetSharedModule(
41-
*module_spec.m_opaque_up, module_sp, nullptr, nullptr, nullptr);
40+
Status error = ModuleList::GetSharedModule(*module_spec.m_opaque_up,
41+
module_sp, nullptr, nullptr);
4242
if (module_sp)
4343
SetSP(module_sp);
4444
}

lldb/source/Core/DynamicLoader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
227227
}
228228
}
229229
ModuleSpec module_spec;
230+
module_spec.SetTarget(&target);
230231
module_spec.GetUUID() = uuid;
231232
FileSpec name_filespec(name);
232233
if (FileSystem::Instance().Exists(name_filespec))
@@ -238,8 +239,8 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
238239
// Has lldb already seen a module with this UUID?
239240
// Or have external lookup enabled in DebugSymbols on macOS.
240241
if (!module_sp)
241-
error = ModuleList::GetSharedModule(module_spec, module_sp, nullptr,
242-
nullptr, nullptr);
242+
error =
243+
ModuleList::GetSharedModule(module_spec, module_sp, nullptr, nullptr);
243244

244245
// Can lldb's symbol/executable location schemes
245246
// find an executable and symbol file.

lldb/source/Core/ModuleList.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "lldb/Symbol/SymbolContext.h"
2020
#include "lldb/Symbol/TypeList.h"
2121
#include "lldb/Symbol/VariableList.h"
22+
#include "lldb/Target/Target.h"
2223
#include "lldb/Utility/ArchSpec.h"
2324
#include "lldb/Utility/ConstString.h"
2425
#include "lldb/Utility/FileSpecList.h"
@@ -1029,7 +1030,6 @@ size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) {
10291030

10301031
Status
10311032
ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
1032-
const FileSpecList *module_search_paths_ptr,
10331033
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
10341034
bool *did_create_ptr, bool always_create) {
10351035
ModuleList &shared_module_list = GetSharedModuleList();
@@ -1114,6 +1114,16 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
11141114
module_sp.reset();
11151115
}
11161116

1117+
// Get module search paths from the target if available
1118+
ModuleSpec module_spec_copy(module_spec);
1119+
Target *target = module_spec_copy.GetTargetPtr();
1120+
FileSpecList module_search_paths;
1121+
FileSpecList *module_search_paths_ptr = nullptr;
1122+
if (target) {
1123+
module_search_paths = target->GetExecutableSearchPaths();
1124+
module_search_paths_ptr = &module_search_paths;
1125+
}
1126+
11171127
if (module_search_paths_ptr) {
11181128
const auto num_directories = module_search_paths_ptr->GetSize();
11191129
for (size_t idx = 0; idx < num_directories; ++idx) {

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
789789
// Search for the kext on the local filesystem via the UUID
790790
if (!m_module_sp && m_uuid.IsValid()) {
791791
ModuleSpec module_spec;
792+
module_spec.SetTarget(&target);
792793
module_spec.GetUUID() = m_uuid;
793794
if (!m_uuid.IsValid())
794795
module_spec.GetArchitecture() = target.GetArchitecture();
@@ -801,9 +802,8 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
801802
// system.
802803
PlatformSP platform_sp(target.GetPlatform());
803804
if (platform_sp) {
804-
FileSpecList search_paths = target.GetExecutableSearchPaths();
805-
platform_sp->GetSharedModule(module_spec, process, m_module_sp,
806-
&search_paths, nullptr, nullptr);
805+
platform_sp->GetSharedModule(module_spec, process, m_module_sp, nullptr,
806+
nullptr);
807807
}
808808

809809
// Ask the Target to find this file on the local system, if possible.

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,9 @@ void DynamicLoaderPOSIXDYLD::ResolveExecutableModule(
901901
if (module_sp && module_sp->MatchesModuleSpec(module_spec))
902902
return;
903903

904+
module_spec.SetTarget(&target);
904905
const auto executable_search_paths(Target::GetDefaultExecutableSearchPaths());
905-
auto error = platform_sp->ResolveExecutable(
906-
module_spec, module_sp,
907-
!executable_search_paths.IsEmpty() ? &executable_search_paths : nullptr);
906+
auto error = platform_sp->ResolveExecutable(module_spec, module_sp);
908907
if (error.Fail()) {
909908
StreamString stream;
910909
module_spec.Dump(stream);

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ Status PlatformAppleSimulator::GetSymbolFile(const FileSpec &platform_file,
420420

421421
Status PlatformAppleSimulator::GetSharedModule(
422422
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
423-
const FileSpecList *module_search_paths_ptr,
424423
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr) {
425424
// For iOS/tvOS/watchOS, the SDK files are all cached locally on the
426425
// host system. So first we ask for the file in the cached SDK, then
@@ -432,12 +431,10 @@ Status PlatformAppleSimulator::GetSharedModule(
432431
error = GetSymbolFile(platform_file, module_spec.GetUUIDPtr(),
433432
platform_module_spec.GetFileSpec());
434433
if (error.Success()) {
435-
error = ResolveExecutable(platform_module_spec, module_sp,
436-
module_search_paths_ptr);
434+
error = ResolveExecutable(platform_module_spec, module_sp);
437435
} else {
438436
const bool always_create = false;
439-
error = ModuleList::GetSharedModule(module_spec, module_sp,
440-
module_search_paths_ptr, old_modules,
437+
error = ModuleList::GetSharedModule(module_spec, module_sp, old_modules,
441438
did_create_ptr, always_create);
442439
}
443440
if (module_sp)
@@ -660,4 +657,3 @@ void PlatformAppleSimulator::Terminate() {
660657
PlatformDarwin::Terminate();
661658
}
662659
}
663-

0 commit comments

Comments
 (0)