Skip to content

Commit d6a556a

Browse files
committed
[lldb-dap] Finish refactoring the request handlers (NFC)
This removes the old way of register request handlers with callbacks.
1 parent b248817 commit d6a556a

File tree

3 files changed

+4
-34
lines changed

3 files changed

+4
-34
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -758,20 +758,12 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
758758
if (packet_type == "request") {
759759
const auto command = GetString(object, "command");
760760

761-
// Try the new request handler first.
762-
auto new_handler_pos = new_request_handlers.find(command);
763-
if (new_handler_pos != new_request_handlers.end()) {
761+
auto new_handler_pos = request_handlers.find(command);
762+
if (new_handler_pos != request_handlers.end()) {
764763
(*new_handler_pos->second)(object);
765764
return true; // Success
766765
}
767766

768-
// FIXME: Remove request_handlers once everything has been migrated.
769-
auto handler_pos = request_handlers.find(command);
770-
if (handler_pos != request_handlers.end()) {
771-
handler_pos->second(*this, object);
772-
return true; // Success
773-
}
774-
775767
if (log)
776768
*log << "error: unhandled command \"" << command.data() << "\""
777769
<< std::endl;
@@ -900,11 +892,6 @@ void DAP::SendReverseRequest(llvm::StringRef command,
900892
});
901893
}
902894

903-
void DAP::RegisterRequestCallback(std::string request,
904-
RequestCallback callback) {
905-
request_handlers[request] = callback;
906-
}
907-
908895
lldb::SBError DAP::WaitForProcessToStop(uint32_t seconds) {
909896
lldb::SBError error;
910897
lldb::SBProcess process = target.GetProcess();

lldb/tools/lldb-dap/DAP.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ enum DAPBroadcasterBits {
6868
eBroadcastBitStopProgressThread = 1u << 1
6969
};
7070

71-
typedef void (*RequestCallback)(DAP &dap, const llvm::json::Object &command);
7271
typedef void (*ResponseCallback)(llvm::Expected<llvm::json::Value> value);
7372

7473
enum class PacketStatus {
@@ -190,8 +189,7 @@ struct DAP {
190189
// the old process here so we can detect this case and keep running.
191190
lldb::pid_t restarting_process_id;
192191
bool configuration_done_sent;
193-
std::map<std::string, RequestCallback, std::less<>> request_handlers;
194-
llvm::StringMap<std::unique_ptr<RequestHandler>> new_request_handlers;
192+
llvm::StringMap<std::unique_ptr<RequestHandler>> request_handlers;
195193
bool waiting_for_run_in_terminal;
196194
ProgressEventReporter progress_event_reporter;
197195
// Keep track of the last stop thread index IDs as threads won't go away
@@ -309,8 +307,6 @@ struct DAP {
309307
/// listeing for its breakpoint events.
310308
void SetTarget(const lldb::SBTarget target);
311309

312-
const std::map<std::string, RequestCallback> &GetRequestHandlers();
313-
314310
PacketStatus GetNextObject(llvm::json::Object &object);
315311
bool HandleObject(const llvm::json::Object &object);
316312

@@ -338,20 +334,9 @@ struct DAP {
338334
void SendReverseRequest(llvm::StringRef command, llvm::json::Value arguments,
339335
ResponseCallback callback);
340336

341-
/// Registers a callback handler for a Debug Adapter Protocol request
342-
///
343-
/// \param[in] request
344-
/// The name of the request following the Debug Adapter Protocol
345-
/// specification.
346-
///
347-
/// \param[in] callback
348-
/// The callback to execute when the given request is triggered by the
349-
/// IDE.
350-
void RegisterRequestCallback(std::string request, RequestCallback callback);
351-
352337
/// Registers a request handler.
353338
template <typename Handler> void RegisterRequest() {
354-
new_request_handlers[Handler::getCommand()] =
339+
request_handlers[Handler::getCommand()] =
355340
std::make_unique<Handler>(*this);
356341
}
357342

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ class LLDBDAPOptTable : public llvm::opt::GenericOptTable {
123123
InfoTable, true) {}
124124
};
125125

126-
typedef void (*RequestCallback)(const llvm::json::Object &command);
127-
128126
void RegisterRequestCallbacks(DAP &dap) {
129127
dap.RegisterRequest<AttachRequestHandler>();
130128
dap.RegisterRequest<BreakpointLocationsRequestHandler>();

0 commit comments

Comments
 (0)