Skip to content

Commit 0c04ef2

Browse files
committed
PlatformMacOSX should be activated for lldb built to run on an iOS etc device
In the changes Jonas made in https://reviews.llvm.org/D117340 , a small oversight was that PlatformMacOSX (despite the name) is active for any native Darwin operating system, where lldb and the target process are running on the same system. This patch uses compile-time checks to return the appropriate OSType for the OS lldb is being compiled to, so the "host" platform will correctly be selected when lldb & the inferior are both running on that OS. And a small change to PlatformMacOSX::GetSupportedArchitectures which adds additional recognized triples when running on macOS but not other native Darwin systems. Differential Revision: https://reviews.llvm.org/D120517 rdar://89247060 (cherry picked from commit cd2ba23)
1 parent 06653e8 commit 0c04ef2

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,3 +1329,23 @@ FileSpec PlatformDarwin::GetCurrentCommandLineToolsDirectory() {
13291329
return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
13301330
return {};
13311331
}
1332+
1333+
llvm::Triple::OSType PlatformDarwin::GetHostOSType() {
1334+
#if !defined(__APPLE__)
1335+
return llvm::Triple::MacOSX;
1336+
#else
1337+
#if TARGET_OS_OSX
1338+
return llvm::Triple::MacOSX;
1339+
#elif TARGET_OS_IOS
1340+
return llvm::Triple::IOS;
1341+
#elif TARGET_OS_WATCH
1342+
return llvm::Triple::WatchOS;
1343+
#elif TARGET_OS_TV
1344+
return llvm::Triple::TvOS;
1345+
#elif TARGET_OS_BRIDGE
1346+
return llvm::Triple::BridgeOS;
1347+
#else
1348+
#error "LLDB being compiled for an unrecognized Darwin OS"
1349+
#endif
1350+
#endif // __APPLE__
1351+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ class PlatformDarwin : public PlatformPOSIX {
174174
static std::string FindComponentInPath(llvm::StringRef path,
175175
llvm::StringRef component);
176176

177+
// The OSType where lldb is running.
178+
static llvm::Triple::OSType GetHostOSType();
179+
177180
std::string m_developer_directory;
178181
llvm::StringMap<std::string> m_sdk_path;
179182
std::mutex m_sdk_path_mutex;

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,21 @@ std::vector<ArchSpec> PlatformMacOSX::GetSupportedArchitectures() {
137137
std::vector<ArchSpec> result;
138138
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
139139
// macOS for ARM64 support both native and translated x86_64 processes
140-
ARMGetSupportedArchitectures(result, llvm::Triple::MacOSX);
141140

142-
// We can't use x86GetSupportedArchitectures() because it uses
143-
// the system architecture for some of its return values and also
144-
// has a 32bits variant.
145-
result.push_back(ArchSpec("x86_64-apple-macosx"));
146-
result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
147-
result.push_back(ArchSpec("arm64-apple-ios-macabi"));
148-
result.push_back(ArchSpec("arm64e-apple-ios-macabi"));
141+
// When cmdline lldb is run on iOS, watchOS, etc, it is still
142+
// using "PlatformMacOSX".
143+
llvm::Triple::OSType host_os = GetHostOSType();
144+
ARMGetSupportedArchitectures(result, host_os);
145+
146+
if (host_os == llvm::Triple::MacOSX) {
147+
// We can't use x86GetSupportedArchitectures() because it uses
148+
// the system architecture for some of its return values and also
149+
// has a 32bits variant.
150+
result.push_back(ArchSpec("x86_64-apple-macosx"));
151+
result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
152+
result.push_back(ArchSpec("arm64-apple-ios-macabi"));
153+
result.push_back(ArchSpec("arm64e-apple-ios-macabi"));
154+
}
149155
#else
150156
x86GetSupportedArchitectures(result);
151157
result.push_back(ArchSpec("x86_64-apple-ios-macabi"));

0 commit comments

Comments
 (0)