Skip to content

Commit 3bcf4d7

Browse files
committed
[lldb] Plumb process host architecture through platform selection
To allow us to select a different platform based on where the process is running, plumb the process host architecture through platform selection. This patch is in preparation for D121444 which needs this functionality to tell apart iOS binaries running on Apple Silicon vs on a remote iOS device. Differential revision: https://reviews.llvm.org/D121484 (cherry picked from commit dde487e)
1 parent db86abd commit 3bcf4d7

36 files changed

+126
-75
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ class Platform : public PluginInterface {
9595
static lldb::PlatformSP GetHostPlatform();
9696

9797
static lldb::PlatformSP
98-
GetPlatformForArchitecture(const ArchSpec &arch, ArchSpec *platform_arch_ptr);
98+
GetPlatformForArchitecture(const ArchSpec &arch,
99+
const ArchSpec &process_host_arch = {},
100+
ArchSpec *platform_arch_ptr = nullptr);
99101

100102
static const char *GetHostPlatformName();
101103

@@ -107,6 +109,7 @@ class Platform : public PluginInterface {
107109
static lldb::PlatformSP Create(ConstString name, Status &error);
108110

109111
static lldb::PlatformSP Create(const ArchSpec &arch,
112+
const ArchSpec &process_host_arch,
110113
ArchSpec *platform_arch_ptr, Status &error);
111114

112115
/// Augments the triple either with information from platform or the host
@@ -311,7 +314,8 @@ class Platform : public PluginInterface {
311314

312315
/// Get the platform's supported architectures in the order in which they
313316
/// should be searched.
314-
virtual std::vector<ArchSpec> GetSupportedArchitectures() = 0;
317+
virtual std::vector<ArchSpec>
318+
GetSupportedArchitectures(const ArchSpec &process_host_arch) = 0;
315319

316320
virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target,
317321
BreakpointSite *bp_site);
@@ -333,6 +337,7 @@ class Platform : public PluginInterface {
333337
/// Lets a platform answer if it is compatible with a given architecture and
334338
/// the target triple contained within.
335339
virtual bool IsCompatibleArchitecture(const ArchSpec &arch,
340+
const ArchSpec &process_host_arch,
336341
bool exact_arch_match,
337342
ArchSpec *compatible_arch_ptr);
338343

lldb/source/Interpreter/OptionGroupPlatform.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
2323
if (!m_platform_name.empty()) {
2424
platform_sp = Platform::Create(ConstString(m_platform_name.c_str()), error);
2525
if (platform_sp) {
26-
if (platform_arch.IsValid() &&
27-
!platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) {
28-
error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'",
29-
platform_sp->GetName().GetCString(),
30-
arch.GetTriple().getTriple().c_str());
26+
if (platform_arch.IsValid() && !platform_sp->IsCompatibleArchitecture(
27+
arch, {}, false, &platform_arch)) {
28+
error.SetErrorStringWithFormatv("platform '{0}' doesn't support '{1}'",
29+
platform_sp->GetPluginName(),
30+
arch.GetTriple().getTriple());
3131
platform_sp.reset();
3232
return platform_sp;
3333
}
3434
}
3535
} else if (arch.IsValid()) {
36-
platform_sp = Platform::Create(arch, &platform_arch, error);
36+
platform_sp = Platform::Create(arch, {}, &platform_arch, error);
3737
}
3838

3939
if (platform_sp) {

lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ PlatformFreeBSD::PlatformFreeBSD(bool is_host)
129129
}
130130
}
131131

132-
std::vector<ArchSpec> PlatformFreeBSD::GetSupportedArchitectures() {
132+
std::vector<ArchSpec>
133+
PlatformFreeBSD::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
133134
if (m_remote_platform_sp)
134-
return m_remote_platform_sp->GetSupportedArchitectures();
135+
return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
135136
return m_supported_architectures;
136137
}
137138

lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class PlatformFreeBSD : public PlatformPOSIX {
4242

4343
void GetStatus(Stream &strm) override;
4444

45-
std::vector<ArchSpec> GetSupportedArchitectures() override;
45+
std::vector<ArchSpec>
46+
GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
4647

4748
bool CanDebugProcess() override;
4849

lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ PlatformLinux::PlatformLinux(bool is_host)
126126
}
127127
}
128128

129-
std::vector<ArchSpec> PlatformLinux::GetSupportedArchitectures() {
129+
std::vector<ArchSpec>
130+
PlatformLinux::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
130131
if (m_remote_platform_sp)
131-
return m_remote_platform_sp->GetSupportedArchitectures();
132+
return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
132133
return m_supported_architectures;
133134
}
134135

lldb/source/Plugins/Platform/Linux/PlatformLinux.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class PlatformLinux : public PlatformPOSIX {
4242

4343
void GetStatus(Stream &strm) override;
4444

45-
std::vector<ArchSpec> GetSupportedArchitectures() override;
45+
std::vector<ArchSpec>
46+
GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
4647

4748
uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override;
4849

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ CoreSimulatorSupport::Device PlatformAppleSimulator::GetSimulatorDevice() {
266266
}
267267
#endif
268268

269-
std::vector<ArchSpec> PlatformAppleSimulator::GetSupportedArchitectures() {
269+
std::vector<ArchSpec> PlatformAppleSimulator::GetSupportedArchitectures(
270+
const ArchSpec &process_host_arch) {
270271
std::vector<ArchSpec> result(m_supported_triples.size());
271272
llvm::transform(m_supported_triples, result.begin(),
272273
[](llvm::StringRef triple) { return ArchSpec(triple); });
@@ -382,7 +383,7 @@ Status PlatformAppleSimulator::ResolveExecutable(
382383
StreamString arch_names;
383384
llvm::ListSeparator LS;
384385
ArchSpec platform_arch;
385-
for (const ArchSpec &arch : GetSupportedArchitectures()) {
386+
for (const ArchSpec &arch : GetSupportedArchitectures({})) {
386387
resolved_module_spec.GetArchitecture() = arch;
387388

388389
// Only match x86 with x86 and x86_64 with x86_64...

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class PlatformAppleSimulator : public PlatformDarwin {
6565
lldb_private::Target &target,
6666
lldb_private::Status &error) override;
6767

68-
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
68+
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
69+
const lldb_private::ArchSpec &process_host_arch) override;
6970

7071
lldb_private::Status ResolveExecutable(
7172
const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,8 @@ Status PlatformDarwinKernel::ExamineKextForMatchingUUID(
909909
return {};
910910
}
911911

912-
std::vector<ArchSpec> PlatformDarwinKernel::GetSupportedArchitectures() {
912+
std::vector<ArchSpec> PlatformDarwinKernel::GetSupportedArchitectures(
913+
const ArchSpec &process_host_arch) {
913914
std::vector<ArchSpec> result;
914915
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
915916
ARMGetSupportedArchitectures(result);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class PlatformDarwinKernel : public PlatformDarwin {
5656
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
5757
bool *did_create_ptr) override;
5858

59-
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
59+
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
60+
const lldb_private::ArchSpec &process_host_arch) override;
6061

6162
bool SupportsModules() override { return false; }
6263

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
133133
return {};
134134
}
135135

136-
std::vector<ArchSpec> PlatformMacOSX::GetSupportedArchitectures() {
136+
std::vector<ArchSpec>
137+
PlatformMacOSX::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
137138
std::vector<ArchSpec> result;
138139
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
139140
// macOS for ARM64 support both native and translated x86_64 processes

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class PlatformMacOSX : public PlatformDarwin {
4747
return PlatformDarwin::GetFile(source, destination);
4848
}
4949

50-
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
50+
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
51+
const lldb_private::ArchSpec &process_host_arch) override;
5152

5253
lldb_private::ConstString
5354
GetSDKDirectory(lldb_private::Target &target) override;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ llvm::StringRef PlatformRemoteAppleBridge::GetDescriptionStatic() {
138138
return "Remote BridgeOS platform plug-in.";
139139
}
140140

141-
std::vector<ArchSpec> PlatformRemoteAppleBridge::GetSupportedArchitectures() {
141+
std::vector<ArchSpec> PlatformRemoteAppleBridge::GetSupportedArchitectures(
142+
const ArchSpec &process_host_arch) {
142143
return {ArchSpec("arm64-apple-bridgeos")};
143144
}
144145

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class PlatformRemoteAppleBridge : public PlatformRemoteDarwinDevice {
4040

4141
llvm::StringRef GetDescription() override { return GetDescriptionStatic(); }
4242

43-
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
43+
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
44+
const lldb_private::ArchSpec &process_host_arch) override;
4445

4546
protected:
4647
llvm::StringRef GetDeviceSupportDirectoryName() override;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ llvm::StringRef PlatformRemoteAppleTV::GetDescriptionStatic() {
133133
return "Remote Apple TV platform plug-in.";
134134
}
135135

136-
std::vector<ArchSpec> PlatformRemoteAppleTV::GetSupportedArchitectures() {
136+
std::vector<ArchSpec> PlatformRemoteAppleTV::GetSupportedArchitectures(
137+
const ArchSpec &process_host_arch) {
137138
ArchSpec system_arch(GetSystemArchitecture());
138139

139140
const ArchSpec::Core system_core = system_arch.GetCore();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class PlatformRemoteAppleTV : public PlatformRemoteDarwinDevice {
4040

4141
llvm::StringRef GetDescription() override { return GetDescriptionStatic(); }
4242

43-
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
43+
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
44+
const lldb_private::ArchSpec &process_host_arch) override;
4445

4546
protected:
4647
llvm::StringRef GetDeviceSupportDirectoryName() override;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ llvm::StringRef PlatformRemoteAppleWatch::GetDescriptionStatic() {
144144
PlatformRemoteAppleWatch::PlatformRemoteAppleWatch()
145145
: PlatformRemoteDarwinDevice() {}
146146

147-
std::vector<ArchSpec> PlatformRemoteAppleWatch::GetSupportedArchitectures() {
147+
std::vector<ArchSpec>
148+
PlatformRemoteAppleWatch::GetSupportedArchitectures(const ArchSpec &host_info) {
148149
ArchSpec system_arch(GetSystemArchitecture());
149150

150151
const ArchSpec::Core system_core = system_arch.GetCore();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class PlatformRemoteAppleWatch : public PlatformRemoteDarwinDevice {
4343

4444
// lldb_private::Platform functions
4545

46-
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
46+
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
47+
const lldb_private::ArchSpec &process_host_arch) override;
4748

4849
protected:
4950
llvm::StringRef GetDeviceSupportDirectoryName() override;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ Status PlatformRemoteDarwinDevice::ResolveExecutable(
9292
// the correct order) and see if we can find a match that way
9393
StreamString arch_names;
9494
llvm::ListSeparator LS;
95-
for (const ArchSpec &arch : GetSupportedArchitectures()) {
95+
ArchSpec process_host_arch;
96+
for (const ArchSpec &arch : GetSupportedArchitectures(process_host_arch)) {
9697
resolved_module_spec.GetArchitecture() = arch;
9798
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
9899
nullptr, nullptr, nullptr);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ PlatformSP PlatformRemoteMacOSX::CreateInstance(bool force,
125125
return PlatformSP();
126126
}
127127

128-
std::vector<ArchSpec> PlatformRemoteMacOSX::GetSupportedArchitectures() {
128+
std::vector<ArchSpec>
129+
PlatformRemoteMacOSX::GetSupportedArchitectures(const ArchSpec &host_info) {
129130
// macOS for ARM64 support both native and translated x86_64 processes
130131
std::vector<ArchSpec> result;
131132
ARMGetSupportedArchitectures(result, llvm::Triple::MacOSX);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class PlatformRemoteMacOSX : public virtual PlatformRemoteDarwinDevice {
4242
const lldb_private::UUID *uuid_ptr,
4343
lldb_private::FileSpec &local_file) override;
4444

45-
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
45+
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
46+
const lldb_private::ArchSpec &process_host_arch) override;
4647

4748
protected:
4849
llvm::StringRef GetDeviceSupportDirectoryName() override;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ llvm::StringRef PlatformRemoteiOS::GetDescriptionStatic() {
134134
PlatformRemoteiOS::PlatformRemoteiOS()
135135
: PlatformRemoteDarwinDevice() {}
136136

137-
std::vector<ArchSpec> PlatformRemoteiOS::GetSupportedArchitectures() {
137+
std::vector<ArchSpec> PlatformRemoteiOS::GetSupportedArchitectures(
138+
const ArchSpec &process_host_arch) {
138139
std::vector<ArchSpec> result;
139140
ARMGetSupportedArchitectures(result, llvm::Triple::IOS);
140141
return result;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class PlatformRemoteiOS : public PlatformRemoteDarwinDevice {
3939
// lldb_private::PluginInterface functions
4040
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
4141

42-
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
42+
std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
43+
const lldb_private::ArchSpec &process_host_arch) override;
4344

4445
protected:
4546
bool CheckLocalSharedCache() const override;

lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ PlatformNetBSD::PlatformNetBSD(bool is_host)
115115
}
116116
}
117117

118-
std::vector<ArchSpec> PlatformNetBSD::GetSupportedArchitectures() {
118+
std::vector<ArchSpec>
119+
PlatformNetBSD::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
119120
if (m_remote_platform_sp)
120-
return m_remote_platform_sp->GetSupportedArchitectures();
121+
return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
121122
return m_supported_architectures;
122123
}
123124

lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class PlatformNetBSD : public PlatformPOSIX {
4242

4343
void GetStatus(Stream &strm) override;
4444

45-
std::vector<ArchSpec> GetSupportedArchitectures() override;
45+
std::vector<ArchSpec>
46+
GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
4647

4748
uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override;
4849

lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ PlatformOpenBSD::PlatformOpenBSD(bool is_host)
118118
}
119119
}
120120

121-
std::vector<ArchSpec> PlatformOpenBSD::GetSupportedArchitectures() {
121+
std::vector<ArchSpec>
122+
PlatformOpenBSD::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
122123
if (m_remote_platform_sp)
123-
return m_remote_platform_sp->GetSupportedArchitectures();
124+
return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
124125
return m_supported_architectures;
125126
}
126127

lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class PlatformOpenBSD : public PlatformPOSIX {
4242

4343
void GetStatus(Stream &strm) override;
4444

45-
std::vector<ArchSpec> GetSupportedArchitectures() override;
45+
std::vector<ArchSpec>
46+
GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
4647

4748
bool CanDebugProcess() override;
4849

lldb/source/Plugins/Platform/Windows/PlatformWindows.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class PlatformWindows : public RemoteAwarePlatform {
6363
lldb_private::Target *target,
6464
lldb_private::Status &error) override;
6565

66-
std::vector<ArchSpec> GetSupportedArchitectures() override {
66+
std::vector<ArchSpec>
67+
GetSupportedArchitectures(const ArchSpec &process_host_arch) override {
6768
return m_supported_architectures;
6869
}
6970

lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {
6565
// target, else use existing one
6666
Status &error) override;
6767

68-
std::vector<ArchSpec> GetSupportedArchitectures() override {
68+
std::vector<ArchSpec>
69+
GetSupportedArchitectures(const ArchSpec &process_host_arch) override {
6970
return m_supported_architectures;
7071
}
7172

0 commit comments

Comments
 (0)