summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/pending.exp
blob: f5b196ea9aeb1237a408dcb6d23ae25bc17d4dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#   Copyright 2003, 2004, 2005, 2007, 2008, 2009, 2010
#   Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file was created by Jeff Johnston. (jjohnstn@redhat.com)

if $tracelevel then {
    strace $tracelevel
}

#
# test running programs
#

if {[skip_shlib_tests]} {
    return 0
}

set testfile "pending"
set libfile "pendshr"
set srcfile $testfile.c
set libsrc  $srcdir/$subdir/$libfile.c
set binfile $objdir/$subdir/$testfile
set lib_sl  $objdir/$subdir/$libfile.sl

set lib_opts  debug
set exec_opts [list debug shlib=$lib_sl]

if [get_compiler_info ${binfile}] {
    return -1
}

if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
     || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
    untested "Could not compile either $libsrc or $srcdir/$subdir/$srcfile."
    return -1
}

# Start with a fresh gdb.

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
     -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
	    gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint (without symbols)"
     }
}

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*" \
"single pending breakpoint info (without symbols)"

gdb_load ${binfile}
gdb_load_shlibs $lib_sl

set pendfunc1_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]

gdb_run_cmd

gdb_test "" \
".*Breakpoint.*pendfunc1.*at.*pendshr.c:$pendfunc1_loc.*y = x \\+ 4.*" \
"run to resolved breakpoint 1 (without symbols)"

# Restart with a fresh gdb.

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

gdb_load ${binfile}
gdb_load_shlibs $lib_sl

if [target_info exists gdb_stub] {
    gdb_step_for_stub;
}
#
# Test setting, querying, and modifying pending breakpoints
#

gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
     -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
	    gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint"
     }
}

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*" \
"single pending breakpoint info"

#
# Test breaking at existing function
#

set mainline [gdb_get_line_number "break main here"]

gdb_test "break main" \
    "Breakpoint.*at.* file .*$srcfile, line $mainline.*" \
    "breakpoint function"

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
"pending plus real breakpoint info"


# 
# Test not setting a pending breakpoint 
#
gdb_test "break pendfunc2" \
    "" \
    "Don't set pending breakpoint" \
    ".*Make breakpoint pending.*y or \\\[n\\\]. $" \
    "n"

#
# Add condition to pending breakpoint 
#

gdb_test_no_output "condition 1 k == 1"

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*
\[\t \]+stop only if k == 1.*
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
"pending plus condition"

#
# Disable pending breakpoint
#

gdb_test_no_output "disable 1"

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
\[\t \]+stop only if k == 1.*
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
"pending disabled"

#
# Add commands to pending breakpoint
#
gdb_test "commands 1\nprint k\nend" "" \
    "Set commands for pending breakpoint"

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
\[\t \]+stop only if k == 1.*
\[\t \]+print k.*
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
"pending disabled plus commands"

#
# Try a pending break for a line in a source file with a condition
#

set bp2_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
gdb_test_multiple "break pendshr.c:$bp2_loc if x > 3" "Set pending breakpoint 2" {
     -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
	    gdb_test "y" "Breakpoint.*pendshr.c:$bp2_loc.*pending." \
		"Set pending breakpoint 2"
     }
}

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
\[\t \]+stop only if k == 1.*
\[\t \]+print k.*
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
\[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*" \
"multiple pending breakpoints"


#
# Try a pending break for a line in a source file with ignore count:
#

set bp3_loc [gdb_get_line_number "printf" ${libfile}.c]
gdb_test_multiple "break pendshr.c:$bp3_loc" "Set pending breakpoint 3" {
     -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
	    gdb_test "y" "Breakpoint.*pendshr.c:$bp3_loc.*pending." \
		"Set pending breakpoint 3"
     }
}

gdb_test {ignore $bpnum 2} "Will ignore next 2 crossings of breakpoint .*" \
    "set ignore count on pending breakpoint 3"

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
\[\t \]+stop only if k == 1.*
\[\t \]+print k.*
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
\[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*
\[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp3_loc.*ignore next 2 hits.*" \
"multiple pending breakpoints 2"

#
# Run to main which should resolve a pending breakpoint
#

gdb_run_cmd
gdb_test "" \
".*Breakpoint.*, main.*$mainline.*" \
"running to main"

#
# Re-enable the first pending breakpoint which should resolve
#

gdb_test_no_output "enable 1" \
"re-enabling pending breakpoint that can resolve instantly"

#
# Continue to verify conditionals and commands for breakpoints are honored
#

gdb_test "continue" \
".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*4;" \
"continue to resolved breakpoint 2"

gdb_test "continue" \
".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*
\[$\]1 = 1." \
"continue to resolved breakpoint 1"

#
# Disable the other two breakpoints, and continue to the one with
# the ignore count.  Make sure you hit it the third time, x should
# be 3 then.
#

gdb_test "disable 7" "" "Disable other breakpoints"
gdb_test "disable 5" "" "Disable other breakpoints"

gdb_test "continue" \
	 ".*Breakpoint.*pendfunc1.*\\\(x=3\\\) at.*pendshr.c:$bp3_loc.*printf.*;" \
"continue to resolved breakpoint 3"

delete_breakpoints

gdb_breakpoint "main"

#
# Set non-existent pending breakpoint
#
gdb_test_multiple "break imaginary" "set imaginary pending breakpoint" {
     -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
	    gdb_test "y" "Breakpoint.*imaginary.*pending." \
		"set imaginary pending breakpoint"
     }
}

#
# rerun program and make sure that any pending breakpoint remains and no
# error messages are issued for the missing function
#

rerun_to_main

gdb_test "info break" \
    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
\[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*imaginary.*" \
"verify pending breakpoint after restart"