Skip to content

Commit 91a4fa4

Browse files
author
Miro Bucko
committed
Report exit status message in lldb-dap, same as lldb cli
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: Subscribers: Tasks: lldb-dap Tags:
1 parent 3a4bc11 commit 91a4fa4

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lldb/test/API/tools/lldb-dap/console/TestDAP_console.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,30 @@
44

55
import dap_server
66
import lldbdap_testcase
7+
import psutil
8+
from collections import deque
79
from lldbsuite.test import lldbutil
810
from lldbsuite.test.decorators import *
911
from lldbsuite.test.lldbtest import *
1012

13+
def get_subprocess_pid(process_name):
14+
queue = deque([psutil.Process(os.getpid())])
15+
while queue:
16+
process = queue.popleft()
17+
if process.name() == process_name:
18+
return process.pid
19+
queue.extend(process.children())
20+
21+
print(f"No subprocess with name {process_name} found", flush=True, file=sys.stderr)
22+
return None
23+
24+
def killProcess(pid, process_name):
25+
process = psutil.Process(pid)
26+
process.terminate()
27+
try:
28+
process.wait(timeout=5)
29+
except psutil.TimeoutExpired:
30+
self.assertTrue(False, process_name + " process should have exited by now")
1131

1232
class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
1333
def check_lldb_command(
@@ -104,3 +124,27 @@ def test_empty_escape_prefix(self):
104124
"Help can be invoked",
105125
command_escape_prefix="",
106126
)
127+
128+
@skipIfWindows
129+
@skipIfRemote
130+
def test_exit_status_message(self):
131+
source = "main.cpp"
132+
program = self.getBuildArtifact("a.out")
133+
self.build_and_launch(program, commandEscapePrefix="")
134+
breakpoint1_line = line_number(source, "// breakpoint 1")
135+
breakpoint_ids = self.set_source_breakpoints(source, [breakpoint1_line])
136+
self.continue_to_breakpoints(breakpoint_ids)
137+
138+
# Kill lldb-server process.
139+
process_name = "lldb-server"
140+
pid = get_subprocess_pid(process_name)
141+
killProcess(pid, process_name)
142+
# Get the console output
143+
console_output = self.collect_console(1.0)
144+
145+
# Verify the exit status message is printed.
146+
self.assertIn(
147+
"exited with status = -1 (0xffffffff) debugserver died with signal SIGTERM",
148+
console_output,
149+
"Exit status does not contain message 'exited with status'"
150+
)

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ void EventThreadFunction() {
503503
SendContinuedEvent();
504504
break;
505505
case lldb::eStateExited:
506+
const int exit_status = process.GetExitStatus();
507+
const char *const exit_description = process.GetExitDescription();
508+
g_dap.SendFormattedOutput(
509+
OutputType::Console,
510+
"Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n",
511+
process.GetProcessID(), exit_status, exit_status,
512+
exit_description ? exit_description : "");
513+
506514
// When restarting, we can get an "exited" event for the process we
507515
// just killed with the old PID, or even with no PID. In that case
508516
// we don't have to terminate the session.

0 commit comments

Comments
 (0)