|
| 1 | +//===-- StepInRequestHandler.cpp ------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "DAP.h" |
| 10 | +#include "EventHelper.h" |
| 11 | +#include "JSONUtils.h" |
| 12 | +#include "RequestHandler.h" |
| 13 | + |
| 14 | +namespace lldb_dap { |
| 15 | + |
| 16 | +// "StepInRequest": { |
| 17 | +// "allOf": [ { "$ref": "#/definitions/Request" }, { |
| 18 | +// "type": "object", |
| 19 | +// "description": "StepIn request; value of command field is 'stepIn'. The |
| 20 | +// request starts the debuggee to step into a function/method if possible. |
| 21 | +// If it cannot step into a target, 'stepIn' behaves like 'next'. The debug |
| 22 | +// adapter first sends the StepInResponse and then a StoppedEvent (event |
| 23 | +// type 'step') after the step has completed. If there are multiple |
| 24 | +// function/method calls (or other targets) on the source line, the optional |
| 25 | +// argument 'targetId' can be used to control into which target the 'stepIn' |
| 26 | +// should occur. The list of possible targets for a given source line can be |
| 27 | +// retrieved via the 'stepInTargets' request.", "properties": { |
| 28 | +// "command": { |
| 29 | +// "type": "string", |
| 30 | +// "enum": [ "stepIn" ] |
| 31 | +// }, |
| 32 | +// "arguments": { |
| 33 | +// "$ref": "#/definitions/StepInArguments" |
| 34 | +// } |
| 35 | +// }, |
| 36 | +// "required": [ "command", "arguments" ] |
| 37 | +// }] |
| 38 | +// }, |
| 39 | +// "StepInArguments": { |
| 40 | +// "type": "object", |
| 41 | +// "description": "Arguments for 'stepIn' request.", |
| 42 | +// "properties": { |
| 43 | +// "threadId": { |
| 44 | +// "type": "integer", |
| 45 | +// "description": "Execute 'stepIn' for this thread." |
| 46 | +// }, |
| 47 | +// "targetId": { |
| 48 | +// "type": "integer", |
| 49 | +// "description": "Optional id of the target to step into." |
| 50 | +// }, |
| 51 | +// "granularity": { |
| 52 | +// "$ref": "#/definitions/SteppingGranularity", |
| 53 | +// "description": "Stepping granularity. If no granularity is specified, a |
| 54 | +// granularity of `statement` is assumed." |
| 55 | +// } |
| 56 | +// }, |
| 57 | +// "required": [ "threadId" ] |
| 58 | +// }, |
| 59 | +// "StepInResponse": { |
| 60 | +// "allOf": [ { "$ref": "#/definitions/Response" }, { |
| 61 | +// "type": "object", |
| 62 | +// "description": "Response to 'stepIn' request. This is just an |
| 63 | +// acknowledgement, so no body field is required." |
| 64 | +// }] |
| 65 | +// } |
| 66 | +void StepInRequestHandler::operator()(const llvm::json::Object &request) { |
| 67 | + llvm::json::Object response; |
| 68 | + FillResponse(request, response); |
| 69 | + const auto *arguments = request.getObject("arguments"); |
| 70 | + |
| 71 | + std::string step_in_target; |
| 72 | + uint64_t target_id = GetUnsigned(arguments, "targetId", 0); |
| 73 | + auto it = dap.step_in_targets.find(target_id); |
| 74 | + if (it != dap.step_in_targets.end()) |
| 75 | + step_in_target = it->second; |
| 76 | + |
| 77 | + const bool single_thread = GetBoolean(arguments, "singleThread", false); |
| 78 | + lldb::RunMode run_mode = |
| 79 | + single_thread ? lldb::eOnlyThisThread : lldb::eOnlyDuringStepping; |
| 80 | + lldb::SBThread thread = dap.GetLLDBThread(*arguments); |
| 81 | + if (thread.IsValid()) { |
| 82 | + // Remember the thread ID that caused the resume so we can set the |
| 83 | + // "threadCausedFocus" boolean value in the "stopped" events. |
| 84 | + dap.focus_tid = thread.GetThreadID(); |
| 85 | + if (HasInstructionGranularity(*arguments)) { |
| 86 | + thread.StepInstruction(/*step_over=*/false); |
| 87 | + } else { |
| 88 | + thread.StepInto(step_in_target.c_str(), run_mode); |
| 89 | + } |
| 90 | + } else { |
| 91 | + response["success"] = llvm::json::Value(false); |
| 92 | + } |
| 93 | + dap.SendJSON(llvm::json::Value(std::move(response))); |
| 94 | +} |
| 95 | + |
| 96 | +} // namespace lldb_dap |
0 commit comments