Skip to content

Commit 2b6bb92

Browse files
committed
Moving 'program', 'targetTriple' and 'platform' to the protocol::Configuration since they're shared between launch and attach.
Additionally, I tried to be more consistent with how we apply default flags state in the protocol definition.
1 parent 335468a commit 2b6bb92

File tree

8 files changed

+189
-198
lines changed

8 files changed

+189
-198
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,7 @@ void DAP::RunTerminateCommands() {
654654
configuration.terminateCommands);
655655
}
656656

657-
lldb::SBTarget DAP::CreateTargetFromArguments(llvm::StringRef program,
658-
llvm::StringRef targetTriple,
659-
llvm::StringRef platformName,
660-
lldb::SBError &error) {
657+
lldb::SBTarget DAP::CreateTarget(lldb::SBError &error) {
661658
// Grab the name of the program we need to debug and create a target using
662659
// the given program as an argument. Executable file can be a source of target
663660
// architecture and platform, if they differ from the host. Setting exe path
@@ -668,16 +665,17 @@ lldb::SBTarget DAP::CreateTargetFromArguments(llvm::StringRef program,
668665
// enough information to determine correct arch and platform (or ELF can be
669666
// omitted at all), so it is good to leave the user an apportunity to specify
670667
// those. Any of those three can be left empty.
671-
auto target = this->debugger.CreateTarget(program.data(), targetTriple.data(),
672-
platformName.data(),
673-
true, // Add dependent modules.
674-
error);
668+
auto target = this->debugger.CreateTarget(
669+
configuration.program.value_or("").data(),
670+
configuration.targetTriple.value_or("").data(),
671+
configuration.platformName.value_or("").data(),
672+
true, // Add dependent modules.
673+
error);
675674

676675
if (error.Fail()) {
677676
// Update message if there was an error.
678677
error.SetErrorStringWithFormat(
679-
"Could not create a target for a program '%s': %s.", program.data(),
680-
error.GetCString());
678+
"Could not create a target for a program: %s.", error.GetCString());
681679
}
682680

683681
return target;

lldb/tools/lldb-dap/DAP.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,14 @@ struct DAP {
316316
void RunTerminateCommands();
317317

318318
/// Create a new SBTarget object from the given request arguments.
319-
/// \param[in] arguments
320-
/// Launch configuration arguments.
321319
///
322320
/// \param[out] error
323321
/// An SBError object that will contain an error description if
324322
/// function failed to create the target.
325323
///
326324
/// \return
327325
/// An SBTarget object.
328-
lldb::SBTarget CreateTargetFromArguments(llvm::StringRef program,
329-
llvm::StringRef targetTriple,
330-
llvm::StringRef platformName,
331-
lldb::SBError &error);
326+
lldb::SBTarget CreateTarget(lldb::SBError &error);
332327

333328
/// Set given target object as a current target for lldb-dap and start
334329
/// listeing for its breakpoint events.

lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
8585
GetBoolean(arguments, "displayExtendedBacktrace").value_or(false);
8686
dap.configuration.commandEscapePrefix =
8787
GetString(arguments, "commandEscapePrefix").value_or("`");
88+
dap.configuration.program = GetString(arguments, "program");
89+
dap.configuration.targetTriple = GetString(arguments, "targetTriple");
90+
dap.configuration.platformName = GetString(arguments, "platformName");
8891
dap.SetFrameFormat(GetString(arguments, "customFrameFormat").value_or(""));
8992
dap.SetThreadFormat(GetString(arguments, "customThreadFormat").value_or(""));
9093

@@ -107,14 +110,8 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
107110

108111
SetSourceMapFromArguments(*arguments);
109112

110-
llvm::StringRef program = GetString(arguments, "program").value_or("");
111-
llvm::StringRef target_triple =
112-
GetString(arguments, "targetTriple").value_or("");
113-
llvm::StringRef platform_name =
114-
GetString(arguments, "platformName").value_or("");
115113
lldb::SBError status;
116-
dap.SetTarget(dap.CreateTargetFromArguments(program, target_triple,
117-
platform_name, status));
114+
dap.SetTarget(dap.CreateTarget(status));
118115
if (status.Fail()) {
119116
response["success"] = llvm::json::Value(false);
120117
EmplaceSafeString(response, "message", status.GetCString());

lldb/tools/lldb-dap/Handler/LaunchRequestHandler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "JSONUtils.h"
1212
#include "Protocol/ProtocolRequests.h"
1313
#include "RequestHandler.h"
14+
#include "llvm/Support/Error.h"
1415
#include "llvm/Support/FileSystem.h"
1516

1617
namespace lldb_dap {
@@ -20,7 +21,12 @@ llvm::Expected<protocol::LaunchResponseBody> LaunchRequestHandler::Run(
2021
const protocol::LaunchRequestArguments &arguments) const {
2122
dap.SetConfiguration(arguments.configuration, /*is_attach=*/false);
2223
dap.last_launch_request = arguments;
23-
dap.stop_at_entry = arguments.stopOnEntry.value_or(false);
24+
dap.stop_at_entry = arguments.stopOnEntry;
25+
26+
if (!arguments.launchCommands.empty() && arguments.runInTerminal) {
27+
return llvm::make_error<DAPError>("launchCommands and runInTerminal cannot "
28+
"both be set, use one or the other.");
29+
}
2430

2531
PrintWelcomeMessage();
2632

@@ -41,9 +47,7 @@ llvm::Expected<protocol::LaunchResponseBody> LaunchRequestHandler::Run(
4147
dap.ConfigureSourceMaps();
4248

4349
lldb::SBError status;
44-
dap.SetTarget(dap.CreateTargetFromArguments(
45-
arguments.program.value_or(""), arguments.targetTriple.value_or(""),
46-
arguments.platformName.value_or(""), status));
50+
dap.SetTarget(dap.CreateTarget(status));
4751
if (status.Fail())
4852
return llvm::make_error<DAPError>(status.GetCString());
4953

lldb/tools/lldb-dap/Handler/RequestHandler.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ MakeArgv(const llvm::ArrayRef<std::string> &strs) {
3838
return argv;
3939
}
4040

41-
static uint32_t SetLaunchFlag(uint32_t flags, std::optional<bool> flag,
41+
static uint32_t SetLaunchFlag(uint32_t flags, bool flag,
4242
lldb::LaunchFlags mask) {
43-
if (flag) {
44-
if (*flag)
45-
flags |= mask;
46-
else
47-
flags &= ~mask;
48-
}
43+
if (flag)
44+
flags |= mask;
45+
else
46+
flags &= ~mask;
4947

5048
return flags;
5149
}
@@ -107,7 +105,8 @@ RunInTerminal(DAP &dap, const protocol::LaunchRequestArguments &arguments) {
107105
return llvm::make_error<DAPError>("Cannot use runInTerminal, feature is "
108106
"not supported by the connected client");
109107

110-
if (!arguments.program || arguments.program->empty())
108+
if (!arguments.configuration.program ||
109+
arguments.configuration.program->empty())
111110
return llvm::make_error<DAPError>(
112111
"program must be set to when using runInTerminal");
113112

@@ -128,7 +127,7 @@ RunInTerminal(DAP &dap, const protocol::LaunchRequestArguments &arguments) {
128127
#endif
129128

130129
llvm::json::Object reverse_request = CreateRunInTerminalReverseRequest(
131-
*arguments.program, arguments.args, arguments.env,
130+
*arguments.configuration.program, arguments.args, arguments.env,
132131
arguments.cwd.value_or(""), comm_file.m_path, debugger_pid);
133132
dap.SendReverseRequest<LogFailureResponseHandler>("runInTerminal",
134133
std::move(reverse_request));
@@ -223,23 +222,21 @@ llvm::Error BaseRequestHandler::LaunchProcess(
223222
launch_info.SetEnvironment(env, true);
224223
}
225224

226-
auto flags = launch_info.GetLaunchFlags();
225+
launch_info.SetDetachOnError(arguments.detachOnError);
226+
launch_info.SetShellExpandArguments(arguments.shellExpandArguments);
227227

228+
auto flags = launch_info.GetLaunchFlags();
228229
flags =
229230
SetLaunchFlag(flags, arguments.disableASLR, lldb::eLaunchFlagDisableASLR);
230231
flags = SetLaunchFlag(flags, arguments.disableSTDIO,
231232
lldb::eLaunchFlagDisableSTDIO);
232-
flags = SetLaunchFlag(flags, arguments.shellExpandArguments,
233-
lldb::eLaunchFlagShellExpandArguments);
234-
if (arguments.detachOnError)
235-
launch_info.SetDetachOnError(*arguments.detachOnError);
236233
launch_info.SetLaunchFlags(flags | lldb::eLaunchFlagDebug |
237234
lldb::eLaunchFlagStopAtEntry);
238235

239236
if (arguments.runInTerminal) {
240237
if (llvm::Error err = RunInTerminal(dap, arguments))
241238
return err;
242-
} else if (!launchCommands) {
239+
} else if (launchCommands.empty()) {
243240
lldb::SBError error;
244241
// Disable async events so the launch will be successful when we return from
245242
// the launch call and the launch will happen synchronously
@@ -252,7 +249,7 @@ llvm::Error BaseRequestHandler::LaunchProcess(
252249
// Set the launch info so that run commands can access the configured
253250
// launch details.
254251
dap.target.SetLaunchInfo(launch_info);
255-
if (llvm::Error err = dap.RunLaunchCommands(*launchCommands))
252+
if (llvm::Error err = dap.RunLaunchCommands(launchCommands))
256253
return err;
257254

258255
// The custom commands might have created a new target so we should use the

lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void RestartRequestHandler::operator()(
108108
// Update DAP configuration based on the latest copy of the launch
109109
// arguments.
110110
dap.SetConfiguration(updated_arguments.configuration, false);
111-
dap.stop_at_entry = updated_arguments.stopOnEntry.value_or(false);
111+
dap.stop_at_entry = updated_arguments.stopOnEntry;
112112
dap.ConfigureSourceMaps();
113113
}
114114
}

0 commit comments

Comments
 (0)