1 # Copyright 1997-2001, 2003, 2007-2012 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This test was written by Rich Title.
17 # Purpose is to test conditional breakpoints.
18 # Modeled after "break.exp".
21 # test running programs
25 set srcfile ${testfile}.c
26 set srcfile1 ${testfile}1.c
27 set binfile ${objdir}/${subdir}/${testfile}
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
30 untested condbreak.exp
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
35 untested condbreak.exp
39 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
40 untested condbreak.exp
44 if [get_compiler_info] {
50 gdb_reinitialize_dir $srcdir/$subdir
54 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
55 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
56 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
57 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
58 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
59 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
60 set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1]
61 set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1]
62 set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile1]
63 set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile1]
66 # test break at function
68 gdb_test "break main" \
69 "Breakpoint.*at.* file .*$srcfile, line.*" \
73 # test conditional break at function
75 gdb_test "break marker1 if 1==1" \
76 "Breakpoint.*at.* file .*$srcfile1, line.*"
78 gdb_test_no_output "delete 2"
81 # test conditional break at line number
83 gdb_test "break $srcfile:$bp_location1 if 1==1" \
84 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
86 gdb_test_no_output "delete 3"
89 # test conditional break at function
91 gdb_test "break marker1 if (1==1)" \
92 "Breakpoint.*at.* file .*$srcfile1, line.*"
95 # test conditional break at line number
97 gdb_test "break $srcfile:$bp_location1 if (1==1)" \
98 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
100 gdb_test "break marker2 if (a==43)" \
101 "Breakpoint.*at.* file .*$srcfile1, line.*"
104 # Check break involving inferior function call.
105 # Ensure there is at least one additional breakpoint with higher VMA.
107 gdb_test "break marker3 if (multi_line_if_conditional(1,1,1)==0)" \
108 "Breakpoint.*at.* file .*$srcfile1, line.*"
109 gdb_test "break marker4" \
110 "Breakpoint.*at.* file .*$srcfile1, line.*"
113 # check to see what breakpoints are set
116 if {$hp_aCC_compiler} {
117 set marker1_proto "\\(void\\)"
118 set marker2_proto "\\(int\\)"
120 set marker3_proto "\\(char \\*, char \\*\\)"
121 set marker4_proto "\\(long\\)"
129 gdb_test "info break" \
130 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
131 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location6.*
132 \[0-9\]+\[\t \]+breakpoint keep y.* in marker1$marker1_proto at .*$srcfile1:($bp_location15|$bp_location16).*
133 \[\t \]+stop only if \\(1==1\\).*
134 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
135 \[\t \]+stop only if \\(1==1\\).*
136 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2$marker2_proto at .*$srcfile1:($bp_location8|$bp_location9).*
137 \[\t \]+stop only if \\(a==43\\).*
138 \[0-9\]+\[\t \]+breakpoint keep y.* in marker3$marker3_proto at .*$srcfile1:($bp_location17|$bp_location18).*
139 \[\t \]+stop only if \\(multi_line_if_conditional\\(1,1,1\\)==0\\).*
140 \[0-9\]+\[\t \]+breakpoint keep y.* in marker4$marker4_proto at .*$srcfile1:($bp_location13|$bp_location14).*" \
145 # run until the breakpoint at main is hit.
152 # run until the breakpoint at a line number
154 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
155 "run until breakpoint set at a line number"
158 # run until the breakpoint at marker1
160 # If the inferior stops at the first instruction of a source line, GDB
161 # won't print the actual PC value; the source line is enough to
162 # exactly specify the PC. But if the inferior is instead stopped in
163 # the midst of a source line, GDB will include the PC in the
164 # breakpoint hit message. This way, GDB always provides the exact
165 # stop location, but avoids clutter when possible.
167 # Suppose you have a function written completely on one source line, like:
168 # int foo (int x) { return 0; }
169 # Setting a breakpoint at `foo' actually places the breakpoint after
172 # GCC's STABS writer always emits a line entry attributing the
173 # prologue instructions to the line containing the function's open
174 # brace, even if the first user instruction is also on that line.
175 # This means that, in the case of a one-line function, you will get
176 # two line entries in the debug info for the same line: one at the
177 # function's entry point, and another at the first user instruction.
178 # GDB preserves these duplicated line entries, and prefers the later
179 # one; thus, when the program stops after the prologue, at the first
180 # user instruction, GDB's search finds the second line entry, decides
181 # that the PC is indeed at the beginning of a source line, and doesn't
182 # print an address in the breakpoint hit message.
184 # GCC's Dwarf2 writer, on the other hand, squeezes out duplicate line
185 # entries, so GDB considers the source line to begin at the start of
186 # the function's prologue. Thus, if the program stops at the
187 # breakpoint, GDB will decide that the PC is not at the beginning of a
188 # source line, and will print an address.
190 # I think the Dwarf2 writer's behavior is arguably correct, but not
191 # helpful. If the user sets a breakpoint at that source line, they
192 # want that breakpoint to fall after the prologue. Identifying the
193 # prologue's code with the opening brace is nice, but it shouldn't
194 # take precedence over real code.
196 # Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior.
197 gdb_test_multiple "continue" "run until breakpoint at marker1" {
198 -re "Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile1:($bp_location15|$bp_location16).*($bp_location15|$bp_location16)\[\t \]+.*$gdb_prompt $" {
199 pass "run until breakpoint at marker1"
201 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile1:($bp_location15|$bp_location16).*($bp_location15|$bp_location16)\[\t \]+.*$gdb_prompt $" {
202 xfail "run until breakpoint at marker1"
206 # run until the breakpoint at marker2
207 # Same issues here as above.
208 setup_xfail hppa2.0w-*-* 11512CLLbs
209 gdb_test_multiple "continue" "run until breakpoint at marker2" {
210 -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*$gdb_prompt $" {
211 pass "run until breakpoint at marker2"
213 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*$gdb_prompt $" {
214 xfail "run until breakpoint at marker2"
218 # Test combinations of conditional and thread-specific breakpoints.
219 gdb_test "break main if (1==1) thread 999" \
220 "Unknown thread 999\\."
221 gdb_test "break main thread 999 if (1==1)" \
222 "Unknown thread 999\\."
224 # Verify that both if and thread can be distinguished from a breakpoint
225 # address expression.
226 gdb_test "break *main if (1==1) thread 999" \
227 "Unknown thread 999\\."
228 gdb_test "break *main thread 999 if (1==1)" \
229 "Unknown thread 999\\."
231 # Similarly for task.
232 gdb_test "break *main if (1==1) task 999" \
233 "Unknown task 999\\."
234 gdb_test "break *main task 999 if (1==1)" \
235 "Unknown task 999\\."
237 # GDB accepts abbreviations for "thread" and "task".
238 gdb_test "break *main if (1==1) t 999" \
239 "Unknown thread 999\\."
240 gdb_test "break *main if (1==1) th 999" \
241 "Unknown thread 999\\."
242 gdb_test "break *main if (1==1) ta 999" \
243 "Unknown task 999\\."
245 set test "run until breakpoint at marker3"
246 gdb_test_multiple "continue" $test {
247 -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 $" {
250 -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 set test "run until breakpoint at marker4"
256 gdb_test_multiple "continue" $test {
257 -re "Continuing\\..*Breakpoint \[0-9\]+, marker4 \\(d=177601976\\) at .*$srcfile1:($bp_location13|$bp_location14).*($bp_location13|$bp_location14)\[\t \]+.*$gdb_prompt $" {
260 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:($bp_location13|$bp_location14).*($bp_location13|$bp_location14)\[\t \]+.*$gdb_prompt $" {
265 gdb_test "complete cond 1" "cond 1"
266 gdb_test "set variable \$var = 1"
267 gdb_test "complete cond \$v" "cond \\\$var"
268 gdb_test "complete cond 1 values\[0\].a" "cond 1 values.0..a_field"