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