Skip to content

Commit 58d84eb

Browse files
committed
debugserver: Support ios simulator load command disambiguation in qProcessInfo
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
1 parent 8a4878c commit 58d84eb

File tree

4 files changed

+41
-38
lines changed

4 files changed

+41
-38
lines changed

lldb/test/API/macosx/simulator/TestSimulatorPlatform.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,28 @@ def check_debugserver(self, log, expected_platform, expected_version):
2727
"""scan the debugserver packet log"""
2828
logfile = open(log, "r")
2929
dylib_info = None
30-
response = False
30+
process_info_ostype = None
31+
expect_dylib_info_response = False
32+
expect_process_info_response = False
3133
for line in logfile:
32-
if response:
34+
if expect_dylib_info_response:
3335
while line[0] != '$':
3436
line = line[1:]
3537
line = line[1:]
3638
# Unescape '}'.
3739
dylib_info = json.loads(line.replace('}]','}')[:-4])
38-
response = False
40+
expect_dylib_info_response = False
3941
if 'send packet: $jGetLoadedDynamicLibrariesInfos:{' in line:
40-
response = True
41-
42+
expect_dylib_info_response = True
43+
if expect_process_info_response:
44+
for pair in line.split(';'):
45+
keyval = pair.split(':')
46+
if len(keyval) == 2 and keyval[0] == 'ostype':
47+
process_info_ostype = keyval[1]
48+
if 'send packet: $qProcessInfo#' in line:
49+
expect_process_info_response = True
50+
51+
self.assertEquals(process_info_ostype, expected_platform)
4252
self.assertTrue(dylib_info)
4353
aout_info = None
4454
for image in dylib_info['images']:

lldb/tools/debugserver/source/DNB.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,10 @@ const char *DNBGetDeploymentInfo(nub_process_t pid,
13931393
uint32_t& patch_version) {
13941394
MachProcessSP procSP;
13951395
if (GetProcessSP(pid, procSP)) {
1396-
// FIXME: This doesn't correct for older ios simulator and macCatalyst.
1396+
// FIXME: This doesn't return the correct result when xctest (a
1397+
// macOS binary) is loaded with the macCatalyst dyld platform
1398+
// override. The image info corrects for this, but qProcessInfo
1399+
// will return what is in the binary.
13971400
auto info = procSP->GetDeploymentInfo(lc, load_command_address);
13981401
major_version = info.major_version;
13991402
minor_version = info.minor_version;

lldb/tools/debugserver/source/MacOSX/MachProcess.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,6 @@ class MachProcess {
236236
operator bool() { return platform > 0; }
237237
/// The Mach-O platform type;
238238
unsigned char platform = 0;
239-
/// Pre-LC_BUILD_VERSION files don't disambiguate between ios and ios
240-
/// simulator.
241-
bool maybe_simulator = false;
242239
uint32_t major_version = 0;
243240
uint32_t minor_version = 0;
244241
uint32_t patch_version = 0;

lldb/tools/debugserver/source/MacOSX/MachProcess.mm

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,28 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
617617
info.major_version = vers_cmd.version >> 16;
618618
info.minor_version = (vers_cmd.version >> 8) & 0xffu;
619619
info.patch_version = vers_cmd.version & 0xffu;
620-
info.maybe_simulator = true;
620+
621+
// Disambiguate legacy simulator platforms.
622+
#if (defined(__x86_64__) || defined(__i386__))
623+
// If we are running on Intel macOS, it is safe to assume this is
624+
// really a back-deploying simulator binary.
625+
switch (info.platform) {
626+
case PLATFORM_IOS:
627+
info.platform = PLATFORM_IOSSIMULATOR;
628+
break;
629+
case PLATFORM_TVOS:
630+
info.platform = PLATFORM_TVOSSIMULATOR;
631+
break;
632+
case PLATFORM_WATCHOS:
633+
info.platform = PLATFORM_WATCHOSSIMULATOR;
634+
break;
635+
}
636+
#else
637+
// On an Apple Silicon macOS host, there is no ambiguity. The only
638+
// binaries that use legacy load commands are back-deploying
639+
// native iOS binaries. All simulator binaries use the newer,
640+
// unambiguous LC_BUILD_VERSION load commands.
641+
#endif
621642
};
622643
switch (cmd) {
623644
case LC_VERSION_MIN_IPHONEOS:
@@ -778,34 +799,6 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
778799
uuid_copy(inf.uuid, uuidcmd.uuid);
779800
}
780801
if (DeploymentInfo deployment_info = GetDeploymentInfo(lc, load_cmds_p)) {
781-
// Simulator support. If the platform is ambiguous, use the dyld info.
782-
if (deployment_info.maybe_simulator) {
783-
if (deployment_info.maybe_simulator) {
784-
#if (defined(__x86_64__) || defined(__i386__))
785-
// If dyld doesn't return a platform, use a heuristic.
786-
// If we are running on Intel macOS, it is safe to assume
787-
// this is really a back-deploying simulator binary.
788-
switch (deployment_info.platform) {
789-
case PLATFORM_IOS:
790-
deployment_info.platform = PLATFORM_IOSSIMULATOR;
791-
break;
792-
case PLATFORM_TVOS:
793-
deployment_info.platform = PLATFORM_TVOSSIMULATOR;
794-
break;
795-
case PLATFORM_WATCHOS:
796-
deployment_info.platform = PLATFORM_WATCHOSSIMULATOR;
797-
break;
798-
}
799-
#else
800-
// On an Apple Silicon macOS host, there is no
801-
// ambiguity. The only binaries that use legacy load
802-
// commands are back-deploying native iOS binaries. All
803-
// simulator binaries use the newer, unambiguous
804-
// LC_BUILD_VERSION load commands.
805-
deployment_info.maybe_simulator = false;
806-
#endif
807-
}
808-
}
809802
const char *lc_platform = GetPlatformString(deployment_info.platform);
810803
// macCatalyst support.
811804
//

0 commit comments

Comments
 (0)