1 | //===-- ConfigurationDoneRequestHandler..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 "ProtocolUtils.h" |
14 | #include "RequestHandler.h" |
15 | #include "lldb/API/SBDebugger.h" |
16 | |
17 | using namespace llvm; |
18 | using namespace lldb_dap::protocol; |
19 | |
20 | namespace lldb_dap { |
21 | |
22 | /// This request indicates that the client has finished initialization of the |
23 | /// debug adapter. |
24 | /// |
25 | /// So it is the last request in the sequence of configuration requests (which |
26 | /// was started by the `initialized` event). |
27 | /// |
28 | /// Clients should only call this request if the corresponding capability |
29 | /// `supportsConfigurationDoneRequest` is true. |
30 | llvm::Error |
31 | ConfigurationDoneRequestHandler::Run(const ConfigurationDoneArguments &) const { |
32 | dap.configuration_done = true; |
33 | |
34 | // Ensure any command scripts did not leave us in an unexpected state. |
35 | lldb::SBProcess process = dap.target.GetProcess(); |
36 | if (!process.IsValid() || |
37 | !lldb::SBDebugger::StateIsStoppedState(state: process.GetState())) |
38 | return make_error<DAPError>( |
39 | Args: "Expected process to be stopped.\r\n\r\nProcess is in an unexpected " |
40 | "state and may have missed an initial configuration. Please check that " |
41 | "any debugger command scripts are not resuming the process during the " |
42 | "launch sequence." ); |
43 | |
44 | // Waiting until 'configurationDone' to send target based capabilities in case |
45 | // the launch or attach scripts adjust the target. The initial dummy target |
46 | // may have different capabilities than the final target. |
47 | SendTargetBasedCapabilities(dap); |
48 | |
49 | // Clients can request a baseline of currently existing threads after |
50 | // we acknowledge the configurationDone request. |
51 | // Client requests the baseline of currently existing threads after |
52 | // a successful or attach by sending a 'threads' request |
53 | // right after receiving the configurationDone response. |
54 | // Obtain the list of threads before we resume the process |
55 | dap.initial_thread_list = GetThreads(process, format&: dap.thread_format); |
56 | |
57 | SendProcessEvent(dap, launch_method: dap.is_attach ? Attach : Launch); |
58 | |
59 | if (dap.stop_at_entry) |
60 | return SendThreadStoppedEvent(dap, /*on_entry=*/true); |
61 | |
62 | return ToError(error: process.Continue()); |
63 | } |
64 | |
65 | } // namespace lldb_dap |
66 | |