Skip to content

Commit 8602d97

Browse files
committed
Revert "[lldb] Unify Platform::ResolveExecutable (llvm#96256)"
This reverts commit bf3e328.
1 parent 7a253c2 commit 8602d97

File tree

11 files changed

+348
-15
lines changed

11 files changed

+348
-15
lines changed

lldb/include/lldb/Target/Platform.h

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

130130
/// Find a symbol file given a symbol file module specification.
@@ -989,6 +989,11 @@ class Platform : public PluginInterface {
989989

990990
virtual const char *GetCacheHostname();
991991

992+
virtual Status
993+
ResolveRemoteExecutable(const ModuleSpec &module_spec,
994+
lldb::ModuleSP &exe_module_sp,
995+
const FileSpecList *module_search_paths_ptr);
996+
992997
private:
993998
typedef std::function<Status(const ModuleSpec &)> ModuleResolver;
994999

lldb/include/lldb/Target/RemoteAwarePlatform.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class RemoteAwarePlatform : public Platform {
2323
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
2424
ModuleSpec &module_spec) override;
2525

26+
Status
27+
ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
28+
const FileSpecList *module_search_paths_ptr) override;
29+
2630
lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
2731
uint32_t mode, Status &error) override;
2832

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,81 @@ PlatformSP PlatformAppleSimulator::CreateInstance(
383383
return PlatformSP();
384384
}
385385

386+
Status PlatformAppleSimulator::ResolveExecutable(
387+
const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp,
388+
const FileSpecList *module_search_paths_ptr) {
389+
Status error;
390+
// Nothing special to do here, just use the actual file and architecture
391+
392+
ModuleSpec resolved_module_spec(module_spec);
393+
394+
// If we have "ls" as the exe_file, resolve the executable loation based on
395+
// the current path variables
396+
// TODO: resolve bare executables in the Platform SDK
397+
// if (!resolved_exe_file.Exists())
398+
// resolved_exe_file.ResolveExecutableLocation ();
399+
400+
// Resolve any executable within a bundle on MacOSX
401+
// TODO: verify that this handles shallow bundles, if not then implement one
402+
// ourselves
403+
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
404+
405+
if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) {
406+
if (resolved_module_spec.GetArchitecture().IsValid()) {
407+
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
408+
NULL, NULL, NULL);
409+
410+
if (exe_module_sp && exe_module_sp->GetObjectFile())
411+
return error;
412+
exe_module_sp.reset();
413+
}
414+
// No valid architecture was specified or the exact ARM slice wasn't found
415+
// so ask the platform for the architectures that we should be using (in
416+
// the correct order) and see if we can find a match that way
417+
StreamString arch_names;
418+
llvm::ListSeparator LS;
419+
ArchSpec platform_arch;
420+
for (const ArchSpec &arch : GetSupportedArchitectures({})) {
421+
resolved_module_spec.GetArchitecture() = arch;
422+
423+
// Only match x86 with x86 and x86_64 with x86_64...
424+
if (!module_spec.GetArchitecture().IsValid() ||
425+
module_spec.GetArchitecture().GetCore() ==
426+
resolved_module_spec.GetArchitecture().GetCore()) {
427+
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
428+
NULL, NULL, NULL);
429+
// Did we find an executable using one of the
430+
if (error.Success()) {
431+
if (exe_module_sp && exe_module_sp->GetObjectFile())
432+
break;
433+
else
434+
error.SetErrorToGenericError();
435+
}
436+
437+
arch_names << LS << platform_arch.GetArchitectureName();
438+
}
439+
}
440+
441+
if (error.Fail() || !exe_module_sp) {
442+
if (FileSystem::Instance().Readable(resolved_module_spec.GetFileSpec())) {
443+
error.SetErrorStringWithFormatv(
444+
"'{0}' doesn't contain any '{1}' platform architectures: {2}",
445+
resolved_module_spec.GetFileSpec(), GetPluginName(),
446+
arch_names.GetString());
447+
} else {
448+
error.SetErrorStringWithFormat(
449+
"'%s' is not readable",
450+
resolved_module_spec.GetFileSpec().GetPath().c_str());
451+
}
452+
}
453+
} else {
454+
error.SetErrorStringWithFormat("'%s' does not exist",
455+
module_spec.GetFileSpec().GetPath().c_str());
456+
}
457+
458+
return error;
459+
}
460+
386461
Status PlatformAppleSimulator::GetSymbolFile(const FileSpec &platform_file,
387462
const UUID *uuid_ptr,
388463
FileSpec &local_file) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class PlatformAppleSimulator : public PlatformDarwin {
8787
std::vector<ArchSpec>
8888
GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
8989

90+
Status
91+
ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
92+
const FileSpecList *module_search_paths_ptr) override;
93+
9094
Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
9195
lldb::ModuleSP &module_sp,
9296
const FileSpecList *module_search_paths_ptr,

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,71 @@ void PlatformRemoteDarwinDevice::GetStatus(Stream &strm) {
6363
}
6464
}
6565

66+
Status PlatformRemoteDarwinDevice::ResolveExecutable(
67+
const ModuleSpec &ms, lldb::ModuleSP &exe_module_sp,
68+
const FileSpecList *module_search_paths_ptr) {
69+
Status error;
70+
// Nothing special to do here, just use the actual file and architecture
71+
72+
ModuleSpec resolved_module_spec(ms);
73+
74+
// Resolve any executable within a bundle on MacOSX
75+
// TODO: verify that this handles shallow bundles, if not then implement one
76+
// ourselves
77+
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
78+
79+
if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) {
80+
if (resolved_module_spec.GetArchitecture().IsValid() ||
81+
resolved_module_spec.GetUUID().IsValid()) {
82+
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
83+
nullptr, nullptr, nullptr);
84+
85+
if (exe_module_sp && exe_module_sp->GetObjectFile())
86+
return error;
87+
exe_module_sp.reset();
88+
}
89+
// No valid architecture was specified or the exact ARM slice wasn't found
90+
// so ask the platform for the architectures that we should be using (in
91+
// the correct order) and see if we can find a match that way
92+
StreamString arch_names;
93+
llvm::ListSeparator LS;
94+
ArchSpec process_host_arch;
95+
for (const ArchSpec &arch : GetSupportedArchitectures(process_host_arch)) {
96+
resolved_module_spec.GetArchitecture() = arch;
97+
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
98+
nullptr, nullptr, nullptr);
99+
// Did we find an executable using one of the
100+
if (error.Success()) {
101+
if (exe_module_sp && exe_module_sp->GetObjectFile())
102+
break;
103+
else
104+
error.SetErrorToGenericError();
105+
}
106+
107+
arch_names << LS << arch.GetArchitectureName();
108+
}
109+
110+
if (error.Fail() || !exe_module_sp) {
111+
if (FileSystem::Instance().Readable(resolved_module_spec.GetFileSpec())) {
112+
error.SetErrorStringWithFormatv(
113+
"'{0}' doesn't contain any '{1}' platform architectures: {2}",
114+
resolved_module_spec.GetFileSpec(), GetPluginName(),
115+
arch_names.GetData());
116+
} else {
117+
error.SetErrorStringWithFormat(
118+
"'%s' is not readable",
119+
resolved_module_spec.GetFileSpec().GetPath().c_str());
120+
}
121+
}
122+
} else {
123+
error.SetErrorStringWithFormat(
124+
"'%s' does not exist",
125+
resolved_module_spec.GetFileSpec().GetPath().c_str());
126+
}
127+
128+
return error;
129+
}
130+
66131
bool PlatformRemoteDarwinDevice::GetFileInSDK(const char *platform_file_path,
67132
uint32_t sdk_idx,
68133
lldb_private::FileSpec &local_file) {

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class PlatformRemoteDarwinDevice : public PlatformDarwinDevice {
4040
~PlatformRemoteDarwinDevice() override;
4141

4242
// Platform functions
43+
Status
44+
ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
45+
const FileSpecList *module_search_paths_ptr) override;
46+
4347
void GetStatus(Stream &strm) override;
4448

4549
virtual Status GetSymbolFile(const FileSpec &platform_file,

lldb/source/Target/Platform.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,41 @@ Platform::ResolveExecutable(const ModuleSpec &module_spec,
734734
const FileSpecList *module_search_paths_ptr) {
735735
Status error;
736736

737+
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
738+
if (module_spec.GetArchitecture().IsValid()) {
739+
error = ModuleList::GetSharedModule(module_spec, exe_module_sp,
740+
module_search_paths_ptr, nullptr,
741+
nullptr);
742+
} else {
743+
// No valid architecture was specified, ask the platform for the
744+
// architectures that we should be using (in the correct order) and see
745+
// if we can find a match that way
746+
ModuleSpec arch_module_spec(module_spec);
747+
ArchSpec process_host_arch;
748+
for (const ArchSpec &arch :
749+
GetSupportedArchitectures(process_host_arch)) {
750+
arch_module_spec.GetArchitecture() = arch;
751+
error = ModuleList::GetSharedModule(arch_module_spec, exe_module_sp,
752+
module_search_paths_ptr, nullptr,
753+
nullptr);
754+
// Did we find an executable using one of the
755+
if (error.Success() && exe_module_sp)
756+
break;
757+
}
758+
}
759+
} else {
760+
error.SetErrorStringWithFormat(
761+
"'%s' does not exist", module_spec.GetFileSpec().GetPath().c_str());
762+
}
763+
return error;
764+
}
765+
766+
Status
767+
Platform::ResolveRemoteExecutable(const ModuleSpec &module_spec,
768+
lldb::ModuleSP &exe_module_sp,
769+
const FileSpecList *module_search_paths_ptr) {
770+
Status error;
771+
737772
// We may connect to a process and use the provided executable (Don't use
738773
// local $PATH).
739774
ModuleSpec resolved_module_spec(module_spec);
@@ -753,9 +788,9 @@ Platform::ResolveExecutable(const ModuleSpec &module_spec,
753788
return error;
754789
exe_module_sp.reset();
755790
}
756-
// No valid architecture was specified or the exact arch wasn't found.
757-
// Ask the platform for the architectures that we should be using (in the
758-
// correct order) and see if we can find a match that way.
791+
// No valid architecture was specified or the exact arch wasn't found so
792+
// ask the platform for the architectures that we should be using (in the
793+
// correct order) and see if we can find a match that way
759794
StreamString arch_names;
760795
llvm::ListSeparator LS;
761796
ArchSpec process_host_arch;
@@ -764,10 +799,12 @@ Platform::ResolveExecutable(const ModuleSpec &module_spec,
764799
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
765800
module_search_paths_ptr, nullptr,
766801
nullptr);
802+
// Did we find an executable using one of the
767803
if (error.Success()) {
768804
if (exe_module_sp && exe_module_sp->GetObjectFile())
769805
break;
770-
error.SetErrorToGenericError();
806+
else
807+
error.SetErrorToGenericError();
771808
}
772809

773810
arch_names << LS << arch.GetArchitectureName();
@@ -1445,7 +1482,8 @@ Platform::GetCachedExecutable(ModuleSpec &module_spec,
14451482
Status error = GetRemoteSharedModule(
14461483
module_spec, nullptr, module_sp,
14471484
[&](const ModuleSpec &spec) {
1448-
return ResolveExecutable(spec, module_sp, module_search_paths_ptr);
1485+
return ResolveRemoteExecutable(spec, module_sp,
1486+
module_search_paths_ptr);
14491487
},
14501488
nullptr);
14511489
if (error.Success()) {

0 commit comments

Comments
 (0)