[Lldb-commits] [PATCH] D84263: [debugserver/Apple Silicon] Handoff connections when attaching to translated processes
Davide Italiano via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 21 12:16:28 PDT 2020
davide created this revision.
davide added a reviewer: jasonmolenda.
When we detect a process that the native debugserver cannot handle, handoff the connection fd to the translated debugserver.
https://reviews.llvm.org/D84263
Files:
lldb/tools/debugserver/source/DNB.cpp
lldb/tools/debugserver/source/debugserver.cpp
Index: lldb/tools/debugserver/source/debugserver.cpp
===================================================================
--- lldb/tools/debugserver/source/debugserver.cpp
+++ lldb/tools/debugserver/source/debugserver.cpp
@@ -878,6 +878,8 @@
// -F localhost:1234 -- /bin/ls"
{NULL, 0, NULL, 0}};
+int communication_fd = -1;
+
// main
int main(int argc, char *argv[]) {
// If debugserver is launched with DYLD_INSERT_LIBRARIES, unset it so we
@@ -944,7 +946,6 @@
int ch;
int long_option_index = 0;
int debug = 0;
- int communication_fd = -1;
std::string compile_options;
std::string waitfor_pid_name; // Wait for a process that starts with this name
std::string attach_pid_name;
Index: lldb/tools/debugserver/source/DNB.cpp
===================================================================
--- lldb/tools/debugserver/source/DNB.cpp
+++ lldb/tools/debugserver/source/DNB.cpp
@@ -442,6 +442,33 @@
if (err_str && err_len > 0)
err_str[0] = '\0';
+ if (getenv("LLDB_DEBUGSERVER_PATH") == NULL) {
+ int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID,
+ static_cast<int>(attach_pid)};
+ 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) == P_TRANSLATED) {
+ const char *translated_debugserver =
+ "/Library/Apple/usr/libexec/oah/debugserver";
+ char fdstr[16];
+ char pidstr[16];
+ extern int communication_fd;
+
+ snprintf(fdstr, sizeof(fdstr), "--fd=%d", communication_fd);
+ snprintf(pidstr, sizeof(pidstr), "--attach=%d", attach_pid);
+ execl(translated_debugserver, "--native-regs", "--setsid", fdstr,
+ "--handoff-attach-from-native", pidstr, (char *)0);
+ DNBLogThreadedIf(LOG_PROCESS, "Failed to launch debugserver for "
+ "translated process: ", errno, strerror(errno));
+ __builtin_trap();
+ }
+ }
+ }
+
pid_t pid = INVALID_NUB_PROCESS;
MachProcessSP processSP(new MachProcess);
if (processSP.get()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84263.279607.patch
Type: text/x-patch
Size: 2229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200721/fe272891/attachment.bin>
More information about the lldb-commits
mailing list