Skip to content

Commit b17f1fd

Browse files
authored
[lldb-dap] Report any errors during attach request (llvm#165270)
Attaching using `core`, `gdbremote` or `attachInfo` may have an error. fail early if it does.
1 parent db6ba82 commit b17f1fd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ def test_core_file(self):
6161
self.dap_server.request_next(threadId=32259)
6262
self.assertEqual(self.get_stackFrames(), expected_frames)
6363

64+
def test_wrong_core_file(self):
65+
exe_file = self.getSourcePath("linux-x86_64.out")
66+
wrong_core_file = self.getSourcePath("main.c")
67+
68+
self.create_debug_adapter()
69+
resp = self.attach(
70+
program=exe_file, coreFile=wrong_core_file, expectFailure=True
71+
)
72+
self.assertIsNotNone(resp)
73+
self.assertFalse(resp["success"], "Expected failure in response {resp!r}")
74+
error_msg = resp["body"]["error"]["format"]
75+
76+
# attach may fail for mutilple reasons.
77+
self.assertEqual(error_msg, "Failed to create the process")
78+
6479
@skipIfLLVMTargetMissing("X86")
6580
def test_core_file_source_mapping_array(self):
6681
"""Test that sourceMap property is correctly applied when loading a core"""

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Error AttachRequestHandler::Run(const AttachRequestArguments &args) const {
124124
attach_info.SetWaitForLaunch(args.waitFor, /*async=*/false);
125125
dap.target.Attach(attach_info, error);
126126
}
127+
if (error.Fail())
128+
return ToError(error);
127129
}
128130

129131
// Make sure the process is attached and stopped.

0 commit comments

Comments
 (0)