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
15 class WatchpointPythonCommandTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
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(self.source, '// Set break point at this line.')
26 # And the watchpoint variable declaration line number.
27 self.decl = line_number(self.source, '// Watchpoint variable declaration.')
28 # Build dictionary to have unique executable names for each test method.
29 self.exe_name = self.testMethodName
30 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
32 @skipIfFreeBSD # timing out on buildbot
33 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
34 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
35 @expectedFailureAll(oslist=["linux"], archs=["aarch64"], bugnumber="llvm.org/pr27710")
36 def test_watchpoint_command(self):
37 """Test 'watchpoint command'."""
38 self.build(dictionary=self.d)
39 self.setTearDownCleanup(dictionary=self.d)
41 exe = os.path.join(os.getcwd(), self.exe_name)
42 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
44 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
45 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
46 # self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED,
47 # startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
48 # (self.source, self.line))#
51 self.runCmd("run", RUN_SUCCEEDED)
53 # We should be stopped again due to the breakpoint.
54 # The stop reason of the thread should be breakpoint.
55 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
57 'stop reason = breakpoint'])
59 # Now let's set a write-type watchpoint for 'global'.
60 self.expect("watchpoint set variable -w write global", WATCHPOINT_CREATED,
61 substrs = ['Watchpoint created', 'size = 4', 'type = w',
62 '%s:%d' % (self.source, self.decl)])
64 self.runCmd('watchpoint command add -s python 1 -o \'frame.EvaluateExpression("cookie = 777")\'')
66 # List the watchpoint command we just added.
67 self.expect("watchpoint command list 1",
68 substrs = ['frame.EvaluateExpression', 'cookie = 777'])
70 # Use the '-v' option to do verbose listing of the watchpoint.
71 # The hit count should be 0 initially.
72 self.expect("watchpoint list -v",
73 substrs = ['hit_count = 0'])
75 self.runCmd("process continue")
77 # We should be stopped again due to the watchpoint (write type).
78 # The stop reason of the thread should be watchpoint.
79 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
80 substrs = ['stop reason = watchpoint'])
82 # Check that the watchpoint snapshoting mechanism is working.
83 self.expect("watchpoint list -v",
84 substrs = ['old value:', ' = 0',
85 'new value:', ' = 1'])
87 # The watchpoint command "forced" our global variable 'cookie' to become 777.
88 self.expect("frame variable --show-globals cookie",
89 substrs = ['(int32_t)', 'cookie = 777'])
91 @skipIfFreeBSD # timing out on buildbot
92 @expectedFailureAll(bugnumber="llvm.org/pr28055: continue in watchpoint commands disables the watchpoint")
93 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
94 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
95 @expectedFailureAll(oslist=["linux"], archs=["aarch64"], bugnumber="llvm.org/pr27710")
96 def test_continue_in_watchpoint_command(self):
97 """Test continue in a watchpoint command."""
98 self.build(dictionary=self.d)
99 self.setTearDownCleanup(dictionary=self.d)
101 exe = os.path.join(os.getcwd(), self.exe_name)
102 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
104 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
105 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
106 # self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED,
107 # startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
108 # (self.source, self.line))#
111 self.runCmd("run", RUN_SUCCEEDED)
113 # We should be stopped again due to the breakpoint.
114 # The stop reason of the thread should be breakpoint.
115 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
116 substrs = ['stopped',
117 'stop reason = breakpoint'])
119 # Now let's set a write-type watchpoint for 'global'.
120 self.expect("watchpoint set variable -w write global", WATCHPOINT_CREATED,
121 substrs = ['Watchpoint created', 'size = 4', 'type = w',
122 '%s:%d' % (self.source, self.decl)])
124 cmd_script_file = os.path.join(os.getcwd(), "watchpoint_command.py")
125 self.runCmd("command script import '%s'"%(cmd_script_file))
127 self.runCmd('watchpoint command add -F watchpoint_command.watchpoint_command')
129 # List the watchpoint command we just added.
130 self.expect("watchpoint command list 1",
131 substrs = ['watchpoint_command.watchpoint_command'])
133 self.runCmd("process continue")
135 # We should be stopped again due to the watchpoint (write type).
136 # The stop reason of the thread should be watchpoint.
137 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
138 substrs = ['stop reason = watchpoint'])
140 # We should have hit the watchpoint once, set cookie to 888, then continued to the
141 # second hit and set it to 999
142 self.expect("frame variable --show-globals cookie",
143 substrs = ['(int32_t)', 'cookie = 999'])