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
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
16 class WatchLocationUsingWatchpointSetTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
21 # Call super's setUp().
23 # Our simple source filename.
24 self.source = 'main.cpp'
25 # Find the line number to break inside main().
26 self.line = line_number(
27 self.source, '// Set break point at this line.')
28 # This is for verifying that watch location works.
29 self.violating_func = "do_bad_thing_with_location"
30 # Build dictionary to have unique executable names for each test
33 # Watchpoints not supported
34 @expectedFailureAndroid(archs=['arm', 'aarch64'])
40 bugnumber="llvm.org/pr26031")
43 bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
44 def test_watchlocation_using_watchpoint_set(self):
45 """Test watching a location with 'watchpoint set expression -w write -s size' option."""
47 self.setTearDownCleanup()
49 exe = os.path.join(os.getcwd(), 'a.out')
50 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
52 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
53 lldbutil.run_break_set_by_file_and_line(
54 self, None, self.line, num_expected_locations=1)
57 self.runCmd("run", RUN_SUCCEEDED)
59 # We should be stopped again due to the breakpoint.
60 # The stop reason of the thread should be breakpoint.
61 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
63 'stop reason = breakpoint'])
65 # Now let's set a write-type watchpoint pointed to by 'g_char_ptr' and
67 # The main.cpp, by design, misbehaves by not following the agreed upon
68 # protocol of only accessing the allowable index range of [0, 6].
70 "watchpoint set expression -w write -s 1 -- g_char_ptr + 7",
76 self.runCmd("expr unsigned val = g_char_ptr[7]; val")
77 self.expect(self.res.GetOutput().splitlines()[0], exe=False,
80 # Use the '-v' option to do verbose listing of the watchpoint.
81 # The hit count should be 0 initially.
82 self.expect("watchpoint list -v",
83 substrs=['hit_count = 0'])
85 self.runCmd("process continue")
87 # We should be stopped again due to the watchpoint (write type), but
88 # only once. The stop reason of the thread should be watchpoint.
89 self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
91 'stop reason = watchpoint',
94 # Switch to the thread stopped due to watchpoint and issue some
96 self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
97 self.runCmd("thread backtrace")
98 self.runCmd("expr unsigned val = g_char_ptr[7]; val")
99 self.expect(self.res.GetOutput().splitlines()[0], exe=False,
102 # Use the '-v' option to do verbose listing of the watchpoint.
103 # The hit count should now be the same as the number of threads that
104 # stopped on a watchpoint.
105 threads = lldbutil.get_stopped_threads(
106 self.process(), lldb.eStopReasonWatchpoint)
107 self.expect("watchpoint list -v",
108 substrs=['hit_count = %d' % len(threads)])
110 self.runCmd("thread backtrace all")