Commit | Line | Data |
---|---|---|
4c38e0a4 JB |
1 | # Copyright 2000, 2001, 2004, 2007, 2008, 2009, 2010 |
2 | # Free Software Foundation, Inc. | |
efb66345 MS |
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 | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
efb66345 | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
efb66345 MS |
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. | |
e22f8b7c | 13 | # |
efb66345 | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
efb66345 | 16 | |
efb66345 MS |
17 | # This file was written by Michael Snyder (msnyder@redhat.com) |
18 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
efb66345 MS |
23 | |
24 | set testfile "return2" | |
25 | set srcfile ${testfile}.c | |
26 | set binfile ${objdir}/${subdir}/${testfile} | |
27 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
28 | untested return2.exp |
29 | return -1 | |
efb66345 MS |
30 | } |
31 | ||
32 | proc return_1 { type } { | |
33 | global gdb_prompt | |
34 | ||
35 | gdb_test "break ${type}_func" "Breakpoint \[0123456789\].*" \ | |
36 | "set break on ${type}_func" | |
37 | gdb_test "continue" "Breakpoint.* ${type}_func.*" \ | |
38 | "continue to ${type}_func" | |
02746bbc MS |
39 | |
40 | gdb_test_multiple "return testval.${type}_testval" \ | |
41 | "return from ${type}_func" { | |
42 | -re "Make ${type}_func return now.*y or n. $" { | |
43 | send_gdb "y\n" | |
44 | exp_continue | |
45 | } | |
46 | -re ".*${type}_resultval *= ${type}_func.*$gdb_prompt $" { | |
47 | send_gdb "step\n" | |
48 | exp_continue | |
49 | } | |
50 | -re ".*${type}_checkpoint.*$gdb_prompt $" { | |
51 | pass "return from ${type}_func" | |
52 | } | |
efb66345 | 53 | } |
efb66345 MS |
54 | gdb_test "print ${type}_resultval == testval.${type}_testval" ".* = 1" \ |
55 | "${type} value returned successfully" | |
56 | gdb_test "print ${type}_resultval != ${type}_returnval" ".* = 1" \ | |
57 | "validate result value not equal to program return value" | |
58 | } | |
59 | ||
60 | proc return_void { } { | |
61 | global gdb_prompt | |
62 | ||
63 | gdb_test "break void_func" "Breakpoint \[0123456789\].*" \ | |
64 | "set break on void_func" | |
65 | gdb_test "continue" "Breakpoint.* void_func.*" \ | |
66 | "continue to void_func" | |
02746bbc MS |
67 | |
68 | gdb_test_multiple "return" "return from void_func" { | |
efb66345 MS |
69 | -re "Make void_func return now.*y or n. $" { |
70 | send_gdb "y\n" | |
71 | exp_continue | |
72 | } | |
73 | -re ".*void_func.*call to void_func.*$gdb_prompt $" { | |
74 | send_gdb "step\n" | |
75 | exp_continue | |
76 | } | |
77 | -re ".*void_checkpoint.*$gdb_prompt $" { | |
78 | pass "return from void_func" | |
79 | } | |
efb66345 MS |
80 | } |
81 | gdb_test "print void_test == 0" ".* = 1" \ | |
82 | "void function returned successfully" | |
83 | } | |
84 | ||
85 | proc return2_tests { } { | |
86 | global gdb_prompt | |
87 | ||
3ad13771 | 88 | if { ! [ runto_main ] } then { |
b60f0898 JB |
89 | untested return2.exp |
90 | return -1 | |
efb66345 MS |
91 | } |
92 | ||
93 | return_void | |
94 | return_1 "char" | |
95 | return_1 "short" | |
96 | return_1 "int" | |
97 | return_1 "long" | |
686d097c | 98 | if { ! [istarget "m6811-*-*"] && ![istarget "h8300*-*"] } then { |
d6f5fea1 SC |
99 | return_1 "long_long" |
100 | } | |
efb66345 | 101 | return_1 "float" |
d6f5fea1 SC |
102 | if { ! [istarget "m6811-*-*"] } then { |
103 | return_1 "double" | |
104 | } | |
efb66345 MS |
105 | } |
106 | ||
107 | # Start with a fresh gdb. | |
108 | ||
109 | gdb_exit | |
110 | gdb_start | |
111 | gdb_reinitialize_dir $srcdir/$subdir | |
112 | gdb_load ${binfile} | |
113 | ||
114 | set timeout 30 | |
115 | return2_tests |