Skip to content

Conversation

@DrSergei
Copy link
Contributor

@DrSergei DrSergei commented Dec 8, 2025

This patch migrates pause request into structured types and adds test for it.

@llvmbot
Copy link
Member

llvmbot commented Dec 8, 2025

@llvm/pr-subscribers-lldb

Author: Sergei Druzhkov (DrSergei)

Changes

This patch migrates pause request into structured types and adds test for it.


Full diff: https://github.com/llvm/llvm-project/pull/171096.diff

5 Files Affected:

  • (modified) lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp (+7-41)
  • (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+4-3)
  • (modified) lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp (+6)
  • (modified) lldb/tools/lldb-dap/Protocol/ProtocolRequests.h (+11)
  • (modified) lldb/unittests/DAP/ProtocolRequestsTest.cpp (+11)
diff --git a/lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp
index 99917b2e28223..1589c7c1142e9 100644
--- a/lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp
@@ -8,53 +8,19 @@
 
 #include "DAP.h"
 #include "EventHelper.h"
-#include "JSONUtils.h"
+#include "Protocol/ProtocolRequests.h"
 #include "RequestHandler.h"
 
 namespace lldb_dap {
 
-// "PauseRequest": {
-//   "allOf": [ { "$ref": "#/definitions/Request" }, {
-//     "type": "object",
-//     "description": "Pause request; value of command field is 'pause'. The
-//     request suspenses the debuggee. The debug adapter first sends the
-//     PauseResponse and then a StoppedEvent (event type 'pause') after the
-//     thread has been paused successfully.", "properties": {
-//       "command": {
-//         "type": "string",
-//         "enum": [ "pause" ]
-//       },
-//       "arguments": {
-//         "$ref": "#/definitions/PauseArguments"
-//       }
-//     },
-//     "required": [ "command", "arguments"  ]
-//   }]
-// },
-// "PauseArguments": {
-//   "type": "object",
-//   "description": "Arguments for 'pause' request.",
-//   "properties": {
-//     "threadId": {
-//       "type": "integer",
-//       "description": "Pause execution for this thread."
-//     }
-//   },
-//   "required": [ "threadId" ]
-// },
-// "PauseResponse": {
-//   "allOf": [ { "$ref": "#/definitions/Response" }, {
-//     "type": "object",
-//     "description": "Response to 'pause' request. This is just an
-//     acknowledgement, so no body field is required."
-//   }]
-// }
-void PauseRequestHandler::operator()(const llvm::json::Object &request) const {
-  llvm::json::Object response;
-  FillResponse(request, response);
+/// The request suspenses the debuggee. The debug adapter first sends the
+/// PauseResponse and then a StoppedEvent (event type 'pause') after the thread
+/// has been paused successfully.
+llvm::Error
+PauseRequestHandler::Run(const protocol::PauseArguments &args) const {
   lldb::SBProcess process = dap.target.GetProcess();
   lldb::SBError error = process.Stop();
-  dap.SendJSON(llvm::json::Value(std::move(response)));
+  return llvm::Error::success();
 }
 
 } // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.h b/lldb/tools/lldb-dap/Handler/RequestHandler.h
index 5d235352b7738..fdce33de3f680 100644
--- a/lldb/tools/lldb-dap/Handler/RequestHandler.h
+++ b/lldb/tools/lldb-dap/Handler/RequestHandler.h
@@ -492,11 +492,12 @@ class ModulesRequestHandler final
   Run(const std::optional<protocol::ModulesArguments> &args) const override;
 };
 
-class PauseRequestHandler : public LegacyRequestHandler {
+class PauseRequestHandler
+    : public RequestHandler<protocol::PauseArguments, protocol::PauseResponse> {
 public:
-  using LegacyRequestHandler::LegacyRequestHandler;
+  using RequestHandler::RequestHandler;
   static llvm::StringLiteral GetCommand() { return "pause"; }
-  void operator()(const llvm::json::Object &request) const override;
+  llvm::Error Run(const protocol::PauseArguments &args) const override;
 };
 
 class ScopesRequestHandler final
diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp
index 0a1d580bffd68..95ecc7e4e7e40 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp
@@ -695,4 +695,10 @@ llvm::json::Value toJSON(const EvaluateResponseBody &Body) {
   return result;
 }
 
+bool fromJSON(const llvm::json::Value &Params, PauseArguments &Args,
+              llvm::json::Path Path) {
+  json::ObjectMapper O(Params, Path);
+  return O && O.map("threadId", Args.threadId);
+}
+
 } // namespace lldb_dap::protocol
diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h
index 6a85033ae7ef2..dc84e90ae03b4 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h
@@ -1184,6 +1184,17 @@ struct EvaluateResponseBody {
 };
 llvm::json::Value toJSON(const EvaluateResponseBody &);
 
+/// Arguments for `pause` request.
+struct PauseArguments {
+  /// Pause execution for this thread.
+  lldb::tid_t threadId = LLDB_INVALID_THREAD_ID;
+};
+bool fromJSON(const llvm::json::Value &, PauseArguments &, llvm::json::Path);
+
+/// Response to `pause` request. This is just an acknowledgement, so no body
+/// field is required.
+using PauseResponse = VoidResponse;
+
 } // namespace lldb_dap::protocol
 
 #endif
diff --git a/lldb/unittests/DAP/ProtocolRequestsTest.cpp b/lldb/unittests/DAP/ProtocolRequestsTest.cpp
index a74c369924b8e..c830690a8e4fe 100644
--- a/lldb/unittests/DAP/ProtocolRequestsTest.cpp
+++ b/lldb/unittests/DAP/ProtocolRequestsTest.cpp
@@ -182,3 +182,14 @@ TEST(ProtocolRequestsTest, InitializeRequestArguments) {
   EXPECT_THAT_EXPECTED(parse<InitializeRequestArguments>(R"({})"),
                        FailedWithMessage("missing value at (root).adapterID"));
 }
+
+TEST(ProtocolRequestsTest, PauseRequestArguments) {
+  llvm::Expected<PauseArguments> expected =
+      parse<PauseArguments>(R"({"threadId": 123})");
+  ASSERT_THAT_EXPECTED(expected, llvm::Succeeded());
+  EXPECT_EQ(expected->threadId, 123U);
+
+  // Check required keys.
+  EXPECT_THAT_EXPECTED(parse<PauseArguments>(R"({})"),
+                       FailedWithMessage("missing value at (root).threadId"));
+}

@DrSergei DrSergei merged commit 371da58 into llvm:main Dec 8, 2025
10 checks passed
honeygoyal pushed a commit to honeygoyal/llvm-project that referenced this pull request Dec 9, 2025
This patch migrates `pause` request into structured types and adds test
for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants