2 Test that lldb watchpoint works for multiple threads.
5 from __future__ import print_function
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
15 class WatchpointForMultipleThreadsTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
18 NO_DEBUG_INFO_TESTCASE = True
19 main_spec = lldb.SBFileSpec("main.cpp", False)
21 def test_watchpoint_before_thread_start(self):
22 """Test that we can hit a watchpoint we set before starting another thread"""
23 self.do_watchpoint_test("Before running the thread")
25 def test_watchpoint_after_thread_start(self):
26 """Test that we can hit a watchpoint we set after starting another thread"""
27 self.do_watchpoint_test("After running the thread")
29 def do_watchpoint_test(self, line):
31 lldbutil.run_to_source_breakpoint(self, line, self.main_spec)
33 # Now let's set a write-type watchpoint for variable 'g_val'.
35 "watchpoint set variable -w write g_val",
42 # Use the '-v' option to do verbose listing of the watchpoint.
43 # The hit count should be 0 initially.
44 self.expect("watchpoint list -v",
45 substrs=['hit_count = 0'])
47 self.runCmd("process continue")
49 self.runCmd("thread list")
50 if "stop reason = watchpoint" in self.res.GetOutput():
51 # Good, we verified that the watchpoint works!
52 self.runCmd("thread backtrace all")
54 self.fail("The stop reason should be either break or watchpoint")
56 # Use the '-v' option to do verbose listing of the watchpoint.
57 # The hit count should now be 1.
58 self.expect("watchpoint list -v",
59 substrs=['hit_count = 1'])
61 def test_watchpoint_multiple_threads_wp_set_and_then_delete(self):
62 """Test that lldb watchpoint works for multiple threads, and after the watchpoint is deleted, the watchpoint event should no longer fires."""
64 self.setTearDownCleanup()
66 lldbutil.run_to_source_breakpoint(self, "After running the thread", self.main_spec)
68 # Now let's set a write-type watchpoint for variable 'g_val'.
70 "watchpoint set variable -w write g_val",
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'])
84 self.runCmd("process continue")
85 self.runCmd("process status")
86 if re.search("Process .* exited", self.res.GetOutput()):
87 # Great, we are done with this test!
90 self.runCmd("thread list")
91 if "stop reason = watchpoint" in self.res.GetOutput():
92 self.runCmd("thread backtrace all")
94 if watchpoint_stops > 1:
96 "Watchpoint hits not supposed to exceed 1 by design!")
97 # Good, we verified that the watchpoint works! Now delete the
101 "watchpoint_stops=%d at the moment we delete the watchpoint" %
103 self.runCmd("watchpoint delete 1")
104 self.expect("watchpoint list -v",
105 substrs=['No watchpoints currently set.'])
108 self.fail("The stop reason should be either break or watchpoint")