[Lldb-commits] [lldb] [lldb] Fix FindProcessImpl() for iOS simulators (PR #139174)

via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 16 13:51:17 PDT 2025


https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/139174

>From d98210b81f7b49f5384e968b1a18e00e432aaf2c Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Thu, 8 May 2025 16:21:53 -0700
Subject: [PATCH 1/2] Fix macOS FindProcessImpl()

---
 lldb/source/Host/macosx/objcxx/Host.mm | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm
index e187bf98188ae..e8a1c597eea53 100644
--- a/lldb/source/Host/macosx/objcxx/Host.mm
+++ b/lldb/source/Host/macosx/objcxx/Host.mm
@@ -595,7 +595,9 @@ DataExtractor data(arg_data.GetBytes(), arg_data_size,
       const llvm::Triple::ArchType triple_arch = triple.getArch();
       const bool check_for_ios_simulator =
           (triple_arch == llvm::Triple::x86 ||
-           triple_arch == llvm::Triple::x86_64);
+           triple_arch == llvm::Triple::x86_64 ||
+           triple_arch == llvm::Triple::aarch64);
+
       const char *cstr = data.GetCStr(&offset);
       if (cstr) {
         process_info.GetExecutableFile().SetFile(cstr, FileSpec::Style::native);
@@ -621,22 +623,25 @@ DataExtractor data(arg_data.GetBytes(), arg_data_size,
           }
 
           Environment &proc_env = process_info.GetEnvironment();
+          bool is_simulator = false;
           while ((cstr = data.GetCStr(&offset))) {
             if (cstr[0] == '\0')
               break;
 
-            if (check_for_ios_simulator) {
-              if (strncmp(cstr, "SIMULATOR_UDID=", strlen("SIMULATOR_UDID=")) ==
-                  0)
-                process_info.GetArchitecture().GetTriple().setOS(
-                    llvm::Triple::IOS);
-              else
-                process_info.GetArchitecture().GetTriple().setOS(
-                    llvm::Triple::MacOSX);
-            }
+            if (check_for_ios_simulator &&
+                strncmp(cstr, "SIMULATOR_UDID=", strlen("SIMULATOR_UDID=")) ==
+                    0)
+              is_simulator = true;
 
             proc_env.insert(cstr);
           }
+          llvm::Triple &triple = process_info.GetArchitecture().GetTriple();
+          if (is_simulator) {
+            triple.setOS(llvm::Triple::IOS);
+            triple.setEnvironment(llvm::Triple::Simulator);
+          } else {
+            triple.setOS(llvm::Triple::MacOSX);
+          }
           return true;
         }
       }

>From 8377bc3b61fb30c003d1d188d6e8d879baea58ab Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Mon, 16 Jun 2025 11:06:47 -0700
Subject: [PATCH 2/2] Add test

---
 lldb/test/API/macosx/simulator/TestSimulatorPlatform.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
index 74ba0ee6c83bb..8406ee45479fd 100644
--- a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
+++ b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
@@ -39,7 +39,7 @@ def check_debugserver(self, log, expected_platform, expected_version):
         if expected_version:
             self.assertEqual(aout_info["min_version_os_sdk"], expected_version)
 
-    def run_with(self, arch, os, vers, env, expected_load_command):
+    def run_with(self, arch, os, vers, env, expected_load_command, expected_platform=None):
         env_list = [env] if env else []
         triple = "-".join([arch, "apple", os + vers] + env_list)
         sdk = lldbutil.get_xcode_sdk(os, env)
@@ -75,6 +75,11 @@ def run_with(self, arch, os, vers, env, expected_load_command):
             self, "break here", lldb.SBFileSpec("hello.c")
         )
         triple_re = "-".join([arch, "apple", os + vers + ".*"] + env_list)
+        if expected_platform is not None:
+            # The current platform should be expected
+            self.expect("platform status", patterns=[r"Platform: " + expected_platform])
+            # Should be able to list processes on the current platform
+            self.expect("platform process list", patterns=[r"\d+ matching processes were found on \"%s\"" % expected_platform])
         self.expect("image list -b -t", patterns=[r"a\.out " + triple_re])
         self.check_debugserver(log, os + env, vers)
 
@@ -90,6 +95,7 @@ def test_ios(self):
             vers="",
             env="simulator",
             expected_load_command="LC_BUILD_VERSION",
+            expected_platform="ios-simulator",
         )
 
     @skipIfAsan



More information about the lldb-commits mailing list