import gdb-1999-11-08 snapshot
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / condbreak.exp
CommitLineData
c2c6d25f 1# Copyright (C) 1997, 1998, 1999 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
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
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.
12#
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. */
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This test was written by Rich Title.
21# Purpose is to test conditional breakpoints.
22# Modeled after "break.exp".
23
c906108c
SS
24if $tracelevel then {
25 strace $tracelevel
26 }
27
28global usestubs
29
30#
31# test running programs
32#
33set prms_id 0
34set bug_id 0
35
c2c6d25f 36set testfile "break"
c906108c
SS
37set srcfile ${testfile}.c
38set binfile ${objdir}/${subdir}/${testfile}
39
40if { [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."
42}
43
085dd6e6
JM
44if [get_compiler_info ${binfile}] {
45 return -1;
46}
47
c906108c
SS
48gdb_exit
49gdb_start
50gdb_reinitialize_dir $srcdir/$subdir
51gdb_load ${binfile}
52
53
54if [target_info exists gdb_stub] {
55 gdb_step_for_stub;
56}
57
58#
59# test break at function
60#
61gdb_test "break main" \
62 "Breakpoint.*at.* file .*$srcfile, line.*" \
63 "breakpoint function"
64
65#
66# test conditional break at function
67#
68gdb_test "break marker1 if 1==1" \
69 "Breakpoint.*at.* file .*$srcfile, line.*" \
70 "break function if condition"
71
72gdb_test "delete 2" \
73 "" \
74 "delete break"
75
76#
77# test conditional break at line number
78#
085dd6e6
JM
79gdb_test "break 79 if 1==1" \
80 "Breakpoint.*at.* file .*$srcfile, line 79\\." \
c906108c
SS
81 "break line if condition"
82
83gdb_test "delete 3" \
84 "" \
85 "delete break"
86
87#
88# test conditional break at function
89#
90gdb_test "break marker1 if (1==1)" \
91 "Breakpoint.*at.* file .*$srcfile, line.*" \
92 "break function if (condition)"
93
94#
95# test conditional break at line number
96#
085dd6e6
JM
97gdb_test "break 79 if (1==1)" \
98 "Breakpoint.*at.* file .*$srcfile, line 79\\." \
c906108c
SS
99 "break line if (condition)"
100
101gdb_test "break marker2 if (a==43)" \
102 "Breakpoint.*at.* file .*$srcfile, line.*" \
103 "break function if (condition)"
104
105#
106# check to see what breakpoints are set
107#
108
085dd6e6
JM
109if {$hp_aCC_compiler} {
110 set marker1_proto "\\(void\\)"
111 set marker2_proto "\\(int\\)"
112} else {
113 set marker1_proto ""
114 set marker2_proto ""
115}
116
117set main_line 75
c906108c
SS
118gdb_test "info break" \
119 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
120\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
085dd6e6 121\[0-9\]+\[\t \]+breakpoint keep y.* in marker1$marker1_proto at .*$srcfile:4\[38\].*
c906108c 122\[\t \]+stop only if 1 == 1.*
085dd6e6 123\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:79.*
c906108c 124\[\t \]+stop only if 1 == 1.*
085dd6e6 125\[0-9\]+\[\t \]+breakpoint keep y.* in marker2$marker2_proto at .*$srcfile:4\[49\].*
c906108c
SS
126\[\t \]+stop only if a == 43.*" \
127 "breakpoint info"
128
129
130#
7a292a7a 131# run until the breakpoint at main is hit.
c906108c 132#
7a292a7a
SS
133
134
cce74817 135rerun_to_main
c906108c
SS
136
137#
138# run until the breakpoint at a line number
139#
085dd6e6 140gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:79.*79\[\t \]+printf.*factorial.*" \
c906108c
SS
141 "run until breakpoint set at a line number"
142
143#
144# run until the breakpoint at marker1
145#
11cf8741
JM
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.
152#
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
156# foo's prologue.
157#
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.
169#
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.
175#
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.
181#
182# Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior.
183send_gdb "continue\n"
184gdb_expect {
185 -re "Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile:4\[38\].*4\[38\]\[\t \]+.*" {
186 pass "run until breakpoint at marker1"
187 }
188 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile:4\[38\].*4\[38\]\[\t \]+.*" {
189 xfail "run until breakpoint at marker1"
190 }
191 -re "$gdb_prompt $" {
192 fail "run until breakpoint at marker1"
193 }
194 timeout {
195 fail "(timeout) run until breakpoint at marker1"
196 }
197}
c906108c
SS
198
199#
200# run until the breakpoint at marker2
201#
a0b3c4fd 202setup_xfail hppa2.0w-*-* 11512CLLbs
085dd6e6 203gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile:4\[49\].*4\[49\]\[\t \]+.*" \
c906108c
SS
204 "run until breakpoint at marker2"
205
206
207
208
209
210
211
212
213
214
215
216
217
218
This page took 0.047431 seconds and 4 git commands to generate.