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 <roy...@meta.com> Date: Thu, 8 May 2025 16:21:53 -0700 Subject: [PATCH 1/4] 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 <roy...@meta.com> Date: Mon, 16 Jun 2025 11:06:47 -0700 Subject: [PATCH 2/4] 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 >From 2c31b44d01a7a8bc0fece27fed8162c599aa8387 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Mon, 16 Jun 2025 15:02:56 -0700 Subject: [PATCH 3/4] Fix format --- .../API/macosx/simulator/TestSimulatorPlatform.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py index 8406ee45479fd..44a5a942ab513 100644 --- a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py +++ b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py @@ -39,7 +39,9 @@ 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, expected_platform=None): + 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) @@ -79,7 +81,12 @@ def run_with(self, arch, os, vers, env, expected_load_command, expected_platform # 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( + "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) >From 3d6715699007bb22bda26cf196bee91f24ef9e91 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Tue, 17 Jun 2025 07:39:17 -0700 Subject: [PATCH 4/4] Minor updates to code and comments --- lldb/source/Host/macosx/objcxx/Host.mm | 4 ++-- .../API/macosx/simulator/TestSimulatorPlatform.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm index e8a1c597eea53..66e7741fc53e7 100644 --- a/lldb/source/Host/macosx/objcxx/Host.mm +++ b/lldb/source/Host/macosx/objcxx/Host.mm @@ -746,8 +746,8 @@ static bool GetMacOSXProcessUserAndGroup(ProcessInstanceInfo &process_info) { !match_info.ProcessIDsMatch(process_info)) continue; - // Get CPU type first so we can know to look for iOS simulator is we have - // x86 or x86_64 + // Get CPU type first so we can know to look for iOS simulator if we have + // a compatible type. if (GetMacOSXProcessCPUType(process_info)) { if (GetMacOSXProcessArgs(&match_info, process_info)) { if (match_info.Matches(process_info)) diff --git a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py index 44a5a942ab513..0d09bfee9b961 100644 --- a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py +++ b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py @@ -77,17 +77,22 @@ def run_with( self, "break here", lldb.SBFileSpec("hello.c") ) triple_re = "-".join([arch, "apple", os + vers + ".*"] + env_list) + self.expect("image list -b -t", patterns=[r"a\.out " + triple_re]) if expected_platform is not None: - # The current platform should be expected + # Verify the platform name. self.expect("platform status", patterns=[r"Platform: " + expected_platform]) - # Should be able to list processes on the current platform + # Verify that processes on the platform can be listed. + # + # Note: The `Host::FindProcessesImpl()` of some of the Hosts filters out processes which are being debugged. + # (e.g. code for iOS simulator linked below). So we cannot verify that `a.out` is in the process list + # (because its already being debugged by this test). + # https://github.com/llvm/llvm-project/blob/b5dbf8210a57b986b9802304745f4c5c108cf37b/lldb/source/Host/macosx/objcxx/Host.mm#L724 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) @skipIfAsan _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits