]> Git Repo - binutils.git/blame - gdb/testsuite/gdb.base/condbreak.exp
Automatic Copyright Year update after running gdb/copyright.py
[binutils.git] / gdb / testsuite / gdb.base / condbreak.exp
CommitLineData
4a94e368 1# Copyright 1997-2022 Free Software Foundation, Inc.
c906108c
SS
2
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This test was written by Rich Title.
17# Purpose is to test conditional breakpoints.
18# Modeled after "break.exp".
19
c906108c
SS
20#
21# test running programs
22#
c906108c 23
f76495c8 24standard_testfile break.c break1.c
a1dea79a 25
5b362f04 26if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $srcfile2] \
f76495c8
TT
27 {debug nowarnings}]} {
28 return -1
c906108c
SS
29}
30
4c93b1db 31if [get_compiler_info] {
ae59b1da 32 return -1
085dd6e6
JM
33}
34
a1dea79a
FF
35set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
36set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
f76495c8 37set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile2]
f76495c8
TT
38set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile2]
39set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile2]
f76495c8 40set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile2]
a1dea79a 41
c906108c
SS
42#
43# test break at function
44#
e777225b 45gdb_test "break -q main" \
c906108c
SS
46 "Breakpoint.*at.* file .*$srcfile, line.*" \
47 "breakpoint function"
48
49#
50# test conditional break at function
51#
52gdb_test "break marker1 if 1==1" \
f76495c8 53 "Breakpoint.*at.* file .*$srcfile2, line.*"
c906108c 54
27d3a1a2 55gdb_test_no_output "delete 2"
c906108c
SS
56
57#
58# test conditional break at line number
59#
a1dea79a
FF
60gdb_test "break $srcfile:$bp_location1 if 1==1" \
61 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
c906108c 62
27d3a1a2 63gdb_test_no_output "delete 3"
c906108c
SS
64
65#
66# test conditional break at function
67#
68gdb_test "break marker1 if (1==1)" \
f76495c8 69 "Breakpoint.*at.* file .*$srcfile2, line.*"
c906108c
SS
70
71#
72# test conditional break at line number
73#
a1dea79a
FF
74gdb_test "break $srcfile:$bp_location1 if (1==1)" \
75 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
c906108c
SS
76
77gdb_test "break marker2 if (a==43)" \
f76495c8 78 "Breakpoint.*at.* file .*$srcfile2, line.*"
c906108c 79
429374b8
JK
80#
81# Check break involving inferior function call.
82# Ensure there is at least one additional breakpoint with higher VMA.
83#
84gdb_test "break marker3 if (multi_line_if_conditional(1,1,1)==0)" \
f76495c8 85 "Breakpoint.*at.* file .*$srcfile2, line.*"
429374b8 86gdb_test "break marker4" \
f76495c8 87 "Breakpoint.*at.* file .*$srcfile2, line.*"
429374b8 88
c906108c
SS
89#
90# check to see what breakpoints are set
91#
c906108c 92gdb_test "info break" \
54e52265 93 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
a1dea79a 94\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location6.*
b6304613 95\[0-9\]+\[\t \]+breakpoint keep y.* in marker1 at .*$srcfile2:$bp_location15.*
0d381245 96\[\t \]+stop only if \\(1==1\\).*
a1dea79a 97\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
0d381245 98\[\t \]+stop only if \\(1==1\\).*
b6304613 99\[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile2:$bp_location8.*
429374b8 100\[\t \]+stop only if \\(a==43\\).*
b6304613 101\[0-9\]+\[\t \]+breakpoint keep y.* in marker3 at .*$srcfile2:$bp_location17.*
429374b8 102\[\t \]+stop only if \\(multi_line_if_conditional\\(1,1,1\\)==0\\).*
b6304613 103\[0-9\]+\[\t \]+breakpoint keep y.* in marker4 at .*$srcfile2:$bp_location14.*" \
c906108c
SS
104 "breakpoint info"
105
106
107#
7a292a7a 108# run until the breakpoint at main is hit.
c906108c 109#
7a292a7a
SS
110
111
cce74817 112rerun_to_main
c906108c
SS
113
114#
115# run until the breakpoint at a line number
116#
a1dea79a 117gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
c906108c
SS
118 "run until breakpoint set at a line number"
119
120#
121# run until the breakpoint at marker1
122#
11cf8741
JM
123# If the inferior stops at the first instruction of a source line, GDB
124# won't print the actual PC value; the source line is enough to
125# exactly specify the PC. But if the inferior is instead stopped in
126# the midst of a source line, GDB will include the PC in the
127# breakpoint hit message. This way, GDB always provides the exact
128# stop location, but avoids clutter when possible.
129#
130# Suppose you have a function written completely on one source line, like:
2c415c0f 131# int foo (int x) { return 0; }
11cf8741
JM
132# Setting a breakpoint at `foo' actually places the breakpoint after
133# foo's prologue.
134#
135# GCC's STABS writer always emits a line entry attributing the
136# prologue instructions to the line containing the function's open
137# brace, even if the first user instruction is also on that line.
138# This means that, in the case of a one-line function, you will get
139# two line entries in the debug info for the same line: one at the
140# function's entry point, and another at the first user instruction.
141# GDB preserves these duplicated line entries, and prefers the later
142# one; thus, when the program stops after the prologue, at the first
143# user instruction, GDB's search finds the second line entry, decides
144# that the PC is indeed at the beginning of a source line, and doesn't
145# print an address in the breakpoint hit message.
146#
147# GCC's Dwarf2 writer, on the other hand, squeezes out duplicate line
148# entries, so GDB considers the source line to begin at the start of
149# the function's prologue. Thus, if the program stops at the
150# breakpoint, GDB will decide that the PC is not at the beginning of a
151# source line, and will print an address.
152#
153# I think the Dwarf2 writer's behavior is arguably correct, but not
154# helpful. If the user sets a breakpoint at that source line, they
155# want that breakpoint to fall after the prologue. Identifying the
156# prologue's code with the opening brace is nice, but it shouldn't
157# take precedence over real code.
158#
159# Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior.
ad3986f0 160gdb_test_multiple "continue" "run until breakpoint at marker1" {
dc7e1a77 161 -re "Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile2:$bp_location15.*$bp_location15\[\t \]+.*$gdb_prompt $" {
11cf8741
JM
162 pass "run until breakpoint at marker1"
163 }
dc7e1a77 164 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile2:$bp_location15.*$bp_location15\[\t \]+.*$gdb_prompt $" {
11cf8741
JM
165 xfail "run until breakpoint at marker1"
166 }
11cf8741 167}
c906108c 168
c906108c 169# run until the breakpoint at marker2
dfcd3bfb 170# Same issues here as above.
a0b3c4fd 171setup_xfail hppa2.0w-*-* 11512CLLbs
ad3986f0 172gdb_test_multiple "continue" "run until breakpoint at marker2" {
dc7e1a77 173 -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile2:$bp_location8.*$bp_location8\[\t \]+.*$gdb_prompt $" {
dfcd3bfb
JM
174 pass "run until breakpoint at marker2"
175 }
dc7e1a77 176 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile2:$bp_location8.*$bp_location8\[\t \]+.*$gdb_prompt $" {
dfcd3bfb
JM
177 xfail "run until breakpoint at marker2"
178 }
dfcd3bfb 179}
b6199126
DJ
180
181# Test combinations of conditional and thread-specific breakpoints.
e777225b 182gdb_test "break -q main if (1==1) thread 999" \
b6199126 183 "Unknown thread 999\\."
e777225b 184gdb_test "break -q main thread 999 if (1==1)" \
b6199126
DJ
185 "Unknown thread 999\\."
186
187# Verify that both if and thread can be distinguished from a breakpoint
188# address expression.
189gdb_test "break *main if (1==1) thread 999" \
190 "Unknown thread 999\\."
191gdb_test "break *main thread 999 if (1==1)" \
192 "Unknown thread 999\\."
193
194# Similarly for task.
195gdb_test "break *main if (1==1) task 999" \
196 "Unknown task 999\\."
197gdb_test "break *main task 999 if (1==1)" \
198 "Unknown task 999\\."
199
200# GDB accepts abbreviations for "thread" and "task".
201gdb_test "break *main if (1==1) t 999" \
202 "Unknown thread 999\\."
203gdb_test "break *main if (1==1) th 999" \
204 "Unknown thread 999\\."
205gdb_test "break *main if (1==1) ta 999" \
206 "Unknown task 999\\."
429374b8
JK
207
208set test "run until breakpoint at marker3"
209gdb_test_multiple "continue" $test {
dc7e1a77 210 -re "Continuing\\..*Breakpoint \[0-9\]+, marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile2:$bp_location17.*$bp_location17\[\t \]+.*$gdb_prompt $" {
429374b8
JK
211 pass $test
212 }
dc7e1a77 213 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile2:$bp_location17.*$bp_location17\[\t \]+.*$gdb_prompt $" {
429374b8
JK
214 xfail $test
215 }
216}
217
218set test "run until breakpoint at marker4"
219gdb_test_multiple "continue" $test {
dc7e1a77 220 -re "Continuing\\..*Breakpoint \[0-9\]+, marker4 \\(d=177601976\\) at .*$srcfile2:$bp_location14.*$bp_location14\[\t \]+.*$gdb_prompt $" {
429374b8
JK
221 pass $test
222 }
dc7e1a77 223 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker4 \\(d=177601976\\) at .*$srcfile2:$bp_location14.*$bp_location14\[\t \]+.*$gdb_prompt $" {
429374b8
JK
224 xfail $test
225 }
226}
d55637df
TT
227
228gdb_test "complete cond 1" "cond 1"
229gdb_test "set variable \$var = 1"
230gdb_test "complete cond \$v" "cond \\\$var"
231gdb_test "complete cond 1 values\[0\].a" "cond 1 values.0..a_field"
b1d4d8d1
TBA
232
233set cond_completion "condition ($decimal|-force)"
234gdb_test "complete condition " "($cond_completion\r\n)+$cond_completion"
235gdb_test "complete cond -" "cond -force"
236
237# If '-force' is already given, it should not be suggested again.
238set cond_completion "cond -force $decimal"
239gdb_test "complete cond -force " "($cond_completion\r\n)+$cond_completion"
This page took 5.36377 seconds and 4 git commands to generate.