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

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 3 15:01:14 PDT 2024


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

>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 1/2] [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",

>From af1d05509f58f5670c524814059fc3c765acad6c Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmolenda at apple.com>
Date: Thu, 3 Oct 2024 15:00:36 -0700
Subject: [PATCH 2/2] Update another error exit to DNBLogError the error
 message and then return attach failed.

---
 lldb/tools/debugserver/source/DNB.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp
index 3e213a1f8b9bc0..10c55dc3f769fa 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -475,9 +475,9 @@ nub_process_t DNBProcessAttach(nub_process_t attach_pid,
         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);
+          DNBLogError("Trying to attach to a translated process with the "
+                      "native debugserver, exiting...\n");
+          return INVALID_NUB_PROCESS_ARCH;
         }
 
         struct stat st;



More information about the lldb-commits mailing list