[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / commands / watchpoints / watchpoint_commands / command / TestWatchpointCommandPython.py
blob57dd214ba639860920f3fe30ed23b73eb646a2a8
1 """
2 Test 'watchpoint command'.
3 """
6 import os
7 import lldb
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
16 def setUp(self):
17 # Call super's setUp().
18 TestBase.setUp(self)
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
27 # method.
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
44 # Run the program.
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.
49 self.expect(
50 "thread list",
51 STOPPED_DUE_TO_BREAKPOINT,
52 substrs=["stopped", "stop reason = breakpoint"],
55 # Now let's set a write-type watchpoint for 'global'.
56 self.expect(
57 "watchpoint set variable -w write global",
58 WATCHPOINT_CREATED,
59 substrs=[
60 "Watchpoint created",
61 "size = 4",
62 "type = w",
63 "%s:%d" % (self.source, self.decl),
67 self.runCmd(
68 "watchpoint command add -s python 1 -o 'frame.EvaluateExpression(\"cookie = 777\")'"
71 # List the watchpoint command we just added.
72 self.expect(
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.
85 self.expect(
86 "thread backtrace",
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
95 # become 777.
96 self.expect(
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
114 # Run the program.
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.
119 self.expect(
120 "thread list",
121 STOPPED_DUE_TO_BREAKPOINT,
122 substrs=["stopped", "stop reason = breakpoint"],
125 # Now let's set a write-type watchpoint for 'global'.
126 self.expect(
127 "watchpoint set variable -w write global",
128 WATCHPOINT_CREATED,
129 substrs=[
130 "Watchpoint created",
131 "size = 4",
132 "type = w",
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.
143 self.expect(
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.
152 self.expect(
153 "thread backtrace",
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.
160 self.expect(
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.
169 self.expect(
170 "thread backtrace",
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.
177 self.expect(
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")
189 self.expect(
190 "thread backtrace",
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
197 self.expect(
198 "frame variable --show-globals cookie",
199 substrs=["(int32_t)", "cookie = 999"],