Skip to content

Commit 4c22c23

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 4c22c23

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

lldb/include/lldb/API/SBProcess.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ class LLDB_API SBProcess {
562562

563563
lldb::SBScriptObject GetScriptedImplementation();
564564

565+
void GetStatus(SBStream &status);
566+
565567
protected:
566568
friend class SBAddress;
567569
friend class SBBreakpoint;

lldb/source/API/SBProcess.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,14 @@ size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
928928
return bytes_written;
929929
}
930930

931+
void SBProcess::GetStatus(SBStream &status) {
932+
LLDB_INSTRUMENT_VA(this, status);
933+
934+
ProcessSP process_sp(GetSP());
935+
if (process_sp)
936+
process_sp->GetStatus(status.ref());
937+
}
938+
931939
bool SBProcess::GetDescription(SBStream &description) {
932940
LLDB_INSTRUMENT_VA(this, description);
933941

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
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(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
19+
queue.extend(process.children())
20+
21+
self.assertTrue(False, "No subprocess with name %s found" % process_name)
1122

1223
class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
1324
def check_lldb_command(
@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
104115
"Help can be invoked",
105116
command_escape_prefix="",
106117
)
118+
119+
@skipIfWindows
120+
@skipIfRemote
121+
def test_exit_status_message_sigterm(self):
122+
source = "main.cpp"
123+
program = self.getBuildArtifact("a.out")
124+
self.build_and_launch(program, commandEscapePrefix="")
125+
breakpoint1_line = line_number(source, "// breakpoint 1")
126+
breakpoint_ids = self.set_source_breakpoints(source, [breakpoint1_line])
127+
self.continue_to_breakpoints(breakpoint_ids)
128+
129+
# Kill lldb-server process.
130+
process_name = (
131+
"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
132+
)
133+
process = get_subprocess(process_name)
134+
process.terminate()
135+
process.wait()
136+
137+
# Get the console output
138+
console_output = self.collect_console(1.0)
139+
140+
# Verify the exit status message is printed.
141+
self.assertIn(
142+
"exited with status = -1 (0xffffffff) debugserver died with signal SIGTERM",
143+
console_output,
144+
"Exit status does not contain message 'exited with status'",
145+
)
146+
147+
@skipIfWindows
148+
@skipIfRemote
149+
def test_exit_status_message_ok(self):
150+
source = "main.cpp"
151+
program = self.getBuildArtifact("a.out")
152+
self.build_and_launch(program, commandEscapePrefix="")
153+
self.continue_to_exit()
154+
155+
# Get the console output
156+
console_output = self.collect_console(1.0)
157+
158+
# Verify the exit status message is printed.
159+
self.assertIn(
160+
"exited with status = 0 (0x00000000)",
161+
console_output,
162+
"Exit status does not contain message 'exited with status'",
163+
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <thread>
5151
#include <vector>
5252

53+
#include "lldb/API/SBStream.h"
5354
#include "lldb/Host/Config.h"
5455
#include "llvm/ADT/ArrayRef.h"
5556
#include "llvm/ADT/DenseMap.h"
@@ -503,6 +504,10 @@ void EventThreadFunction() {
503504
SendContinuedEvent();
504505
break;
505506
case lldb::eStateExited:
507+
lldb::SBStream stream;
508+
process.GetStatus(stream);
509+
g_dap.SendOutput(OutputType::Console, stream.GetData());
510+
506511
// When restarting, we can get an "exited" event for the process we
507512
// just killed with the old PID, or even with no PID. In that case
508513
// we don't have to terminate the session.

0 commit comments

Comments
 (0)