[Lldb-commits] [lldb] [lldb][debugserver] Check if Rosetta debugserver exists (PR #110943)

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 2 17:49:22 PDT 2024


https://github.com/jasonmolenda created https://github.com/llvm/llvm-project/pull/110943

If lldb tries to attach to a process that is marked 'Translated' with debugserver, it will exec the Rosetta debugserver to handle the debug session without checking if it is present.  If there is a configuration that is somehow missing this, it will fail poorly.

rdar://135641680

>From e1ea95287aeaa216e332aa221039247feaeb48e1 Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmolenda at apple.com>
Date: Wed, 2 Oct 2024 17:45:36 -0700
Subject: [PATCH] [lldb][debugserver] Check if Rosetta debugserver exists

If lldb tries to attach to a process that is marked 'Translated'
with debugserver, it will exec the Rosetta debugserver to handle
the debug session without checking if it is present.  If there is
a configuration that is somehow missing this, it will fail poorly.

rdar://135641680
---
 lldb/tools/debugserver/source/DNB.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp
index 1ac9a8040c6163..3e213a1f8b9bc0 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -480,6 +480,14 @@ nub_process_t DNBProcessAttach(nub_process_t attach_pid,
           exit(1);
         }
 
+        struct stat st;
+        if (::stat(translated_debugserver, &st) != 0) {
+          DNBLogError("Translated inferior process but Rosetta debugserver not "
+                      "found at %s",
+                      translated_debugserver);
+          return INVALID_NUB_PROCESS_ARCH;
+        }
+
         snprintf(fdstr, sizeof(fdstr), "--fd=%d", communication_fd);
         snprintf(pidstr, sizeof(pidstr), "--attach=%d", attach_pid);
         execl(translated_debugserver, translated_debugserver, "--native-regs",



More information about the lldb-commits mailing list