[Lldb-commits] [lldb] 8faca2e - [lldb] Fix platform selection on Apple Silicon

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 14 16:03:54 PST 2022


Author: Jonas Devlieghere
Date: 2022-01-14T16:03:49-08:00
New Revision: 8faca2ed6adebffa76c6eb506f15dfd38ab512a7

URL: https://github.com/llvm/llvm-project/commit/8faca2ed6adebffa76c6eb506f15dfd38ab512a7
DIFF: https://github.com/llvm/llvm-project/commit/8faca2ed6adebffa76c6eb506f15dfd38ab512a7.diff

LOG: [lldb] Fix platform selection on Apple Silicon

Currently, when connecting to a remote iOS device from the command line
on Apple Silicon, we end up using the host platform (PlatfromMacOSX)
instead of remote-ios (PlatformRemoteiOS). This happens because
PlatfromMacOSX includes arm64-apple-ios and arm64e-apple-ios as
compatible architectures, presumably to support debugging iOS Apps on
Apple Silicon [1].

This is a problem for debugging remote ios devices, because the host
platform doesn't look for an expanded shared cache on disk and as a
result we end up reading everything from memory, incurring a significant
performance hit.

The crux of this patch is to make PlatfromMacOSX *not* compatible with
arm64(e)-apple-ios. This also means that we now use remote-ios
(PlatformRemoteiOS) as the platform for debugging iOS apps on Apple
Silicon. This has the (unintended) side effect that unlike we do for the
host platform, we no longer check our local shared cache, and incur a
performance hit on debugging these apps.

To avoid that, PlatformRemoteiOS now also check the local cache to
support this use case, which is cheap enough to do unconditionally for
PlatformRemoteiOS.

[1] https://support.apple.com/guide/app-store/iphone-ipad-apps-mac-apple-silicon-fird2c7092da/mac

Differential revision: https://reviews.llvm.org/D117340

Added: 
    

Modified: 
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
    lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index de64426d7b647..29d2d82136018 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -237,7 +237,7 @@ lldb_private::Status PlatformDarwin::GetSharedModuleWithLocalCache(
 
   Status err;
 
-  if (IsHost()) {
+  if (CheckLocalSharedCache()) {
     // When debugging on the host, we are most likely using the same shared
     // cache as our inferior. The dylibs from the shared cache might not
     // exist on the filesystem, so let's use the images in our own memory
@@ -644,7 +644,7 @@ const char *PlatformDarwin::GetCompatibleArch(ArchSpec::Core core, size_t idx) {
 /// distinct names (e.g. armv7f) but armv7 binaries run fine on an armv7f
 /// processor.
 void PlatformDarwin::ARMGetSupportedArchitectures(
-    std::vector<ArchSpec> &archs) {
+    std::vector<ArchSpec> &archs, llvm::Optional<llvm::Triple::OSType> os) {
   const ArchSpec system_arch = GetSystemArchitecture();
   const ArchSpec::Core system_core = system_arch.GetCore();
 
@@ -654,6 +654,8 @@ void PlatformDarwin::ARMGetSupportedArchitectures(
     llvm::Triple triple;
     triple.setArchName(compatible_arch);
     triple.setVendor(llvm::Triple::VendorType::Apple);
+    if (os)
+      triple.setOS(*os);
     archs.push_back(ArchSpec(triple));
   }
 }

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index bbb2a336c56e0..57617ae58c89d 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -60,7 +60,9 @@ class PlatformDarwin : public PlatformPOSIX {
   bool ModuleIsExcludedForUnconstrainedSearches(
       lldb_private::Target &target, const lldb::ModuleSP &module_sp) override;
 
-  void ARMGetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs);
+  void
+  ARMGetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs,
+                               llvm::Optional<llvm::Triple::OSType> os = {});
 
   void x86GetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs);
 
@@ -141,6 +143,8 @@ class PlatformDarwin : public PlatformPOSIX {
       const lldb_private::FileSpecList *module_search_paths_ptr,
       llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
 
+  virtual bool CheckLocalSharedCache() const { return IsHost(); }
+
   struct SDKEnumeratorInfo {
     lldb_private::FileSpec found_path;
     lldb_private::XcodeSDK::Type sdk_type;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
index 3f2fb53ad654d..afe321538b179 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
@@ -137,15 +137,13 @@ std::vector<ArchSpec> PlatformMacOSX::GetSupportedArchitectures() {
   std::vector<ArchSpec> result;
 #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
   // macOS for ARM64 support both native and translated x86_64 processes
-  ARMGetSupportedArchitectures(result);
+  ARMGetSupportedArchitectures(result, llvm::Triple::MacOSX);
 
   // We can't use x86GetSupportedArchitectures() because it uses
   // the system architecture for some of its return values and also
   // has a 32bits variant.
   result.push_back(ArchSpec("x86_64-apple-macosx"));
   result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
-  result.push_back(ArchSpec("arm64-apple-ios"));
-  result.push_back(ArchSpec("arm64e-apple-ios"));
 #else
   x86GetSupportedArchitectures(result);
 #endif

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
index 1e969f05e15bc..1ddfee67fa1e5 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
@@ -127,7 +127,7 @@ PlatformSP PlatformRemoteMacOSX::CreateInstance(bool force,
 std::vector<ArchSpec> PlatformRemoteMacOSX::GetSupportedArchitectures() {
   // macOS for ARM64 support both native and translated x86_64 processes
   std::vector<ArchSpec> result;
-  ARMGetSupportedArchitectures(result);
+  ARMGetSupportedArchitectures(result, llvm::Triple::MacOSX);
 
   // We can't use x86GetSupportedArchitectures() because it uses
   // the system architecture for some of its return values and also

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
index 616123698e664..94e231748afe2 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
@@ -135,10 +135,17 @@ PlatformRemoteiOS::PlatformRemoteiOS()
 
 std::vector<ArchSpec> PlatformRemoteiOS::GetSupportedArchitectures() {
   std::vector<ArchSpec> result;
-  ARMGetSupportedArchitectures(result);
+  ARMGetSupportedArchitectures(result, llvm::Triple::IOS);
   return result;
 }
 
+bool PlatformRemoteiOS::CheckLocalSharedCache() const {
+  // You can run iPhone and iPad apps on Mac with Apple Silicon. At the
+  // platform level there's no way to distinguish them from remote iOS
+  // applications. Make sure we still read from our own shared cache.
+  return true;
+}
+
 llvm::StringRef PlatformRemoteiOS::GetDeviceSupportDirectoryName() {
   return "iOS DeviceSupport";
 }

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
index 94be124d4310b..0fe5a274a3d4a 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
@@ -42,6 +42,8 @@ class PlatformRemoteiOS : public PlatformRemoteDarwinDevice {
   std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
 protected:
+  bool CheckLocalSharedCache() const override;
+
   llvm::StringRef GetDeviceSupportDirectoryName() override;
   llvm::StringRef GetPlatformName() override;
 };


        


More information about the lldb-commits mailing list