Skip to content

Commit

Permalink
debugserver: Support ios simulator load command disambiguation in qPr…
Browse files Browse the repository at this point in the history
…ocessInfo

This patch basically moves the disambiguation code from a place where
it was complicated to implement straight to where the load command is
parsed, which has the neat side affect of actually supporting all call
sites!

rdar://problem/66011909

Differential Revision: https://reviews.llvm.org/D84480
  • Loading branch information
adrian-prantl committed Jul 24, 2020
1 parent 8a4878c commit 58d84eb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
20 changes: 15 additions & 5 deletions lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
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
Expand Up @@ -1393,7 +1393,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
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
Expand Up @@ -617,7 +617,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 @@ -778,34 +799,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 (deployment_info.maybe_simulator) {
#if (defined(__x86_64__) || defined(__i386__))
// If dyld doesn't return a platform, use a heuristic.
// If we are running on Intel macOS, it is safe to assume
// this is really a back-deploying simulator binary.
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

0 comments on commit 58d84eb

Please sign in to comment.