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
17 changes: 2 additions & 15 deletions lldb/tools/lldb-dap/DAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,20 +758,12 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
if (packet_type == "request") {
const auto command = GetString(object, "command");

// Try the new request handler first.
auto new_handler_pos = new_request_handlers.find(command);
if (new_handler_pos != new_request_handlers.end()) {
auto new_handler_pos = request_handlers.find(command);
if (new_handler_pos != request_handlers.end()) {
(*new_handler_pos->second)(object);
return true; // Success
}

// FIXME: Remove request_handlers once everything has been migrated.
auto handler_pos = request_handlers.find(command);
if (handler_pos != request_handlers.end()) {
handler_pos->second(*this, object);
return true; // Success
}

if (log)
*log << "error: unhandled command \"" << command.data() << "\""
<< std::endl;
Expand Down Expand Up @@ -900,11 +892,6 @@ void DAP::SendReverseRequest(llvm::StringRef command,
});
}

void DAP::RegisterRequestCallback(std::string request,
RequestCallback callback) {
request_handlers[request] = callback;
}

lldb::SBError DAP::WaitForProcessToStop(uint32_t seconds) {
lldb::SBError error;
lldb::SBProcess process = target.GetProcess();
Expand Down
20 changes: 2 additions & 18 deletions lldb/tools/lldb-dap/DAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ enum DAPBroadcasterBits {
eBroadcastBitStopProgressThread = 1u << 1
};

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

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

const std::map<std::string, RequestCallback> &GetRequestHandlers();

PacketStatus GetNextObject(llvm::json::Object &object);
bool HandleObject(const llvm::json::Object &object);

Expand Down Expand Up @@ -338,21 +334,9 @@ struct DAP {
void SendReverseRequest(llvm::StringRef command, llvm::json::Value arguments,
ResponseCallback callback);

/// Registers a callback handler for a Debug Adapter Protocol request
///
/// \param[in] request
/// The name of the request following the Debug Adapter Protocol
/// specification.
///
/// \param[in] callback
/// The callback to execute when the given request is triggered by the
/// IDE.
void RegisterRequestCallback(std::string request, RequestCallback callback);

/// Registers a request handler.
template <typename Handler> void RegisterRequest() {
new_request_handlers[Handler::getCommand()] =
std::make_unique<Handler>(*this);
request_handlers[Handler::getCommand()] = std::make_unique<Handler>(*this);
}

/// Debuggee will continue from stopped state.
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace lldb_dap {
// }]
// }

void AttachRequestHandler::operator()(const llvm::json::Object &request) {
void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
dap.is_attach = true;
dap.last_launch_or_attach_request = request;
llvm::json::Object response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace lldb_dap {
// "required": [ "line" ]
// },
void BreakpointLocationsRequestHandler::operator()(
const llvm::json::Object &request) {
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
auto *arguments = request.getObject("arguments");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ namespace lldb_dap {
// }
// }]
// }
void CompileUnitsRequestHandler::operator()(const llvm::json::Object &request) {
void CompileUnitsRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
llvm::json::Object body;
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/CompletionsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ namespace lldb_dap {
// "interface", "module", "property", "unit", "value", "enum", "keyword",
// "snippet", "text", "color", "file", "reference", "customcolor" ]
// }
void CompletionsRequestHandler::operator()(const llvm::json::Object &request) {
void CompletionsRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
llvm::json::Object body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace lldb_dap {
// }]
// },
void ConfigurationDoneRequestHandler::operator()(
const llvm::json::Object &request) {
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
dap.SendJSON(llvm::json::Value(std::move(response)));
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/ContinueRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ namespace lldb_dap {
// "required": [ "body" ]
// }]
// }
void ContinueRequestHandler::operator()(const llvm::json::Object &request) {
void ContinueRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
lldb::SBProcess process = dap.target.GetProcess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace lldb_dap {
// }]
// }
void DataBreakpointInfoRequestHandler::operator()(
const llvm::json::Object &request) {
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
llvm::json::Object body;
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ namespace lldb_dap {
// }
// }]
// }
void DisassembleRequestHandler::operator()(const llvm::json::Object &request) {
void DisassembleRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
auto *arguments = request.getObject("arguments");
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/DisconnectRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ namespace lldb_dap {
// acknowledgement, so no body field is required."
// }]
// }
void DisconnectRequestHandler::operator()(const llvm::json::Object &request) {
void DisconnectRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
const auto *arguments = request.getObject("arguments");
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ namespace lldb_dap {
// "required": [ "body" ]
// }]
// }
void EvaluateRequestHandler::operator()(const llvm::json::Object &request) {
void EvaluateRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
llvm::json::Object body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace lldb_dap {
// }
// },
void ExceptionInfoRequestHandler::operator()(
const llvm::json::Object &request) {
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
const auto *arguments = request.getObject("arguments");
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ static void EventThreadFunction(DAP &dap) {
// }
// }]
// }
void InitializeRequestHandler::operator()(const llvm::json::Object &request) {
void InitializeRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
llvm::json::Object body;
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-dap/Handler/LaunchRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace lldb_dap {
// acknowledgement, so no body field is required."
// }]
// }
void LaunchRequestHandler::operator()(const llvm::json::Object &request) {
void LaunchRequestHandler::operator()(const llvm::json::Object &request) const {
dap.is_attach = false;
dap.last_launch_or_attach_request = request;
llvm::json::Object response;
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/LocationsRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ namespace lldb_dap {
// }
// }]
// },
void LocationsRequestHandler::operator()(const llvm::json::Object &request) {
void LocationsRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
auto *arguments = request.getObject("arguments");
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace lldb_dap {
// }
// }]
// }
void ModulesRequestHandler::operator()(const llvm::json::Object &request) {
void ModulesRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);

Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace lldb_dap {
// acknowledgement, so no body field is required."
// }]
// }
void NextRequestHandler::operator()(const llvm::json::Object &request) {
void NextRequestHandler::operator()(const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
const auto *arguments = request.getObject("arguments");
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace lldb_dap {
// acknowledgement, so no body field is required."
// }]
// }
void PauseRequestHandler::operator()(const llvm::json::Object &request) {
void PauseRequestHandler::operator()(const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
lldb::SBProcess process = dap.target.GetProcess();
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ namespace lldb_dap {
// }
// }]
// },
void ReadMemoryRequestHandler::operator()(const llvm::json::Object &request) {
void ReadMemoryRequestHandler::operator()(
const llvm::json::Object &request) const {
llvm::json::Object response;
FillResponse(request, response);
auto *arguments = request.getObject("arguments");
Expand Down
9 changes: 5 additions & 4 deletions lldb/tools/lldb-dap/Handler/RequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MakeArgv(const llvm::ArrayRef<std::string> &strs) {
// Both attach and launch take a either a sourcePath or sourceMap
// argument (or neither), from which we need to set the target.source-map.
void RequestHandler::SetSourceMapFromArguments(
const llvm::json::Object &arguments) {
const llvm::json::Object &arguments) const {
const char *sourceMapHelp =
"source must be be an array of two-element arrays, "
"each containing a source and replacement path string.\n";
Expand Down Expand Up @@ -153,7 +153,8 @@ static llvm::Error RunInTerminal(DAP &dap,
error.GetCString());
}

lldb::SBError RequestHandler::LaunchProcess(const llvm::json::Object &request) {
lldb::SBError
RequestHandler::LaunchProcess(const llvm::json::Object &request) const {
lldb::SBError error;
const auto *arguments = request.getObject("arguments");
auto launchCommands = GetStrings(arguments, "launchCommands");
Expand Down Expand Up @@ -219,14 +220,14 @@ lldb::SBError RequestHandler::LaunchProcess(const llvm::json::Object &request) {
return error;
}

void RequestHandler::PrintWelcomeMessage() {
void RequestHandler::PrintWelcomeMessage() const {
#ifdef LLDB_DAP_WELCOME_MESSAGE
dap.SendOutput(OutputType::Console, LLDB_DAP_WELCOME_MESSAGE);
#endif
}

bool RequestHandler::HasInstructionGranularity(
const llvm::json::Object &arguments) {
const llvm::json::Object &arguments) const {
if (std::optional<llvm::StringRef> value = arguments.getString("granularity"))
return value == "instruction";
return false;
Expand Down
Loading