JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, jasonmolenda, mib.
Herald added subscribers: jsji, ctetreau, pengfei.
Herald added a project: All.
JDevlieghere requested review of this revision.

Xcode 14 no longer puts the Rosetta expanded shared cache under `16.0`. 
Instead, it includes the real version number (e.g. 13.0), the build string  and 
the architecture, similar to the device support directory names for iOS, tvOS 
and watchOS.

Currently, when there are multiple directories, we end up picking the wrong one 
in `GetSDKDirectoryForCurrentOSVersion`. The problem is that without the build 
string we have no way to differentiate between directories with the same 
version number.

  13.0 (22A111) x86_64/
  13.0 (22A222) x86_64/
  13.0 (22A333) x86_64/

This patch fixes the problem by using `GetOSBuildString` which, as the name 
implies, returns the build string if it's known. For the host platform this 
returns the host build string while for a remote platform this returns the 
remote build string.


https://reviews.llvm.org/D130540

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
  lldb/test/API/macosx/rosetta/Makefile
  lldb/test/API/macosx/rosetta/TestRosetta.py
  lldb/test/API/macosx/rosetta/main.c

Index: lldb/test/API/macosx/rosetta/main.c
===================================================================
--- /dev/null
+++ lldb/test/API/macosx/rosetta/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main() {
+  int i = 0; // Set a breakpoint here
+  return i;
+}
Index: lldb/test/API/macosx/rosetta/TestRosetta.py
===================================================================
--- /dev/null
+++ lldb/test/API/macosx/rosetta/TestRosetta.py
@@ -0,0 +1,36 @@
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+
+
+def apple_silicon(test):
+    return platform.system() == 'Darwin' and test.getArchitecture() in [
+        'arm64', 'arm64e'
+    ]
+
+
+class TestRosetta(TestBase):
+
+    NO_DEBUG_INFO_TESTCASE = True
+
+    def no_apple_silicon(self):
+        if not apple_silicon(self):
+            return "Rosetta requires Apple Silicon"
+        return None
+
+    @skipTestIfFn(no_apple_silicon)
+    def test_rosetta(self):
+        """There can be many tests in a test case - describe this test here."""
+        self.build()
+        self.main_source_file = lldb.SBFileSpec("main.c")
+
+        broadcaster = self.dbg.GetBroadcaster()
+        listener = lldbutil.start_listening_from(
+            broadcaster, lldb.SBDebugger.eBroadcastBitWarning)
+
+        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
+            self, "Set a breakpoint here", self.main_source_file)
+
+        event = lldb.SBEvent()
+        self.assertFalse(listener.GetNextEvent(event))
Index: lldb/test/API/macosx/rosetta/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/macosx/rosetta/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+override ARCH = x86_64
+
+include Makefile.rules
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
===================================================================
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
@@ -148,11 +148,20 @@
   uint32_t i;
   if (UpdateSDKDirectoryInfosIfNeeded()) {
     const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
-
-    // Check to see if the user specified a build string. If they did, then be
-    // sure to match it.
     std::vector<bool> check_sdk_info(num_sdk_infos, true);
-    ConstString build(m_sdk_build);
+
+    // Prefer the user SDK build string.
+    ConstString build = GetSDKBuild();
+
+    // Fall back to the platform's build string.
+    if (!build) {
+      if (llvm::Optional<std::string> os_build_str = GetOSBuildString()) {
+        build = ConstString(*os_build_str);
+      }
+    }
+
+    // If we have a build string, only check platforms for which the build
+    // string matches.
     if (build) {
       for (i = 0; i < num_sdk_infos; ++i)
         check_sdk_info[i] = m_sdk_directory_infos[i].build == build;
@@ -163,14 +172,14 @@
     llvm::VersionTuple version = GetOSVersion();
     if (!version.empty()) {
       if (UpdateSDKDirectoryInfosIfNeeded()) {
-        // First try for an exact match of major, minor and update
+        // First try for an exact match of major, minor and update.
         for (i = 0; i < num_sdk_infos; ++i) {
           if (check_sdk_info[i]) {
             if (m_sdk_directory_infos[i].version == version)
               return &m_sdk_directory_infos[i];
           }
         }
-        // First try for an exact match of major and minor
+        // Try for an exact match of major and minor.
         for (i = 0; i < num_sdk_infos; ++i) {
           if (check_sdk_info[i]) {
             if (m_sdk_directory_infos[i].version.getMajor() ==
@@ -181,7 +190,7 @@
             }
           }
         }
-        // Lastly try to match of major version only..
+        // Lastly try to match of major version only.
         for (i = 0; i < num_sdk_infos; ++i) {
           if (check_sdk_info[i]) {
             if (m_sdk_directory_infos[i].version.getMajor() ==
@@ -192,7 +201,7 @@
         }
       }
     } else if (build) {
-      // No version, just a build number, search for the first one that matches
+      // No version, just a build number, return the first one that matches.
       for (i = 0; i < num_sdk_infos; ++i)
         if (check_sdk_info[i])
           return &m_sdk_directory_infos[i];
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to