xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/annota3.exp (revision 1580a27b92f58fcdcb23fdfbc04a7c2b54a0b7c8)
1# Copyright 2003-2015 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
15
16# This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
18
19# are we on a target board? If so, don't run these tests.
20# note: this is necessary because we cannot use runto_main (which would
21# work for remote targets too) because of the different prompt we get
22# when using annotation level 2.
23#
24if [is_remote target] then {
25    return 0
26}
27
28
29#
30# test running programs
31#
32
33standard_testfile .c
34
35if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
36    untested annota3.exp
37    return -1
38}
39
40
41clean_restart ${binfile}
42
43# The commands we test here produce many lines of output; disable "press
44# <return> to continue" prompts.
45gdb_test_no_output "set height 0"
46
47#
48# break at main
49#
50
51set main_line [gdb_get_line_number "break main"]
52
53gdb_test "break main" \
54    "Breakpoint.*at.* file .*$srcfile, line $main_line\\." \
55    "breakpoint main"
56
57
58# NOTE: this prompt is OK only when the annotation level is > 1
59
60# NOTE: When this prompt is in use the gdb_test procedure cannot be
61# used because it assumes that the last char after the gdb_prompt is a
62# white space. This is not true with this annotated prompt. So we must
63# use send_gdb and gdb_expect or gdb_expect_list.
64
65set old_gdb_prompt $gdb_prompt
66set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
67
68
69
70#
71# set the annotation level to 3
72#
73# of course, this will test:
74# annotate-pre-prompt
75# annotate-prompt
76# annotate-post-prompt (in the next block)
77#
78send_gdb "set annotate 3\n"
79gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
80    "set annotate 3"
81}
82
83#
84# if construct:
85#
86gdb_test_multiple "if 1" "start if construct" {
87    -re "^if 1\r\n\r\n\032\032post-prompt\r\n\r\n\032\032pre-commands\r\n >\r\n\032\032commands\r\n$" {
88	pass "start if construct"
89    }
90}
91
92gdb_test_multiple "end" "end if construct" {
93    -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
94 	pass "end if construct"
95    }
96}
97
98#
99# info break:
100#
101send_gdb "info break\n"
102gdb_expect_list "breakpoint info" "$gdb_prompt$" [concat {
103    "\r\n\032\032post-prompt\r\n"
104    "Num     Type           Disp Enb Address    +What\r\n" } [list \
105    "1       breakpoint     keep y   0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:$main_line\r\n"]]
106
107
108#
109# run to a break point will test:
110#
111#exp_internal 1
112send_gdb "run\n"
113gdb_expect_list "run until main breakpoint" "$gdb_prompt$" [concat {
114    "\r\n\032\032post-prompt\r\n"
115    "Starting program: .*annota3(|\.exe) \r\n"
116    "\r\n\032\032starting\r\n"
117    "\r\n\032\032breakpoint 1\r\n"
118    "\r\n"
119    "Breakpoint 1, "
120    "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
121    "main \\(\\) at .*annota3.c:$main_line\r\n"] [list \
122    "\r\n\032\032source.*annota3.c:$main_line:.*:beg:0x\[0-9a-z\]+\r\n"] {
123    "\r\n\032\032stopped\r\n"
124}]
125#exp_internal 0
126#exit 0
127
128#
129# Let's do a next, to get to a point where the array is initialized
130# We don't care about the annotated output for this operation, it is the same as
131# the one produced by run above
132#
133send_gdb "next\n"
134gdb_expect_list "go after array init line" "$gdb_prompt$" {
135    "\r\n\032\032post-prompt\r\n"
136    "\r\n\032\032starting\r\n"
137    "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
138    "\r\n\032\032stopped\r\n"
139}
140
141
142#
143# printing the array:
144#
145send_gdb "print my_array\n"
146gdb_expect_list "print array" "$gdb_prompt$" {
147    "\r\n\032\032post-prompt\r\n"
148    ".*= .1, 2, 3.\r\n"
149}
150
151
152#
153# this should generate an error message, so to test:
154# annotate-error-begin
155# FIXME: annotate-error not tested
156#
157
158#exp_internal 1
159send_gdb "print non_existent_value\n"
160gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
161    "\r\n\032\032post-prompt\r\n"
162    "\r\n\032\032error-begin\r\n"
163    "No symbol \"non_existent_value\" in current context.\r\n"
164    "\r\n\032\032error\r\n"
165}
166
167
168#
169# break at signal handler
170#
171send_gdb "break handle_USR1\n"
172gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
173    "\r\n\032\032post-prompt\r\n"
174    "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
175}
176
177#
178# break at printf. When we are stopped at printf, we can test
179#
180send_gdb "break printf\n"
181gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
182    "\r\n\032\032post-prompt\r\n"
183    "Breakpoint.*at 0x\[0-9a-z\]+.*"
184}
185
186#
187# get to printf
188#
189send_gdb "continue\n"
190gdb_expect_list "continue to printf" "$gdb_prompt$" {
191    "\r\n\032\032post-prompt\r\n"
192    "Continuing.\r\n"
193    "\r\n\032\032starting\r\n"
194    "\r\n\032\032breakpoint 3\r\n"
195    "\r\n"
196    "Breakpoint 3, \[^\r\n\]*\r\n"
197    "\r\n\032\032stopped\r\n"
198}
199
200send_gdb "backtrace\n"
201gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
202    "\r\n\032\032post-prompt\r\n"
203    "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
204    "#1 .* main \[^\r\n\]*\r\n"
205}
206
207
208#
209# test printing a frame with some arguments:
210#
211
212if [target_info exists gdb,nosignals] {
213    unsupported "send SIGUSR1"
214    unsupported "backtrace @ signal handler"
215} else {
216    send_gdb "signal SIGUSR1\n"
217    gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
218	"\r\n\032\032post-prompt\r\n"
219	"Continuing with signal SIGUSR1.\r\n"
220	"\r\n\032\032starting\r\n"
221	"\r\n\032\032breakpoint 2\r\n"
222	"\r\n"
223	"Breakpoint 2, "
224	"\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
225	"handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
226	"\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
227	"\r\n\032\032stopped\r\n"
228    }
229
230    #
231    # test:
232    #
233    send_gdb "backtrace\n"
234    gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
235	"#0 +handle_USR1 \[^\r\n\]+\r\n"
236	"#1 +.signal handler called.\r\n"
237	"#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
238	"#3 .* main \[^\r\n\]+\r\n"
239    }
240}
241
242#
243# delete all the breakpoints
244#
245send_gdb "delete 1\n"
246gdb_expect_list "delete bp 1" "$gdb_prompt$" {
247    "\r\n\032\032post-prompt\r\n"
248}
249
250send_gdb "delete 2\n"
251gdb_expect_list "delete bp 2" "$gdb_prompt$" {
252    "\r\n\032\032post-prompt\r\n"
253}
254
255send_gdb "delete 3\n"
256gdb_expect_list "delete bp 3" "$gdb_prompt$" {
257    "\r\n\032\032post-prompt\r\n"
258}
259
260#
261# break at main, after value is initialized. This is in preparation
262# to test the annotate output for the display command.
263#
264send_gdb "break main\n"
265gdb_expect_list "break at main" "$gdb_prompt$" [concat {
266    "\r\n\032\032post-prompt\r\n" } [list \
267    "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line $main_line.\r\n"]]
268
269#
270# display the value
271#
272send_gdb "display value\n"
273gdb_expect_list "set up display" "$gdb_prompt$" {
274    "\r\n\032\032post-prompt\r\n"
275    "1: value = 7\r\n"
276}
277
278
279# should ask query. Test annotate-query.
280# we don't care about anything else here, only the query.
281
282send_gdb "run\n"
283gdb_expect {
284  -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
285         send_gdb "y\n"
286         gdb_expect {
287	     -re ".*post-query.*$gdb_prompt$" \
288		     { pass "re-run" }
289	     -re ".*$gdb_prompt$"  { fail "re-run" }
290	     timeout { fail "re-run (timeout)" }
291	 }
292     }
293  -re ".*$gdb_prompt$"  { fail "re-run" }
294  timeout { fail "re-run (timeout)" }
295}
296
297#
298# Test that breakpoints-invalid is issued once and only once for
299# breakpoint ignore count changes, after annotation stopped.
300# NOTE: breakpoints-invalid annotations have been removed from
301# level 3 but keep these tests for continuity and comparison
302# with annota1.exp.
303
304set value_inc_line [gdb_get_line_number "increment value"]
305
306send_gdb "break $value_inc_line\n"
307gdb_expect_list  "break at value++" "$gdb_prompt$" [concat {
308    "\r\n\032\032post-prompt\r\n" } [list \
309    "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line $value_inc_line.\r\n"]]
310
311send_gdb "ignore 5 4\n"
312gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
313    "\r\n\032\032post-prompt\r\n"
314    "Will ignore next 4 crossings of breakpoint 5"
315    "\r\n"
316}
317
318send_gdb "continue\n"
319gdb_expect_list "annotate ignore count change" "$gdb_prompt$" [concat {
320    "\r\n\032\032post-prompt\r\n"
321    "\r\n\032\032breakpoint 5\r\n"
322    "\r\n"
323    "Breakpoint 5, "
324    "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
325    "main \\(\\) at .*annota3.c:$value_inc_line\r\n"] [list \
326    "\r\n\032\032source .*annota3.c:$value_inc_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
327    "1: value = 11\r\n"
328    "\r\n\032\032stopped\r\n"
329}]
330
331# check that ignore command is working, or the above can provide
332# misleading assurance ...
333
334send_gdb "next\n"
335gdb_expect_list "next to exit loop" "$gdb_prompt$"  {
336    "\r\n\032\032post-prompt\r\n"
337    "\r\n\032\032starting\r\n"
338    "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
339    "1: value = 12\r\n"
340    "\r\n\032\032stopped\r\n"
341}
342
343set after_loop_line [gdb_get_line_number "after loop"]
344
345send_gdb "next\n"
346gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" [concat {
347    "\r\n\032\032post-prompt\r\n"
348    "\r\n\032\032starting\r\n" } [list \
349    "\r\n\032\032source.*annota3.c:$after_loop_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
350    "1: value = 12\r\n"
351    "\r\n\032\032stopped\r\n"
352}]
353
354# Get the inferior's PID for later.
355
356set test "get inferior pid"
357set pid -1
358gdb_test_multiple "info inferior 1" "$test" {
359    -re "process (\[0-9\]*).*$gdb_prompt$" {
360	set pid $expect_out(1,string)
361	pass "$test"
362    }
363}
364
365#
366# Send a signal that is not handled
367#
368# SIGTRAP signals are dropped before they get to the inferior process
369# on hpux11.  In theory, this behaivor can be controlled by setting
370# TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
371# the signal to be properly delivered.
372#
373# It has been verified that other signals will be delivered.  However,
374# rather than twiddle the test, I choose to leave it as-is as it
375# exposes an interesting failure on hpux11.
376
377if [target_info exists gdb,nosignals] {
378    unsupported "signal sent"
379} else {
380    setup_xfail hppa*-*-hpux11*
381    send_gdb "signal SIGTRAP\n"
382    gdb_expect_list "signal sent" "$gdb_prompt$" {
383	"\r\n\032\032post-prompt\r\n"
384	"Continuing with signal SIGTRAP.\r\n"
385	"\r\n\032\032starting\r\n"
386	"\r\n\032\032signalled\r\n"
387	"\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
388	"The program no longer exists.\r\n"
389	"\r\n\032\032stopped\r\n"
390    }
391}
392
393
394# Check for production of a core file and remove it!
395
396set test "cleanup core file"
397if { [remote_file host exists core] } {
398    remote_file host delete core
399    pass "$test (removed)"
400} elseif { $pid != -1 && [remote_file host exists core.$pid] } {
401    remote_file host delete core.$pid
402    pass "$test (removed)"
403} else {
404    pass "$test (not dumped)"
405}
406
407# restore the original prompt for the rest of the testsuite
408
409set gdb_prompt $old_gdb_prompt
410