Skip to content

Commit 0389640

Browse files
authored
[lldb-dap] Migrate attach to typed RequestHandler. (#137911)
This updates the `attach` request to the typed `RequestHandler<protocol::AttachRequestArguments, protocol::AttachResponse>`. Added a few more overlapping configurations to `lldb_dap::protocol::Configuration` that are shared between launching and attaching. There may be some additional code we could clean-up that is no longer referenced now that this has migrated to use well defined types.
1 parent 47fb5bd commit 0389640

File tree

12 files changed

+285
-325
lines changed

12 files changed

+285
-325
lines changed

lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_by_name(self):
7878
def test_by_name_waitFor(self):
7979
"""
8080
Tests attaching to a process by process name and waiting for the
81-
next instance of a process to be launched, ingoring all current
81+
next instance of a process to be launched, ignoring all current
8282
ones.
8383
"""
8484
program = self.build_and_create_debug_adapter_for_attach()
@@ -101,7 +101,7 @@ def test_commands(self):
101101
that can be passed during attach.
102102
103103
"initCommands" are a list of LLDB commands that get executed
104-
before the targt is created.
104+
before the target is created.
105105
"preRunCommands" are a list of LLDB commands that get executed
106106
after the target has been created and before the launch.
107107
"stopCommands" are a list of LLDB commands that get executed each
@@ -179,6 +179,24 @@ def test_commands(self):
179179
self.verify_commands("exitCommands", output, exitCommands)
180180
self.verify_commands("terminateCommands", output, terminateCommands)
181181

182+
def test_attach_command_process_failures(self):
183+
"""
184+
Tests that a 'attachCommands' is expected to leave the debugger's
185+
selected target with a valid process.
186+
"""
187+
program = self.build_and_create_debug_adapter_for_attach()
188+
attachCommands = ['script print("oops, forgot to attach to a process...")']
189+
resp = self.attach(
190+
program=program,
191+
attachCommands=attachCommands,
192+
expectFailure=True,
193+
)
194+
self.assertFalse(resp["success"])
195+
self.assertIn(
196+
"attachCommands failed to attach to a process",
197+
resp["body"]["error"]["format"],
198+
)
199+
182200
@skipIfNetBSD # Hangs on NetBSD as well
183201
@skipIf(
184202
archs=["arm", "aarch64"]

lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_failing_launch_commands_and_run_in_terminal(self):
5656
self.assertFalse(response["success"])
5757
self.assertTrue(self.get_dict_value(response, ["body", "error", "showUser"]))
5858
self.assertEqual(
59-
"launchCommands and runInTerminal are mutually exclusive",
59+
"'launchCommands' and 'runInTerminal' are mutually exclusive",
6060
self.get_dict_value(response, ["body", "error", "format"]),
6161
)
6262

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,10 @@ lldb::SBTarget DAP::CreateTarget(lldb::SBError &error) {
676676
// omitted at all), so it is good to leave the user an opportunity to specify
677677
// those. Any of those three can be left empty.
678678
auto target = this->debugger.CreateTarget(
679-
configuration.program.value_or("").data(),
680-
configuration.targetTriple.value_or("").data(),
681-
configuration.platformName.value_or("").data(),
682-
true, // Add dependent modules.
679+
/*filename=*/configuration.program.data(),
680+
/*target_triple=*/configuration.targetTriple.data(),
681+
/*platform_name=*/configuration.platformName.data(),
682+
/*add_dependent_modules=*/true, // Add dependent modules.
683683
error);
684684

685685
return target;
@@ -1203,7 +1203,7 @@ bool SendEventRequestHandler::DoExecute(lldb::SBDebugger debugger,
12031203
}
12041204

12051205
void DAP::ConfigureSourceMaps() {
1206-
if (configuration.sourceMap.empty() && !configuration.sourcePath)
1206+
if (configuration.sourceMap.empty() && configuration.sourcePath.empty())
12071207
return;
12081208

12091209
std::string sourceMapCommand;
@@ -1214,8 +1214,8 @@ void DAP::ConfigureSourceMaps() {
12141214
for (const auto &kv : configuration.sourceMap) {
12151215
strm << "\"" << kv.first << "\" \"" << kv.second << "\" ";
12161216
}
1217-
} else if (configuration.sourcePath) {
1218-
strm << "\".\" \"" << *configuration.sourcePath << "\"";
1217+
} else if (!configuration.sourcePath.empty()) {
1218+
strm << "\".\" \"" << configuration.sourcePath << "\"";
12191219
}
12201220

12211221
RunLLDBCommands("Setting source map:", {sourceMapCommand});
@@ -1224,6 +1224,7 @@ void DAP::ConfigureSourceMaps() {
12241224
void DAP::SetConfiguration(const protocol::Configuration &config,
12251225
bool is_attach) {
12261226
configuration = config;
1227+
stop_at_entry = config.stopOnEntry;
12271228
this->is_attach = is_attach;
12281229

12291230
if (configuration.customFrameFormat)
@@ -1243,8 +1244,6 @@ void DAP::SetConfigurationDone() {
12431244
}
12441245

12451246
void DAP::SetFrameFormat(llvm::StringRef format) {
1246-
if (format.empty())
1247-
return;
12481247
lldb::SBError error;
12491248
frame_format = lldb::SBFormat(format.str().c_str(), error);
12501249
if (error.Fail()) {
@@ -1257,8 +1256,6 @@ void DAP::SetFrameFormat(llvm::StringRef format) {
12571256
}
12581257

12591258
void DAP::SetThreadFormat(llvm::StringRef format) {
1260-
if (format.empty())
1261-
return;
12621259
lldb::SBError error;
12631260
thread_format = lldb::SBFormat(format.str().c_str(), error);
12641261
if (error.Fail()) {

0 commit comments

Comments
 (0)