GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.base / condbreak.exp
blob1f07bb51fd8e9a3a521ad93b03b7f7493a5c818a
1 # Copyright 1997-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This test was written by Rich Title.
17 # Purpose is to test conditional breakpoints.
18 # Modeled after "break.exp".
21 # test running programs
24 standard_testfile break.c break1.c
26 if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $srcfile2] \
27 {debug nowarnings}]} {
28 return -1
31 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
32 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
33 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile2]
34 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile2]
35 set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile2]
36 set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile2]
39 # test break at function
41 gdb_test "break -q main" \
42 "Breakpoint.*at.* file .*$srcfile, line.*" \
43 "breakpoint function"
46 # test conditional break at function
48 gdb_test "break marker1 if 1==1" \
49 "Breakpoint.*at.* file .*$srcfile2, line.*"
51 gdb_test_no_output "delete 2"
54 # test conditional break at line number
56 gdb_test "break $srcfile:$bp_location1 if 1==1" \
57 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
59 gdb_test_no_output "delete 3"
62 # test conditional break at function
64 gdb_test "break marker1 if (1==1)" \
65 "Breakpoint.*at.* file .*$srcfile2, line.*"
68 # test conditional break at line number
70 gdb_test "break $srcfile:$bp_location1 if (1==1)" \
71 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
73 gdb_test "break marker2 if (a==43)" \
74 "Breakpoint.*at.* file .*$srcfile2, line.*"
77 # Check break involving inferior function call.
78 # Ensure there is at least one additional breakpoint with higher VMA.
80 gdb_test "break marker3 if (multi_line_if_conditional(1,1,1)==0)" \
81 "Breakpoint.*at.* file .*$srcfile2, line.*"
82 gdb_test "break marker4" \
83 "Breakpoint.*at.* file .*$srcfile2, line.*"
86 # check to see what breakpoints are set
88 gdb_test "info break" \
89 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
90 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location6.*
91 \[0-9\]+\[\t \]+breakpoint keep y.* in marker1 at .*$srcfile2:$bp_location15.*
92 \[\t \]+stop only if \\(1==1\\).*
93 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
94 \[\t \]+stop only if \\(1==1\\).*
95 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile2:$bp_location8.*
96 \[\t \]+stop only if \\(a==43\\).*
97 \[0-9\]+\[\t \]+breakpoint keep y.* in marker3 at .*$srcfile2:$bp_location17.*
98 \[\t \]+stop only if \\(multi_line_if_conditional\\(1,1,1\\)==0\\).*
99 \[0-9\]+\[\t \]+breakpoint keep y.* in marker4 at .*$srcfile2:$bp_location14.*" \
100 "breakpoint info"
104 # run until the breakpoint at main is hit.
108 rerun_to_main
111 # run until the breakpoint at a line number
113 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
114 "run until breakpoint set at a line number"
117 # run until the breakpoint at marker1
119 # If the inferior stops at the first instruction of a source line, GDB
120 # won't print the actual PC value; the source line is enough to
121 # exactly specify the PC. But if the inferior is instead stopped in
122 # the midst of a source line, GDB will include the PC in the
123 # breakpoint hit message. This way, GDB always provides the exact
124 # stop location, but avoids clutter when possible.
126 # Suppose you have a function written completely on one source line, like:
127 # int foo (int x) { return 0; }
128 # Setting a breakpoint at `foo' actually places the breakpoint after
129 # foo's prologue.
131 # GCC's STABS writer always emits a line entry attributing the
132 # prologue instructions to the line containing the function's open
133 # brace, even if the first user instruction is also on that line.
134 # This means that, in the case of a one-line function, you will get
135 # two line entries in the debug info for the same line: one at the
136 # function's entry point, and another at the first user instruction.
137 # GDB preserves these duplicated line entries, and prefers the later
138 # one; thus, when the program stops after the prologue, at the first
139 # user instruction, GDB's search finds the second line entry, decides
140 # that the PC is indeed at the beginning of a source line, and doesn't
141 # print an address in the breakpoint hit message.
143 # GCC's Dwarf2 writer, on the other hand, squeezes out duplicate line
144 # entries, so GDB considers the source line to begin at the start of
145 # the function's prologue. Thus, if the program stops at the
146 # breakpoint, GDB will decide that the PC is not at the beginning of a
147 # source line, and will print an address.
149 # I think the Dwarf2 writer's behavior is arguably correct, but not
150 # helpful. If the user sets a breakpoint at that source line, they
151 # want that breakpoint to fall after the prologue. Identifying the
152 # prologue's code with the opening brace is nice, but it shouldn't
153 # take precedence over real code.
155 # Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior.
156 gdb_test_multiple "continue" "run until breakpoint at marker1" {
157 -re "Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile2:$bp_location15.*$bp_location15\[\t \]+.*$gdb_prompt $" {
158 pass "run until breakpoint at marker1"
160 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile2:$bp_location15.*$bp_location15\[\t \]+.*$gdb_prompt $" {
161 xfail "run until breakpoint at marker1"
165 # run until the breakpoint at marker2
166 # Same issues here as above.
167 setup_xfail hppa2.0w-*-* 11512CLLbs
168 gdb_test_multiple "continue" "run until breakpoint at marker2" {
169 -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile2:$bp_location8.*$bp_location8\[\t \]+.*$gdb_prompt $" {
170 pass "run until breakpoint at marker2"
172 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile2:$bp_location8.*$bp_location8\[\t \]+.*$gdb_prompt $" {
173 xfail "run until breakpoint at marker2"
177 # Test combinations of conditional and thread-specific breakpoints.
178 gdb_test "break -q main if (1==1) thread 999" \
179 "Unknown thread 999\\."
180 gdb_test "break -q main thread 999 if (1==1)" \
181 "Unknown thread 999\\."
182 gdb_test "break -q main if (1==1) thread 999 -force-condition" \
183 "Unknown thread 999\\."
184 gdb_test "break -q main thread 999 if (1==1) -force-condition" \
185 "Unknown thread 999\\."
187 # Verify that both if and thread can be distinguished from a breakpoint
188 # address expression.
189 gdb_test "break *main if (1==1) thread 999" \
190 "Unknown thread 999\\."
191 gdb_test "break *main thread 999 if (1==1)" \
192 "Unknown thread 999\\."
193 gdb_test "break *main if (1==1) thread 999 -force-condition" \
194 "Unknown thread 999\\."
195 gdb_test "break *main thread 999 if (1==1) -force-condition" \
196 "Unknown thread 999\\."
198 # Similarly for task.
199 gdb_test "break *main if (1==1) task 999" \
200 "Unknown task 999\\."
201 gdb_test "break *main task 999 if (1==1)" \
202 "Unknown task 999\\."
203 gdb_test "break *main if (1==1) task 999 -force-condition" \
204 "Unknown task 999\\."
205 gdb_test "break *main task 999 if (1==1) -force-condition" \
206 "Unknown task 999\\."
208 # GDB accepts abbreviations for "thread", "task" and
209 # "-force-condition", when these keywords appear after
210 # the breakpoint condition.
211 gdb_test "break *main if (1==1) t 999" \
212 "Unknown thread 999\\."
213 gdb_test "break *main if (1==1) th 999" \
214 "Unknown thread 999\\."
215 gdb_test "break *main if (1==1) ta 999" \
216 "Unknown task 999\\."
217 gdb_test "break *main if (1==1) t 999 -force" \
218 "Unknown thread 999\\."
219 gdb_test "break *main if (1==1) th 999 -force" \
220 "Unknown thread 999\\."
221 gdb_test "break *main if (1==1) ta 999 -force" \
222 "Unknown task 999\\."
224 # Check the use of abbreviations before the condition. This works
225 # because, when the location spec starts with '*' GDB is able to
226 # figure out that the complete location is '*main'.
227 gdb_test "break *main t 999 if (1==1)" \
228 "Unknown thread 999\\."
229 gdb_test "break *main th 999 if (1==1)" \
230 "Unknown thread 999\\."
231 gdb_test "break *main ta 999 if (1==1)" \
232 "Unknown task 999\\."
233 gdb_test "break *main t 999 -force if (1==1)" \
234 "Unknown thread 999\\."
235 gdb_test "break *main th 999 -force if (1==1)" \
236 "Unknown thread 999\\."
237 gdb_test "break *main ta 999 -force if (1==1)" \
238 "Unknown task 999\\."
240 # However, when the location spec doesn't start with '*' GDB relies on
241 # the linespec parser to spot the keyword which marks the end of the
242 # linespec, and this parser doesn't check for abbreviations.
243 gdb_test "with breakpoint pending off -- break main t 999 if (1==1)" \
244 "Function \"main t 999\" not defined\\."
245 gdb_test "with breakpoint pending off -- break main th 999 if (1==1)" \
246 "Function \"main th 999\" not defined\\."
247 gdb_test "with breakpoint pending off -- break main ta 999 if (1==1)" \
248 "Function \"main ta 999\" not defined\\."
250 # GDB does not treat a "-force-condition" flag that appears
251 # immediately after the condition as the flag, but instead treats it
252 # as " - force - condition", that is, subtraction of the symbol
253 # "force" followed by subtraction of symbol "context". This is really
254 # just a quirk of how this used to be implemented, and should maybe be
255 # changed in the future. However, for now GDB retains this behavior.
256 gdb_test "break *main if (1==1) -force-condition" \
257 "No symbol \"force\" in current context\\."
259 set test "run until breakpoint at marker3"
260 gdb_test_multiple "continue" $test {
261 -re "Continuing\\..*Breakpoint \[0-9\]+, marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile2:$bp_location17.*$bp_location17\[\t \]+.*$gdb_prompt $" {
262 pass $test
264 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile2:$bp_location17.*$bp_location17\[\t \]+.*$gdb_prompt $" {
265 xfail $test
269 set test "run until breakpoint at marker4"
270 gdb_test_multiple "continue" $test {
271 -re "Continuing\\..*Breakpoint \[0-9\]+, marker4 \\(d=177601976\\) at .*$srcfile2:$bp_location14.*$bp_location14\[\t \]+.*$gdb_prompt $" {
272 pass $test
274 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker4 \\(d=177601976\\) at .*$srcfile2:$bp_location14.*$bp_location14\[\t \]+.*$gdb_prompt $" {
275 xfail $test
279 gdb_test "complete cond 1" "cond 1"
280 gdb_test "set variable \$var = 1"
281 gdb_test "complete cond \$v" "cond \\\$var"
282 gdb_test "complete cond 1 values\[0\].a" "cond 1 values.0..a_field"
284 set cond_completion "condition ($decimal|-force)"
285 gdb_test "complete condition " "($cond_completion\r\n)+$cond_completion"
286 gdb_test "complete cond -" "cond -force"
288 # If '-force' is already given, it should not be suggested again.
289 set cond_completion "cond -force $decimal"
290 gdb_test "complete cond -force " "($cond_completion\r\n)+$cond_completion"