aboutsummaryrefslogtreecommitdiff
path: root/lldb/tools/lldb-dap/Handler/ConfigurationDoneRequestHandler.cpp
blob: e7735a705d0aa8406bc1b5e865aaa5a1631ae00a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//===-- ConfigurationDoneRequestHandler..cpp ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DAP.h"
#include "EventHelper.h"
#include "LLDBUtils.h"
#include "Protocol/ProtocolRequests.h"
#include "ProtocolUtils.h"
#include "RequestHandler.h"
#include "lldb/API/SBDebugger.h"

using namespace llvm;
using namespace lldb_dap::protocol;

namespace lldb_dap {

/// This request indicates that the client has finished initialization of the
/// debug adapter.
///
/// So it is the last request in the sequence of configuration requests (which
/// was started by the `initialized` event).
///
/// Clients should only call this request if the corresponding capability
/// `supportsConfigurationDoneRequest` is true.
llvm::Error
ConfigurationDoneRequestHandler::Run(const ConfigurationDoneArguments &) const {
  dap.configuration_done = true;

  // Ensure any command scripts did not leave us in an unexpected state.
  lldb::SBProcess process = dap.target.GetProcess();
  if (!process.IsValid() ||
      !lldb::SBDebugger::StateIsStoppedState(process.GetState()))
    return make_error<DAPError>(
        "Expected process to be stopped.\r\n\r\nProcess is in an unexpected "
        "state and may have missed an initial configuration. Please check that "
        "any debugger command scripts are not resuming the process during the "
        "launch sequence.");

  // Waiting until 'configurationDone' to send target based capabilities in case
  // the launch or attach scripts adjust the target. The initial dummy target
  // may have different capabilities than the final target.
  SendTargetBasedCapabilities(dap);

  // Clients can request a baseline of currently existing threads after
  // we acknowledge the configurationDone request.
  // Client requests the baseline of currently existing threads after
  // a successful or attach by sending a 'threads' request
  // right after receiving the configurationDone response.
  // Obtain the list of threads before we resume the process
  dap.initial_thread_list = GetThreads(process, dap.thread_format);

  SendProcessEvent(dap, dap.is_attach ? Attach : Launch);

  if (dap.stop_at_entry)
    return SendThreadStoppedEvent(dap, /*on_entry=*/true);

  return ToError(process.Continue());
}

} // namespace lldb_dap