Skip to content

Commit 1c0187c

Browse files
ashgtiDebadri Basak
authored andcommitted
[lldb-dap] Correctly trigger 'entry' stop reasons. (llvm#165901)
Noticed this while looking into test stability that the 'entry' stop reason is not triggering correctly. This should ensure we correctly trigger the 'entry' stop reason when launching a process with `"stopOnEntry": true`. I've also updated the tests to ensure we receive the 'entry' stop reason to catch this regression.
1 parent 33892e5 commit 1c0187c

File tree

5 files changed

+18
-55
lines changed

5 files changed

+18
-55
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ def verify_stop_exception_info(self, expected_description):
223223
return True
224224
return False
225225

226+
def verify_stop_on_entry(self) -> None:
227+
"""Waits for the process to be stopped and then verifies at least one
228+
thread has the stop reason 'entry'."""
229+
self.dap_server.wait_for_stopped()
230+
self.assertIn(
231+
"entry",
232+
(t["reason"] for t in self.dap_server.thread_stop_reasons.values()),
233+
"Expected at least one thread to report stop reason 'entry' in {self.dap_server.thread_stop_reasons}",
234+
)
235+
226236
def verify_commands(self, flavor: str, output: str, commands: list[str]):
227237
self.assertTrue(output and len(output) > 0, "expect console output")
228238
lines = output.splitlines()

lldb/test/API/tools/lldb-dap/restart/TestDAP_restart.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,8 @@ def test_stopOnEntry(self):
5151
self.build_and_launch(program, stopOnEntry=True)
5252
[bp_main] = self.set_function_breakpoints(["main"])
5353

54-
self.dap_server.request_configurationDone()
55-
self.dap_server.wait_for_stopped()
56-
# Once the "configuration done" event is sent, we should get a stopped
57-
# event immediately because of stopOnEntry.
58-
self.assertTrue(
59-
len(self.dap_server.thread_stop_reasons) > 0,
60-
"expected stopped event during launch",
61-
)
62-
for _, body in self.dap_server.thread_stop_reasons.items():
63-
if "reason" in body:
64-
reason = body["reason"]
65-
self.assertNotEqual(
66-
reason, "breakpoint", 'verify stop isn\'t "main" breakpoint'
67-
)
54+
self.continue_to_next_stop()
55+
self.verify_stop_on_entry()
6856

6957
# Then, if we continue, we should hit the breakpoint at main.
7058
self.continue_to_breakpoints([bp_main])
@@ -73,17 +61,7 @@ def test_stopOnEntry(self):
7361
# main.
7462
resp = self.dap_server.request_restart()
7563
self.assertTrue(resp["success"])
76-
stopped_events = self.dap_server.wait_for_stopped()
77-
for stopped_event in stopped_events:
78-
if "body" in stopped_event:
79-
body = stopped_event["body"]
80-
if "reason" in body:
81-
reason = body["reason"]
82-
self.assertNotEqual(
83-
reason,
84-
"breakpoint",
85-
'verify stop after restart isn\'t "main" breakpoint',
86-
)
64+
self.verify_stop_on_entry()
8765

8866
@skipIfWindows
8967
def test_arguments(self):

lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_console.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,6 @@
1111

1212
@skipIfBuildType(["debug"])
1313
class TestDAP_restart_console(lldbdap_testcase.DAPTestCaseBase):
14-
def verify_stopped_on_entry(self, stopped_events: List[Dict[str, Any]]):
15-
seen_stopped_event = 0
16-
for stopped_event in stopped_events:
17-
body = stopped_event.get("body")
18-
if body is None:
19-
continue
20-
21-
reason = body.get("reason")
22-
if reason is None:
23-
continue
24-
25-
self.assertNotEqual(
26-
reason,
27-
"breakpoint",
28-
'verify stop after restart isn\'t "main" breakpoint',
29-
)
30-
if reason == "entry":
31-
seen_stopped_event += 1
32-
33-
self.assertEqual(seen_stopped_event, 1, "expect only one stopped entry event.")
34-
3514
@skipIfAsan
3615
@skipIfWindows
3716
@skipIf(oslist=["linux"], archs=["arm$"]) # Always times out on buildbot
@@ -92,11 +71,8 @@ def test_stopOnEntry(self):
9271
self.build_and_launch(program, console="integratedTerminal", stopOnEntry=True)
9372
[bp_main] = self.set_function_breakpoints(["main"])
9473

95-
self.dap_server.request_continue() # sends configuration done
96-
stopped_events = self.dap_server.wait_for_stopped()
97-
# We should be stopped at the entry point.
98-
self.assertGreaterEqual(len(stopped_events), 0, "expect stopped events")
99-
self.verify_stopped_on_entry(stopped_events)
74+
self.dap_server.request_configurationDone()
75+
self.verify_stop_on_entry()
10076

10177
# Then, if we continue, we should hit the breakpoint at main.
10278
self.dap_server.request_continue()
@@ -105,8 +81,7 @@ def test_stopOnEntry(self):
10581
# Restart and check that we still get a stopped event before reaching
10682
# main.
10783
self.dap_server.request_restart()
108-
stopped_events = self.dap_server.wait_for_stopped()
109-
self.verify_stopped_on_entry(stopped_events)
84+
self.verify_stop_on_entry()
11085

11186
# continue to main
11287
self.dap_server.request_continue()

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ llvm::Error SendThreadStoppedEvent(DAP &dap, bool on_entry) {
176176

177177
llvm::DenseSet<lldb::tid_t> old_thread_ids;
178178
old_thread_ids.swap(dap.thread_ids);
179-
uint32_t stop_id = process.GetStopID();
179+
uint32_t stop_id = on_entry ? 0 : process.GetStopID();
180180
const uint32_t num_threads = process.GetNumThreads();
181181

182182
// First make a pass through the threads to see if the focused thread

lldb/tools/lldb-dap/JSONUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ llvm::json::Value CreateThreadStopped(DAP &dap, lldb::SBThread &thread,
711711
break;
712712
}
713713
if (stop_id == 0)
714-
body.try_emplace("reason", "entry");
714+
body["reason"] = "entry";
715715
const lldb::tid_t tid = thread.GetThreadID();
716716
body.try_emplace("threadId", (int64_t)tid);
717717
// If no description has been set, then set it to the default thread stopped

0 commit comments

Comments
 (0)