1 | //===-- LaunchRequestHandler.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 "LLDBUtils.h" |
13 | #include "Protocol/ProtocolRequests.h" |
14 | #include "RequestHandler.h" |
15 | #include "llvm/Support/Error.h" |
16 | #include "llvm/Support/FileSystem.h" |
17 | |
18 | using namespace llvm; |
19 | using namespace lldb_dap::protocol; |
20 | |
21 | namespace lldb_dap { |
22 | |
23 | /// Launch request; value of command field is 'launch'. |
24 | Error LaunchRequestHandler::Run(const LaunchRequestArguments &arguments) const { |
25 | // Validate that we have a well formed launch request. |
26 | if (!arguments.launchCommands.empty() && arguments.runInTerminal) |
27 | return make_error<DAPError>( |
28 | Args: "'launchCommands' and 'runInTerminal' are mutually exclusive"); |
29 | |
30 | dap.SetConfiguration(confing: arguments.configuration, /*is_attach=*/false); |
31 | dap.last_launch_request = arguments; |
32 | |
33 | PrintWelcomeMessage(); |
34 | |
35 | // This is a hack for loading DWARF in .o files on Mac where the .o files |
36 | // in the debug map of the main executable have relative paths which |
37 | // require the lldb-dap binary to have its working directory set to that |
38 | // relative root for the .o files in order to be able to load debug info. |
39 | if (!dap.configuration.debuggerRoot.empty()) |
40 | sys::fs::set_current_path(dap.configuration.debuggerRoot); |
41 | |
42 | // Run any initialize LLDB commands the user specified in the launch.json. |
43 | // This is run before target is created, so commands can't do anything with |
44 | // the targets - preRunCommands are run with the target. |
45 | if (Error err = dap.RunInitCommands()) |
46 | return err; |
47 | |
48 | dap.ConfigureSourceMaps(); |
49 | |
50 | lldb::SBError error; |
51 | lldb::SBTarget target = dap.CreateTarget(error); |
52 | if (error.Fail()) |
53 | return ToError(error); |
54 | |
55 | dap.SetTarget(target); |
56 | |
57 | // Run any pre run LLDB commands the user specified in the launch.json |
58 | if (Error err = dap.RunPreRunCommands()) |
59 | return err; |
60 | |
61 | if (Error err = LaunchProcess(request: arguments)) |
62 | return err; |
63 | |
64 | dap.RunPostRunCommands(); |
65 | |
66 | return Error::success(); |
67 | } |
68 | |
69 | void LaunchRequestHandler::PostRun() const { |
70 | dap.SendJSON(json: CreateEventObject(event_name: "initialized")); |
71 | } |
72 | |
73 | } // namespace lldb_dap |
74 |