1""" 2Test lldb-dap variables/stackTrace request for optimized code 3""" 4 5import dap_server 6import lldbdap_testcase 7from lldbsuite.test import lldbutil 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10 11 12class TestDAP_optimized(lldbdap_testcase.DAPTestCaseBase): 13 @skipIfWindows 14 def test_stack_frame_name(self): 15 """Test optimized frame has special name suffix.""" 16 program = self.getBuildArtifact("a.out") 17 self.build_and_launch(program) 18 source = "main.cpp" 19 breakpoint_line = line_number(source, "// breakpoint 1") 20 lines = [breakpoint_line] 21 breakpoint_ids = self.set_source_breakpoints(source, lines) 22 self.assertEqual( 23 len(breakpoint_ids), len(lines), "expect correct number of breakpoints" 24 ) 25 self.continue_to_breakpoints(breakpoint_ids) 26 leaf_frame = self.dap_server.get_stackFrame(frameIndex=0) 27 self.assertTrue(leaf_frame["name"].endswith(" [opt]")) 28 parent_frame = self.dap_server.get_stackFrame(frameIndex=1) 29 self.assertTrue(parent_frame["name"].endswith(" [opt]")) 30 31 @skipIfAsan # On ASAN builds this test intermittently fails https://github.com/llvm/llvm-project/issues/111061 32 @skipIfWindows 33 def test_optimized_variable(self): 34 """Test optimized variable value contains error.""" 35 program = self.getBuildArtifact("a.out") 36 self.build_and_launch(program) 37 source = "main.cpp" 38 breakpoint_line = line_number(source, "// breakpoint 2") 39 lines = [breakpoint_line] 40 # Set breakpoint in the thread function so we can step the threads 41 breakpoint_ids = self.set_source_breakpoints(source, lines) 42 self.assertEqual( 43 len(breakpoint_ids), len(lines), "expect correct number of breakpoints" 44 ) 45 self.continue_to_breakpoints(breakpoint_ids) 46 optimized_variable = self.dap_server.get_local_variable("argc") 47 48 self.assertTrue(optimized_variable["value"].startswith("<error:")) 49 error_msg = optimized_variable["$__lldb_extensions"]["error"] 50 self.assertTrue( 51 ("could not evaluate DW_OP_entry_value: no parent function" in error_msg) 52 or ("variable not available" in error_msg) 53 ) 54