Skip to content

Commit 6957699

Browse files
authored
[lldb-dap] Migrating the 'stepOut' request to use typed RequestHandler. (#137362)
This moves the 'stepOut' request to the typed RequestHandler.
1 parent 9f7a587 commit 6957699

File tree

4 files changed

+57
-55
lines changed

4 files changed

+57
-55
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,12 @@ class StepInTargetsRequestHandler : public LegacyRequestHandler {
331331
void operator()(const llvm::json::Object &request) const override;
332332
};
333333

334-
class StepOutRequestHandler : public LegacyRequestHandler {
334+
class StepOutRequestHandler : public RequestHandler<protocol::StepOutArguments,
335+
protocol::StepOutResponse> {
335336
public:
336-
using LegacyRequestHandler::LegacyRequestHandler;
337+
using RequestHandler::RequestHandler;
337338
static llvm::StringLiteral GetCommand() { return "stepOut"; }
338-
void operator()(const llvm::json::Object &request) const override;
339+
llvm::Error Run(const protocol::StepOutArguments &args) const override;
339340
};
340341

341342
class SetBreakpointsRequestHandler : public LegacyRequestHandler {

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

+26-52
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,36 @@
88

99
#include "DAP.h"
1010
#include "EventHelper.h"
11-
#include "JSONUtils.h"
11+
#include "Protocol/ProtocolRequests.h"
1212
#include "RequestHandler.h"
13+
#include "llvm/Support/Error.h"
14+
15+
using namespace llvm;
16+
using namespace lldb_dap::protocol;
1317

1418
namespace lldb_dap {
1519

16-
// "StepOutRequest": {
17-
// "allOf": [ { "$ref": "#/definitions/Request" }, {
18-
// "type": "object",
19-
// "description": "StepOut request; value of command field is 'stepOut'. The
20-
// request starts the debuggee to run again for one step. The debug adapter
21-
// first sends the StepOutResponse and then a StoppedEvent (event type
22-
// 'step') after the step has completed.", "properties": {
23-
// "command": {
24-
// "type": "string",
25-
// "enum": [ "stepOut" ]
26-
// },
27-
// "arguments": {
28-
// "$ref": "#/definitions/StepOutArguments"
29-
// }
30-
// },
31-
// "required": [ "command", "arguments" ]
32-
// }]
33-
// },
34-
// "StepOutArguments": {
35-
// "type": "object",
36-
// "description": "Arguments for 'stepOut' request.",
37-
// "properties": {
38-
// "threadId": {
39-
// "type": "integer",
40-
// "description": "Execute 'stepOut' for this thread."
41-
// }
42-
// },
43-
// "required": [ "threadId" ]
44-
// },
45-
// "StepOutResponse": {
46-
// "allOf": [ { "$ref": "#/definitions/Response" }, {
47-
// "type": "object",
48-
// "description": "Response to 'stepOut' request. This is just an
49-
// acknowledgement, so no body field is required."
50-
// }]
51-
// }
52-
void StepOutRequestHandler::operator()(
53-
const llvm::json::Object &request) const {
54-
llvm::json::Object response;
55-
FillResponse(request, response);
56-
const auto *arguments = request.getObject("arguments");
57-
lldb::SBThread thread = dap.GetLLDBThread(*arguments);
58-
if (thread.IsValid()) {
59-
// Remember the thread ID that caused the resume so we can set the
60-
// "threadCausedFocus" boolean value in the "stopped" events.
61-
dap.focus_tid = thread.GetThreadID();
62-
thread.StepOut();
63-
} else {
64-
response["success"] = llvm::json::Value(false);
65-
}
66-
dap.SendJSON(llvm::json::Value(std::move(response)));
20+
/// The request resumes the given thread to step out (return) from a
21+
/// function/method and allows all other threads to run freely by resuming
22+
/// them.
23+
///
24+
/// If the debug adapter supports single thread execution (see capability
25+
/// `supportsSingleThreadExecutionRequests`), setting the `singleThread`
26+
/// argument to true prevents other suspended threads from resuming.
27+
///
28+
/// The debug adapter first sends the response and then a `stopped` event (with
29+
/// reason `step`) after the step has completed."
30+
Error StepOutRequestHandler::Run(const StepOutArguments &arguments) const {
31+
lldb::SBThread thread = dap.GetLLDBThread(arguments.threadId);
32+
if (!thread.IsValid())
33+
return make_error<DAPError>("invalid thread");
34+
35+
// Remember the thread ID that caused the resume so we can set the
36+
// "threadCausedFocus" boolean value in the "stopped" events.
37+
dap.focus_tid = thread.GetThreadID();
38+
thread.StepOut();
39+
40+
return Error::success();
6741
}
6842

6943
} // namespace lldb_dap

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

+8
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,12 @@ bool fromJSON(const llvm::json::Value &Params, StepInArguments &SIA,
293293
OM.mapOptional("granularity", SIA.granularity);
294294
}
295295

296+
bool fromJSON(const llvm::json::Value &Params, StepOutArguments &SOA,
297+
llvm::json::Path P) {
298+
json::ObjectMapper OM(Params, P);
299+
return OM && OM.map("threadId", SOA.threadId) &&
300+
OM.mapOptional("singleThread", SOA.singleThread) &&
301+
OM.mapOptional("granularity", SOA.granularity);
302+
}
303+
296304
} // namespace lldb_dap::protocol

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

+19
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,25 @@ bool fromJSON(const llvm::json::Value &, StepInArguments &, llvm::json::Path);
358358
/// body field is required.
359359
using StepInResponse = VoidResponse;
360360

361+
/// Arguments for `stepOut` request.
362+
struct StepOutArguments {
363+
/// Specifies the thread for which to resume execution for one step-out (of
364+
/// the given granularity).
365+
uint64_t threadId = LLDB_INVALID_THREAD_ID;
366+
367+
/// If this flag is true, all other suspended threads are not resumed.
368+
std::optional<bool> singleThread;
369+
370+
/// Stepping granularity. If no granularity is specified, a granularity of
371+
/// `statement` is assumed.
372+
SteppingGranularity granularity = eSteppingGranularityStatement;
373+
};
374+
bool fromJSON(const llvm::json::Value &, StepOutArguments &, llvm::json::Path);
375+
376+
/// Response to `stepOut` request. This is just an acknowledgement, so no
377+
/// body field is required.
378+
using StepOutResponse = VoidResponse;
379+
361380
} // namespace lldb_dap::protocol
362381

363382
#endif

0 commit comments

Comments
 (0)