Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_output(self):
program = self.getBuildArtifact("a.out")
self.build_and_launch(
program,
disconnectAutomatically=False,
exitCommands=[
# Ensure that output produced by lldb itself is not consumed by the OutputRedirector.
"?script print('out\\0\\0', end='\\r\\n', file=sys.stdout)",
Expand All @@ -33,6 +34,9 @@ def test_output(self):

self.continue_to_exit()

# Disconnecting from the server to ensure any pending IO is flushed.
self.dap_server.request_disconnect()

output += self.get_stdout(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval)
self.assertTrue(output and len(output) > 0, "expect program stdout")
self.assertIn(
Expand Down
11 changes: 6 additions & 5 deletions lldb/tools/lldb-dap/DAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, std::FILE *overrideErr) {
return llvm::Error::success();
}

void DAP::StopIO() {
out.Stop();
err.Stop();

void DAP::StopEventHandlers() {
if (event_thread.joinable()) {
broadcaster.BroadcastEventByType(eBroadcastBitStopEventThread);
event_thread.join();
Expand Down Expand Up @@ -853,13 +850,17 @@ lldb::SBError DAP::Disconnect(bool terminateDebuggee) {

SendTerminatedEvent();

// Stop forwarding the debugger output and error handles.
out.Stop();
err.Stop();

disconnecting = true;

return error;
}

llvm::Error DAP::Loop() {
auto stop_io = llvm::make_scope_exit([this]() { StopIO(); });
auto cleanup = llvm::make_scope_exit([this]() { StopEventHandlers(); });
while (!disconnecting) {
llvm::json::Object object;
lldb_dap::PacketStatus status = GetNextObject(object);
Expand Down
4 changes: 2 additions & 2 deletions lldb/tools/lldb-dap/DAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ struct DAP {
llvm::Error ConfigureIO(std::FILE *overrideOut = nullptr,
std::FILE *overrideErr = nullptr);

/// Stop the redirected IO threads and associated pipes.
void StopIO();
/// Stop event handler threads.
void StopEventHandlers();

// Serialize the JSON value into a string and send the JSON packet to
// the "out" stream.
Expand Down