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

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