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