Skip to content

Commit eb3136f

Browse files
committed
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
1 parent f9f7aa3 commit eb3136f

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

lldb/tools/debugserver/source/DNB.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ nub_process_t DNBProcessAttach(nub_process_t attach_pid,
477477
}
478478
}
479479

480+
if (DNBDebugserverIsTranslated()) {
481+
return INVALID_NUB_PROCESS_ARCH;
482+
}
483+
480484
pid_t pid = INVALID_NUB_PROCESS;
481485
MachProcessSP processSP(new MachProcess);
482486
if (processSP.get()) {

lldb/tools/debugserver/source/DNBDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef uint32_t nub_event_t;
5454
typedef uint32_t nub_bool_t;
5555

5656
#define INVALID_NUB_PROCESS ((nub_process_t)0)
57+
#define INVALID_NUB_PROCESS_ARCH ((nub_process_t)-1)
5758
#define INVALID_NUB_THREAD ((nub_thread_t)0)
5859
#define INVALID_NUB_WATCH_ID ((nub_watch_t)0)
5960
#define INVALID_NUB_HW_INDEX UINT32_MAX

lldb/tools/debugserver/source/RNBRemote.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,17 +3753,6 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) {
37533753
char err_str[1024] = {'\0'};
37543754
std::string attach_name;
37553755

3756-
if (DNBDebugserverIsTranslated()) {
3757-
DNBLogError("debugserver is x86_64 binary running in translation, attach "
3758-
"failed.");
3759-
std::string return_message = "E96;";
3760-
return_message +=
3761-
cstring_to_asciihex_string("debugserver is x86_64 binary running in "
3762-
"translation, attached failed.");
3763-
SendPacket(return_message);
3764-
return rnb_err;
3765-
}
3766-
37673756
if (strstr(p, "vAttachWait;") == p) {
37683757
p += strlen("vAttachWait;");
37693758
if (!GetProcessNameFrom_vAttach(p, attach_name)) {
@@ -3823,6 +3812,17 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) {
38233812
return HandlePacket_UNIMPLEMENTED(p);
38243813
}
38253814

3815+
if (attach_pid == INVALID_NUB_PROCESS_ARCH) {
3816+
DNBLogError("debugserver is x86_64 binary running in translation, attach "
3817+
"failed.");
3818+
std::string return_message = "E96;";
3819+
return_message +=
3820+
cstring_to_asciihex_string("debugserver is x86_64 binary running in "
3821+
"translation, attach failed.");
3822+
SendPacket(return_message.c_str());
3823+
return rnb_err;
3824+
}
3825+
38263826
if (attach_pid != INVALID_NUB_PROCESS) {
38273827
if (m_ctx.ProcessID() != attach_pid)
38283828
m_ctx.SetProcessID(attach_pid);

0 commit comments

Comments
 (0)