| 1 | //===-- NextRequestHandler.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/ProtocolTypes.h" |
| 13 | #include "RequestHandler.h" |
| 14 | #include "llvm/Support/Error.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | using namespace lldb; |
| 18 | using namespace lldb_dap::protocol; |
| 19 | |
| 20 | namespace lldb_dap { |
| 21 | |
| 22 | /// The request executes one step (in the given granularity) for the specified |
| 23 | /// thread and allows all other threads to run freely by resuming them. If the |
| 24 | /// debug adapter supports single thread execution (see capability |
| 25 | /// `supportsSingleThreadExecutionRequests`), setting the `singleThread` |
| 26 | /// argument to true prevents other suspended threads from resuming. The debug |
| 27 | /// adapter first sends the response and then a `stopped` event (with reason |
| 28 | /// `step`) after the step has completed. |
| 29 | Error NextRequestHandler::Run(const NextArguments &args) const { |
| 30 | lldb::SBThread thread = dap.GetLLDBThread(id: args.threadId); |
| 31 | if (!thread.IsValid()) |
| 32 | return make_error<DAPError>(Args: "invalid thread"); |
| 33 | |
| 34 | if (!SBDebugger::StateIsStoppedState(state: dap.target.GetProcess().GetState())) |
| 35 | return make_error<NotStoppedError>(); |
| 36 | |
| 37 | // Remember the thread ID that caused the resume so we can set the |
| 38 | // "threadCausedFocus" boolean value in the "stopped" events. |
| 39 | dap.focus_tid = thread.GetThreadID(); |
| 40 | lldb::SBError error; |
| 41 | if (args.granularity == eSteppingGranularityInstruction) { |
| 42 | thread.StepInstruction(/*step_over=*/true, error); |
| 43 | } else { |
| 44 | thread.StepOver(stop_other_threads: args.singleThread ? eOnlyThisThread : eOnlyDuringStepping, |
| 45 | error); |
| 46 | } |
| 47 | |
| 48 | return ToError(error); |
| 49 | } |
| 50 | |
| 51 | } // namespace lldb_dap |
| 52 |
