[Lldb-commits] [PATCH] D121444: [lldb] Fix platform selection on Apple Silicon (again)

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 10 23:10:44 PST 2022


JDevlieghere created this revision.
JDevlieghere added reviewers: jasonmolenda, friss, labath.
Herald added a project: All.
JDevlieghere requested review of this revision.

This patch is another attempt to fix platform selection on Apple Silicon. It partially undoes D117340 <https://reviews.llvm.org/D117340> which tried to fix the issue by always instantiating a remote-ios platform for "iPhone and iPad Apps on Apple Silicon Macs". While the previous patch worked for attaching, it broke launching and everything else that expects the remote platform to be connected. I made an attempt to work around that, but quickly found out that there were just too may places that had this assumption baked in.

This patch takes a different approach and reverts back to marking the host platform compatible with iOS triples. This brings us back to the original situation where platform selection was broken for remote iOS debugging on Apple Silicon. To fix that, I now look at the process' system architecture to differentiate between iOS binaries running remotely and iOS binaries running locally. I wish I could make this distinction in the platform, but you need a connected process to do this.

I tested the following scenarios, which now all uses the desired platform:

- Launching an iOS binary on macOS: uses the `host` platform
- Attaching to an iOS binary on macOS: uses the `host` platform
- Attaching to a remote iOS binary: uses the `remote-ios` platform

rdar://89840215


https://reviews.llvm.org/D121444

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
  lldb/source/Target/Process.cpp


Index: lldb/source/Target/Process.cpp
===================================================================
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -2922,6 +2922,30 @@
     }
   }
 
+#if TARGET_OS_OSX
+#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
+  // On Apple Silicon the host platform is compatible with arm64(e)-apple-ios
+  // to support unmodified "iPhone and iPad Apps on Apple Silicon Macs".
+  //
+  // Because the binaries are identical and platform selection relies on the
+  // triple, there's no way to differentiate the two statically. Once we have a
+  // process, we can use its system architecture to tell the two apart and
+  // change the platform if necessary.
+  if (platform_sp->GetPluginName() == "host") {
+    llvm::Triple target_triple = GetTarget().GetArchitecture().GetTriple();
+    if (target_triple.getOS() == llvm::Triple::IOS &&
+        target_triple.getVendor() == llvm::Triple::Apple) {
+      llvm::Triple system_triple = GetSystemArchitecture().GetTriple();
+      if (system_triple.getOS() == llvm::Triple::IOS) {
+        Status error;
+        GetTarget().SetPlatform(
+            Platform::Create(ConstString("remote-ios"), error));
+      }
+    }
+  }
+#endif
+#endif
+
   // We have completed the attach, now it is time to find the dynamic loader
   // plug-in
   DynamicLoader *dyld = GetDynamicLoader();
Index: lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
===================================================================
--- lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
+++ lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
@@ -42,8 +42,6 @@
   std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
 protected:
-  bool CheckLocalSharedCache() const override;
-
   llvm::StringRef GetDeviceSupportDirectoryName() override;
   llvm::StringRef GetPlatformName() override;
 };
Index: lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
===================================================================
--- lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
@@ -140,13 +140,6 @@
   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";
 }
Index: lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
===================================================================
--- lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
@@ -151,6 +151,8 @@
     result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
     result.push_back(ArchSpec("arm64-apple-ios-macabi"));
     result.push_back(ArchSpec("arm64e-apple-ios-macabi"));
+    result.push_back(ArchSpec("arm64-apple-ios"));
+    result.push_back(ArchSpec("arm64e-apple-ios"));
   }
 #else
   x86GetSupportedArchitectures(result);
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
===================================================================
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -143,7 +143,7 @@
       const lldb_private::FileSpecList *module_search_paths_ptr,
       llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
 
-  virtual bool CheckLocalSharedCache() const { return IsHost(); }
+  bool CheckLocalSharedCache() const { return IsHost(); }
 
   struct SDKEnumeratorInfo {
     lldb_private::FileSpec found_path;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121444.414587.patch
Type: text/x-patch
Size: 3841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220311/a8d04a16/attachment-0001.bin>


More information about the lldb-commits mailing list