Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2014-2020 Free Software Foundation, Inc. |
078a0207 KS |
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 3 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, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | load_lib compile-support.exp | |
17 | ||
18 | standard_testfile .c compile-shlib.c compile-constvar.S compile-nodebug.c | |
19 | ||
20 | get_compiler_info | |
21 | set options {} | |
678048e8 | 22 | if { [test_compiler_info gcc*] || [test_compiler_info clang*] } { |
078a0207 KS |
23 | lappend options additional_flags=-g3 |
24 | lappend options additional_flags=-std=gnu++11 | |
25 | lappend options c++ | |
26 | } | |
678048e8 GB |
27 | if [test_compiler_info clang*] { |
28 | # Treating C input as C++ is deprecated in Clang, so | |
29 | # the build will fail without disabling -Wdeprecated. | |
30 | lappend options additional_flags=-Wno-deprecated | |
31 | } | |
078a0207 KS |
32 | |
33 | if { ![istarget x86_64-*-* ] || ![is_lp64_target] } { | |
34 | verbose "Skipping x86_64 LOC_CONST test." | |
35 | set srcfile3 "" | |
36 | } | |
37 | ||
38 | set srcfilesoptions [list ${srcfile} ${options}] | |
39 | if { $srcfile3 != "" } { | |
40 | lappend srcfilesoptions $srcfile3 ${options} | |
41 | } | |
678048e8 GB |
42 | set srcfile4options "nodebug c++" |
43 | if [test_compiler_info clang*] { | |
44 | # Treating C input as C++ is deprecated in Clang, so | |
45 | # the build will fail without disabling -Wdeprecated. | |
46 | set srcfile4options "$srcfile4options additional_flags=-Wno-deprecated" | |
47 | } | |
48 | lappend srcfilesoptions $srcfile4 $srcfile4options | |
078a0207 KS |
49 | if { [eval build_executable_from_specs ${testfile}.exp $testfile {$options} ${srcfilesoptions}] } { |
50 | return -1 | |
51 | } | |
52 | ||
53 | clean_restart ${testfile} | |
54 | ||
55 | # | |
56 | # FIXME: Right now, for C++ we just duplicate the C tests, but force | |
57 | # the language to C++ | |
58 | # | |
59 | gdb_test_no_output "set language c++" \ | |
60 | "Set language to C++" | |
61 | ||
62 | if ![runto_main] { | |
63 | return -1 | |
64 | } | |
65 | ||
66 | if {[skip_compile_feature_tests]} { | |
67 | untested "compile command not supported (could not find libcc1 shared library?)" | |
68 | return -1 | |
69 | } | |
70 | ||
71 | # | |
72 | # Test delimiter for code, and arguments. | |
73 | # | |
74 | ||
75 | ||
76 | gdb_test_no_output "compile code globalvar = SOME_MACRO;" \ | |
77 | "set variable from macro" | |
78 | gdb_test "p globalvar" " = 23" "expect 23" | |
79 | ||
80 | gdb_test_no_output "compile code globalvar = ARG_MACRO(0, 0);" \ | |
81 | "set variable from function-like macro" | |
82 | gdb_test "p globalvar" " = -1" "expect -1" | |
83 | ||
84 | gdb_test_no_output "compile code globalvar = 42;" "set variable" | |
85 | gdb_test "p globalvar" " = 42" "expect 42" | |
86 | ||
87 | gdb_test_no_output "compile code globalvar *= 2;" "modify variable" | |
88 | gdb_test "p globalvar" " = 84" "expect 84" | |
89 | ||
90 | gdb_test_no_output "compile file -r ${srcdir}/${subdir}/${testfile}-mod.c" \ | |
91 | "use external source file" | |
92 | gdb_test "p globalvar" " = 7" "expect 7" | |
93 | ||
94 | gdb_test_no_output "compile code func_static (2);" "call static function" | |
95 | gdb_test "p globalvar" " = 9" "expect 9" | |
96 | gdb_test_no_output "compile code func_global (1);" "call global function" | |
97 | gdb_test "p globalvar" " = 8" "expect 8" | |
98 | ||
99 | gdb_test_no_output \ | |
100 | "compile code globalvar = (sizeof (ulonger) == sizeof (long))" \ | |
101 | "compute size of ulonger" | |
102 | gdb_test "p globalvar" " = 1" "check size of ulonger" | |
103 | gdb_test_no_output \ | |
104 | "compile code globalvar = (sizeof (longer) == sizeof (long))" \ | |
105 | "compute size of longer" | |
106 | gdb_test "p globalvar" " = 1" "check size of longer" | |
107 | gdb_test_no_output "compile code globalvar = MINUS_1" | |
108 | gdb_test "p globalvar" " = -1" "check MINUS_1" | |
109 | ||
110 | gdb_test_no_output "compile code globalvar = static_local" | |
111 | gdb_test "p globalvar" " = 77000" "check static_local" | |
112 | ||
113 | gdb_test_no_output \ | |
114 | "compile code static int staticvar = 5; intptr = &staticvar" \ | |
115 | "do not keep jit in memory" | |
116 | gdb_test "p *intptr" "Cannot access memory at address 0x\[0-9a-f\]+" \ | |
117 | "expect 5" | |
118 | ||
119 | gdb_test "compile code func_doesnotexist ();" "error: \'func_doesnotexist\' was not declared in this scope.*" | |
120 | ||
121 | gdb_test "compile code *(volatile int *) 0 = 0;" \ | |
122 | "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB remains in the frame where the signal was received\\.\r\n.*" \ | |
123 | "compile code segfault first" | |
124 | gdb_test "bt" \ | |
125 | "\r\n#0 \[^\r\n\]* in _gdb_expr \[^\r\n\]*\r\n#1 <function called from gdb>\r\n.*" | |
126 | ||
127 | set test "p/x \$pc" | |
128 | set infcall_pc 0 | |
129 | gdb_test_multiple $test $test { | |
130 | -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" { | |
131 | set infcall_pc $expect_out(1,string) | |
132 | pass $test | |
133 | } | |
134 | } | |
135 | ||
136 | gdb_test "info sym $infcall_pc" "\r\n_gdb_expr.*" "info sym found" | |
137 | gdb_test "return" "\r\n#0 main .*" "return" \ | |
138 | "Make _gdb_expr\\(__gdb_regs\\*\\) return now\\? \\(y or n\\) " "y" | |
139 | gdb_test "info sym $infcall_pc" "\r\nNo symbol matches .*" "info sym not found" | |
140 | ||
141 | gdb_test_no_output "set unwindonsignal on" | |
142 | gdb_test "compile code *(volatile int *) 0 = 0;" \ | |
143 | "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB has restored the context to what it was before the call\\.\r\n.*" \ | |
144 | "compile code segfault second" | |
145 | ||
146 | gdb_breakpoint [gdb_get_line_number "break-here"] | |
147 | gdb_continue_to_breakpoint "break-here" ".* break-here .*" | |
148 | ||
149 | # C++ Specific tests. | |
150 | ## Public methods and members | |
151 | ||
152 | gdb_test "print foovar.public_var" "42" \ | |
153 | "Test compile code foovar.public_var = 42 setting." | |
154 | gdb_test_no_output "compile code foovar.public_var = 43;" \ | |
155 | "set foobar.public_var to 43" | |
156 | gdb_test "print foovar.public_var" "43" \ | |
157 | "Test compile code foovar.public_var = 43 setting." | |
158 | gdb_test "print foovar.public_method ()" "43" \ | |
159 | "Test compile code foovar.public_method = 43 setting." | |
160 | ||
161 | ## Private methods and members | |
162 | gdb_test_no_output "compile code foovar.set_private_var (84);" \ | |
163 | "Call class function to set private_var" | |
164 | gdb_test "print foovar.private_var" "84" \ | |
165 | "Test compile code foovar.set_private_var = 84 setting." | |
166 | gdb_test_no_output "compile code foovar.private_var = 85" \ | |
167 | "Directly set a private member in GDB compile5" | |
168 | gdb_test "print foovar.private_var" "85" \ | |
169 | "Test compile code foovar.set_private_var = 85 setting." | |
170 | ||
171 | ## Simple inheritance | |
172 | CompileExpression::new "var" | |
173 | CompileExpression::test "class Baz: public Foo {public: int z = 12;}; Baz bazvar; bazvar.z = 24; var = bazvar.z" 24 -explicit | |
174 | ## Multiple inheritance | |
175 | CompileExpression::test "class MI: public Base, public Base2 {int pure_virt () {return 42;}}; MI MIVar; var = MIVar.pure_virt();" 42 -explicit | |
176 | CompileExpression::test "class MI: public Base, public Base2 {int pure_virt () {return Base::return_value() + 42;}}; MI MIVar; var = MIVar.pure_virt();" 43 -explicit | |
177 | CompileExpression::test "class Base3 {public: int z = 99;}; class MI: public Base, public Base3 {int pure_virt () {return Base3::z + 42;}}; MI MIVar; var = MIVar.pure_virt();" 141 -explicit | |
178 | ||
179 | gdb_test "p localvar" " = 50" "expect localvar 50" | |
180 | ||
181 | gdb_test_no_output "compile code localvar = 12;" "set localvar" | |
182 | gdb_test "p localvar" " = 12" "expect 12" | |
183 | ||
184 | gdb_test_no_output "compile code localvar *= 2;" "modify localvar" | |
185 | gdb_test "p localvar" " = 24" "expect 24" | |
186 | ||
187 | gdb_test_no_output "compile code localvar = shadowed" \ | |
188 | "test shadowing" | |
189 | gdb_test "p localvar" " = 52" "expect 52" | |
190 | ||
191 | gdb_test_no_output "compile code localvar = externed" | |
192 | gdb_test "p localvar" " = 7" "test extern in inner scope" | |
193 | ||
194 | gdb_test_no_output "compile code vla\[2\] = 7" | |
195 | gdb_test "p vla\[2\]" " = 7" | |
196 | gdb_test_no_output \ | |
197 | "compile code localvar = (sizeof (vla) == bound * sizeof (vla\[0\]))" | |
198 | gdb_test "p localvar" " = 1" | |
199 | ||
200 | # | |
201 | # Test setting fields and also many different types. | |
202 | # | |
203 | ||
204 | gdb_test_no_output "compile code struct_object.selffield = (struct_type*)&struct_object" | |
205 | gdb_test "print struct_object.selffield == &struct_object" " = true" | |
206 | ||
207 | gdb_test_no_output "compile code struct_object.charfield = 1" | |
208 | gdb_test "print struct_object.charfield" " = 1 '\\\\001'" | |
209 | gdb_test_no_output "compile code struct_object.ucharfield = 1" | |
210 | gdb_test "print struct_object.ucharfield" " = 1 '\\\\001'" | |
211 | ||
212 | foreach {field value} { | |
213 | shortfield -5 | |
214 | ushortfield 5 | |
215 | intfield -7 | |
216 | uintfield 7 | |
217 | bitfield 2 | |
218 | longfield -9 | |
219 | ulongfield 9 | |
220 | enumfield ONE | |
221 | floatfield 1 | |
222 | doublefield 2 | |
223 | } { | |
224 | gdb_test_no_output "compile code struct_object.$field = $value" | |
225 | gdb_test "print struct_object.$field" " = $value" | |
226 | } | |
227 | ||
228 | gdb_test_no_output "compile code struct_object.arrayfield\[2\] = 7" | |
229 | gdb_test "print struct_object.arrayfield" \ | |
230 | " = \\{0, 0, 7, 0, 0\\}" | |
231 | ||
232 | gdb_test_no_output "compile code struct_object.complexfield = 7 + 5i" | |
981c08ce | 233 | gdb_test "print struct_object.complexfield" " = 7 \\+ 5i" |
078a0207 KS |
234 | |
235 | gdb_test_no_output "compile code struct_object.boolfield = 1" | |
236 | gdb_test "print struct_object.boolfield" " = true" | |
237 | ||
238 | gdb_test_no_output "compile code struct_object.vectorfield\[2\] = 7" | |
239 | gdb_test "print struct_object.vectorfield" \ | |
240 | " = \\{0, 0, 7, 0\\}" | |
241 | ||
242 | gdb_test_no_output "compile code union_object.typedeffield = 7" | |
243 | gdb_test "print union_object.typedeffield" " = 7" | |
244 | gdb_test "print union_object.intfield" " = 7" | |
245 | ||
246 | ||
247 | # LOC_UNRESOLVED tests. | |
248 | ||
249 | gdb_test "print unresolved" " = 20" | |
250 | gdb_test "compile code globalvar = unresolved;" | |
251 | gdb_test "print globalvar" " = 20" "print unresolved value" | |
252 | ||
253 | # Test shadowing with global and static variables. | |
254 | ||
255 | gdb_test_no_output "compile code globalshadow += 1;" | |
256 | gdb_test "print globalshadow" " = 101" | |
257 | gdb_test_no_output "compile code extern int globalshadow; globalshadow += 5;" | |
258 | gdb_test "print 'compile-cplus.c'::globalshadow" " = 15" | |
259 | gdb_test "print globalshadow" " = 101" "print globalshadow second time" | |
260 | gdb_test_no_output "compile code staticshadow += 2;" | |
261 | gdb_test "print staticshadow" " = 202" | |
262 | # "extern int staticshadow;" cannot access static variable. | |
263 | ||
264 | # Raw code cannot refer to locals. | |
265 | # As it references global variable we need the #pragma. | |
266 | # For #pragma we need multiline input. | |
267 | gdb_test_multiple "compile code -r" "compile code -r multiline 1" { -re "\r\n>$" {} } | |
268 | gdb_test_multiple "void _gdb_expr(void) {" "compile code -r multiline 2" { -re "\r\n>$" {} } | |
269 | gdb_test_multiple "#pragma GCC push_user_expression" "compile code -r multiline 3" { -re "\r\n>$" {} } | |
270 | gdb_test_multiple " globalshadow = 77000;" "compile code -r multiline 4" { -re "\r\n>$" {} } | |
271 | gdb_test_multiple "#pragma GCC pop_user_expression" "compile code -r multiline 5" { -re "\r\n>$" {} } | |
272 | gdb_test_multiple "}" "compile code -r multiline 6" { -re "\r\n>$" {} } | |
273 | gdb_test_no_output "end" "compile code -r multiline 7" | |
274 | gdb_test "print 'compile-cplus.c'::globalshadow" " = 77000" \ | |
275 | "check globalshadow with -r" | |
276 | ||
277 | # Test GOT vs. resolving jit function pointers. | |
278 | ||
279 | gdb_test_no_output "compile -raw -- extern \"C\" void abort(); int func(){return 21;} void _gdb_expr(){int (*funcp)()=func; if (funcp()!=21) abort();}" \ | |
280 | "pointer to jit function" | |
281 | ||
282 | # | |
283 | # Test the case where the registers structure would not normally have | |
284 | # any fields. | |
285 | # | |
286 | ||
287 | gdb_breakpoint [gdb_get_line_number "no_args_or_locals breakpoint"] | |
288 | gdb_continue_to_breakpoint "no_args_or_locals" | |
289 | ||
290 | gdb_test_no_output "compile code globalvar = 77;" "set variable to 77" | |
291 | gdb_test "p globalvar" " = 77" "expect 77" | |
292 | ||
293 | ||
294 | # Test reference to minimal_symbol, not (full) symbol. | |
295 | ||
296 | setup_kfail compile/23585 *-*-* | |
297 | gdb_test_no_output "compile code globalvar = func_nodebug (75);" \ | |
298 | "call func_nodebug" | |
299 | ||
300 | setup_kfail compile/23585 *-*-* | |
301 | gdb_test "p globalvar" " = -75" "expect -75" | |
302 | ||
303 | setup_kfail compile/23585 *-*-* | |
304 | gdb_test_no_output \ | |
305 | "compile code int (*funcp) (int) = (int(*)(int))func_nodebug; globalvar = funcp (76);" \ | |
306 | "call func_nodebug indirectly" | |
307 | setup_kfail compile/23585 *-*-* | |
308 | gdb_test "p globalvar" " = -76" "expect -76" | |
309 | ||
310 | ||
311 | # Test compiled module memory protection. | |
312 | ||
313 | gdb_test_no_output "set debug compile on" | |
314 | gdb_test "compile code static const int readonly = 1; *(int *) &readonly = 2;" \ | |
315 | "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB has restored the context to what it was before the call\\.\r\n.*" | |
316 | gdb_test_no_output "set debug compile off" | |
317 | ||
318 | ||
319 | # | |
320 | # Some simple coverage tests. | |
321 | # | |
322 | ||
323 | gdb_test "show debug compile" "Compile debugging is .*" | |
324 | gdb_test "show compile-args" \ | |
325 | "Compile command command-line arguments are .*" | |
326 | gdb_test "compile code -z" "Unknown argument.*" | |
327 | ||
328 | gdb_test "set lang rust" \ | |
329 | "Warning: the current language does not match this frame." | |
330 | gdb_test "compile code globalvar" "No compiler support for language rust\." | |
331 | gdb_test_no_output "set lang auto" | |
332 | ||
333 | gdb_test_no_output "compile code union union_type newdecl_u" | |
334 | gdb_test_no_output "compile code struct struct_type newdecl_s" | |
335 | gdb_test_no_output "compile code inttypedef newdecl_i" | |
336 | ||
337 | gdb_test "compile file" \ | |
338 | "You must provide a filename for this command.*" \ | |
339 | "Test compile file without a filename" | |
340 | gdb_test "compile file -r" \ | |
341 | "You must provide a filename with the raw option set.*" \ | |
342 | "Test compile file and raw option without a filename" | |
343 | gdb_test "compile file -z" \ | |
344 | "Unknown argument.*" \ | |
345 | "Test compile file with unknown argument" | |
346 | ||
347 | ||
348 | # LOC_CONST tests. | |
349 | ||
350 | if { $srcfile3 != "" } { | |
351 | gdb_test "p constvar" " = 3" | |
352 | gdb_test "info addr constvar" {Symbol "constvar" is constant\.} | |
353 | ||
354 | gdb_test_no_output "compile code globalvar = constvar;" | |
355 | gdb_test "print globalvar" " = 3" "print constvar value" | |
356 | } else { | |
357 | untested "print constvar value" | |
358 | } |