Skip to content

Commit 18e4af1

Browse files
committed
[lldb-dap] Always stop on enrty for attaching
Recently upon debugging a program with thousands of threads, lldb-dap would hang at a `threads` request sent right after receiving the `configurationDone` response. Soon after it will end the debug session with "Process <pid> ex ited with status = -1 (0xffffffff) lost connection". This is because LLDB is still in the middle of resuming all the threads. And requesting threads will require stopp ing the process. From the gdb-remote log it ended up getting `lldb::StateType::eStateInvalid` and just exit with s tatus -1. I don't think it's reasonable to allow getting threads from a running process. The alternative will be reject the `threads` request if the process is not stopped.
1 parent 158684a commit 18e4af1

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Test lldb-dap setBreakpoints request
2+
Test lldb-dap attach request
33
"""
44

55

@@ -35,6 +35,9 @@ def set_and_hit_breakpoint(self, continueToExit=True):
3535
self.assertEqual(
3636
len(breakpoint_ids), len(lines), "expect correct number of breakpoints"
3737
)
38+
# Send a configurationDone request when process is ready to continue
39+
self.dap_server.request_configurationDone()
40+
self.assertTrue(self.verify_stop_exception_info("signal SIGSTOP"))
3841
self.continue_to_breakpoints(breakpoint_ids)
3942
if continueToExit:
4043
self.continue_to_exit()
@@ -175,6 +178,9 @@ def test_commands(self):
175178
functions = ["main"]
176179
breakpoint_ids = self.set_function_breakpoints(functions)
177180
self.assertEqual(len(breakpoint_ids), len(functions), "expect one breakpoint")
181+
# Execute the configurationDone even if this is not real attaching
182+
self.dap_server.request_configurationDone()
183+
self.assertTrue(self.verify_stop_exception_info("signal SIGSTOP"))
178184
self.continue_to_breakpoints(breakpoint_ids)
179185
output = self.collect_console(timeout_secs=10, pattern=stopCommands[-1])
180186
self.verify_commands("stopCommands", output, stopCommands)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def set_and_hit_breakpoint(self, continueToExit=True):
3232
self.assertEqual(
3333
len(breakpoint_ids), len(lines), "expect correct number of breakpoints"
3434
)
35+
# Send a configurationDone request when process is ready to continue
36+
self.dap_server.request_configurationDone()
37+
self.assertTrue(self.verify_stop_exception_info("signal SIGSTOP"))
3538
self.continue_to_breakpoints(breakpoint_ids)
3639
if continueToExit:
3740
self.continue_to_exit()

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
7373
llvm::StringRef core_file = GetString(arguments, "coreFile").value_or("");
7474
const uint64_t timeout_seconds =
7575
GetInteger<uint64_t>(arguments, "timeout").value_or(30);
76-
dap.stop_at_entry = core_file.empty()
77-
? GetBoolean(arguments, "stopOnEntry").value_or(false)
78-
: true;
76+
// Clients like VS Code sends threads request right after receiving
77+
// configurationDone reponse where the process might be resuming.
78+
// Getting threads list on a running process is not supported by LLDB.
79+
// Always stop the process after attaching.
80+
dap.stop_at_entry = true;
7981
dap.configuration.postRunCommands = GetStrings(arguments, "postRunCommands");
8082
const llvm::StringRef debuggerRoot =
8183
GetString(arguments, "debuggerRoot").value_or("");

0 commit comments

Comments
 (0)