aprantl updated this revision to Diff 280307.
aprantl added a comment.

Update comment. I wonder if it is feasible to give the macCatalyst code the 
same treatment. It's more tricky because supporting zippered objects would 
force some additional state into the function.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84480/new/

https://reviews.llvm.org/D84480

Files:
  lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
  lldb/tools/debugserver/source/DNB.cpp
  lldb/tools/debugserver/source/MacOSX/MachProcess.h
  lldb/tools/debugserver/source/MacOSX/MachProcess.mm

Index: lldb/tools/debugserver/source/MacOSX/MachProcess.mm
===================================================================
--- lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -617,7 +617,28 @@
     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:
@@ -778,34 +799,6 @@
         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.
       //
Index: lldb/tools/debugserver/source/MacOSX/MachProcess.h
===================================================================
--- lldb/tools/debugserver/source/MacOSX/MachProcess.h
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.h
@@ -236,9 +236,6 @@
     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;
Index: lldb/tools/debugserver/source/DNB.cpp
===================================================================
--- lldb/tools/debugserver/source/DNB.cpp
+++ lldb/tools/debugserver/source/DNB.cpp
@@ -1393,7 +1393,7 @@
                                  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 correct for macCatalyst.
     auto info = procSP->GetDeploymentInfo(lc, load_command_address);
     major_version = info.major_version;
     minor_version = info.minor_version;
Index: lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
===================================================================
--- lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
+++ lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
@@ -27,18 +27,28 @@
         """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']:
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to