2 Test lldb watchpoint that uses 'watchpoint set -w write -s size' to watch a pointed location with size.
5 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class WatchLocationUsingWatchpointSetTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
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")
39 bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
40 @expectedFailureNetBSD
41 def test_watchlocation_using_watchpoint_set(self):
42 """Test watching a location with 'watchpoint set expression -w write -s size' option."""
44 self.setTearDownCleanup()
46 exe = self.getBuildArtifact("a.out")
47 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
49 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
50 lldbutil.run_break_set_by_file_and_line(
51 self, None, self.line, num_expected_locations=1)
54 self.runCmd("run", RUN_SUCCEEDED)
56 # We should be stopped again due to the breakpoint.
57 # The stop reason of the thread should be breakpoint.
58 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
60 'stop reason = breakpoint'])
62 # Now let's set a write-type watchpoint pointed to by 'g_char_ptr' and
64 # The main.cpp, by design, misbehaves by not following the agreed upon
65 # protocol of only accessing the allowable index range of [0, 6].
67 "watchpoint set expression -w write -s 1 -- g_char_ptr + 7",
73 self.runCmd("expr unsigned val = g_char_ptr[7]; val")
74 self.expect(self.res.GetOutput().splitlines()[0], exe=False,
77 # Use the '-v' option to do verbose listing of the watchpoint.
78 # The hit count should be 0 initially.
79 self.expect("watchpoint list -v",
80 substrs=['hit_count = 0'])
82 self.runCmd("process continue")
84 # We should be stopped again due to the watchpoint (write type), but
85 # only once. The stop reason of the thread should be watchpoint.
86 self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
88 'stop reason = watchpoint',
91 # Switch to the thread stopped due to watchpoint and issue some
93 self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
94 self.runCmd("thread backtrace")
95 self.runCmd("expr unsigned val = g_char_ptr[7]; val")
96 self.expect(self.res.GetOutput().splitlines()[0], exe=False,
99 # Use the '-v' option to do verbose listing of the watchpoint.
100 # The hit count should now be the same as the number of threads that
101 # stopped on a watchpoint.
102 threads = lldbutil.get_stopped_threads(
103 self.process(), lldb.eStopReasonWatchpoint)
104 self.expect("watchpoint list -v",
105 substrs=['hit_count = %d' % len(threads)])
107 self.runCmd("thread backtrace all")