Author: Alexandre Perez Date: 2022-05-05T11:31:23-07:00 New Revision: eb3136f022b3e5061fe790e7886f4bb592d8a1d1
URL: https://github.com/llvm/llvm-project/commit/eb3136f022b3e5061fe790e7886f4bb592d8a1d1 DIFF: https://github.com/llvm/llvm-project/commit/eb3136f022b3e5061fe790e7886f4bb592d8a1d1.diff LOG: Fix debugserver translation check Currently, debugserver has a test to check if it was launched in translation. The intent was to cover the case where an x86_64 debugserver attempts to control an arm64/arm64e process, returning an error. However, this check also covers the case where users are attaching to an x86_64 process, exiting out before attempting to hand off control to the translated debugserver at `/Library/Apple/usr/libexec/oah/debugserver`. This diff delays the debugserver translation check until after determining whether to hand off control to `/Library/Apple/usr/libexec/oah/debugserver`. Only when the process is not translated and thus has not been handed off do we check if the debugserver is translated, erroring out in that case. Reviewed By: jasonmolenda Differential Revision: https://reviews.llvm.org/D124814 Added: Modified: lldb/tools/debugserver/source/DNB.cpp lldb/tools/debugserver/source/DNBDefs.h lldb/tools/debugserver/source/RNBRemote.cpp Removed: ################################################################################ diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp index 59bb91b82c351..c037c48c02868 100644 --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -477,6 +477,10 @@ nub_process_t DNBProcessAttach(nub_process_t attach_pid, } } + if (DNBDebugserverIsTranslated()) { + return INVALID_NUB_PROCESS_ARCH; + } + pid_t pid = INVALID_NUB_PROCESS; MachProcessSP processSP(new MachProcess); if (processSP.get()) { diff --git a/lldb/tools/debugserver/source/DNBDefs.h b/lldb/tools/debugserver/source/DNBDefs.h index 657964215d0f3..ee31f1c7a4ba0 100644 --- a/lldb/tools/debugserver/source/DNBDefs.h +++ b/lldb/tools/debugserver/source/DNBDefs.h @@ -54,6 +54,7 @@ typedef uint32_t nub_event_t; typedef uint32_t nub_bool_t; #define INVALID_NUB_PROCESS ((nub_process_t)0) +#define INVALID_NUB_PROCESS_ARCH ((nub_process_t)-1) #define INVALID_NUB_THREAD ((nub_thread_t)0) #define INVALID_NUB_WATCH_ID ((nub_watch_t)0) #define INVALID_NUB_HW_INDEX UINT32_MAX diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp index c909cba872f7c..7c68f85225a24 100644 --- a/lldb/tools/debugserver/source/RNBRemote.cpp +++ b/lldb/tools/debugserver/source/RNBRemote.cpp @@ -3753,17 +3753,6 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) { char err_str[1024] = {'\0'}; std::string attach_name; - if (DNBDebugserverIsTranslated()) { - DNBLogError("debugserver is x86_64 binary running in translation, attach " - "failed."); - std::string return_message = "E96;"; - return_message += - cstring_to_asciihex_string("debugserver is x86_64 binary running in " - "translation, attached failed."); - SendPacket(return_message); - return rnb_err; - } - if (strstr(p, "vAttachWait;") == p) { p += strlen("vAttachWait;"); if (!GetProcessNameFrom_vAttach(p, attach_name)) { @@ -3823,6 +3812,17 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) { return HandlePacket_UNIMPLEMENTED(p); } + if (attach_pid == INVALID_NUB_PROCESS_ARCH) { + DNBLogError("debugserver is x86_64 binary running in translation, attach " + "failed."); + std::string return_message = "E96;"; + return_message += + cstring_to_asciihex_string("debugserver is x86_64 binary running in " + "translation, attach failed."); + SendPacket(return_message.c_str()); + return rnb_err; + } + if (attach_pid != INVALID_NUB_PROCESS) { if (m_ctx.ProcessID() != attach_pid) m_ctx.SetProcessID(attach_pid); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits