2 Test watchpoint size cases (1-byte, 2-byte, 4-byte).
3 Make sure we can watch all bytes, words or double words individually
4 when they are packed in a 8-byte region.
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
15 class WatchpointSizeTestCase(TestBase):
16 NO_DEBUG_INFO_TESTCASE = True
18 mydir = TestBase.compute_mydir(__file__)
21 # Call super's setUp().
25 self.source = 'main.c'
28 self.exe_name = self.getBuildArtifact("a.out")
29 self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
31 # Read-write watchpoints not supported on SystemZ
32 @expectedFailureAll(archs=['s390x'])
33 def test_byte_size_watchpoints_with_byte_selection(self):
34 """Test to selectively watch different bytes in a 8-byte array."""
35 self.run_watchpoint_size_test('byteArray', 8, '1')
37 # Read-write watchpoints not supported on SystemZ
38 @expectedFailureAll(archs=['s390x'])
39 def test_two_byte_watchpoints_with_word_selection(self):
40 """Test to selectively watch different words in an 8-byte word array."""
41 self.run_watchpoint_size_test('wordArray', 4, '2')
43 # Read-write watchpoints not supported on SystemZ
44 @expectedFailureAll(archs=['s390x'])
45 def test_four_byte_watchpoints_with_dword_selection(self):
46 """Test to selectively watch two double words in an 8-byte dword array."""
47 self.run_watchpoint_size_test('dwordArray', 2, '4')
49 def run_watchpoint_size_test(self, arrayName, array_size, watchsize):
50 self.build(dictionary=self.d)
51 self.setTearDownCleanup(dictionary=self.d)
53 exe = self.getBuildArtifact(self.exe_name)
54 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
56 # Detect line number after which we are going to increment arrayName.
57 loc_line = line_number('main.c', '// About to write ' + arrayName)
59 # Set a breakpoint on the line detected above.
60 lldbutil.run_break_set_by_file_and_line(
61 self, "main.c", loc_line, num_expected_locations=1, loc_exact=True)
64 self.runCmd("run", RUN_SUCCEEDED)
66 for i in range(array_size):
67 # We should be stopped again due to the breakpoint.
68 # The stop reason of the thread should be breakpoint.
69 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
70 substrs=['stopped', 'stop reason = breakpoint'])
72 # Set a read_write type watchpoint arrayName
73 watch_loc = arrayName + "[" + str(i) + "]"
75 "watchpoint set variable -w read_write " +
84 # Use the '-v' option to do verbose listing of the watchpoint.
85 # The hit count should be 0 initially.
86 self.expect("watchpoint list -v", substrs=['hit_count = 0'])
88 self.runCmd("process continue")
90 # We should be stopped due to the watchpoint.
91 # The stop reason of the thread should be watchpoint.
92 self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
93 substrs=['stopped', 'stop reason = watchpoint'])
95 # Use the '-v' option to do verbose listing of the watchpoint.
96 # The hit count should now be 1.
97 self.expect("watchpoint list -v",
98 substrs=['hit_count = 1'])
100 self.runCmd("process continue")
102 # We should be stopped due to the watchpoint.
103 # The stop reason of the thread should be watchpoint.
104 self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
105 substrs=['stopped', 'stop reason = watchpoint'])
107 # Use the '-v' option to do verbose listing of the watchpoint.
108 # The hit count should now be 1.
109 # Verify hit_count has been updated after value has been read.
110 self.expect("watchpoint list -v",
111 substrs=['hit_count = 2'])
113 # Delete the watchpoint immediately, but set auto-confirm to true
115 self.runCmd("settings set auto-confirm true")
118 substrs=['All watchpoints removed.'])
119 # Restore the original setting of auto-confirm.
120 self.runCmd("settings clear auto-confirm")
122 self.runCmd("process continue")