2 Test 'watchpoint command'.
8 from lldbsuite
.test
.decorators
import *
9 from lldbsuite
.test
.lldbtest
import *
10 from lldbsuite
.test
import lldbutil
13 class WatchpointPythonCommandTestCase(TestBase
):
14 NO_DEBUG_INFO_TESTCASE
= True
17 # Call super's setUp().
19 # Our simple source filename.
20 self
.source
= "main.cpp"
21 # Find the line number to break inside main().
22 self
.line
= line_number(self
.source
, "// Set break point at this line.")
23 self
.second_line
= line_number(self
.source
, "// Set another breakpoint here.")
24 # And the watchpoint variable declaration line number.
25 self
.decl
= line_number(self
.source
, "// Watchpoint variable declaration.")
26 # Build dictionary to have unique executable names for each test
28 self
.exe_name
= self
.testMethodName
29 self
.d
= {"CXX_SOURCES": self
.source
, "EXE": self
.exe_name
}
31 def test_watchpoint_command(self
):
32 """Test 'watchpoint command'."""
33 self
.build(dictionary
=self
.d
)
34 self
.setTearDownCleanup(dictionary
=self
.d
)
36 exe
= self
.getBuildArtifact(self
.exe_name
)
37 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
39 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
40 lldbutil
.run_break_set_by_file_and_line(
41 self
, None, self
.line
, num_expected_locations
=1
45 self
.runCmd("run", RUN_SUCCEEDED
)
47 # We should be stopped again due to the breakpoint.
48 # The stop reason of the thread should be breakpoint.
51 STOPPED_DUE_TO_BREAKPOINT
,
52 substrs
=["stopped", "stop reason = breakpoint"],
55 # Now let's set a write-type watchpoint for 'global'.
57 "watchpoint set variable -w write global",
63 "%s:%d" % (self
.source
, self
.decl
),
68 "watchpoint command add -s python 1 -o 'frame.EvaluateExpression(\"cookie = 777\")'"
71 # List the watchpoint command we just added.
73 "watchpoint command list 1",
74 substrs
=["frame.EvaluateExpression", "cookie = 777"],
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", substrs
=["hit_count = 0"])
81 self
.runCmd("process continue")
83 # We should be stopped again due to the watchpoint (write type).
84 # The stop reason of the thread should be watchpoint.
87 STOPPED_DUE_TO_WATCHPOINT
,
88 substrs
=["stop reason = watchpoint"],
91 # Check that the watchpoint snapshoting mechanism is working.
92 self
.expect("watchpoint list -v", substrs
=["old value: 0", "new value: 1"])
94 # The watchpoint command "forced" our global variable 'cookie' to
97 "frame variable --show-globals cookie",
98 substrs
=["(int32_t)", "cookie = 777"],
101 def test_continue_in_watchpoint_command(self
):
102 """Test continue in a watchpoint command."""
103 self
.build(dictionary
=self
.d
)
104 self
.setTearDownCleanup(dictionary
=self
.d
)
106 exe
= self
.getBuildArtifact(self
.exe_name
)
107 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
109 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
110 lldbutil
.run_break_set_by_file_and_line(
111 self
, None, self
.line
, num_expected_locations
=1
115 self
.runCmd("run", RUN_SUCCEEDED
)
117 # We should be stopped again due to the breakpoint.
118 # The stop reason of the thread should be breakpoint.
121 STOPPED_DUE_TO_BREAKPOINT
,
122 substrs
=["stopped", "stop reason = breakpoint"],
125 # Now let's set a write-type watchpoint for 'global'.
127 "watchpoint set variable -w write global",
130 "Watchpoint created",
133 "%s:%d" % (self
.source
, self
.decl
),
137 cmd_script_file
= os
.path
.join(self
.getSourceDir(), "watchpoint_command.py")
138 self
.runCmd("command script import '%s'" % (cmd_script_file
))
140 self
.runCmd("watchpoint command add -F watchpoint_command.watchpoint_command")
142 # List the watchpoint command we just added.
144 "watchpoint command list 1",
145 substrs
=["watchpoint_command.watchpoint_command"],
148 self
.runCmd("process continue")
150 # We should be stopped again due to the watchpoint (write type).
151 # The stop reason of the thread should be watchpoint.
154 STOPPED_DUE_TO_WATCHPOINT
,
155 substrs
=["stop reason = watchpoint"],
158 # We should have hit the watchpoint once, set cookie to 888, since the
159 # user callback returned True.
161 "frame variable --show-globals cookie",
162 substrs
=["(int32_t)", "cookie = 888"],
165 self
.runCmd("process continue")
167 # We should be stopped again due to the watchpoint (write type).
168 # The stop reason of the thread should be watchpoint.
171 STOPPED_DUE_TO_WATCHPOINT
,
172 substrs
=["stop reason = watchpoint"],
175 # We should have hit the watchpoint a second time, set cookie to 666,
176 # even if the user callback didn't return anything and then continue.
178 "frame variable --show-globals cookie",
179 substrs
=["(int32_t)", "cookie = 666"],
182 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
183 lldbutil
.run_break_set_by_file_and_line(
184 self
, None, self
.second_line
, num_expected_locations
=1
187 self
.runCmd("process continue")
191 STOPPED_DUE_TO_BREAKPOINT
,
192 substrs
=["stop reason = breakpoint"],
195 # We should have hit the watchpoint once, set cookie to 888, then continued to the
196 # second hit and set it to 999
198 "frame variable --show-globals cookie",
199 substrs
=["(int32_t)", "cookie = 999"],