Skip to content
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

[lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. #82051

Merged
merged 1 commit into from
Feb 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def verify_commands(self, flavor, output, commands):
for cmd in commands:
found = False
for line in lines:
if len(cmd) > 0 and (cmd[0] == "!" or cmd[0] == "?"):
cmd = cmd[1:]
if line.startswith(prefix) and cmd in line:
found = True
break
Expand Down
44 changes: 42 additions & 2 deletions lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test lldb-dap setBreakpoints request
"""


import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
Expand Down Expand Up @@ -398,7 +397,7 @@ def test_extra_launch_commands(self):
# Verify all "preRunCommands" were found in console output
self.verify_commands("preRunCommands", output, preRunCommands)

# Verify all "launchCommands" were founc in console output
# Verify all "launchCommands" were found in console output
# After execution, program should launch
self.verify_commands("launchCommands", output, launchCommands)
# Verify the "stopCommands" here
Expand All @@ -420,6 +419,47 @@ def test_extra_launch_commands(self):
output = self.get_console(timeout=1.0)
self.verify_commands("exitCommands", output, exitCommands)

@skipIfWindows
@skipIfRemote
def test_failing_launch_commands(self):
"""
Tests "launchCommands" failures prevents a launch.
"""
self.build_and_create_debug_adaptor()
program = self.getBuildArtifact("a.out")

# Run an invalid launch command, in this case a bad path.
launchCommands = ['!target create "/bad/path%s"' % (program)]

initCommands = ["target list", "platform list"]
preRunCommands = ["image list a.out", "image dump sections a.out"]
response = self.launch(
program,
initCommands=initCommands,
preRunCommands=preRunCommands,
launchCommands=launchCommands,
expectFailure=True,
)

self.assertFalse(response["success"])
self.assertRegex(
response["message"],
r"Failed to run launch commands\. See the Debug Console for more details",
)

# Get output from the console. This should contain both the
# "initCommands" and the "preRunCommands".
output = self.get_console()
# Verify all "initCommands" were found in console output
self.verify_commands("initCommands", output, initCommands)
# Verify all "preRunCommands" were found in console output
self.verify_commands("preRunCommands", output, preRunCommands)

# Verify all "launchCommands" were founc in console output
# The launch should fail due to the invalid command.
self.verify_commands("launchCommands", output, launchCommands)
self.assertRegex(output, r"unable to find executable for '/bad/path/")

@skipIfWindows
@skipIfNetBSD # Hangs on NetBSD as well
@skipIf(archs=["arm", "aarch64"], oslist=["linux"])
Expand Down
4 changes: 3 additions & 1 deletion lldb/tools/lldb-dap/lldb-dap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,8 +1779,10 @@ lldb::SBError LaunchProcess(const llvm::json::Object &request) {
// Set the launch info so that run commands can access the configured
// launch details.
g_dap.target.SetLaunchInfo(launch_info);
if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands))
if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) {
error.SetErrorString(llvm::toString(std::move(err)).c_str());
return error;
}
// The custom commands might have created a new target so we should use the
// selected target after these commands are run.
g_dap.target = g_dap.debugger.GetSelectedTarget();
Expand Down
Loading