From f0699d9109143754088c26604c58f5ab3e9d4678 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Thu, 3 Sep 2020 09:17:03 +0200 Subject: [PATCH] [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 --- lldb/test/Shell/Process/Inputs/abort.c | 3 +++ lldb/test/Shell/Process/TestAbortExitCode.test | 6 ++++++ lldb/tools/debugserver/source/RNBRemote.cpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 lldb/test/Shell/Process/Inputs/abort.c create mode 100644 lldb/test/Shell/Process/TestAbortExitCode.test 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 + +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));