2 Test 'watchpoint command'.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class WatchpointLLDBCommandTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
16 NO_DEBUG_INFO_TESTCASE = True
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 # And the watchpoint variable declaration line number.
27 self.decl = line_number(self.source,
28 '// Watchpoint variable declaration.')
29 # Build dictionary to have unique executable names for each test
31 self.exe_name = 'a%d.out' % self.test_number
32 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
34 def test_watchpoint_command(self):
35 """Test 'watchpoint command'."""
36 self.build(dictionary=self.d)
37 self.setTearDownCleanup(dictionary=self.d)
39 exe = self.getBuildArtifact(self.exe_name)
40 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
42 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
43 lldbutil.run_break_set_by_file_and_line(
44 self, None, self.line, num_expected_locations=1)
47 self.runCmd("run", RUN_SUCCEEDED)
49 # We should be stopped again due to the breakpoint.
50 # The stop reason of the thread should be breakpoint.
51 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
53 'stop reason = breakpoint'])
55 # Now let's set a write-type watchpoint for 'global'.
57 "watchpoint set variable -w write global",
67 self.runCmd('watchpoint command add 1 -o "expr -- cookie = 777"')
69 # List the watchpoint command we just added.
70 self.expect("watchpoint command list 1",
71 substrs=['expr -- cookie = 777'])
73 # Use the '-v' option to do verbose listing of the watchpoint.
74 # The hit count should be 0 initially.
75 self.expect("watchpoint list -v",
76 substrs=['hit_count = 0'])
78 self.runCmd("process continue")
80 # We should be stopped again due to the watchpoint (write type).
81 # The stop reason of the thread should be watchpoint.
82 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
83 substrs=['stop reason = watchpoint'])
85 # Check that the watchpoint snapshoting mechanism is working.
86 self.expect("watchpoint list -v",
87 substrs=['old value:', ' = 0',
88 'new value:', ' = 1'])
90 # The watchpoint command "forced" our global variable 'cookie' to
92 self.expect("frame variable --show-globals cookie",
93 substrs=['(int32_t)', 'cookie = 777'])
95 def test_watchpoint_command_can_disable_a_watchpoint(self):
96 """Test that 'watchpoint command' action can disable a watchpoint after it is triggered."""
97 self.build(dictionary=self.d)
98 self.setTearDownCleanup(dictionary=self.d)
100 exe = self.getBuildArtifact(self.exe_name)
101 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
103 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
104 lldbutil.run_break_set_by_file_and_line(
105 self, None, self.line, num_expected_locations=1)
108 self.runCmd("run", RUN_SUCCEEDED)
110 # We should be stopped again due to the breakpoint.
111 # The stop reason of the thread should be breakpoint.
112 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
114 'stop reason = breakpoint'])
116 # Now let's set a write-type watchpoint for 'global'.
118 "watchpoint set variable -w write global",
121 'Watchpoint created',
128 self.runCmd('watchpoint command add 1 -o "watchpoint disable 1"')
130 # List the watchpoint command we just added.
131 self.expect("watchpoint command list 1",
132 substrs=['watchpoint disable 1'])
134 # Use the '-v' option to do verbose listing of the watchpoint.
135 # The hit count should be 0 initially.
136 self.expect("watchpoint list -v",
137 substrs=['hit_count = 0'])
139 self.runCmd("process continue")
141 # We should be stopped again due to the watchpoint (write type).
142 # The stop reason of the thread should be watchpoint.
143 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
144 substrs=['stop reason = watchpoint'])
146 # Check that the watchpoint has been disabled.
147 self.expect("watchpoint list -v",
148 substrs=['disabled'])
150 self.runCmd("process continue")
152 # There should be no more watchpoint hit and the process status should
154 self.expect("process status",