https://github.com/DrSergei updated https://github.com/llvm/llvm-project/pull/181109
>From ad090c49e905f5baf90eda151998b9398b13b93f Mon Sep 17 00:00:00 2001 From: Sergei Druzhkov <[email protected]> Date: Thu, 12 Feb 2026 12:24:58 +0300 Subject: [PATCH] [lldb-dap] Add unknown request handler --- .../test/tools/lldb-dap/dap_server.py | 8 ++++++ .../launch/TestDAP_launch_unknown_request.py | 25 +++++++++++++++++++ lldb/tools/lldb-dap/CMakeLists.txt | 1 + lldb/tools/lldb-dap/DAP.cpp | 14 +++++------ lldb/tools/lldb-dap/DAP.h | 2 ++ lldb/tools/lldb-dap/Handler/RequestHandler.h | 9 +++++++ .../Handler/UnknownRequestHandler.cpp | 19 ++++++++++++++ .../lldb-dap/Protocol/ProtocolRequests.h | 5 ++++ .../gn/secondary/lldb/tools/lldb-dap/BUILD.gn | 1 + 9 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_unknown_request.py create mode 100644 lldb/tools/lldb-dap/Handler/UnknownRequestHandler.cpp diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index fdccc9eae9fe4..7bbad52147747 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -1677,6 +1677,14 @@ def request_testGetTargetBreakpoints(self): } return self._send_recv(command_dict) + def request_unknown(self): + command_dict = { + "command": "unknown", + "type": "request", + "arguments": {}, + } + return self._send_recv(command_dict) + def terminate(self): self.send.close() if self._recv_thread.is_alive(): diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_unknown_request.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_unknown_request.py new file mode 100644 index 0000000000000..ac285bce07258 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_unknown_request.py @@ -0,0 +1,25 @@ +""" +Test lldb-dap launch request. +""" + +from lldbsuite.test.decorators import expectedFailureWindows +import lldbdap_testcase + + +class TestDAP_launch_unknown_request(lldbdap_testcase.DAPTestCaseBase): + """ + Tests handling of unknown request. + """ + + @expectedFailureWindows( + bugnumber="https://github.com/llvm/llvm-project/issues/137599" + ) + def test(self): + program = self.getBuildArtifact("a.out") + self.build_and_launch(program) + + response = self.dap_server.request_unknown() + self.assertFalse(response["success"]) + self.assertEqual(response["body"]["error"]["format"], "Unknown request") + + self.continue_to_exit() diff --git a/lldb/tools/lldb-dap/CMakeLists.txt b/lldb/tools/lldb-dap/CMakeLists.txt index 8566c663fcc06..1bb7a2e498b9b 100644 --- a/lldb/tools/lldb-dap/CMakeLists.txt +++ b/lldb/tools/lldb-dap/CMakeLists.txt @@ -64,6 +64,7 @@ add_lldb_library(lldbDAP Handler/StepOutRequestHandler.cpp Handler/TestGetTargetBreakpointsRequestHandler.cpp Handler/ThreadsRequestHandler.cpp + Handler/UnknownRequestHandler.cpp Handler/VariablesRequestHandler.cpp Handler/WriteMemoryRequestHandler.cpp diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index b76b05c5d1459..0a0d3c3903409 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -849,15 +849,11 @@ bool DAP::HandleObject(const Message &M) { auto handler_pos = request_handlers.find(req->command); dispatcher.Set("client_data", llvm::Twine("request_command:", req->command).str()); - if (handler_pos != request_handlers.end()) { + if (handler_pos != request_handlers.end()) handler_pos->second->Run(*req); - return true; // Success - } - - dispatcher.Set("error", - llvm::Twine("unhandled-command:" + req->command).str()); - DAP_LOG(log, "error: unhandled command '{0}'", req->command); - return false; // Fail + else + unknown_request_handler->Run(*req); + return true; // Success } if (const auto *resp = std::get_if<Response>(&M)) { @@ -1577,6 +1573,8 @@ void DAP::RegisterRequests() { RegisterRequest<VariablesRequestHandler>(); RegisterRequest<WriteMemoryRequestHandler>(); + unknown_request_handler = std::make_unique<UnknownRequestHandler>(*this); + // Custom requests RegisterRequest<CompileUnitsRequestHandler>(); RegisterRequest<ModulesRequestHandler>(); diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h index 34d6a29b3c110..f2e1162eb3a61 100644 --- a/lldb/tools/lldb-dap/DAP.h +++ b/lldb/tools/lldb-dap/DAP.h @@ -482,6 +482,8 @@ struct DAP final : public DAPTransport::MessageHandler { llvm::StringMap<std::unique_ptr<BaseRequestHandler>> request_handlers; /// @} + std::unique_ptr<BaseRequestHandler> unknown_request_handler; + /// Event threads. /// @{ void ProgressEventThread(); diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.h b/lldb/tools/lldb-dap/Handler/RequestHandler.h index 9feb636fd5c28..4b4f1435e7acb 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.h +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.h @@ -658,6 +658,15 @@ class WriteMemoryRequestHandler final Run(const protocol::WriteMemoryArguments &args) const override; }; +class UnknownRequestHandler final + : public RequestHandler<protocol::UnknownArguments, + protocol::UnknownResponseBody> { +public: + using RequestHandler::RequestHandler; + static llvm::StringLiteral GetCommand() { return "unknown"; } + llvm::Error Run(const protocol::UnknownArguments &args) const override; +}; + } // namespace lldb_dap #endif diff --git a/lldb/tools/lldb-dap/Handler/UnknownRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/UnknownRequestHandler.cpp new file mode 100644 index 0000000000000..c576256a48265 --- /dev/null +++ b/lldb/tools/lldb-dap/Handler/UnknownRequestHandler.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "DAPError.h" +#include "Protocol/ProtocolRequests.h" +#include "RequestHandler.h" +#include "llvm/Support/Error.h" + +using namespace lldb_dap; +using namespace lldb_dap::protocol; + +llvm::Error UnknownRequestHandler::Run(const UnknownArguments &args) const { + return llvm::make_error<DAPError>("Unknown request"); +} diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h index 28c9f48200e0c..91fc2a4db6f57 100644 --- a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h +++ b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h @@ -1312,6 +1312,11 @@ struct StackTraceResponseBody { }; llvm::json::Value toJSON(const StackTraceResponseBody &); +/// Arguments for unknown request. +using UnknownArguments = EmptyArguments; +/// Response to unknowns request. +using UnknownResponseBody = VoidResponse; + } // namespace lldb_dap::protocol #endif diff --git a/llvm/utils/gn/secondary/lldb/tools/lldb-dap/BUILD.gn b/llvm/utils/gn/secondary/lldb/tools/lldb-dap/BUILD.gn index 896da7df95bb1..edcbc5e31f4f1 100644 --- a/llvm/utils/gn/secondary/lldb/tools/lldb-dap/BUILD.gn +++ b/llvm/utils/gn/secondary/lldb/tools/lldb-dap/BUILD.gn @@ -68,6 +68,7 @@ static_library("lib") { "Handler/StepOutRequestHandler.cpp", "Handler/TestGetTargetBreakpointsRequestHandler.cpp", "Handler/ThreadsRequestHandler.cpp", + "Handler/UnknownRequestHandler.cpp", "Handler/VariablesRequestHandler.cpp", "Handler/WriteMemoryRequestHandler.cpp", "InstructionBreakpoint.cpp", _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
