Skip to content

Commit d0ed0c6

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 d0ed0c6

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@
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

1113

14+
def get_subprocess(process_name):
15+
queue = deque([psutil.Process(os.getpid())])
16+
while queue:
17+
process = queue.popleft()
18+
if process.name() == process_name:
19+
return process
20+
queue.extend(process.children())
21+
22+
self.assertTrue(False, "No subprocess with name %s found" % process_name)
23+
1224
class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
1325
def check_lldb_command(
1426
self, lldb_command, contains_string, assert_msg, command_escape_prefix="`"
@@ -104,3 +116,49 @@ def test_empty_escape_prefix(self):
104116
"Help can be invoked",
105117
command_escape_prefix="",
106118
)
119+
120+
@skipIfWindows
121+
@skipIfRemote
122+
def test_exit_status_message_sigterm(self):
123+
source = "main.cpp"
124+
program = self.getBuildArtifact("a.out")
125+
self.build_and_launch(program, commandEscapePrefix="")
126+
breakpoint1_line = line_number(source, "// breakpoint 1")
127+
breakpoint_ids = self.set_source_breakpoints(source, [breakpoint1_line])
128+
self.continue_to_breakpoints(breakpoint_ids)
129+
130+
# Kill lldb-server process.
131+
process_name = (
132+
"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
133+
)
134+
process = get_subprocess(process_name)
135+
process.terminate()
136+
process.wait()
137+
138+
# Get the console output
139+
console_output = self.collect_console(1.0)
140+
141+
# Verify the exit status message is printed.
142+
self.assertIn(
143+
"exited with status = -1 (0xffffffff) debugserver died with signal SIGTERM",
144+
console_output,
145+
"Exit status does not contain message 'exited with status'",
146+
)
147+
148+
@skipIfWindows
149+
@skipIfRemote
150+
def test_exit_status_message_ok(self):
151+
source = "main.cpp"
152+
program = self.getBuildArtifact("a.out")
153+
self.build_and_launch(program, commandEscapePrefix="")
154+
self.continue_to_exit()
155+
156+
# Get the console output
157+
console_output = self.collect_console(1.0)
158+
159+
# Verify the exit status message is printed.
160+
self.assertIn(
161+
"exited with status = 0 (0x00000000)",
162+
console_output,
163+
"Exit status does not contain message 'exited with status'",
164+
)

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)