2 Test lldb watchpoint that uses '-s size' to watch a pointed location with size.
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class HelloWatchLocationTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
17 NO_DEBUG_INFO_TESTCASE = True
20 # Call super's setUp().
22 # Our simple source filename.
23 self.source = 'main.cpp'
24 # Find the line number to break inside main().
25 self.line = line_number(
26 self.source, '// Set break point at this line.')
27 # This is for verifying that watch location works.
28 self.violating_func = "do_bad_thing_with_location"
29 # Build dictionary to have unique executable names for each test
31 self.exe_name = self.testMethodName
32 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
34 # Most of the MIPS boards provide only one H/W watchpoints, and S/W
35 # watchpoints are not supported yet
36 @expectedFailureAll(triple=re.compile('^mips'))
37 # SystemZ and PowerPC also currently supports only one H/W watchpoint
38 @expectedFailureAll(archs=['powerpc64le', 's390x'])
40 def test_hello_watchlocation(self):
41 """Test watching a location with '-s size' option."""
42 self.build(dictionary=self.d)
43 self.setTearDownCleanup(dictionary=self.d)
44 exe = self.getBuildArtifact(self.exe_name)
45 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
47 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
48 lldbutil.run_break_set_by_file_and_line(
49 self, None, self.line, num_expected_locations=1, loc_exact=False)
52 self.runCmd("run", RUN_SUCCEEDED)
54 # We should be stopped again due to the breakpoint.
55 # The stop reason of the thread should be breakpoint.
56 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
58 'stop reason = breakpoint'])
60 # Now let's set a write-type watchpoint pointed to by 'g_char_ptr'.
62 "watchpoint set expression -w write -s 1 -- g_char_ptr",
68 # Get a hold of the watchpoint id just created, it is used later on to
69 # match the watchpoint id which is expected to be fired.
71 "Watchpoint created: Watchpoint (.*):",
72 self.res.GetOutput().splitlines()[0])
74 expected_wp_id = int(match.group(1), 0)
76 self.fail("Grokking watchpoint id faailed!")
78 self.runCmd("expr unsigned val = *g_char_ptr; val")
79 self.expect(self.res.GetOutput().splitlines()[0], exe=False,
82 self.runCmd("watchpoint set expression -w write -s 4 -- &threads[0]")
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",
87 substrs=['hit_count = 0'])
89 self.runCmd("process continue")
91 # We should be stopped again due to the watchpoint (write type), but
92 # only once. The stop reason of the thread should be watchpoint.
93 self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
95 'stop reason = watchpoint %d' % expected_wp_id])
97 # Switch to the thread stopped due to watchpoint and issue some
99 self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
100 self.runCmd("thread backtrace")
101 self.expect("frame info",
102 substrs=[self.violating_func])
104 # Use the '-v' option to do verbose listing of the watchpoint.
105 # The hit count should now be 1.
106 self.expect("watchpoint list -v",
107 substrs=['hit_count = 1'])
109 self.runCmd("thread backtrace all")