Skip to content

debugserver: Support ios simulator load command disambiguation in qPr… #1548

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 all 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
20 changes: 15 additions & 5 deletions lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,28 @@ def check_debugserver(self, log, expected_platform, expected_version):
"""scan the debugserver packet log"""
logfile = open(log, "r")
dylib_info = None
response = False
process_info_ostype = None
expect_dylib_info_response = False
expect_process_info_response = False
for line in logfile:
if response:
if expect_dylib_info_response:
while line[0] != '$':
line = line[1:]
line = line[1:]
# Unescape '}'.
dylib_info = json.loads(line.replace('}]','}')[:-4])
response = False
expect_dylib_info_response = False
if 'send packet: $jGetLoadedDynamicLibrariesInfos:{' in line:
response = True

expect_dylib_info_response = True
if expect_process_info_response:
for pair in line.split(';'):
keyval = pair.split(':')
if len(keyval) == 2 and keyval[0] == 'ostype':
process_info_ostype = keyval[1]
if 'send packet: $qProcessInfo#' in line:
expect_process_info_response = True

self.assertEquals(process_info_ostype, expected_platform)
self.assertTrue(dylib_info)
aout_info = None
for image in dylib_info['images']:
Expand Down
5 changes: 4 additions & 1 deletion lldb/tools/debugserver/source/DNB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,10 @@ const char *DNBGetDeploymentInfo(nub_process_t pid,
uint32_t& patch_version) {
MachProcessSP procSP;
if (GetProcessSP(pid, procSP)) {
// FIXME: This doesn't correct for older ios simulator and macCatalyst.
// FIXME: This doesn't return the correct result when xctest (a
// macOS binary) is loaded with the macCatalyst dyld platform
// override. The image info corrects for this, but qProcessInfo
// will return what is in the binary.
auto info = procSP->GetDeploymentInfo(lc, load_command_address);
major_version = info.major_version;
minor_version = info.minor_version;
Expand Down
3 changes: 0 additions & 3 deletions lldb/tools/debugserver/source/MacOSX/MachProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ class MachProcess {
operator bool() { return platform > 0; }
/// The Mach-O platform type;
unsigned char platform = 0;
/// Pre-LC_BUILD_VERSION files don't disambiguate between ios and ios
/// simulator.
bool maybe_simulator = false;
uint32_t major_version = 0;
uint32_t minor_version = 0;
uint32_t patch_version = 0;
Expand Down
51 changes: 22 additions & 29 deletions lldb/tools/debugserver/source/MacOSX/MachProcess.mm
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,28 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
info.major_version = vers_cmd.version >> 16;
info.minor_version = (vers_cmd.version >> 8) & 0xffu;
info.patch_version = vers_cmd.version & 0xffu;
info.maybe_simulator = true;

// Disambiguate legacy simulator platforms.
#if (defined(__x86_64__) || defined(__i386__))
// If we are running on Intel macOS, it is safe to assume this is
// really a back-deploying simulator binary.
switch (info.platform) {
case PLATFORM_IOS:
info.platform = PLATFORM_IOSSIMULATOR;
break;
case PLATFORM_TVOS:
info.platform = PLATFORM_TVOSSIMULATOR;
break;
case PLATFORM_WATCHOS:
info.platform = PLATFORM_WATCHOSSIMULATOR;
break;
}
#else
// On an Apple Silicon macOS host, there is no ambiguity. The only
// binaries that use legacy load commands are back-deploying
// native iOS binaries. All simulator binaries use the newer,
// unambiguous LC_BUILD_VERSION load commands.
#endif
};
switch (cmd) {
case LC_VERSION_MIN_IPHONEOS:
Expand Down Expand Up @@ -774,34 +795,6 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
uuid_copy(inf.uuid, uuidcmd.uuid);
}
if (DeploymentInfo deployment_info = GetDeploymentInfo(lc, load_cmds_p)) {
// Simulator support. If the platform is ambiguous, use the dyld info.
if (deployment_info.maybe_simulator) {
// If dyld doesn't return a platform, use a heuristic.
#if (defined(__x86_64__) || defined(__i386__))
// If we are running on Intel macOS, it is safe to assume
// this is really a back-deploying simulator binary.
if (deployment_info.maybe_simulator) {
switch (deployment_info.platform) {
case PLATFORM_IOS:
deployment_info.platform = PLATFORM_IOSSIMULATOR;
break;
case PLATFORM_TVOS:
deployment_info.platform = PLATFORM_TVOSSIMULATOR;
break;
case PLATFORM_WATCHOS:
deployment_info.platform = PLATFORM_WATCHOSSIMULATOR;
break;
}
#else
// On an Apple Silicon macOS host, there is no
// ambiguity. The only binaries that use legacy load
// commands are back-deploying native iOS binaries. All
// simulator binaries use the newer, unambiguous
// LC_BUILD_VERSION load commands.
deployment_info.maybe_simulator = false;
#endif
}
}
const char *lc_platform = GetPlatformString(deployment_info.platform);
// macCatalyst support.
//
Expand Down