Skip to content

[lldb-dap] Migrate attach to typed RequestHandler. #137911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_by_name(self):
def test_by_name_waitFor(self):
"""
Tests attaching to a process by process name and waiting for the
next instance of a process to be launched, ingoring all current
next instance of a process to be launched, ignoring all current
ones.
"""
program = self.build_and_create_debug_adapter_for_attach()
Expand All @@ -101,7 +101,7 @@ def test_commands(self):
that can be passed during attach.

"initCommands" are a list of LLDB commands that get executed
before the targt is created.
before the target is created.
"preRunCommands" are a list of LLDB commands that get executed
after the target has been created and before the launch.
"stopCommands" are a list of LLDB commands that get executed each
Expand Down Expand Up @@ -179,6 +179,24 @@ def test_commands(self):
self.verify_commands("exitCommands", output, exitCommands)
self.verify_commands("terminateCommands", output, terminateCommands)

def test_attach_command_process_failures(self):
"""
Tests that a 'attachCommands' is expected to leave the debugger's
selected target with a valid process.
"""
program = self.build_and_create_debug_adapter_for_attach()
attachCommands = ['script print("oops, forgot to attach to a process...")']
resp = self.attach(
program=program,
attachCommands=attachCommands,
expectFailure=True,
)
self.assertFalse(resp["success"])
self.assertIn(
"attachCommands failed to attach to a process",
resp["body"]["error"]["format"],
)

@skipIfNetBSD # Hangs on NetBSD as well
@skipIf(
archs=["arm", "aarch64"]
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_failing_launch_commands_and_run_in_terminal(self):
self.assertFalse(response["success"])
self.assertTrue(self.get_dict_value(response, ["body", "error", "showUser"]))
self.assertEqual(
"launchCommands and runInTerminal are mutually exclusive",
"'launchCommands' and 'runInTerminal' are mutually exclusive",
self.get_dict_value(response, ["body", "error", "format"]),
)

Expand Down
19 changes: 8 additions & 11 deletions lldb/tools/lldb-dap/DAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,10 @@ lldb::SBTarget DAP::CreateTarget(lldb::SBError &error) {
// omitted at all), so it is good to leave the user an opportunity to specify
// those. Any of those three can be left empty.
auto target = this->debugger.CreateTarget(
configuration.program.value_or("").data(),
configuration.targetTriple.value_or("").data(),
configuration.platformName.value_or("").data(),
true, // Add dependent modules.
/*filename=*/configuration.program.data(),
/*target_triple=*/configuration.targetTriple.data(),
/*platform_name=*/configuration.platformName.data(),
/*add_dependent_modules=*/true, // Add dependent modules.
error);

return target;
Expand Down Expand Up @@ -1203,7 +1203,7 @@ bool SendEventRequestHandler::DoExecute(lldb::SBDebugger debugger,
}

void DAP::ConfigureSourceMaps() {
if (configuration.sourceMap.empty() && !configuration.sourcePath)
if (configuration.sourceMap.empty() && configuration.sourcePath.empty())
return;

std::string sourceMapCommand;
Expand All @@ -1214,8 +1214,8 @@ void DAP::ConfigureSourceMaps() {
for (const auto &kv : configuration.sourceMap) {
strm << "\"" << kv.first << "\" \"" << kv.second << "\" ";
}
} else if (configuration.sourcePath) {
strm << "\".\" \"" << *configuration.sourcePath << "\"";
} else if (!configuration.sourcePath.empty()) {
strm << "\".\" \"" << configuration.sourcePath << "\"";
}

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

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

void DAP::SetFrameFormat(llvm::StringRef format) {
if (format.empty())
return;
lldb::SBError error;
frame_format = lldb::SBFormat(format.str().c_str(), error);
if (error.Fail()) {
Expand All @@ -1257,8 +1256,6 @@ void DAP::SetFrameFormat(llvm::StringRef format) {
}

void DAP::SetThreadFormat(llvm::StringRef format) {
if (format.empty())
return;
lldb::SBError error;
thread_format = lldb::SBFormat(format.str().c_str(), error);
if (error.Fail()) {
Expand Down
Loading
Loading