Skip to content

Commit 155bf37

Browse files
authored
[lldb-dap] Migrate 'continue' request to new RequestHandler. (#138987)
This adds types for the 'continue' request and updates the existing handler to the new base class.
1 parent 2ec0883 commit 155bf37

File tree

4 files changed

+76
-72
lines changed

4 files changed

+76
-72
lines changed

lldb/tools/lldb-dap/Handler/ContinueRequestHandler.cpp

Lines changed: 33 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,41 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "DAP.h"
10-
#include "JSONUtils.h"
11-
#include "RequestHandler.h"
10+
#include "Handler/RequestHandler.h"
11+
#include "LLDBUtils.h"
12+
#include "Protocol/ProtocolRequests.h"
13+
#include "lldb/API/SBError.h"
14+
#include "lldb/API/SBProcess.h"
15+
#include "llvm/Support/Error.h"
16+
17+
using namespace llvm;
18+
using namespace lldb;
19+
using namespace lldb_dap::protocol;
1220

1321
namespace lldb_dap {
1422

15-
// "ContinueRequest": {
16-
// "allOf": [ { "$ref": "#/definitions/Request" }, {
17-
// "type": "object",
18-
// "description": "Continue request; value of command field is 'continue'.
19-
// The request starts the debuggee to run again.",
20-
// "properties": {
21-
// "command": {
22-
// "type": "string",
23-
// "enum": [ "continue" ]
24-
// },
25-
// "arguments": {
26-
// "$ref": "#/definitions/ContinueArguments"
27-
// }
28-
// },
29-
// "required": [ "command", "arguments" ]
30-
// }]
31-
// },
32-
// "ContinueArguments": {
33-
// "type": "object",
34-
// "description": "Arguments for 'continue' request.",
35-
// "properties": {
36-
// "threadId": {
37-
// "type": "integer",
38-
// "description": "Continue execution for the specified thread (if
39-
// possible). If the backend cannot continue on a single
40-
// thread but will continue on all threads, it should
41-
// set the allThreadsContinued attribute in the response
42-
// to true."
43-
// }
44-
// },
45-
// "required": [ "threadId" ]
46-
// },
47-
// "ContinueResponse": {
48-
// "allOf": [ { "$ref": "#/definitions/Response" }, {
49-
// "type": "object",
50-
// "description": "Response to 'continue' request.",
51-
// "properties": {
52-
// "body": {
53-
// "type": "object",
54-
// "properties": {
55-
// "allThreadsContinued": {
56-
// "type": "boolean",
57-
// "description": "If true, the continue request has ignored the
58-
// specified thread and continued all threads
59-
// instead. If this attribute is missing a value
60-
// of 'true' is assumed for backward
61-
// compatibility."
62-
// }
63-
// }
64-
// }
65-
// },
66-
// "required": [ "body" ]
67-
// }]
68-
// }
69-
void ContinueRequestHandler::operator()(
70-
const llvm::json::Object &request) const {
71-
llvm::json::Object response;
72-
FillResponse(request, response);
73-
lldb::SBProcess process = dap.target.GetProcess();
74-
lldb::SBError error = process.Continue();
75-
llvm::json::Object body;
76-
body.try_emplace("allThreadsContinued", true);
77-
response.try_emplace("body", std::move(body));
78-
dap.SendJSON(llvm::json::Value(std::move(response)));
23+
/// The request resumes execution of all threads. If the debug adapter supports
24+
/// single thread execution (see capability
25+
/// `supportsSingleThreadExecutionRequests`), setting the `singleThread`
26+
/// argument to true resumes only the specified thread. If not all threads were
27+
/// resumed, the `allThreadsContinued` attribute of the response should be set
28+
/// to false.
29+
Expected<ContinueResponseBody>
30+
ContinueRequestHandler::Run(const ContinueArguments &args) const {
31+
SBProcess process = dap.target.GetProcess();
32+
SBError error;
33+
34+
if (args.singleThread)
35+
dap.GetLLDBThread(args.threadId).Resume(error);
36+
else
37+
error = process.Continue();
38+
39+
if (error.Fail())
40+
return ToError(error);
41+
42+
ContinueResponseBody body;
43+
body.allThreadsContinued = args.singleThread;
44+
return body;
7945
}
46+
8047
} // namespace lldb_dap

lldb/tools/lldb-dap/Handler/RequestHandler.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,14 @@ class CompletionsRequestHandler : public LegacyRequestHandler {
224224
void operator()(const llvm::json::Object &request) const override;
225225
};
226226

227-
class ContinueRequestHandler : public LegacyRequestHandler {
227+
class ContinueRequestHandler
228+
: public RequestHandler<protocol::ContinueArguments,
229+
llvm::Expected<protocol::ContinueResponseBody>> {
228230
public:
229-
using LegacyRequestHandler::LegacyRequestHandler;
231+
using RequestHandler::RequestHandler;
230232
static llvm::StringLiteral GetCommand() { return "continue"; }
231-
void operator()(const llvm::json::Object &request) const override;
233+
llvm::Expected<protocol::ContinueResponseBody>
234+
Run(const protocol::ContinueArguments &args) const override;
232235
};
233236

234237
class ConfigurationDoneRequestHandler : public LegacyRequestHandler {

lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ bool fromJSON(const json::Value &Params, LaunchRequestArguments &LRA,
261261
parseEnv(Params, LRA.env, P) && parseTimeout(Params, LRA.timeout, P);
262262
}
263263

264+
bool fromJSON(const llvm::json::Value &Params, ContinueArguments &CA,
265+
llvm::json::Path P) {
266+
json::ObjectMapper O(Params, P);
267+
return O && O.map("threadId", CA.threadId) &&
268+
O.mapOptional("singleThread", CA.singleThread);
269+
}
270+
271+
llvm::json::Value toJSON(const ContinueResponseBody &CRB) {
272+
json::Object Body{{"allThreadsContinued", CRB.allThreadsContinued}};
273+
return std::move(Body);
274+
}
275+
264276
bool fromJSON(const llvm::json::Value &Params, SetVariableArguments &SVA,
265277
llvm::json::Path P) {
266278
json::ObjectMapper O(Params, P);

lldb/tools/lldb-dap/Protocol/ProtocolRequests.h

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,28 @@ bool fromJSON(const llvm::json::Value &, LaunchRequestArguments &,
294294
/// field is required.
295295
using LaunchResponseBody = VoidResponse;
296296

297+
/// Arguments for `continue` request.
298+
struct ContinueArguments {
299+
/// Specifies the active thread. If the debug adapter supports single thread
300+
/// execution (see `supportsSingleThreadExecutionRequests`) and the argument
301+
/// `singleThread` is true, only the thread with this ID is resumed.
302+
lldb::tid_t threadId = LLDB_INVALID_THREAD_ID;
303+
304+
/// If this flag is true, execution is resumed only for the thread with given
305+
/// `threadId`.
306+
bool singleThread = false;
307+
};
308+
bool fromJSON(const llvm::json::Value &, ContinueArguments &, llvm::json::Path);
309+
310+
/// Response to `continue` request.
311+
struct ContinueResponseBody {
312+
// If omitted or set to `true`, this response signals to the client that all
313+
// threads have been resumed. The value `false` indicates that not all threads
314+
// were resumed.
315+
bool allThreadsContinued = true;
316+
};
317+
llvm::json::Value toJSON(const ContinueResponseBody &);
318+
297319
/// Arguments for `setVariable` request.
298320
struct SetVariableArguments {
299321
/// The reference of the variable container. The `variablesReference` must
@@ -390,7 +412,7 @@ llvm::json::Value toJSON(const SourceResponseBody &);
390412
struct NextArguments {
391413
/// Specifies the thread for which to resume execution for one step (of the
392414
/// given granularity).
393-
uint64_t threadId = LLDB_INVALID_THREAD_ID;
415+
lldb::tid_t threadId = LLDB_INVALID_THREAD_ID;
394416

395417
/// If this flag is true, all other suspended threads are not resumed.
396418
bool singleThread = false;
@@ -409,7 +431,7 @@ using NextResponse = VoidResponse;
409431
struct StepInArguments {
410432
/// Specifies the thread for which to resume execution for one step-into (of
411433
/// the given granularity).
412-
uint64_t threadId = LLDB_INVALID_THREAD_ID;
434+
lldb::tid_t threadId = LLDB_INVALID_THREAD_ID;
413435

414436
/// If this flag is true, all other suspended threads are not resumed.
415437
bool singleThread = false;
@@ -431,7 +453,7 @@ using StepInResponse = VoidResponse;
431453
struct StepOutArguments {
432454
/// Specifies the thread for which to resume execution for one step-out (of
433455
/// the given granularity).
434-
uint64_t threadId = LLDB_INVALID_THREAD_ID;
456+
lldb::tid_t threadId = LLDB_INVALID_THREAD_ID;
435457

436458
/// If this flag is true, all other suspended threads are not resumed.
437459
std::optional<bool> singleThread;

0 commit comments

Comments
 (0)