|
| 1 | +""" |
| 2 | +Test lldb-dap recieves invalidated-events when the area such as |
| 3 | +stack, variables, threads has changes but the client does not |
| 4 | +know about it. |
| 5 | +""" |
| 6 | + |
| 7 | +import lldbdap_testcase |
| 8 | +from lldbsuite.test.lldbtest import line_number |
| 9 | +from dap_server import Event |
| 10 | + |
| 11 | + |
| 12 | +class TestDAP_invalidatedEvent(lldbdap_testcase.DAPTestCaseBase): |
| 13 | + def verify_top_frame_name(self, frame_name: str): |
| 14 | + all_frames = self.get_stackFrames() |
| 15 | + self.assertGreaterEqual(len(all_frames), 1, "Expected at least one frame.") |
| 16 | + top_frame_name = all_frames[0]["name"] |
| 17 | + self.assertRegex(top_frame_name, f"{frame_name}.*") |
| 18 | + |
| 19 | + def test_invalidated_stack_area_event(self): |
| 20 | + """ |
| 21 | + Test an invalidated event for the stack area. |
| 22 | + The event is sent when the command `thread return <expr>` is sent by the user. |
| 23 | + """ |
| 24 | + other_source = "other.h" |
| 25 | + return_bp_line = line_number(other_source, "// thread return breakpoint") |
| 26 | + |
| 27 | + program = self.getBuildArtifact("a.out") |
| 28 | + self.build_and_launch(program) |
| 29 | + self.set_source_breakpoints(other_source, [return_bp_line]) |
| 30 | + self.continue_to_next_stop() |
| 31 | + |
| 32 | + self.verify_top_frame_name("add") |
| 33 | + thread_id = self.dap_server.get_thread_id() |
| 34 | + self.assertIsNotNone(thread_id, "Exepected a thread id.") |
| 35 | + |
| 36 | + # run thread return |
| 37 | + thread_command = "thread return 20" |
| 38 | + eval_resp = self.dap_server.request_evaluate(thread_command, context="repl") |
| 39 | + self.assertTrue(eval_resp["success"], f"Failed to evaluate `{thread_command}`.") |
| 40 | + |
| 41 | + # wait for the invalidated stack event. |
| 42 | + stack_event = self.dap_server.wait_for_event(["invalidated"]) |
| 43 | + self.assertIsNotNone(stack_event, "Expected an invalidated event.") |
| 44 | + event_body: Event = stack_event["body"] |
| 45 | + self.assertIn("stacks", event_body["areas"]) |
| 46 | + self.assertIn("threadId", event_body.keys()) |
| 47 | + self.assertEqual( |
| 48 | + thread_id, |
| 49 | + event_body["threadId"], |
| 50 | + f"Expected the event from thread {thread_id}.", |
| 51 | + ) |
| 52 | + |
| 53 | + # confirm we are back at the main frame. |
| 54 | + self.verify_top_frame_name("main") |
| 55 | + self.continue_to_exit() |
0 commit comments