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 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/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(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/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 #endif #include -#if defined(__APPLE__) -#include -#endif #include #include @@ -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(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