[Lldb-commits] [lldb] f0699d9 - [debugserver] Fix that debugserver's stop reply packets always return signal code 0

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 3 00:47:34 PDT 2020


Author: Raphael Isemann
Date: 2020-09-03T09:47:03+02:00
New Revision: f0699d9109143754088c26604c58f5ab3e9d4678

URL: https://github.com/llvm/llvm-project/commit/f0699d9109143754088c26604c58f5ab3e9d4678
DIFF: https://github.com/llvm/llvm-project/commit/f0699d9109143754088c26604c58f5ab3e9d4678.diff

LOG: [debugserver] Fix that debugserver's stop reply packets always return signal code 0

If our process terminates due to an unhandled signal, we are supposed to get the
signal code via WTERMSIG. However, we instead try to get the exit status via
WEXITSTATUS which just ends up always calculating signal code 0 (at least on the
macOS implementation where it just shifts the signal code bits away and we're
left with only 0 bits).

The exit status calculation on the LLDB side also seems a bit off as it claims
an exit status that is just the signal code (instead of for example 128 + signal
code), but that will be another patch.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D86336

Added: 
    lldb/test/Shell/Process/Inputs/abort.c
    lldb/test/Shell/Process/TestAbortExitCode.test

Modified: 
    lldb/tools/debugserver/source/RNBRemote.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/Shell/Process/Inputs/abort.c b/lldb/test/Shell/Process/Inputs/abort.c
new file mode 100644
index 000000000000..9edc9336dc3e
--- /dev/null
+++ b/lldb/test/Shell/Process/Inputs/abort.c
@@ -0,0 +1,3 @@
+#include <stdlib.h>
+
+int main(int argc, char **argv) { abort(); }

diff  --git a/lldb/test/Shell/Process/TestAbortExitCode.test b/lldb/test/Shell/Process/TestAbortExitCode.test
new file mode 100644
index 000000000000..a61c09505112
--- /dev/null
+++ b/lldb/test/Shell/Process/TestAbortExitCode.test
@@ -0,0 +1,6 @@
+UNSUPPORTED: system-windows
+
+RUN: %clang_host %p/Inputs/abort.c -o %t
+RUN: %lldb %t -o run -o continue | FileCheck %s
+
+CHECK: status = 6 (0x00000006) Terminated due to signal 6

diff  --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp
index 5e2512731f39..b66cc8f583e8 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -3066,7 +3066,7 @@ rnb_err_t RNBRemote::HandlePacket_last_signal(const char *unused) {
                  WEXITSTATUS(pid_status));
       else if (WIFSIGNALED(pid_status))
         snprintf(pid_exited_packet, sizeof(pid_exited_packet), "X%02x",
-                 WEXITSTATUS(pid_status));
+                 WTERMSIG(pid_status));
       else if (WIFSTOPPED(pid_status))
         snprintf(pid_exited_packet, sizeof(pid_exited_packet), "S%02x",
                  WSTOPSIG(pid_status));


        


More information about the lldb-commits mailing list