Imported Upstream version 7.9
[platform/upstream/gdb.git] / gdb / testsuite / gdb.arch / amd64-entry-value.cc
1 /* This testcase is part of GDB, the GNU debugger.
2
3    Copyright 2011-2015 Free Software Foundation, Inc.
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 static volatile int v;
19
20 static void __attribute__((noinline, noclone))
21 e (int i, double j)
22 {
23   v = 0;
24 }
25
26 static void __attribute__((noinline, noclone))
27 d (int i, double j)
28 {
29   i++;
30   j++;
31   e (i, j);
32   e (v, v);
33 asm ("breakhere:");
34   e (v, v);
35 }
36
37 static void __attribute__((noinline, noclone))
38 locexpr (int i)
39 {
40   i = i;
41 asm ("breakhere_locexpr:");
42 }
43
44 static void __attribute__((noinline, noclone))
45 c (int i, double j)
46 {
47   d (i * 10, j * 10);
48 }
49
50 static void __attribute__((noinline, noclone))
51 a (int i, double j)
52 {
53   c (i + 1, j + 1);
54 }
55
56 static void __attribute__((noinline, noclone))
57 b (int i, double j)
58 {
59   c (i + 2, j + 2);
60 }
61
62 static void __attribute__((noinline, noclone))
63 amb_z (int i)
64 {
65   d (i + 7, i + 7.5);
66 }
67
68 static void __attribute__((noinline, noclone))
69 amb_y (int i)
70 {
71   amb_z (i + 6);
72 }
73
74 static void __attribute__((noinline, noclone))
75 amb_x (int i)
76 {
77   amb_y (i + 5);
78 }
79
80 static void __attribute__((noinline, noclone))
81 amb (int i)
82 {
83   if (i < 0)
84     amb_x (i + 3);
85   else
86     amb_x (i + 4);
87 }
88
89 static void __attribute__((noinline, noclone))
90 amb_b (int i)
91 {
92   amb (i + 2);
93 }
94
95 static void __attribute__((noinline, noclone))
96 amb_a (int i)
97 {
98   amb_b (i + 1);
99 }
100
101 static void __attribute__((noinline, noclone)) self (int i);
102
103 static void __attribute__((noinline, noclone))
104 self2 (int i)
105 {
106   self (i);
107 }
108
109 static void __attribute__((noinline, noclone))
110 self (int i)
111 {
112   if (i == 200)
113     {
114       /* GCC would inline `self' as `cmovne' without the `self2' indirect.  */
115       self2 (i + 1);
116     }
117   else
118     {
119       e (v, v);
120       d (i + 2, i + 2.5);
121     }
122 }
123
124 static void __attribute__((noinline, noclone))
125 stacktest (int r1, int r2, int r3, int r4, int r5, int r6, int s1, int s2,
126            double d1, double d2, double d3, double d4, double d5, double d6,
127            double d7, double d8, double d9, double da)
128 {
129   s1 = 3;
130   s2 = 4;
131   d9 = 3.5;
132   da = 4.5;
133   e (v, v);
134 asm ("breakhere_stacktest:");
135   e (v, v);
136 }
137
138 /* nodataparam has DW_AT_GNU_call_site_value but it does not have
139    DW_AT_GNU_call_site_data_value.  GDB should not display dereferenced @entry
140    value for it.  */
141
142 static void __attribute__((noinline, noclone))
143 reference (int &regparam, int &nodataparam, int r3, int r4, int r5, int r6,
144            int &stackparam1, int &stackparam2)
145 {
146   int regcopy = regparam, nodatacopy = nodataparam;
147   int stackcopy1 = stackparam1, stackcopy2 = stackparam2;
148
149   regparam = 21;
150   nodataparam = 22;
151   stackparam1 = 31;
152   stackparam2 = 32;
153   e (v, v);
154 asm ("breakhere_reference:");
155   e (v, v);
156 }
157
158 static int *__attribute__((noinline, noclone))
159 datap ()
160 {
161   static int two = 2;
162
163   return &two;
164 }
165
166 static void __attribute__((noinline, noclone))
167 datap_input (int *datap)
168 {
169   (*datap)++;
170 }
171
172 static int __attribute__((noinline, noclone))
173 data (void)
174 {
175   return 10;
176 }
177
178 static int __attribute__((noinline, noclone))
179 data2 (void)
180 {
181   return 20;
182 }
183
184 static int __attribute__((noinline, noclone))
185 different (int val)
186 {
187   val++;
188   e (val, val);
189 asm ("breakhere_different:");
190   return val;
191 }
192
193 static int __attribute__((noinline, noclone))
194 validity (int lost, int born)
195 {
196   lost = data ();
197   e (0, 0.0);
198 asm ("breakhere_validity:");
199   return born;
200 }
201
202 static void __attribute__((noinline, noclone))
203 invalid (int inv)
204 {
205   e (0, 0.0);
206 asm ("breakhere_invalid:");
207 }
208
209 int
210 main ()
211 {
212   d (30, 30.5);
213   locexpr (30);
214   stacktest (1, 2, 3, 4, 5, 6, 11, 12,
215              1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 11.5, 12.5);
216   different (5);
217   validity (5, data ());
218   invalid (data2 ());
219
220   {
221     int regvar = 1, *nodatavarp = datap (), stackvar1 = 11, stackvar2 = 12;
222     reference (regvar, *nodatavarp, 3, 4, 5, 6, stackvar1, stackvar2);
223     datap_input (nodatavarp);
224   }
225
226   if (v)
227     a (1, 1.25);
228   else
229     b (5, 5.25);
230   amb_a (100);
231   self (200);
232   return 0;
233 }