Skip to content

Commit 31d688e

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 31d688e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

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

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

55
import dap_server
66
import lldbdap_testcase
7+
import psutil
78
from lldbsuite.test import lldbutil
89
from lldbsuite.test.decorators import *
910
from lldbsuite.test.lldbtest import *
1011

12+
def get_latest_pid(process_name):
13+
processes = []
14+
for proc in psutil.process_iter():
15+
try:
16+
if proc.name() == process_name:
17+
processes += [proc]
18+
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
19+
pass
20+
if len(processes) == 0:
21+
print("No lldb-server process found", flush=True, file=sys.stderr)
22+
return None
23+
24+
processes = sorted(processes, key=lambda x:x.create_time())
25+
return processes[-1].pid
26+
27+
def killProcess(pid, process_name):
28+
process = psutil.Process(pid)
29+
process.terminate()
30+
try:
31+
process.wait(timeout=5)
32+
except psutil.TimeoutExpired:
33+
self.assertTrue(False, process_name + " process should have exited by now")
1134

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

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)