blob: 553cbeaf849e2185e3c50edf3eb630a0c757cc99 (
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
66
67
68
69
70
71
72
73
74
|
//===-- LaunchRequestHandler.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 "JSONUtils.h"
#include "LLDBUtils.h"
#include "Protocol/ProtocolRequests.h"
#include "RequestHandler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
using namespace llvm;
using namespace lldb_dap::protocol;
namespace lldb_dap {
/// Launch request; value of command field is 'launch'.
Error LaunchRequestHandler::Run(const LaunchRequestArguments &arguments) const {
// Validate that we have a well formed launch request.
if (!arguments.launchCommands.empty() &&
arguments.console != protocol::eConsoleInternal)
return make_error<DAPError>(
"'launchCommands' and non-internal 'console' are mutually exclusive");
dap.SetConfiguration(arguments.configuration, /*is_attach=*/false);
dap.last_launch_request = arguments;
PrintWelcomeMessage();
// This is a hack for loading DWARF in .o files on Mac where the .o files
// in the debug map of the main executable have relative paths which
// require the lldb-dap binary to have its working directory set to that
// relative root for the .o files in order to be able to load debug info.
if (!dap.configuration.debuggerRoot.empty())
sys::fs::set_current_path(dap.configuration.debuggerRoot);
// Run any initialize LLDB commands the user specified in the launch.json.
// This is run before target is created, so commands can't do anything with
// the targets - preRunCommands are run with the target.
if (Error err = dap.RunInitCommands())
return err;
dap.ConfigureSourceMaps();
lldb::SBError error;
lldb::SBTarget target = dap.CreateTarget(error);
if (error.Fail())
return ToError(error);
dap.SetTarget(target);
// Run any pre run LLDB commands the user specified in the launch.json
if (Error err = dap.RunPreRunCommands())
return err;
if (Error err = LaunchProcess(arguments))
return err;
dap.RunPostRunCommands();
return Error::success();
}
void LaunchRequestHandler::PostRun() const {
dap.SendJSON(CreateEventObject("initialized"));
}
} // namespace lldb_dap
|