Update copyright year in most headers.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / condbreak.exp
CommitLineData
4c38e0a4 1# Copyright 1997, 1998, 1999, 2000, 2001, 2003, 2007, 2008, 2009, 2010
6aba47ca 2# Free Software Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# This test was written by Rich Title.
18# Purpose is to test conditional breakpoints.
19# Modeled after "break.exp".
20
c906108c
SS
21if $tracelevel then {
22 strace $tracelevel
23 }
24
25global usestubs
26
27#
28# test running programs
29#
30set prms_id 0
31set bug_id 0
32
c2c6d25f 33set testfile "break"
c906108c 34set srcfile ${testfile}.c
a1dea79a 35set srcfile1 ${testfile}1.c
c906108c
SS
36set binfile ${objdir}/${subdir}/${testfile}
37
fc91c6c2 38if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
b60f0898
JB
39 untested condbreak.exp
40 return -1
a1dea79a
FF
41}
42
fc91c6c2 43if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
b60f0898
JB
44 untested condbreak.exp
45 return -1
a1dea79a
FF
46}
47
fc91c6c2 48if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
49 untested condbreak.exp
50 return -1
c906108c
SS
51}
52
085dd6e6
JM
53if [get_compiler_info ${binfile}] {
54 return -1;
55}
56
c906108c
SS
57gdb_exit
58gdb_start
59gdb_reinitialize_dir $srcdir/$subdir
60gdb_load ${binfile}
61
62
63if [target_info exists gdb_stub] {
64 gdb_step_for_stub;
65}
66
a1dea79a
FF
67set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
68set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
69set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
70set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
429374b8
JK
71set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
72set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
a1dea79a
FF
73set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1]
74set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1]
429374b8
JK
75set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile1]
76set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile1]
a1dea79a 77
c906108c
SS
78#
79# test break at function
80#
81gdb_test "break main" \
82 "Breakpoint.*at.* file .*$srcfile, line.*" \
83 "breakpoint function"
84
85#
86# test conditional break at function
87#
88gdb_test "break marker1 if 1==1" \
a1dea79a 89 "Breakpoint.*at.* file .*$srcfile1, line.*"
c906108c 90
7dbd117d 91gdb_test "delete 2" ""
c906108c
SS
92
93#
94# test conditional break at line number
95#
a1dea79a
FF
96gdb_test "break $srcfile:$bp_location1 if 1==1" \
97 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
c906108c 98
7dbd117d 99gdb_test "delete 3" ""
c906108c
SS
100
101#
102# test conditional break at function
103#
104gdb_test "break marker1 if (1==1)" \
a1dea79a 105 "Breakpoint.*at.* file .*$srcfile1, line.*"
c906108c
SS
106
107#
108# test conditional break at line number
109#
a1dea79a
FF
110gdb_test "break $srcfile:$bp_location1 if (1==1)" \
111 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
c906108c
SS
112
113gdb_test "break marker2 if (a==43)" \
a1dea79a 114 "Breakpoint.*at.* file .*$srcfile1, line.*"
c906108c 115
429374b8
JK
116#
117# Check break involving inferior function call.
118# Ensure there is at least one additional breakpoint with higher VMA.
119#
120gdb_test "break marker3 if (multi_line_if_conditional(1,1,1)==0)" \
121 "Breakpoint.*at.* file .*$srcfile1, line.*"
122gdb_test "break marker4" \
123 "Breakpoint.*at.* file .*$srcfile1, line.*"
124
c906108c
SS
125#
126# check to see what breakpoints are set
127#
128
085dd6e6
JM
129if {$hp_aCC_compiler} {
130 set marker1_proto "\\(void\\)"
131 set marker2_proto "\\(int\\)"
429374b8
JK
132 # Not checked.
133 set marker3_proto "\\(char \\*, char \\*\\)"
134 set marker4_proto "\\(long\\)"
085dd6e6
JM
135} else {
136 set marker1_proto ""
137 set marker2_proto ""
429374b8
JK
138 set marker3_proto ""
139 set marker4_proto ""
085dd6e6
JM
140}
141
c906108c 142gdb_test "info break" \
54e52265 143 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
a1dea79a
FF
144\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location6.*
145\[0-9\]+\[\t \]+breakpoint keep y.* in marker1$marker1_proto at .*$srcfile1:($bp_location15|$bp_location16).*
0d381245 146\[\t \]+stop only if \\(1==1\\).*
a1dea79a 147\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
0d381245 148\[\t \]+stop only if \\(1==1\\).*
a1dea79a 149\[0-9\]+\[\t \]+breakpoint keep y.* in marker2$marker2_proto at .*$srcfile1:($bp_location8|$bp_location9).*
429374b8
JK
150\[\t \]+stop only if \\(a==43\\).*
151\[0-9\]+\[\t \]+breakpoint keep y.* in marker3$marker3_proto at .*$srcfile1:($bp_location17|$bp_location18).*
152\[\t \]+stop only if \\(multi_line_if_conditional\\(1,1,1\\)==0\\).*
153\[0-9\]+\[\t \]+breakpoint keep y.* in marker4$marker4_proto at .*$srcfile1:($bp_location13|$bp_location14).*" \
c906108c
SS
154 "breakpoint info"
155
156
157#
7a292a7a 158# run until the breakpoint at main is hit.
c906108c 159#
7a292a7a
SS
160
161
cce74817 162rerun_to_main
c906108c
SS
163
164#
165# run until the breakpoint at a line number
166#
a1dea79a 167gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
c906108c
SS
168 "run until breakpoint set at a line number"
169
170#
171# run until the breakpoint at marker1
172#
11cf8741
JM
173# If the inferior stops at the first instruction of a source line, GDB
174# won't print the actual PC value; the source line is enough to
175# exactly specify the PC. But if the inferior is instead stopped in
176# the midst of a source line, GDB will include the PC in the
177# breakpoint hit message. This way, GDB always provides the exact
178# stop location, but avoids clutter when possible.
179#
180# Suppose you have a function written completely on one source line, like:
181# int foo (int x) { return 0; }
182# Setting a breakpoint at `foo' actually places the breakpoint after
183# foo's prologue.
184#
185# GCC's STABS writer always emits a line entry attributing the
186# prologue instructions to the line containing the function's open
187# brace, even if the first user instruction is also on that line.
188# This means that, in the case of a one-line function, you will get
189# two line entries in the debug info for the same line: one at the
190# function's entry point, and another at the first user instruction.
191# GDB preserves these duplicated line entries, and prefers the later
192# one; thus, when the program stops after the prologue, at the first
193# user instruction, GDB's search finds the second line entry, decides
194# that the PC is indeed at the beginning of a source line, and doesn't
195# print an address in the breakpoint hit message.
196#
197# GCC's Dwarf2 writer, on the other hand, squeezes out duplicate line
198# entries, so GDB considers the source line to begin at the start of
199# the function's prologue. Thus, if the program stops at the
200# breakpoint, GDB will decide that the PC is not at the beginning of a
201# source line, and will print an address.
202#
203# I think the Dwarf2 writer's behavior is arguably correct, but not
204# helpful. If the user sets a breakpoint at that source line, they
205# want that breakpoint to fall after the prologue. Identifying the
206# prologue's code with the opening brace is nice, but it shouldn't
207# take precedence over real code.
208#
209# Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior.
210send_gdb "continue\n"
211gdb_expect {
a1dea79a 212 -re "Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile1:($bp_location15|$bp_location16).*($bp_location15|$bp_location16)\[\t \]+.*$gdb_prompt $" {
11cf8741
JM
213 pass "run until breakpoint at marker1"
214 }
a1dea79a 215 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile1:($bp_location15|$bp_location16).*($bp_location15|$bp_location16)\[\t \]+.*$gdb_prompt $" {
11cf8741
JM
216 xfail "run until breakpoint at marker1"
217 }
218 -re "$gdb_prompt $" {
219 fail "run until breakpoint at marker1"
220 }
221 timeout {
222 fail "(timeout) run until breakpoint at marker1"
223 }
224}
c906108c 225
c906108c 226# run until the breakpoint at marker2
dfcd3bfb 227# Same issues here as above.
a0b3c4fd 228setup_xfail hppa2.0w-*-* 11512CLLbs
dfcd3bfb
JM
229send_gdb "continue\n"
230gdb_expect {
b6199126 231 -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*$gdb_prompt $" {
dfcd3bfb
JM
232 pass "run until breakpoint at marker2"
233 }
b6199126 234 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*$gdb_prompt $" {
dfcd3bfb
JM
235 xfail "run until breakpoint at marker2"
236 }
237 -re "$gdb_prompt $" {
238 fail "run until breakpoint at marker2"
239 }
240 timeout {
241 fail "(timeout) run until breakpoint at marker2"
242 }
243}
b6199126
DJ
244
245# Test combinations of conditional and thread-specific breakpoints.
246gdb_test "break main if (1==1) thread 999" \
247 "Unknown thread 999\\."
248gdb_test "break main thread 999 if (1==1)" \
249 "Unknown thread 999\\."
250
251# Verify that both if and thread can be distinguished from a breakpoint
252# address expression.
253gdb_test "break *main if (1==1) thread 999" \
254 "Unknown thread 999\\."
255gdb_test "break *main thread 999 if (1==1)" \
256 "Unknown thread 999\\."
257
258# Similarly for task.
259gdb_test "break *main if (1==1) task 999" \
260 "Unknown task 999\\."
261gdb_test "break *main task 999 if (1==1)" \
262 "Unknown task 999\\."
263
264# GDB accepts abbreviations for "thread" and "task".
265gdb_test "break *main if (1==1) t 999" \
266 "Unknown thread 999\\."
267gdb_test "break *main if (1==1) th 999" \
268 "Unknown thread 999\\."
269gdb_test "break *main if (1==1) ta 999" \
270 "Unknown task 999\\."
429374b8
JK
271
272set test "run until breakpoint at marker3"
273gdb_test_multiple "continue" $test {
274 -re "Continuing\\..*Breakpoint \[0-9\]+, marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile1:($bp_location17|$bp_location18).*($bp_location17|$bp_location18)\[\t \]+.*$gdb_prompt $" {
275 pass $test
276 }
277 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile1:($bp_location17|$bp_location18).*($bp_location17|$bp_location18)\[\t \]+.*$gdb_prompt $" {
278 xfail $test
279 }
280}
281
282set test "run until breakpoint at marker4"
283gdb_test_multiple "continue" $test {
284 -re "Continuing\\..*Breakpoint \[0-9\]+, marker4 \\(d=177601976\\) at .*$srcfile1:($bp_location13|$bp_location14).*($bp_location13|$bp_location14)\[\t \]+.*$gdb_prompt $" {
285 pass $test
286 }
287 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:($bp_location13|$bp_location14).*($bp_location13|$bp_location14)\[\t \]+.*$gdb_prompt $" {
288 xfail $test
289 }
290}
This page took 1.042288 seconds and 4 git commands to generate.