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
19 # Call super's setUp().
23 self
.source
= "main.c"
26 self
.exe_name
= self
.getBuildArtifact("a.out")
27 self
.d
= {"C_SOURCES": self
.source
, "EXE": self
.exe_name
}
29 # Read-write watchpoints not supported on SystemZ
30 @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")
35 # Read-write watchpoints not supported on SystemZ
36 @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")
41 # Read-write watchpoints not supported on SystemZ
42 @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")
47 def run_watchpoint_size_test(self
, arrayName
, array_size
, watchsize
):
48 self
.build(dictionary
=self
.d
)
49 self
.setTearDownCleanup(dictionary
=self
.d
)
51 exe
= self
.getBuildArtifact(self
.exe_name
)
52 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
54 # Detect line number after which we are going to increment arrayName.
55 loc_line
= line_number("main.c", "// About to write " + arrayName
)
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
=True
63 self
.runCmd("run", RUN_SUCCEEDED
)
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.
70 STOPPED_DUE_TO_BREAKPOINT
,
71 substrs
=["stopped", "stop reason = breakpoint"],
74 # Set a read_write type watchpoint arrayName
75 watch_loc
= arrayName
+ "[" + str(i
) + "]"
77 "watchpoint set variable -w read_write " + watch_loc
,
79 substrs
=["Watchpoint created", "size = " + watchsize
, "type = rw"],
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"])
86 self
.runCmd("process continue")
88 # We should be stopped due to the watchpoint.
89 # The stop reason of the thread should be watchpoint.
92 STOPPED_DUE_TO_WATCHPOINT
,
93 substrs
=["stopped", "stop reason = watchpoint"],
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"])
100 self
.runCmd("process continue")
102 # We should be stopped due to the watchpoint.
103 # The stop reason of the thread should be watchpoint.
106 STOPPED_DUE_TO_WATCHPOINT
,
107 substrs
=["stopped", "stop reason = watchpoint"],
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"])
115 # Delete the watchpoint immediately, but set auto-confirm to true
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")
122 self
.runCmd("process continue")