Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2014-2020 Free Software Foundation, Inc. |
bb2ec1b3 TT |
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 | standard_testfile .c compile-shlib.c compile-constvar.S compile-nodebug.c | |
17 | ||
18 | get_compiler_info | |
19 | set options {} | |
20 | if [test_compiler_info gcc*] { | |
21 | lappend options additional_flags=-g3 | |
22 | } | |
23 | ||
24 | if { ![istarget x86_64-*-* ] || ![is_lp64_target] } { | |
25 | verbose "Skipping x86_64 LOC_CONST test." | |
26 | set srcfile3 "" | |
27 | } | |
28 | ||
29 | set srcfilesoptions [list ${srcfile} ${options}] | |
30 | if { $srcfile3 != "" } { | |
31 | lappend srcfilesoptions $srcfile3 ${options} | |
32 | } | |
33 | lappend srcfilesoptions $srcfile4 "nodebug" | |
34 | if { [eval build_executable_from_specs ${testfile}.exp $testfile {$options} ${srcfilesoptions}] } { | |
35 | return -1 | |
36 | } | |
37 | ||
38 | clean_restart ${testfile} | |
39 | ||
40 | # | |
41 | # Test command without an running inferior. | |
42 | # | |
43 | gdb_test "compile code int i=2;" \ | |
44 | "The program must be running for the compile command to work.*" \ | |
bb95117e | 45 | "test compile code command without running inferior" |
bb2ec1b3 TT |
46 | |
47 | gdb_test "compile int i=2;" \ | |
48 | "The program must be running for the compile command to work.*" \ | |
bb95117e | 49 | "test compile command without running inferior" |
bb2ec1b3 TT |
50 | |
51 | gdb_test "compile file -r ${srcdir}/${subdir}/${testfile}-mod.c" \ | |
52 | "The program must be running for the compile command to work.*" \ | |
bb95117e | 53 | "test compile file command without running inferior" |
bb2ec1b3 TT |
54 | |
55 | if ![runto_main] { | |
56 | return -1 | |
57 | } | |
58 | ||
59 | if {[skip_compile_feature_tests]} { | |
1bc1068a | 60 | untested "compile command not supported (could not find libcc1 shared library?)" |
bb2ec1b3 TT |
61 | return -1 |
62 | } | |
63 | ||
64 | # | |
65 | # Test delimiter for code, and arguments. | |
66 | # | |
67 | ||
68 | gdb_test_no_output "compile -- f = 10" \ | |
cd2ddb6c | 69 | "test abbreviations and code delimiter" |
bb2ec1b3 TT |
70 | |
71 | gdb_test "compile f = 10;" ".*= 10;: No such file.*" \ | |
72 | "Test abbreviations and code collision" | |
73 | ||
3a9558c4 | 74 | gdb_test_no_output "compile -r -- void _gdb_expr(){int i = 5;}" \ |
cd2ddb6c | 75 | "test delimiter with -r" |
bb2ec1b3 | 76 | |
3a9558c4 | 77 | gdb_test_no_output "compile -raw -- void _gdb_expr(){int i = 5;}" \ |
cd2ddb6c | 78 | "test delimiter with -raw" |
bb2ec1b3 | 79 | |
3a9558c4 | 80 | gdb_test "compile -- -r void _gdb_expr(){int i = 5;}" \ |
bb2ec1b3 | 81 | ".* error: 'r' undeclared \\(first use in this function\\).*" \ |
bb95117e | 82 | "test delimiter with -r after it" |
bb2ec1b3 TT |
83 | |
84 | gdb_test "p globalvar" " = 10" "expect 10" | |
85 | ||
86 | gdb_test_no_output "compile code globalvar = 11" \ | |
87 | "set variable without trailing semicolon" | |
88 | gdb_test "p globalvar" " = 11" "check variable without trailing semicolon" | |
89 | ||
90 | gdb_test_no_output "compile code globalvar = SOME_MACRO;" \ | |
91 | "set variable from macro" | |
92 | gdb_test "p globalvar" " = 23" "expect 23" | |
93 | ||
94 | gdb_test_no_output "compile code globalvar = ARG_MACRO(0, 0);" \ | |
95 | "set variable from function-like macro" | |
96 | gdb_test "p globalvar" " = -1" "expect -1" | |
97 | ||
98 | gdb_test_no_output "compile code globalvar = 42;" "set variable" | |
99 | gdb_test "p globalvar" " = 42" "expect 42" | |
100 | ||
101 | gdb_test_no_output "compile code globalvar *= 2;" "modify variable" | |
102 | gdb_test "p globalvar" " = 84" "expect 84" | |
103 | ||
104 | gdb_test_multiple "compile code" "compile code multiline 1" { -re "\r\n>$" {} } | |
105 | gdb_test_multiple "globalvar = 10;" "compile code multiline 2" { -re "\r\n>$" {} } | |
106 | gdb_test_multiple "globalvar *= 2;" "compile code multiline 3" { -re "\r\n>$" {} } | |
107 | gdb_test_no_output "end" "compile code multiline 4" | |
108 | gdb_test "p globalvar" " = 20" "expect 20" | |
109 | ||
110 | gdb_test_no_output "compile file -r ${srcdir}/${subdir}/${testfile}-mod.c" \ | |
111 | "use external source file" | |
112 | gdb_test "p globalvar" " = 7" "expect 7" | |
113 | ||
114 | gdb_test_no_output "compile code func_static (2);" "call static function" | |
115 | gdb_test "p globalvar" " = 9" "expect 9" | |
116 | gdb_test_no_output "compile code func_global (1);" "call global function" | |
117 | gdb_test "p globalvar" " = 8" "expect 8" | |
118 | ||
119 | gdb_test_no_output \ | |
120 | "compile code globalvar = (sizeof (ulonger) == sizeof (long))" \ | |
121 | "compute size of ulonger" | |
122 | gdb_test "p globalvar" " = 1" "check size of ulonger" | |
123 | gdb_test_no_output \ | |
124 | "compile code globalvar = (sizeof (longer) == sizeof (long))" \ | |
125 | "compute size of longer" | |
126 | gdb_test "p globalvar" " = 1" "check size of longer" | |
127 | gdb_test_no_output "compile code globalvar = MINUS_1" | |
128 | gdb_test "p globalvar" " = -1" "check MINUS_1" | |
129 | ||
130 | gdb_test_no_output "compile code globalvar = static_local" | |
131 | gdb_test "p globalvar" " = 77000" "check static_local" | |
132 | ||
133 | gdb_test_no_output "compile code static int staticvar = 5; intptr = &staticvar" \ | |
7f361056 JK |
134 | "do not keep jit in memory" |
135 | gdb_test "p *intptr" "Cannot access memory at address 0x\[0-9a-f\]+" "expect no 5" | |
bb2ec1b3 TT |
136 | |
137 | gdb_test "compile code func_doesnotexist ();" "warning: Could not find symbol \"func_doesnotexist\" for .*" | |
138 | ||
139 | gdb_test "compile code *(volatile int *) 0 = 0;" \ | |
140 | "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.*" \ | |
141 | "compile code segfault first" | |
d8447b6b YQ |
142 | gdb_test "bt" [multi_line \ |
143 | "#0 ($hex in )?_gdb_expr .*" \ | |
144 | "#1 <function called from gdb>" \ | |
145 | "#2 .*" \ | |
146 | ] | |
bb2ec1b3 TT |
147 | |
148 | set test "p/x \$pc" | |
149 | set infcall_pc 0 | |
150 | gdb_test_multiple $test $test { | |
151 | -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" { | |
152 | set infcall_pc $expect_out(1,string) | |
153 | pass $test | |
154 | } | |
155 | } | |
156 | ||
157 | gdb_test "info sym $infcall_pc" "\r\n_gdb_expr .*" "info sym found" | |
158 | gdb_test "return" "\r\n#0 main .*" "return" \ | |
159 | "Make _gdb_expr return now\\? \\(y or n\\) " "y" | |
160 | gdb_test "info sym $infcall_pc" "\r\nNo symbol matches .*" "info sym not found" | |
161 | ||
162 | gdb_test_no_output "set unwindonsignal on" | |
163 | gdb_test "compile code *(volatile int *) 0 = 0;" \ | |
164 | "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.*" \ | |
165 | "compile code segfault second" | |
166 | ||
167 | gdb_breakpoint [gdb_get_line_number "break-here"] | |
168 | gdb_continue_to_breakpoint "break-here" ".* break-here .*" | |
169 | ||
170 | gdb_test "p localvar" " = 50" "expect localvar 50" | |
171 | ||
172 | gdb_test_no_output "compile code localvar = 12;" "set localvar" | |
173 | gdb_test "p localvar" " = 12" "expect 12" | |
174 | ||
175 | gdb_test_no_output "compile code localvar *= 2;" "modify localvar" | |
176 | gdb_test "p localvar" " = 24" "expect 24" | |
177 | ||
178 | gdb_test_no_output "compile code localvar = shadowed" \ | |
179 | "test shadowing" | |
180 | gdb_test "p localvar" " = 52" "expect 52" | |
181 | ||
182 | gdb_test_no_output "compile code localvar = externed" | |
183 | gdb_test "p localvar" " = 7" "test extern in inner scope" | |
184 | ||
185 | gdb_test_no_output "compile code vla\[2\] = 7" | |
186 | gdb_test "p vla\[2\]" " = 7" | |
187 | gdb_test_no_output \ | |
188 | "compile code localvar = (sizeof (vla) == bound * sizeof (vla\[0\]))" | |
189 | gdb_test "p localvar" " = 1" | |
190 | ||
191 | # | |
192 | # Test setting fields and also many different types. | |
193 | # | |
194 | ||
08464196 | 195 | set skip_struct_object 0 |
3a9558c4 JK |
196 | set test "compile code struct_object.selffield = &struct_object" |
197 | gdb_test_multiple $test $test { | |
198 | -re "^$test\r\n$gdb_prompt $" { | |
199 | pass "$test" | |
200 | } | |
08464196 | 201 | -re " error: Unexpected type id from GCC, check you use recent enough GCC\\.\r\n.*\r\n$gdb_prompt $" { |
3a9558c4 | 202 | xfail "$test (PR compile/18202)" |
08464196 JK |
203 | |
204 | # All following tests will break with the same error message. | |
205 | set skip_struct_object 1 | |
3a9558c4 JK |
206 | } |
207 | } | |
bb2ec1b3 | 208 | |
08464196 JK |
209 | if {$skip_struct_object} { |
210 | untested "all struct_object tests" | |
211 | } else { | |
212 | gdb_test "print struct_object.selffield == &struct_object" " = 1" | |
213 | ||
214 | gdb_test_no_output "compile code struct_object.charfield = 1" | |
215 | gdb_test "print struct_object.charfield" " = 1 '\\\\001'" | |
216 | gdb_test_no_output "compile code struct_object.ucharfield = 1" | |
217 | gdb_test "print struct_object.ucharfield" " = 1 '\\\\001'" | |
218 | ||
219 | foreach {field value} { | |
220 | shortfield -5 | |
221 | ushortfield 5 | |
222 | intfield -7 | |
223 | uintfield 7 | |
224 | bitfield 2 | |
225 | longfield -9 | |
226 | ulongfield 9 | |
227 | enumfield ONE | |
228 | floatfield 1 | |
229 | doublefield 2 | |
230 | } { | |
231 | gdb_test_no_output "compile code struct_object.$field = $value" | |
232 | gdb_test "print struct_object.$field" " = $value" | |
233 | } | |
234 | ||
235 | gdb_test_no_output "compile code struct_object.arrayfield\[2\] = 7" | |
236 | gdb_test "print struct_object.arrayfield" \ | |
237 | " = \\{0, 0, 7, 0, 0\\}" | |
238 | ||
239 | gdb_test_no_output "compile code struct_object.complexfield = 7 + 5i" | |
981c08ce | 240 | gdb_test "print struct_object.complexfield" " = 7 \\+ 5i" |
bb2ec1b3 | 241 | |
08464196 JK |
242 | gdb_test_no_output "compile code struct_object.boolfield = 1" |
243 | gdb_test "print struct_object.boolfield" " = true" | |
bb2ec1b3 | 244 | |
08464196 JK |
245 | gdb_test_no_output "compile code struct_object.vectorfield\[2\] = 7" |
246 | gdb_test "print struct_object.vectorfield" \ | |
247 | " = \\{0, 0, 7, 0\\}" | |
bb2ec1b3 | 248 | |
08464196 | 249 | } |
bb2ec1b3 TT |
250 | |
251 | gdb_test_no_output "compile code union_object.typedeffield = 7" | |
252 | gdb_test "print union_object.typedeffield" " = 7" | |
253 | gdb_test "print union_object.intfield" " = 7" | |
254 | ||
255 | ||
256 | # LOC_UNRESOLVED tests. | |
257 | ||
258 | gdb_test "print unresolved" " = 20" | |
c1854f1d | 259 | gdb_test_no_output "compile code globalvar = unresolved;" |
bb2ec1b3 TT |
260 | gdb_test "print globalvar" " = 20" "print unresolved value" |
261 | ||
262 | # Test shadowing with global and static variables. | |
263 | ||
264 | gdb_test_no_output "compile code globalshadow += 1;" | |
265 | gdb_test "print globalshadow" " = 101" | |
266 | gdb_test_no_output "compile code extern int globalshadow; globalshadow += 5;" | |
267 | gdb_test "print 'compile.c'::globalshadow" " = 15" | |
268 | gdb_test "print globalshadow" " = 101" "print globalshadow second time" | |
269 | gdb_test_no_output "compile code staticshadow += 2;" | |
270 | gdb_test "print staticshadow" " = 202" | |
271 | # "extern int staticshadow;" cannot access static variable. | |
272 | ||
273 | # Raw code cannot refer to locals. | |
274 | # As it references global variable we need the #pragma. | |
275 | # For #pragma we need multiline input. | |
276 | gdb_test_multiple "compile code -r" "compile code -r multiline 1" { -re "\r\n>$" {} } | |
277 | gdb_test_multiple "#pragma GCC user_expression" "compile code -r multiline 2" { -re "\r\n>$" {} } | |
278 | gdb_test_multiple "void _gdb_expr(void) { globalshadow = 77000; }" "compile code -r multiline 3" { -re "\r\n>$" {} } | |
279 | gdb_test_no_output "end" "compile code -r multiline 4" | |
280 | gdb_test "print 'compile.c'::globalshadow" " = 77000" \ | |
281 | "check globalshadow with -r" | |
282 | ||
4b62a76e JK |
283 | # Test GOT vs. resolving jit function pointers. |
284 | ||
3a9558c4 | 285 | gdb_test_no_output "compile -raw -- int func(){return 21;} void _gdb_expr(){ void abort (void); int (*funcp)()=func; if (funcp()!=21) abort(); }" \ |
4b62a76e JK |
286 | "pointer to jit function" |
287 | ||
bb2ec1b3 TT |
288 | # |
289 | # Test the case where the registers structure would not normally have | |
290 | # any fields. | |
291 | # | |
292 | ||
293 | gdb_breakpoint [gdb_get_line_number "no_args_or_locals breakpoint"] | |
294 | gdb_continue_to_breakpoint "no_args_or_locals" | |
295 | ||
296 | gdb_test_no_output "compile code globalvar = 77;" "set variable to 77" | |
297 | gdb_test "p globalvar" " = 77" "expect 77" | |
298 | ||
299 | ||
300 | # Test reference to minimal_symbol, not (full) symbol. | |
301 | ||
7022349d PA |
302 | gdb_test "compile code globalvar = func_nodebug (75);" \ |
303 | "warning: function has unknown return type; assuming int" \ | |
bb2ec1b3 TT |
304 | "call func_nodebug" |
305 | gdb_test "p globalvar" " = -75" "expect -75" | |
7022349d PA |
306 | gdb_test \ |
307 | "compile code int (*funcp) (int) = func_nodebug; globalvar = funcp (76);" \ | |
308 | "warning: function has unknown return type; assuming int" \ | |
309 | "call func_nodebug indirectly" | |
bb2ec1b3 TT |
310 | gdb_test "p globalvar" " = -76" "expect -76" |
311 | ||
312 | ||
313 | # Test compiled module memory protection. | |
314 | ||
315 | gdb_test_no_output "set debug compile on" | |
316 | gdb_test "compile code static const int readonly = 1; *(int *) &readonly = 2;" \ | |
317 | "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.*" | |
318 | gdb_test_no_output "set debug compile off" | |
319 | ||
320 | ||
321 | # | |
322 | # Some simple coverage tests. | |
323 | # | |
324 | ||
325 | gdb_test "show debug compile" "Compile debugging is .*" | |
326 | gdb_test "show compile-args" \ | |
327 | "Compile command command-line arguments are .*" | |
e6ed716c | 328 | gdb_test "compile code -z" "Unrecognized option at: -z" |
bb2ec1b3 | 329 | |
9c37b5ae | 330 | gdb_test "set lang rust" \ |
bb2ec1b3 | 331 | "Warning: the current language does not match this frame." |
9c37b5ae | 332 | gdb_test "compile code globalvar" "No compiler support for language rust\\." |
bb2ec1b3 TT |
333 | gdb_test_no_output "set lang auto" |
334 | ||
335 | gdb_test_no_output "compile code union union_type newdecl_u" | |
336 | gdb_test_no_output "compile code struct struct_type newdecl_s" | |
337 | gdb_test_no_output "compile code inttypedef newdecl_i" | |
338 | ||
339 | gdb_test "compile file" \ | |
340 | "You must provide a filename for this command.*" \ | |
341 | "Test compile file without a filename" | |
342 | gdb_test "compile file -r" \ | |
e6ed716c | 343 | "You must provide a filename for this command.*" \ |
bb2ec1b3 TT |
344 | "Test compile file and raw option without a filename" |
345 | gdb_test "compile file -z" \ | |
e6ed716c PA |
346 | "Unrecognized option at: -z" \ |
347 | "test compile file with unknown option" | |
348 | gdb_test "compile file -z --" \ | |
349 | "Unrecognized option at: -z --" \ | |
350 | "test compile file with unknown option plus --" | |
351 | gdb_test "compile file -raw -- -raw" \ | |
352 | "/-raw: No such file or directory.*" \ | |
353 | "test compile file \"-raw\" file" | |
bb2ec1b3 TT |
354 | |
355 | # LOC_CONST tests. | |
356 | ||
357 | if { $srcfile3 != "" } { | |
358 | gdb_test "p constvar" " = 3" | |
359 | gdb_test "info addr constvar" {Symbol "constvar" is constant\.} | |
360 | ||
c1854f1d | 361 | gdb_test_no_output "compile code globalvar = constvar;" |
bb2ec1b3 TT |
362 | gdb_test "print globalvar" " = 3" "print constvar value" |
363 | } else { | |
364 | untested "print constvar value" | |
365 | } | |
366 | ||
367 | # Shared library tests. | |
368 | ||
369 | if {[skip_shlib_tests]} { | |
370 | untested "skipping shlib tests" | |
371 | return; | |
372 | } | |
373 | ||
374 | set libbin [standard_output_file ${testfile}-shlib.so] | |
9553661a PA |
375 | set binfile [standard_output_file ${testfile}-shlib] |
376 | ||
bb2ec1b3 | 377 | if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile2} $libbin {debug}] != "" |
9553661a PA |
378 | || [gdb_compile ${srcdir}/${subdir}/${srcfile} $binfile executable \ |
379 | [list debug shlib=$libbin]] == -1 } { | |
bb2ec1b3 TT |
380 | return -1 |
381 | } | |
382 | ||
9553661a | 383 | clean_restart $binfile |
d9019901 | 384 | gdb_load_shlib $libbin |
9553661a | 385 | |
bb2ec1b3 TT |
386 | if ![runto_main] { |
387 | return -1 | |
388 | } | |
389 | ||
390 | gdb_test_no_output "compile code shlib_func ();" "call shared library function" | |
391 | gdb_test "p globalvar" " = 1" "expect 1" | |
392 | ||
393 | gdb_test_no_output "compile code shlibvar += 5;" "modify shared library variable" | |
394 | gdb_test "p shlibvar" " = 15" "expect 15" |