2 Test 'watchpoint command'.
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 WatchpointLLDBCommandTestCase(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 # And the watchpoint variable declaration line number.
29 self.decl = line_number(self.source,
30 '// Watchpoint variable declaration.')
31 # Build dictionary to have unique executable names for each test
33 self.exe_name = 'a%d.out' % self.test_number
34 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
36 # Watchpoints not supported
37 @expectedFailureAndroid(archs=['arm', 'aarch64'])
41 bugnumber="llvm.org/pr27710")
44 bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
45 def test_watchpoint_command(self):
46 """Test 'watchpoint command'."""
47 self.build(dictionary=self.d)
48 self.setTearDownCleanup(dictionary=self.d)
50 exe = os.path.join(os.getcwd(), self.exe_name)
51 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
53 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
54 lldbutil.run_break_set_by_file_and_line(
55 self, None, self.line, num_expected_locations=1)
58 self.runCmd("run", RUN_SUCCEEDED)
60 # We should be stopped again due to the breakpoint.
61 # The stop reason of the thread should be breakpoint.
62 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
64 'stop reason = breakpoint'])
66 # Now let's set a write-type watchpoint for 'global'.
68 "watchpoint set variable -w write global",
78 self.runCmd('watchpoint command add 1 -o "expr -- cookie = 777"')
80 # List the watchpoint command we just added.
81 self.expect("watchpoint command list 1",
82 substrs=['expr -- cookie = 777'])
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).
92 # The stop reason of the thread should be watchpoint.
93 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
94 substrs=['stop reason = watchpoint'])
96 # Check that the watchpoint snapshoting mechanism is working.
97 self.expect("watchpoint list -v",
98 substrs=['old value:', ' = 0',
99 'new value:', ' = 1'])
101 # The watchpoint command "forced" our global variable 'cookie' to
103 self.expect("frame variable --show-globals cookie",
104 substrs=['(int32_t)', 'cookie = 777'])
106 # Watchpoints not supported
107 @expectedFailureAndroid(archs=['arm', 'aarch64'])
111 bugnumber="llvm.org/pr27710")
114 bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
115 def test_watchpoint_command_can_disable_a_watchpoint(self):
116 """Test that 'watchpoint command' action can disable a watchpoint after it is triggered."""
117 self.build(dictionary=self.d)
118 self.setTearDownCleanup(dictionary=self.d)
120 exe = os.path.join(os.getcwd(), self.exe_name)
121 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
123 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
124 lldbutil.run_break_set_by_file_and_line(
125 self, None, self.line, num_expected_locations=1)
128 self.runCmd("run", RUN_SUCCEEDED)
130 # We should be stopped again due to the breakpoint.
131 # The stop reason of the thread should be breakpoint.
132 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
134 'stop reason = breakpoint'])
136 # Now let's set a write-type watchpoint for 'global'.
138 "watchpoint set variable -w write global",
141 'Watchpoint created',
148 self.runCmd('watchpoint command add 1 -o "watchpoint disable 1"')
150 # List the watchpoint command we just added.
151 self.expect("watchpoint command list 1",
152 substrs=['watchpoint disable 1'])
154 # Use the '-v' option to do verbose listing of the watchpoint.
155 # The hit count should be 0 initially.
156 self.expect("watchpoint list -v",
157 substrs=['hit_count = 0'])
159 self.runCmd("process continue")
161 # We should be stopped again due to the watchpoint (write type).
162 # The stop reason of the thread should be watchpoint.
163 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
164 substrs=['stop reason = watchpoint'])
166 # Check that the watchpoint has been disabled.
167 self.expect("watchpoint list -v",
168 substrs=['disabled'])
170 self.runCmd("process continue")
172 # There should be no more watchpoint hit and the process status should
174 self.expect("process status",