]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.reverse/finish-reverse.c
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.reverse / finish-reverse.c
CommitLineData
28d41a99
MS
1/* This testcase is part of GDB, the GNU debugger.
2
3666a048 3 Copyright 2008-2021 Free Software Foundation, Inc.
28d41a99
MS
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* Test gdb's "return" command in reverse. */
19
20int void_test = 0;
21int main_test = 0;
22
23char char_returnval = '1';
24short short_returnval = 1;
25int int_returnval = 1;
26long long_returnval = 1;
27long long long_long_returnval = 1;
28float float_returnval = 1;
29double double_returnval = 1;
30
31union {
32 char char_testval;
33 short short_testval;
34 int int_testval;
35 long long_testval;
36 long long long_long_testval;
37 float float_testval;
38 double double_testval;
39 char ffff[80];
40} testval;
41
42void void_func ()
43{
44 void_test = 1; /* VOID FUNC */
45}
46
47char char_func ()
48{
49 return char_returnval; /* CHAR FUNC */
50}
51
52short short_func ()
53{
54 return short_returnval; /* SHORT FUNC */
55}
56
57int int_func ()
58{
59 return int_returnval; /* INT FUNC */
60}
61
62long long_func ()
63{
64 return long_returnval; /* LONG FUNC */
65}
66
67long long long_long_func ()
68{
69 return long_long_returnval; /* LONG LONG FUNC */
70}
71
72float float_func ()
73{
74 return float_returnval; /* FLOAT FUNC */
75}
76
77double double_func ()
78{
79 return double_returnval; /* DOUBLE FUNC */
80}
81
82int main (int argc, char **argv)
83{
84 char char_resultval;
85 short short_resultval;
86 int int_resultval;
87 long long_resultval;
88 long long long_long_resultval;
89 float float_resultval;
90 double double_resultval;
91 int i;
92
93 /* A "test load" that will insure that the function really returns
94 a ${type} (as opposed to just a truncated or part of a ${type}). */
95 for (i = 0; i < sizeof (testval.ffff); i++)
96 testval.ffff[i] = 0xff;
97
98 void_func (); /* call to void_func */
99 char_resultval = char_func (); /* void_checkpoint */
100 short_resultval = short_func (); /* char_checkpoint */
101 int_resultval = int_func (); /* short_checkpoint */
102 long_resultval = long_func (); /* int_checkpoint */
103 long_long_resultval = long_long_func (); /* long_checkpoint */
104
105 /* On machines using IEEE floating point, the test pattern of all
106 1-bits established above turns out to be a floating-point NaN
107 ("Not a Number"). According to the IEEE rules, NaN's aren't even
108 equal to themselves. This can lead to stupid conversations with
109 GDB like:
110
111 (gdb) p testval.float_testval == testval.float_testval
112 $7 = 0
113 (gdb)
114
115 This is the correct answer, but it's not the sort of thing
116 return2.exp wants to see. So to make things work the way they
117 ought, we'll set aside the `union' cleverness and initialize the
118 test values explicitly here. These values have interesting bits
119 throughout the value, so we'll still detect truncated values. */
120
121 testval.float_testval = 2.7182818284590452354;/* long_long_checkpoint */
122 float_resultval = float_func ();
123 testval.double_testval = 3.14159265358979323846; /* float_checkpoint */
124 double_resultval = double_func ();
125 main_test = 1; /* double_checkpoint */
126 return 0;
33b9c32b
MS
127} /* end of main */
128