2 Test that lldb watchpoint works for multiple threads.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
12 class WatchpointForMultipleThreadsTestCase(TestBase
):
13 NO_DEBUG_INFO_TESTCASE
= True
14 main_spec
= lldb
.SBFileSpec("main.cpp", False)
16 @skipIfWindows # This test is flaky on Windows
17 def test_watchpoint_before_thread_start(self
):
18 """Test that we can hit a watchpoint we set before starting another thread"""
19 self
.do_watchpoint_test("Before running the thread")
21 @skipIfWindows # This test is flaky on Windows
22 def test_watchpoint_after_thread_launch(self
):
23 """Test that we can hit a watchpoint we set after launching another thread"""
24 self
.do_watchpoint_test("After launching the thread")
26 def test_watchpoint_after_thread_start(self
):
27 """Test that we can hit a watchpoint we set after another thread starts"""
28 self
.do_watchpoint_test("After running the thread")
30 def do_watchpoint_test(self
, line
):
32 lldbutil
.run_to_source_breakpoint(self
, line
, self
.main_spec
)
34 # Now let's set a write-type watchpoint for variable 'g_val'.
36 "watchpoint set variable -w write g_val",
38 substrs
=["Watchpoint created", "size = 4", "type = w"],
41 # Use the '-v' option to do verbose listing of the watchpoint.
42 # The hit count should be 0 initially.
43 self
.expect("watchpoint list -v", substrs
=["hit_count = 0"])
45 self
.runCmd("process continue")
47 self
.runCmd("thread list")
48 if "stop reason = watchpoint" in self
.res
.GetOutput():
49 # Good, we verified that the watchpoint works!
50 self
.runCmd("thread backtrace all")
52 self
.fail("The stop reason should be either break or watchpoint")
54 # Use the '-v' option to do verbose listing of the watchpoint.
55 # The hit count should now be 1.
56 self
.expect("watchpoint list -v", substrs
=["hit_count = 1"])
58 def test_watchpoint_multiple_threads_wp_set_and_then_delete(self
):
59 """Test that lldb watchpoint works for multiple threads, and after the watchpoint is deleted, the watchpoint event should no longer fires."""
61 self
.setTearDownCleanup()
63 lldbutil
.run_to_source_breakpoint(
64 self
, "After running the thread", self
.main_spec
67 # Now let's set a write-type watchpoint for variable 'g_val'.
69 "watchpoint set variable -w write g_val",
71 substrs
=["Watchpoint created", "size = 4", "type = w"],
74 # Use the '-v' option to do verbose listing of the watchpoint.
75 # The hit count should be 0 initially.
76 self
.expect("watchpoint list -v", substrs
=["hit_count = 0"])
80 self
.runCmd("process continue")
81 self
.runCmd("process status")
82 if re
.search("Process .* exited", self
.res
.GetOutput()):
83 # Great, we are done with this test!
86 self
.runCmd("thread list")
87 if "stop reason = watchpoint" in self
.res
.GetOutput():
88 self
.runCmd("thread backtrace all")
90 if watchpoint_stops
> 1:
91 self
.fail("Watchpoint hits not supposed to exceed 1 by design!")
92 # Good, we verified that the watchpoint works! Now delete the
96 "watchpoint_stops=%d at the moment we delete the watchpoint"
99 self
.runCmd("watchpoint delete 1")
101 "watchpoint list -v", substrs
=["No watchpoints currently set."]
105 self
.fail("The stop reason should be either break or watchpoint")