[Lldb-commits] [lldb] 58d84eb - debugserver: Support ios simulator load command disambiguation in qProcessInfo

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 24 09:52:34 PDT 2020


Author: Adrian Prantl
Date: 2020-07-24T09:49:16-07:00
New Revision: 58d84eb534252747115b358c890a1b79c65d4ad4

URL: https://github.com/llvm/llvm-project/commit/58d84eb534252747115b358c890a1b79c65d4ad4
DIFF: https://github.com/llvm/llvm-project/commit/58d84eb534252747115b358c890a1b79c65d4ad4.diff

LOG: 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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
index 6e67fdc879be..824cb9eee295 100644
--- a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
+++ b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
@@ -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']:

diff  --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp
index af13a8f8208b..0830ea36a91a 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -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;

diff  --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
index c749dd8426c5..9d712390ac2a 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
@@ -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;

diff  --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
index 8a35f605daa3..10eaf38ea435 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -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:
@@ -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.
       //


        


More information about the lldb-commits mailing list