Skip to content

[lldb-dap] fix crash if disconnect request is not sent. #148878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/20.x
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions lldb/tools/lldb-dap/DAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "lldb/lldb-defines.h"
#include "lldb/lldb-enumerations.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
Expand Down Expand Up @@ -224,6 +225,16 @@ llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, std::FILE *overrideErr) {
void DAP::StopIO() {
out.Stop();
err.Stop();

if (event_thread.joinable()) {
broadcaster.BroadcastEventByType(eBroadcastBitStopEventThread);
event_thread.join();
}

if (progress_event_thread.joinable()) {
broadcaster.BroadcastEventByType(eBroadcastBitStopProgressThread);
progress_event_thread.join();
}
}

// Send the JSON in "json_str" to the "out" stream. Correctly send the
Expand Down Expand Up @@ -794,6 +805,7 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
}

llvm::Error DAP::Loop() {
auto stop_io = llvm::make_scope_exit([this]() { StopIO(); });
while (!disconnecting) {
llvm::json::Object object;
lldb_dap::PacketStatus status = GetNextObject(object);
Expand Down
9 changes: 0 additions & 9 deletions lldb/tools/lldb-dap/lldb-dap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,15 +1096,6 @@ void request_disconnect(DAP &dap, const llvm::json::Object &request) {
}
SendTerminatedEvent(dap);
dap.SendJSON(llvm::json::Value(std::move(response)));
if (dap.event_thread.joinable()) {
dap.broadcaster.BroadcastEventByType(eBroadcastBitStopEventThread);
dap.event_thread.join();
}
if (dap.progress_event_thread.joinable()) {
dap.broadcaster.BroadcastEventByType(eBroadcastBitStopProgressThread);
dap.progress_event_thread.join();
}
dap.StopIO();
dap.disconnecting = true;
}

Expand Down
Loading