101263c6cSJonas Devlieghere""" 201263c6cSJonas DevlieghereTest lldb-dap variables/stackTrace request for optimized code 301263c6cSJonas Devlieghere""" 401263c6cSJonas Devlieghere 501263c6cSJonas Devlieghereimport dap_server 6ffd173baSWalter Erquinigoimport lldbdap_testcase 7ffd173baSWalter Erquinigofrom lldbsuite.test import lldbutil 801263c6cSJonas Devliegherefrom lldbsuite.test.decorators import * 901263c6cSJonas Devliegherefrom lldbsuite.test.lldbtest import * 1001263c6cSJonas Devlieghere 1101263c6cSJonas Devlieghere 1201263c6cSJonas Devlieghereclass TestDAP_optimized(lldbdap_testcase.DAPTestCaseBase): 1301263c6cSJonas Devlieghere @skipIfWindows 1401263c6cSJonas Devlieghere def test_stack_frame_name(self): 1501263c6cSJonas Devlieghere """Test optimized frame has special name suffix.""" 1601263c6cSJonas Devlieghere program = self.getBuildArtifact("a.out") 1701263c6cSJonas Devlieghere self.build_and_launch(program) 1801263c6cSJonas Devlieghere source = "main.cpp" 1901263c6cSJonas Devlieghere breakpoint_line = line_number(source, "// breakpoint 1") 2001263c6cSJonas Devlieghere lines = [breakpoint_line] 2101263c6cSJonas Devlieghere breakpoint_ids = self.set_source_breakpoints(source, lines) 2201263c6cSJonas Devlieghere self.assertEqual( 2301263c6cSJonas Devlieghere len(breakpoint_ids), len(lines), "expect correct number of breakpoints" 2401263c6cSJonas Devlieghere ) 2501263c6cSJonas Devlieghere self.continue_to_breakpoints(breakpoint_ids) 2601263c6cSJonas Devlieghere leaf_frame = self.dap_server.get_stackFrame(frameIndex=0) 2701263c6cSJonas Devlieghere self.assertTrue(leaf_frame["name"].endswith(" [opt]")) 2801263c6cSJonas Devlieghere parent_frame = self.dap_server.get_stackFrame(frameIndex=1) 2901263c6cSJonas Devlieghere self.assertTrue(parent_frame["name"].endswith(" [opt]")) 3001263c6cSJonas Devlieghere 31*47ff13b4SAugusto Noronha @skipIfAsan # On ASAN builds this test intermittently fails https://github.com/llvm/llvm-project/issues/111061 3201263c6cSJonas Devlieghere @skipIfWindows 3301263c6cSJonas Devlieghere def test_optimized_variable(self): 3401263c6cSJonas Devlieghere """Test optimized variable value contains error.""" 3501263c6cSJonas Devlieghere program = self.getBuildArtifact("a.out") 3601263c6cSJonas Devlieghere self.build_and_launch(program) 3701263c6cSJonas Devlieghere source = "main.cpp" 3801263c6cSJonas Devlieghere breakpoint_line = line_number(source, "// breakpoint 2") 3901263c6cSJonas Devlieghere lines = [breakpoint_line] 4001263c6cSJonas Devlieghere # Set breakpoint in the thread function so we can step the threads 4101263c6cSJonas Devlieghere breakpoint_ids = self.set_source_breakpoints(source, lines) 4201263c6cSJonas Devlieghere self.assertEqual( 4301263c6cSJonas Devlieghere len(breakpoint_ids), len(lines), "expect correct number of breakpoints" 4401263c6cSJonas Devlieghere ) 4501263c6cSJonas Devlieghere self.continue_to_breakpoints(breakpoint_ids) 4601263c6cSJonas Devlieghere optimized_variable = self.dap_server.get_local_variable("argc") 4701263c6cSJonas Devlieghere 4801263c6cSJonas Devlieghere self.assertTrue(optimized_variable["value"].startswith("<error:")) 490d19a898Swalter erquinigo error_msg = optimized_variable["$__lldb_extensions"]["error"] 500d19a898Swalter erquinigo self.assertTrue( 5139e12e0aSJonas Devlieghere ("could not evaluate DW_OP_entry_value: no parent function" in error_msg) 520d19a898Swalter erquinigo or ("variable not available" in error_msg) 53ffd173baSWalter Erquinigo ) 54