064f26e39dcd84559c3f7b541d29e8fc829f2884
[binutils-gdb.git] / gdb / testsuite / gdb.base / finish.exp
1 # Copyright 2000 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 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 file was written by Michael Snyder (msnyder@redhat.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 # re-use the program from the "return2" test.
30 set testfile "return2"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
35 }
36
37 proc finish_1 { type } {
38 global gdb_prompt
39
40 gdb_test "break ${type}_func" "Breakpoint \[0123456789\].*" \
41 "set break on ${type}_func"
42 gdb_test "continue" "Breakpoint.* ${type}_func.*" \
43 "continue to ${type}_func"
44 send_gdb "finish\n"
45 gdb_expect {
46 -re ".*Value returned is .* = 49 '1'\r\n$gdb_prompt $" {
47 if { $type == "char" } {
48 pass "finish from char_func"
49 } else {
50 fail "finish from ${type}_func"
51 }
52 }
53 -re ".*Value returned is .* = \[0123456789\]* '1'\r\n$gdb_prompt $" {
54 if { $type == "char" } {
55 pass "finish from char_func (non-ASCII char set?)"
56 } else {
57 fail "finish from ${type}_func"
58 }
59 }
60 -re ".*Value returned is .* = 1\r\n$gdb_prompt $" {
61 pass "finish from ${type}_func"
62 }
63 -re ".*$gdb_prompt $" {
64 fail "finish from ${type}_func"
65 }
66 timeout {
67 fail "finish from ${type}_func (timeout)"
68 }
69 }
70 }
71
72 proc finish_void { } {
73 global gdb_prompt
74
75 gdb_test "break void_func" "Breakpoint \[0123456789\].*" \
76 "set break on void_func"
77 gdb_test "continue" "Breakpoint.* void_func.*" \
78 "continue to void_func"
79 send_gdb "finish\n"
80 # Some architectures will have one or more instructions after the
81 # call instruction which still is part of the call sequence, so we
82 # must be prepared for a "finish" to show us the void_func call
83 # again as well as the statement after.
84 gdb_expect {
85 -re ".*void_checkpoint.*$gdb_prompt $" {
86 pass "finish from void_func"
87 }
88 -re "0x\[0-9a-fA-F\]+ in main.*call to void_func.*$gdb_prompt $" {
89 pass "finish from void_func"
90 }
91 -re ".*$gdb_prompt $" {
92 fail "finish from void_func"
93 }
94 timeout {
95 fail "finish from void_func (timeout)"
96 }
97 }
98 }
99
100 proc finish_tests { } {
101 global gdb_prompt
102
103 if { ! [ runto main ] } then {
104 gdb_suppress_entire_file "Run to main failed, so all tests in this file will automatically fail."
105 }
106
107 finish_void
108 finish_1 "char"
109 finish_1 "short"
110 finish_1 "int"
111 finish_1 "long"
112 finish_1 "long_long"
113 finish_1 "float"
114 finish_1 "double"
115 }
116
117 # Start with a fresh gdb.
118
119 gdb_exit
120 gdb_start
121 gdb_reinitialize_dir $srcdir/$subdir
122 gdb_load ${binfile}
123
124 set timeout 30
125 finish_tests