2 Test 'watchpoint command'.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
12 class WatchpointLLDBCommandTestCase(TestBase
):
13 NO_DEBUG_INFO_TESTCASE
= True
16 # Call super's setUp().
18 # Our simple source filename.
19 self
.source
= "main.cpp"
20 # Find the line number to break inside main().
21 self
.line
= line_number(self
.source
, "// Set break point at this line.")
22 # And the watchpoint variable declaration line number.
23 self
.decl
= line_number(self
.source
, "// Watchpoint variable declaration.")
24 # Build dictionary to have unique executable names for each test
26 self
.exe_name
= "a%d.out" % self
.test_number
27 self
.d
= {"CXX_SOURCES": self
.source
, "EXE": self
.exe_name
}
29 def test_watchpoint_command(self
):
30 """Test 'watchpoint command'."""
31 self
.build(dictionary
=self
.d
)
32 self
.setTearDownCleanup(dictionary
=self
.d
)
34 exe
= self
.getBuildArtifact(self
.exe_name
)
35 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
37 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
38 lldbutil
.run_break_set_by_file_and_line(
39 self
, None, self
.line
, num_expected_locations
=1
43 self
.runCmd("run", RUN_SUCCEEDED
)
45 # We should be stopped again due to the breakpoint.
46 # The stop reason of the thread should be breakpoint.
49 STOPPED_DUE_TO_BREAKPOINT
,
50 substrs
=["stopped", "stop reason = breakpoint"],
53 # Now let's set a write-type watchpoint for 'global'.
55 "watchpoint set variable -w write global",
61 "%s:%d" % (self
.source
, self
.decl
),
65 self
.runCmd('watchpoint command add 1 -o "expr -- cookie = 777"')
67 # List the watchpoint command we just added.
68 self
.expect("watchpoint command list 1", substrs
=["expr -- 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", substrs
=["hit_count = 0"])
74 self
.runCmd("process continue")
76 # We should be stopped again due to the watchpoint (write type).
77 # The stop reason of the thread should be watchpoint.
80 STOPPED_DUE_TO_WATCHPOINT
,
81 substrs
=["stop reason = watchpoint"],
84 # Check that the watchpoint snapshoting mechanism is working.
95 # The watchpoint command "forced" our global variable 'cookie' to
98 "frame variable --show-globals cookie",
99 substrs
=["(int32_t)", "cookie = 777"],
102 def test_watchpoint_command_can_disable_a_watchpoint(self
):
103 """Test that 'watchpoint command' action can disable a watchpoint after it is triggered."""
104 self
.build(dictionary
=self
.d
)
105 self
.setTearDownCleanup(dictionary
=self
.d
)
107 exe
= self
.getBuildArtifact(self
.exe_name
)
108 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
110 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
111 lldbutil
.run_break_set_by_file_and_line(
112 self
, None, self
.line
, num_expected_locations
=1
116 self
.runCmd("run", RUN_SUCCEEDED
)
118 # We should be stopped again due to the breakpoint.
119 # The stop reason of the thread should be breakpoint.
122 STOPPED_DUE_TO_BREAKPOINT
,
123 substrs
=["stopped", "stop reason = breakpoint"],
126 # Now let's set a write-type watchpoint for 'global'.
128 "watchpoint set variable -w write global",
131 "Watchpoint created",
134 "%s:%d" % (self
.source
, self
.decl
),
138 self
.runCmd('watchpoint command add 1 -o "watchpoint disable 1"')
140 # List the watchpoint command we just added.
141 self
.expect("watchpoint command list 1", substrs
=["watchpoint disable 1"])
143 # Use the '-v' option to do verbose listing of the watchpoint.
144 # The hit count should be 0 initially.
145 self
.expect("watchpoint list -v", substrs
=["hit_count = 0"])
147 self
.runCmd("process continue")
149 # We should be stopped again due to the watchpoint (write type).
150 # The stop reason of the thread should be watchpoint.
153 STOPPED_DUE_TO_WATCHPOINT
,
154 substrs
=["stop reason = watchpoint"],
157 # Check that the watchpoint has been disabled.
158 self
.expect("watchpoint list -v", substrs
=["disabled"])
160 self
.runCmd("process continue")
162 # There should be no more watchpoint hit and the process status should
164 self
.expect("process status", substrs
=["exited"])