[Lldb-commits] [lldb] ef2ca97 - [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (#89405)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 25 09:20:49 PDT 2024
Author: Miro Bucko
Date: 2024-04-25T09:20:43-07:00
New Revision: ef2ca97f48f1aee1483f0c29de5ba52979bec454
URL: https://github.com/llvm/llvm-project/commit/ef2ca97f48f1aee1483f0c29de5ba52979bec454
DIFF: https://github.com/llvm/llvm-project/commit/ef2ca97f48f1aee1483f0c29de5ba52979bec454.diff
LOG: [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (#89405)
Summary:
When the target inferior process that is being debugged exits in lldb
command line, it emits following message:
`Process 4049526 exited with status = -1 (0xffffffff) debugserver died
with signal SIGTERM`
lldb-dap on the other hand does not emit a similar message. This PR adds
the same status message to lldb-dap.
Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and
observe an exit status message similar to the following: Process 2167677
exited with status = -1 (0xffffffff) debugserver died with signal
SIGTERM
Reviewers:
@jeffreytan81, at clayborg, at kusmour,
Subscribers:
Tasks:
lldb-dap
Tags:
Added:
Modified:
lldb/include/lldb/API/SBProcess.h
lldb/source/API/SBProcess.cpp
lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
lldb/tools/lldb-dap/lldb-dap.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h
index 7da3335a7234b7..f1b5d1fb92ce29 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -562,6 +562,8 @@ class LLDB_API SBProcess {
lldb::SBScriptObject GetScriptedImplementation();
+ void GetStatus(SBStream &status);
+
protected:
friend class SBAddress;
friend class SBBreakpoint;
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index c73348fde3f74d..c37c111c5a58e0 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -928,6 +928,14 @@ size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
return bytes_written;
}
+void SBProcess::GetStatus(SBStream &status) {
+ LLDB_INSTRUMENT_VA(this, status);
+
+ ProcessSP process_sp(GetSP());
+ if (process_sp)
+ process_sp->GetStatus(status.ref());
+}
+
bool SBProcess::GetDescription(SBStream &description) {
LLDB_INSTRUMENT_VA(this, description);
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..8f456aaf890c7f 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,11 +4,23 @@
import dap_server
import lldbdap_testcase
+import psutil
+from collections import deque
from lldbsuite.test import lldbutil
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
+def get_subprocess(process_name):
+ queue = deque([psutil.Process(os.getpid())])
+ while queue:
+ process = queue.popleft()
+ if process.name() == process_name:
+ return process
+ queue.extend(process.children())
+
+ self.assertTrue(False, "No subprocess with name %s found" % process_name)
+
class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
def check_lldb_command(
self, lldb_command, contains_string, assert_msg, command_escape_prefix="`"
@@ -104,3 +116,49 @@ def test_empty_escape_prefix(self):
"Help can be invoked",
command_escape_prefix="",
)
+
+ @skipIfWindows
+ @skipIfRemote
+ def test_exit_status_message_sigterm(self):
+ source = "main.cpp"
+ program = self.getBuildArtifact("a.out")
+ self.build_and_launch(program, commandEscapePrefix="")
+ breakpoint1_line = line_number(source, "// breakpoint 1")
+ breakpoint_ids = self.set_source_breakpoints(source, [breakpoint1_line])
+ self.continue_to_breakpoints(breakpoint_ids)
+
+ # Kill lldb-server process.
+ process_name = (
+ "debugserver" if platform.system() in ["Darwin"] else "lldb-server"
+ )
+ process = get_subprocess(process_name)
+ process.terminate()
+ process.wait()
+
+ # Get the console output
+ console_output = self.collect_console(1.0)
+
+ # Verify the exit status message is printed.
+ self.assertIn(
+ "exited with status = -1 (0xffffffff) debugserver died with signal SIGTERM",
+ console_output,
+ "Exit status does not contain message 'exited with status'",
+ )
+
+ @skipIfWindows
+ @skipIfRemote
+ def test_exit_status_message_ok(self):
+ source = "main.cpp"
+ program = self.getBuildArtifact("a.out")
+ self.build_and_launch(program, commandEscapePrefix="")
+ self.continue_to_exit()
+
+ # Get the console output
+ console_output = self.collect_console(1.0)
+
+ # Verify the exit status message is printed.
+ self.assertIn(
+ "exited with status = 0 (0x00000000)",
+ console_output,
+ "Exit status does not contain message 'exited with status'",
+ )
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 25c5ad56e3d6fe..16c50ed5791b0a 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -50,6 +50,7 @@
#include <thread>
#include <vector>
+#include "lldb/API/SBStream.h"
#include "lldb/Host/Config.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
@@ -503,6 +504,10 @@ void EventThreadFunction() {
SendContinuedEvent();
break;
case lldb::eStateExited:
+ lldb::SBStream stream;
+ process.GetStatus(stream);
+ g_dap.SendOutput(OutputType::Console, stream.GetData());
+
// When restarting, we can get an "exited" event for the process we
// just killed with the old PID, or even with no PID. In that case
// we don't have to terminate the session.
More information about the lldb-commits
mailing list