56 lines · python
1"""2Test lldb-dap recieves invalidated-events when the area such as3stack, variables, threads has changes but the client does not4know about it.5"""6 7import lldbdap_testcase8from lldbsuite.test.lldbtest import line_number9from dap_server import Event10 11 12class 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 return37 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()56