Index: lldb/tools/debugserver/source/DNB.cpp =================================================================== --- lldb/tools/debugserver/source/DNB.cpp +++ lldb/tools/debugserver/source/DNB.cpp @@ -442,6 +442,39 @@ 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(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; + + if (communication_fd == -1) { + fprintf(stderr, "Trying to attach to a translated process with the " + "native debugserver, exiting...\n"); + exit(1); + } + + 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()) { 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;