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