brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 329f0a7 Raw
79 lines · cpp
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-exception6//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  // Initialize DAP debugger.26  if (Error err = dap.InitializeDebugger())27    return err;28 29  // Validate that we have a well formed launch request.30  if (!arguments.launchCommands.empty() &&31      arguments.console != protocol::eConsoleInternal)32    return make_error<DAPError>(33        "'launchCommands' and non-internal 'console' are mutually exclusive");34 35  dap.SetConfiguration(arguments.configuration, /*is_attach=*/false);36  dap.last_launch_request = arguments;37 38  PrintWelcomeMessage();39 40  // This is a hack for loading DWARF in .o files on Mac where the .o files41  // in the debug map of the main executable have relative paths which42  // require the lldb-dap binary to have its working directory set to that43  // relative root for the .o files in order to be able to load debug info.44  if (!dap.configuration.debuggerRoot.empty())45    sys::fs::set_current_path(dap.configuration.debuggerRoot);46 47  // Run any initialize LLDB commands the user specified in the launch.json.48  // This is run before target is created, so commands can't do anything with49  // the targets - preRunCommands are run with the target.50  if (Error err = dap.RunInitCommands())51    return err;52 53  dap.ConfigureSourceMaps();54 55  lldb::SBError error;56  lldb::SBTarget target = dap.CreateTarget(error);57  if (error.Fail())58    return ToError(error);59 60  dap.SetTarget(target);61 62  // Run any pre run LLDB commands the user specified in the launch.json63  if (Error err = dap.RunPreRunCommands())64    return err;65 66  if (Error err = LaunchProcess(arguments))67    return err;68 69  dap.RunPostRunCommands();70 71  return Error::success();72}73 74void LaunchRequestHandler::PostRun() const {75  dap.SendJSON(CreateEventObject("initialized"));76}77 78} // namespace lldb_dap79