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 "LLDBUtils.h"
12#include "Protocol/ProtocolRequests.h"
13#include "Protocol/ProtocolTypes.h"
14#include "RequestHandler.h"
15
16using namespace llvm;
17using namespace lldb;
18using namespace lldb_dap::protocol;
19
20namespace lldb_dap {
21
22// The request resumes the given thread to step into a function/method and
23// allows all other threads to run freely by resuming them. If the debug adapter
24// supports single thread execution (see capability
25// `supportsSingleThreadExecutionRequests`), setting the `singleThread` argument
26// to true prevents other suspended threads from resuming. If the request cannot
27// step into a target, `stepIn` behaves like the `next` request. The debug
28// adapter first sends the response and then a `stopped` event (with reason
29// `step`) after the step has completed. If there are multiple function/method
30// calls (or other targets) on the source line, the argument `targetId` can be
31// used to control into which target the `stepIn` should occur. The list of
32// possible targets for a given source line can be retrieved via the
33// `stepInTargets` request.
34Error StepInRequestHandler::Run(const StepInArguments &args) const {
35 SBThread thread = dap.GetLLDBThread(id: args.threadId);
36 if (!thread.IsValid())
37 return make_error<DAPError>(Args: "invalid thread");
38
39 // Remember the thread ID that caused the resume so we can set the
40 // "threadCausedFocus" boolean value in the "stopped" events.
41 dap.focus_tid = thread.GetThreadID();
42
43 if (!SBDebugger::StateIsStoppedState(state: dap.target.GetProcess().GetState()))
44 return make_error<NotStoppedError>();
45
46 lldb::SBError error;
47 if (args.granularity == eSteppingGranularityInstruction) {
48 thread.StepInstruction(/*step_over=*/false, error);
49 return ToError(error);
50 }
51
52 std::string step_in_target;
53 auto it = dap.step_in_targets.find(Val: args.targetId.value_or(u: 0));
54 if (it != dap.step_in_targets.end())
55 step_in_target = it->second;
56
57 RunMode run_mode = args.singleThread ? eOnlyThisThread : eOnlyDuringStepping;
58 thread.StepInto(target_name: step_in_target.c_str(), LLDB_INVALID_LINE_NUMBER, error,
59 stop_other_threads: run_mode);
60 return ToError(error);
61}
62
63} // namespace lldb_dap
64

source code of lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp