2 Test lldb watchpoint that uses 'watchpoint set -w write -s size' to watch a pointed location with size.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class WatchLocationUsingWatchpointSetTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
16 NO_DEBUG_INFO_TESTCASE = True
19 # Call super's setUp().
21 # Our simple source filename.
22 self.source = 'main.cpp'
23 # Find the line number to break inside main().
24 self.line = line_number(
25 self.source, '// Set break point at this line.')
26 # This is for verifying that watch location works.
27 self.violating_func = "do_bad_thing_with_location"
28 # Build dictionary to have unique executable names for each test
36 bugnumber="llvm.org/pr26031")
37 def test_watchlocation_using_watchpoint_set(self):
38 """Test watching a location with 'watchpoint set expression -w write -s size' option."""
40 self.setTearDownCleanup()
42 exe = self.getBuildArtifact("a.out")
43 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
45 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
46 lldbutil.run_break_set_by_file_and_line(
47 self, None, self.line, num_expected_locations=1)
50 self.runCmd("run", RUN_SUCCEEDED)
52 # We should be stopped again due to the breakpoint.
53 # The stop reason of the thread should be breakpoint.
54 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
56 'stop reason = breakpoint'])
58 # Now let's set a write-type watchpoint pointed to by 'g_char_ptr' and
60 # The main.cpp, by design, misbehaves by not following the agreed upon
61 # protocol of only accessing the allowable index range of [0, 6].
63 "watchpoint set expression -w write -s 1 -- g_char_ptr + 7",
69 self.runCmd("expr unsigned val = g_char_ptr[7]; val")
70 self.expect(self.res.GetOutput().splitlines()[0], exe=False,
73 # Use the '-v' option to do verbose listing of the watchpoint.
74 # The hit count should be 0 initially.
75 self.expect("watchpoint list -v",
76 substrs=['hit_count = 0'])
78 self.runCmd("process continue")
80 # We should be stopped again due to the watchpoint (write type), but
81 # only once. The stop reason of the thread should be watchpoint.
82 self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
84 'stop reason = watchpoint',
87 # Switch to the thread stopped due to watchpoint and issue some
89 self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
90 self.runCmd("thread backtrace")
91 self.runCmd("expr unsigned val = g_char_ptr[7]; val")
92 self.expect(self.res.GetOutput().splitlines()[0], exe=False,
95 # Use the '-v' option to do verbose listing of the watchpoint.
96 # The hit count should now be the same as the number of threads that
97 # stopped on a watchpoint.
98 threads = lldbutil.get_stopped_threads(
99 self.process(), lldb.eStopReasonWatchpoint)
100 self.expect("watchpoint list -v",
101 substrs=['hit_count = %d' % len(threads)])
103 self.runCmd("thread backtrace all")