Skip to content

Commit d09721b

Browse files
committed
[lldb-dap] Refactor lldb-dap.cpp to not use a global variable.
This removes the global DAP variable and instead allocates a DAP instance in main. This should allow us to refactor lldb-dap to enable a server mode that accepts multiple connections.
1 parent 8781a43 commit d09721b

File tree

3 files changed

+547
-552
lines changed

3 files changed

+547
-552
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ using namespace lldb_dap;
3232

3333
namespace lldb_dap {
3434

35-
DAP g_dap;
36-
3735
DAP::DAP()
3836
: broadcaster("lldb-dap"), exception_breakpoints(),
3937
focus_tid(LLDB_INVALID_THREAD_ID), stop_at_entry(false), is_attach(false),
@@ -693,15 +691,15 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
693691
if (packet_type == "request") {
694692
const auto command = GetString(object, "command");
695693
auto handler_pos = request_handlers.find(command);
696-
if (handler_pos != request_handlers.end()) {
697-
handler_pos->second(object);
698-
return true; // Success
699-
} else {
694+
if (handler_pos == request_handlers.end()) {
700695
if (log)
701696
*log << "error: unhandled command \"" << command.data() << "\""
702697
<< std::endl;
703698
return false; // Fail
704699
}
700+
701+
handler_pos->second(*this, object);
702+
return true; // Success
705703
}
706704

707705
if (packet_type == "response") {

lldb/tools/lldb-dap/DAP.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ enum DAPBroadcasterBits {
6363
eBroadcastBitStopProgressThread = 1u << 1
6464
};
6565

66-
typedef void (*RequestCallback)(const llvm::json::Object &command);
66+
typedef void (*RequestCallback)(DAP &dap, const llvm::json::Object &command);
6767
typedef void (*ResponseCallback)(llvm::Expected<llvm::json::Value> value);
6868

6969
enum class PacketStatus {
@@ -353,8 +353,6 @@ struct DAP {
353353
void SendJSON(const std::string &json_str);
354354
};
355355

356-
extern DAP g_dap;
357-
358356
} // namespace lldb_dap
359357

360358
#endif

0 commit comments

Comments
 (0)