[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Sun Mar 16 18:25:17 PDT 2025
================
@@ -663,58 +671,64 @@ void DAP::SetTarget(const lldb::SBTarget target) {
}
bool DAP::HandleObject(const protocol::Message &M) {
- // FIXME: Directly handle `Message` instead of serializing to JSON.
- llvm::json::Value v = toJSON(M);
- llvm::json::Object object = *v.getAsObject();
- const auto packet_type = GetString(object, "type");
- if (packet_type == "request") {
- const auto command = GetString(object, "command");
-
- auto new_handler_pos = request_handlers.find(command);
- if (new_handler_pos != request_handlers.end()) {
- (*new_handler_pos->second)(object);
+ if (const auto *req = std::get_if<protocol::Request>(&M)) {
+ auto handler_pos = request_handlers.find(req->command);
+ if (handler_pos != request_handlers.end()) {
+ (*handler_pos->second)(*req);
return true; // Success
}
DAP_LOG(log, "({0}) error: unhandled command '{1}'",
- transport.GetClientName(), command);
+ transport.GetClientName(), req->command);
return false; // Fail
}
- if (packet_type == "response") {
- auto id = GetInteger<int64_t>(object, "request_seq").value_or(0);
-
+ if (const auto *resp = std::get_if<protocol::Response>(&M)) {
std::unique_ptr<ResponseHandler> response_handler;
{
std::lock_guard<std::mutex> locker(call_mutex);
- auto inflight = inflight_reverse_requests.find(id);
+ auto inflight = inflight_reverse_requests.find(resp->request_seq);
if (inflight != inflight_reverse_requests.end()) {
response_handler = std::move(inflight->second);
inflight_reverse_requests.erase(inflight);
}
}
if (!response_handler)
- response_handler = std::make_unique<UnknownResponseHandler>("", id);
+ response_handler =
+ std::make_unique<UnknownResponseHandler>("", resp->request_seq);
// Result should be given, use null if not.
- if (GetBoolean(object, "success").value_or(false)) {
- llvm::json::Value Result = nullptr;
- if (auto *B = object.get("body"))
- Result = std::move(*B);
- (*response_handler)(Result);
+ if (resp->success) {
+ (*response_handler)(resp->body);
} else {
- llvm::StringRef message = GetString(object, "message");
- if (message.empty()) {
- message = "Unknown error, response failed";
+ std::string message = "Unknown error, response failed";
+ if (resp->message) {
+ message = std::visit(
+ llvm::makeVisitor(
+ [](const std::string &message) -> std::string {
+ return message;
+ },
+ [](const protocol::Response::Message &message) -> std::string {
----------------
JDevlieghere wrote:
Any reason these can't remain StringRefs? They're all string literals, right?
https://github.com/llvm/llvm-project/pull/130090
More information about the lldb-commits
mailing list