Skip to content

[lldb] Fix FindProcessImpl() for iOS simulators #139174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions lldb/source/Host/macosx/objcxx/Host.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -741,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))
Expand Down
20 changes: 19 additions & 1 deletion lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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)
Expand Down Expand Up @@ -76,6 +78,21 @@ def run_with(self, arch, os, vers, env, expected_load_command):
)
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:
# Verify the platform name.
self.expect("platform status", patterns=[r"Platform: " + expected_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.check_debugserver(log, os + env, vers)

@skipIfAsan
Expand All @@ -90,6 +107,7 @@ def test_ios(self):
vers="",
env="simulator",
expected_load_command="LC_BUILD_VERSION",
expected_platform="ios-simulator",
)

@skipIfAsan
Expand Down
Loading