1 # Copyright (C) 1997, 1998, 1999 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This test was written by Rich Title.
21 # Purpose is to test conditional breakpoints.
22 # Modeled after "break.exp".
31 # test running programs
37 set srcfile ${testfile}.c
38 set binfile ${objdir}/${subdir}/${testfile}
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
41 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44 if [get_compiler_info ${binfile}] {
50 gdb_reinitialize_dir $srcdir/$subdir
54 if [target_info exists gdb_stub] {
59 # test break at function
61 gdb_test "break main" \
62 "Breakpoint.*at.* file .*$srcfile, line.*" \
66 # test conditional break at function
68 gdb_test "break marker1 if 1==1" \
69 "Breakpoint.*at.* file .*$srcfile, line.*" \
70 "break function if condition"
77 # test conditional break at line number
79 gdb_test "break 79 if 1==1" \
80 "Breakpoint.*at.* file .*$srcfile, line 79\\." \
81 "break line if condition"
88 # test conditional break at function
90 gdb_test "break marker1 if (1==1)" \
91 "Breakpoint.*at.* file .*$srcfile, line.*" \
92 "break function if (condition)"
95 # test conditional break at line number
97 gdb_test "break 79 if (1==1)" \
98 "Breakpoint.*at.* file .*$srcfile, line 79\\." \
99 "break line if (condition)"
101 gdb_test "break marker2 if (a==43)" \
102 "Breakpoint.*at.* file .*$srcfile, line.*" \
103 "break function if (condition)"
106 # check to see what breakpoints are set
109 if {$hp_aCC_compiler} {
110 set marker1_proto "\\(void\\)"
111 set marker2_proto "\\(int\\)"
118 gdb_test "info break" \
119 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
120 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
121 \[0-9\]+\[\t \]+breakpoint keep y.* in marker1$marker1_proto at .*$srcfile:4\[38\].*
122 \[\t \]+stop only if 1 == 1.*
123 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:79.*
124 \[\t \]+stop only if 1 == 1.*
125 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2$marker2_proto at .*$srcfile:4\[49\].*
126 \[\t \]+stop only if a == 43.*" \
131 # run until the breakpoint at main is hit.
138 # run until the breakpoint at a line number
140 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:79.*79\[\t \]+printf.*factorial.*" \
141 "run until breakpoint set at a line number"
144 # run until the breakpoint at marker1
146 # If the inferior stops at the first instruction of a source line, GDB
147 # won't print the actual PC value; the source line is enough to
148 # exactly specify the PC. But if the inferior is instead stopped in
149 # the midst of a source line, GDB will include the PC in the
150 # breakpoint hit message. This way, GDB always provides the exact
151 # stop location, but avoids clutter when possible.
153 # Suppose you have a function written completely on one source line, like:
154 # int foo (int x) { return 0; }
155 # Setting a breakpoint at `foo' actually places the breakpoint after
158 # GCC's STABS writer always emits a line entry attributing the
159 # prologue instructions to the line containing the function's open
160 # brace, even if the first user instruction is also on that line.
161 # This means that, in the case of a one-line function, you will get
162 # two line entries in the debug info for the same line: one at the
163 # function's entry point, and another at the first user instruction.
164 # GDB preserves these duplicated line entries, and prefers the later
165 # one; thus, when the program stops after the prologue, at the first
166 # user instruction, GDB's search finds the second line entry, decides
167 # that the PC is indeed at the beginning of a source line, and doesn't
168 # print an address in the breakpoint hit message.
170 # GCC's Dwarf2 writer, on the other hand, squeezes out duplicate line
171 # entries, so GDB considers the source line to begin at the start of
172 # the function's prologue. Thus, if the program stops at the
173 # breakpoint, GDB will decide that the PC is not at the beginning of a
174 # source line, and will print an address.
176 # I think the Dwarf2 writer's behavior is arguably correct, but not
177 # helpful. If the user sets a breakpoint at that source line, they
178 # want that breakpoint to fall after the prologue. Identifying the
179 # prologue's code with the opening brace is nice, but it shouldn't
180 # take precedence over real code.
182 # Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior.
183 send_gdb "continue\n"
185 -re "Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile:4\[38\].*4\[38\]\[\t \]+.*$gdb_prompt $" {
186 pass "run until breakpoint at marker1"
188 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile:4\[38\].*4\[38\]\[\t \]+.*$gdb_prompt $" {
189 xfail "run until breakpoint at marker1"
191 -re "$gdb_prompt $" {
192 fail "run until breakpoint at marker1"
195 fail "(timeout) run until breakpoint at marker1"
199 # run until the breakpoint at marker2
200 # Same issues here as above.
201 setup_xfail hppa2.0w-*-* 11512CLLbs
202 send_gdb "continue\n"
204 -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile:4\[49\].*4\[49\]\[\t \]+.*" {
205 pass "run until breakpoint at marker2"
207 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile:4\[49\].*4\[49\]\[\t \]+.*" {
208 xfail "run until breakpoint at marker2"
210 -re "$gdb_prompt $" {
211 fail "run until breakpoint at marker2"
214 fail "(timeout) run until breakpoint at marker2"