brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · d34a962 Raw
123 lines · python
1"""2Test watchpoint size cases (1-byte, 2-byte, 4-byte).3Make sure we can watch all bytes, words or double words individually4when they are packed in a 8-byte region.5 6"""7 8 9import lldb10from lldbsuite.test.decorators import *11from lldbsuite.test.lldbtest import *12from lldbsuite.test import lldbutil13 14 15class WatchpointSizeTestCase(TestBase):16    NO_DEBUG_INFO_TESTCASE = True17 18    def setUp(self):19        # Call super's setUp().20        TestBase.setUp(self)21 22        # Source filename.23        self.source = "main.c"24 25        # Output filename.26        self.exe_name = self.getBuildArtifact("a.out")27        self.d = {"C_SOURCES": self.source, "EXE": self.exe_name}28 29    # Read-write watchpoints not supported on SystemZ30    @expectedFailureAll(archs=["s390x"])31    def test_byte_size_watchpoints_with_byte_selection(self):32        """Test to selectively watch different bytes in a 8-byte array."""33        self.run_watchpoint_size_test("byteArray", 8, "1")34 35    # Read-write watchpoints not supported on SystemZ36    @expectedFailureAll(archs=["s390x"])37    def test_two_byte_watchpoints_with_word_selection(self):38        """Test to selectively watch different words in an 8-byte word array."""39        self.run_watchpoint_size_test("wordArray", 4, "2")40 41    # Read-write watchpoints not supported on SystemZ42    @expectedFailureAll(archs=["s390x"])43    def test_four_byte_watchpoints_with_dword_selection(self):44        """Test to selectively watch two double words in an 8-byte dword array."""45        self.run_watchpoint_size_test("dwordArray", 2, "4")46 47    def run_watchpoint_size_test(self, arrayName, array_size, watchsize):48        self.build(dictionary=self.d)49        self.setTearDownCleanup(dictionary=self.d)50 51        exe = self.getBuildArtifact(self.exe_name)52        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)53 54        # Detect line number after which we are going to increment arrayName.55        loc_line = line_number("main.c", "// About to write " + arrayName)56 57        # Set a breakpoint on the line detected above.58        lldbutil.run_break_set_by_file_and_line(59            self, "main.c", loc_line, num_expected_locations=1, loc_exact=True60        )61 62        # Run the program.63        self.runCmd("run", RUN_SUCCEEDED)64 65        for i in range(array_size):66            # We should be stopped again due to the breakpoint.67            # The stop reason of the thread should be breakpoint.68            self.expect(69                "thread list",70                STOPPED_DUE_TO_BREAKPOINT,71                substrs=["stopped", "stop reason = breakpoint"],72            )73 74            # Set a read_write type watchpoint arrayName75            watch_loc = arrayName + "[" + str(i) + "]"76            self.expect(77                "watchpoint set variable -w read_write " + watch_loc,78                WATCHPOINT_CREATED,79                substrs=["Watchpoint created", "size = " + watchsize, "type = rw"],80            )81 82            # Use the '-v' option to do verbose listing of the watchpoint.83            # The hit count should be 0 initially.84            self.expect("watchpoint list -v", substrs=["hit_count = 0"])85 86            self.runCmd("process continue")87 88            # We should be stopped due to the watchpoint.89            # The stop reason of the thread should be watchpoint.90            self.expect(91                "thread list",92                STOPPED_DUE_TO_WATCHPOINT,93                substrs=["stopped", "stop reason = watchpoint"],94            )95 96            # Use the '-v' option to do verbose listing of the watchpoint.97            # The hit count should now be 1.98            self.expect("watchpoint list -v", substrs=["hit_count = 1"])99 100            self.runCmd("process continue")101 102            # We should be stopped due to the watchpoint.103            # The stop reason of the thread should be watchpoint.104            self.expect(105                "thread list",106                STOPPED_DUE_TO_WATCHPOINT,107                substrs=["stopped", "stop reason = watchpoint"],108            )109 110            # Use the '-v' option to do verbose listing of the watchpoint.111            # The hit count should now be 1.112            # Verify hit_count has been updated after value has been read.113            self.expect("watchpoint list -v", substrs=["hit_count = 2"])114 115            # Delete the watchpoint immediately, but set auto-confirm to true116            # first.117            self.runCmd("settings set auto-confirm true")118            self.expect("watchpoint delete", substrs=["All watchpoints removed."])119            # Restore the original setting of auto-confirm.120            self.runCmd("settings clear auto-confirm")121 122            self.runCmd("process continue")123