1# Copyright 2000, 2004, 2007, 2008, 2009, 2010, 2011 2# Free Software Foundation, Inc. 3 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17# This file was written by Michael Snyder (msnyder@redhat.com) 18 19if $tracelevel then { 20 strace $tracelevel 21} 22 23 24# re-use the program from the "return2" test. 25if { [prepare_for_testing finish.exp finish return2.c] } { 26 return -1 27} 28 29proc finish_1 { type } { 30 global gdb_prompt 31 32 gdb_test "break ${type}_func" "Breakpoint \[0123456789\].*" \ 33 "set break on ${type}_func" 34 gdb_test "continue" "Breakpoint.* ${type}_func.*" \ 35 "continue to ${type}_func" 36 gdb_test_multiple "finish" "finish from ${type}_func" { 37 -re ".*Value returned is .* = 49 '1'\r\n$gdb_prompt $" { 38 if { $type == "char" } { 39 pass "finish from char_func" 40 } else { 41 fail "finish from ${type}_func" 42 } 43 } 44 -re ".*Value returned is .* = \[0123456789\]* '1'\r\n$gdb_prompt $" { 45 if { $type == "char" } { 46 pass "finish from char_func (non-ASCII char set?)" 47 } else { 48 fail "finish from ${type}_func" 49 } 50 } 51 -re ".*Value returned is .* = 1\r\n$gdb_prompt $" { 52 pass "finish from ${type}_func" 53 } 54 } 55} 56 57proc finish_void { } { 58 global gdb_prompt 59 60 gdb_test "break void_func" "Breakpoint \[0123456789\].*" \ 61 "set break on void_func" 62 gdb_test "continue" "Breakpoint.* void_func.*" \ 63 "continue to void_func" 64 # Some architectures will have one or more instructions after the 65 # call instruction which still is part of the call sequence, so we 66 # must be prepared for a "finish" to show us the void_func call 67 # again as well as the statement after. 68 gdb_test_multiple "finish" "finish from void_func" { 69 -re ".*void_checkpoint.*$gdb_prompt $" { 70 pass "finish from void_func" 71 } 72 -re "0x\[0-9a-fA-F\]+ in main.*call to void_func.*$gdb_prompt $" { 73 pass "finish from void_func" 74 } 75 } 76} 77 78# A function that tests that the given ABBREV is a working abbreviation 79# of the "finish" command. 80 81proc finish_abbreviation { abbrev } { 82 83 if { ! [ runto "int_func" ] } then { 84 fail "running to int_func" 85 return -1 86 } 87 88 gdb_test "$abbrev" \ 89 "Value returned is .* = 1" \ 90 "Testing the \"$abbrev\" abbreviation for \"finish\"" 91} 92 93proc finish_tests { } { 94 global gdb_prompt 95 96 if { ! [ runto_main ] } then { 97 untested finish.exp 98 return -1 99 } 100 101 finish_void 102 finish_1 "char" 103 finish_1 "short" 104 finish_1 "int" 105 finish_1 "long" 106 finish_1 "long_long" 107 if ![target_info exists gdb,skip_float_tests] { 108 finish_1 "float" 109 finish_1 "double" 110 } 111 finish_abbreviation "fin" 112} 113 114set prev_timeout $timeout 115set timeout 30 116finish_tests 117set timeout $prev_timeout 118