[Lldb-commits] [PATCH] D82813: [Apple Silicon] Rewrite part of the Rosetta support to be confined in Apple specific files

Davide Italiano via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 29 15:00:29 PDT 2020


davide updated this revision to Diff 274253.

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

https://reviews.llvm.org/D82813

Files:
  lldb/include/lldb/Host/Host.h
  lldb/source/Host/common/Host.cpp
  lldb/source/Host/macosx/objcxx/Host.mm
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp


Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -17,9 +17,6 @@
 #include <unistd.h>
 #endif
 #include <sys/stat.h>
-#if defined(__APPLE__)
-#include <sys/sysctl.h>
-#endif
 #include <sys/types.h>
 #include <time.h>
 
@@ -3420,22 +3417,13 @@
         std::bind(MonitorDebugserverProcess, this_wp, _1, _2, _3, _4), false);
     debugserver_launch_info.SetUserID(process_info.GetUserID());
 
-#if defined(__APPLE__)
     // On macOS 11, we need to support x86_64 applications translated to
     // arm64. We check whether a binary is translated and spawn the correct
     // debugserver accordingly.
-    int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID,
-                  static_cast<int>(process_info.GetProcessID()) };
-    struct kinfo_proc processInfo;
-    size_t bufsize = sizeof(processInfo);
-    if (sysctl(mib, (unsigned)(sizeof(mib)/sizeof(int)), &processInfo,
-               &bufsize, NULL, 0) == 0 && bufsize > 0) {
-      if (processInfo.kp_proc.p_flag & P_TRANSLATED) {
-        FileSpec rosetta_debugserver("/Library/Apple/usr/libexec/oah/debugserver");
-        debugserver_launch_info.SetExecutableFile(rosetta_debugserver, false);
-      }
+    if (Host::IsProcessTranslated(process_info)) {
+      FileSpec rosetta_debugserver("/Library/Apple/usr/libexec/oah/debugserver");
+      debugserver_launch_info.SetExecutableFile(rosetta_debugserver, false);
     }
-#endif
 
     int communication_fd = -1;
 #ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION
Index: lldb/source/Host/macosx/objcxx/Host.mm
===================================================================
--- lldb/source/Host/macosx/objcxx/Host.mm
+++ lldb/source/Host/macosx/objcxx/Host.mm
@@ -1462,3 +1462,14 @@
     ::asl_vlog(NULL, g_aslmsg, asl_level, format, args);
   }
 }
+
+bool Host::IsProcessTranslated(const ProcessInfo &process_info) {
+  int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID,
+                static_cast<int>(process_info.GetProcessID()) };
+  struct kinfo_proc processInfo;
+  size_t bufsize = sizeof(processInfo);
+  if (sysctl(mib, (unsigned)(sizeof(mib)/sizeof(int)), &processInfo,
+             &bufsize, NULL, 0) == 0 && bufsize <= 0)
+    return false;
+  return processInfo.kp_proc.p_flag & P_TRANSLATED;
+}
Index: lldb/source/Host/common/Host.cpp
===================================================================
--- lldb/source/Host/common/Host.cpp
+++ lldb/source/Host/common/Host.cpp
@@ -414,6 +414,10 @@
 }
 
 bool Host::ResolveExecutableInBundle(FileSpec &file) { return false; }
+
+bool Host::IsProcessTranslated(const ProcessInfo &process_info) {
+  return false;
+}
 #endif
 
 #ifndef _WIN32
Index: lldb/include/lldb/Host/Host.h
===================================================================
--- lldb/include/lldb/Host/Host.h
+++ lldb/include/lldb/Host/Host.h
@@ -228,6 +228,10 @@
   static bool OpenFileInExternalEditor(const FileSpec &file_spec,
                                        uint32_t line_no);
 
+  /// Check whether a process is translated (Rosetta).
+  /// \arg process_info The info structure for the process queried.
+  static bool IsProcessTranslated(const ProcessInfo &process_info);
+
   static Environment GetEnvironment();
 
   static std::unique_ptr<Connection>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82813.274253.patch
Type: text/x-patch
Size: 3428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200629/1ef369a1/attachment.bin>


More information about the lldb-commits mailing list