aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
diff options
context:
space:
mode:
authorDavide Italiano <ditaliano@apple.com>2020-06-24 12:18:29 -0700
committerDavide Italiano <ditaliano@apple.com>2020-06-24 12:19:21 -0700
commitfd19ddb8f2a2b082f492fc59f7f360adf3495701 (patch)
tree6ad28fe5a20b8f53e236f465825567b6302dd2df /lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
parent35bb9bfbb099eb78dbed8f96d7cd7f5506d6584f (diff)
downloadllvm-fd19ddb8f2a2b082f492fc59f7f360adf3495701.zip
llvm-fd19ddb8f2a2b082f492fc59f7f360adf3495701.tar.gz
llvm-fd19ddb8f2a2b082f492fc59f7f360adf3495701.tar.bz2
[Apple Silicon] Initial support for Rosetta
Translated processes talk with a different debugserver, shipped with macOS 11. This patch detects whether a process is translated and attaches to the correct debugserver implementation. It's the first patch of a series. Tested on the lldb test suite. Differential Revision: https://reviews.llvm.org/D82491
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index c673a16..ebc9586 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -17,6 +17,7 @@
#include <unistd.h>
#endif
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include <sys/types.h>
#include <time.h>
@@ -3432,6 +3433,23 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
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);
+ }
+ }
+#endif
+
int communication_fd = -1;
#ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION
// Use a socketpair on non-Windows systems for security and performance