Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 2014-2015 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.*" \ | |
45 | "Test compile code command without running inferior" | |
46 | ||
47 | gdb_test "compile int i=2;" \ | |
48 | "The program must be running for the compile command to work.*" \ | |
49 | "Test compile command without running inferior" | |
50 | ||
51 | gdb_test "compile file -r ${srcdir}/${subdir}/${testfile}-mod.c" \ | |
52 | "The program must be running for the compile command to work.*" \ | |
53 | "Test compile file command without running inferior" | |
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" \ | |
69 | "Test abbreviations and code delimiter" | |
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;}" \ |
bb2ec1b3 TT |
75 | "Test delimiter with -r" |
76 | ||
3a9558c4 | 77 | gdb_test_no_output "compile -raw -- void _gdb_expr(){int i = 5;}" \ |
bb2ec1b3 TT |
78 | "Test delimiter with -raw" |
79 | ||
3a9558c4 | 80 | gdb_test "compile -- -r void _gdb_expr(){int i = 5;}" \ |
bb2ec1b3 TT |
81 | ".* error: 'r' undeclared \\(first use in this function\\).*" \ |
82 | "Test delimiter with -r after it" | |
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" | |
142 | gdb_test "bt" \ | |
143 | "\r\n#0 \[^\r\n\]* in _gdb_expr \[^\r\n\]*\r\n#1 <function called from gdb>\r\n.*" | |
144 | ||
145 | set test "p/x \$pc" | |
146 | set infcall_pc 0 | |
147 | gdb_test_multiple $test $test { | |
148 | -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" { | |
149 | set infcall_pc $expect_out(1,string) | |
150 | pass $test | |
151 | } | |
152 | } | |
153 | ||
154 | gdb_test "info sym $infcall_pc" "\r\n_gdb_expr .*" "info sym found" | |
155 | gdb_test "return" "\r\n#0 main .*" "return" \ | |
156 | "Make _gdb_expr return now\\? \\(y or n\\) " "y" | |
157 | gdb_test "info sym $infcall_pc" "\r\nNo symbol matches .*" "info sym not found" | |
158 | ||
159 | gdb_test_no_output "set unwindonsignal on" | |
160 | gdb_test "compile code *(volatile int *) 0 = 0;" \ | |
161 | "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.*" \ | |
162 | "compile code segfault second" | |
163 | ||
164 | gdb_breakpoint [gdb_get_line_number "break-here"] | |
165 | gdb_continue_to_breakpoint "break-here" ".* break-here .*" | |
166 | ||
167 | gdb_test "p localvar" " = 50" "expect localvar 50" | |
168 | ||
169 | gdb_test_no_output "compile code localvar = 12;" "set localvar" | |
170 | gdb_test "p localvar" " = 12" "expect 12" | |
171 | ||
172 | gdb_test_no_output "compile code localvar *= 2;" "modify localvar" | |
173 | gdb_test "p localvar" " = 24" "expect 24" | |
174 | ||
175 | gdb_test_no_output "compile code localvar = shadowed" \ | |
176 | "test shadowing" | |
177 | gdb_test "p localvar" " = 52" "expect 52" | |
178 | ||
179 | gdb_test_no_output "compile code localvar = externed" | |
180 | gdb_test "p localvar" " = 7" "test extern in inner scope" | |
181 | ||
182 | gdb_test_no_output "compile code vla\[2\] = 7" | |
183 | gdb_test "p vla\[2\]" " = 7" | |
184 | gdb_test_no_output \ | |
185 | "compile code localvar = (sizeof (vla) == bound * sizeof (vla\[0\]))" | |
186 | gdb_test "p localvar" " = 1" | |
187 | ||
188 | # | |
189 | # Test setting fields and also many different types. | |
190 | # | |
191 | ||
08464196 | 192 | set skip_struct_object 0 |
3a9558c4 JK |
193 | set test "compile code struct_object.selffield = &struct_object" |
194 | gdb_test_multiple $test $test { | |
195 | -re "^$test\r\n$gdb_prompt $" { | |
196 | pass "$test" | |
197 | } | |
08464196 | 198 | -re " error: Unexpected type id from GCC, check you use recent enough GCC\\.\r\n.*\r\n$gdb_prompt $" { |
3a9558c4 | 199 | xfail "$test (PR compile/18202)" |
08464196 JK |
200 | |
201 | # All following tests will break with the same error message. | |
202 | set skip_struct_object 1 | |
3a9558c4 JK |
203 | } |
204 | } | |
bb2ec1b3 | 205 | |
08464196 JK |
206 | if {$skip_struct_object} { |
207 | untested "all struct_object tests" | |
208 | } else { | |
209 | gdb_test "print struct_object.selffield == &struct_object" " = 1" | |
210 | ||
211 | gdb_test_no_output "compile code struct_object.charfield = 1" | |
212 | gdb_test "print struct_object.charfield" " = 1 '\\\\001'" | |
213 | gdb_test_no_output "compile code struct_object.ucharfield = 1" | |
214 | gdb_test "print struct_object.ucharfield" " = 1 '\\\\001'" | |
215 | ||
216 | foreach {field value} { | |
217 | shortfield -5 | |
218 | ushortfield 5 | |
219 | intfield -7 | |
220 | uintfield 7 | |
221 | bitfield 2 | |
222 | longfield -9 | |
223 | ulongfield 9 | |
224 | enumfield ONE | |
225 | floatfield 1 | |
226 | doublefield 2 | |
227 | } { | |
228 | gdb_test_no_output "compile code struct_object.$field = $value" | |
229 | gdb_test "print struct_object.$field" " = $value" | |
230 | } | |
231 | ||
232 | gdb_test_no_output "compile code struct_object.arrayfield\[2\] = 7" | |
233 | gdb_test "print struct_object.arrayfield" \ | |
234 | " = \\{0, 0, 7, 0, 0\\}" | |
235 | ||
236 | gdb_test_no_output "compile code struct_object.complexfield = 7 + 5i" | |
237 | gdb_test "print struct_object.complexfield" " = 7 \\+ 5 \\* I" | |
bb2ec1b3 | 238 | |
08464196 JK |
239 | gdb_test_no_output "compile code struct_object.boolfield = 1" |
240 | gdb_test "print struct_object.boolfield" " = true" | |
bb2ec1b3 | 241 | |
08464196 JK |
242 | gdb_test_no_output "compile code struct_object.vectorfield\[2\] = 7" |
243 | gdb_test "print struct_object.vectorfield" \ | |
244 | " = \\{0, 0, 7, 0\\}" | |
bb2ec1b3 | 245 | |
08464196 | 246 | } |
bb2ec1b3 TT |
247 | |
248 | gdb_test_no_output "compile code union_object.typedeffield = 7" | |
249 | gdb_test "print union_object.typedeffield" " = 7" | |
250 | gdb_test "print union_object.intfield" " = 7" | |
251 | ||
252 | ||
253 | # LOC_UNRESOLVED tests. | |
254 | ||
255 | gdb_test "print unresolved" " = 20" | |
256 | gdb_test "compile code globalvar = unresolved;" | |
257 | gdb_test "print globalvar" " = 20" "print unresolved value" | |
258 | ||
259 | # Test shadowing with global and static variables. | |
260 | ||
261 | gdb_test_no_output "compile code globalshadow += 1;" | |
262 | gdb_test "print globalshadow" " = 101" | |
263 | gdb_test_no_output "compile code extern int globalshadow; globalshadow += 5;" | |
264 | gdb_test "print 'compile.c'::globalshadow" " = 15" | |
265 | gdb_test "print globalshadow" " = 101" "print globalshadow second time" | |
266 | gdb_test_no_output "compile code staticshadow += 2;" | |
267 | gdb_test "print staticshadow" " = 202" | |
268 | # "extern int staticshadow;" cannot access static variable. | |
269 | ||
270 | # Raw code cannot refer to locals. | |
271 | # As it references global variable we need the #pragma. | |
272 | # For #pragma we need multiline input. | |
273 | gdb_test_multiple "compile code -r" "compile code -r multiline 1" { -re "\r\n>$" {} } | |
274 | gdb_test_multiple "#pragma GCC user_expression" "compile code -r multiline 2" { -re "\r\n>$" {} } | |
275 | gdb_test_multiple "void _gdb_expr(void) { globalshadow = 77000; }" "compile code -r multiline 3" { -re "\r\n>$" {} } | |
276 | gdb_test_no_output "end" "compile code -r multiline 4" | |
277 | gdb_test "print 'compile.c'::globalshadow" " = 77000" \ | |
278 | "check globalshadow with -r" | |
279 | ||
4b62a76e JK |
280 | # Test GOT vs. resolving jit function pointers. |
281 | ||
3a9558c4 | 282 | 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 |
283 | "pointer to jit function" |
284 | ||
bb2ec1b3 TT |
285 | # |
286 | # Test the case where the registers structure would not normally have | |
287 | # any fields. | |
288 | # | |
289 | ||
290 | gdb_breakpoint [gdb_get_line_number "no_args_or_locals breakpoint"] | |
291 | gdb_continue_to_breakpoint "no_args_or_locals" | |
292 | ||
293 | gdb_test_no_output "compile code globalvar = 77;" "set variable to 77" | |
294 | gdb_test "p globalvar" " = 77" "expect 77" | |
295 | ||
296 | ||
297 | # Test reference to minimal_symbol, not (full) symbol. | |
298 | ||
299 | gdb_test_no_output "compile code globalvar = func_nodebug (75);" \ | |
300 | "call func_nodebug" | |
301 | gdb_test "p globalvar" " = -75" "expect -75" | |
302 | gdb_test_no_output \ | |
303 | "compile code int (*funcp) (int) = func_nodebug; globalvar = funcp (76);" \ | |
304 | "call func_nodebug indirectly" | |
305 | gdb_test "p globalvar" " = -76" "expect -76" | |
306 | ||
307 | ||
308 | # Test compiled module memory protection. | |
309 | ||
310 | gdb_test_no_output "set debug compile on" | |
311 | gdb_test "compile code static const int readonly = 1; *(int *) &readonly = 2;" \ | |
312 | "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.*" | |
313 | gdb_test_no_output "set debug compile off" | |
314 | ||
315 | ||
316 | # | |
317 | # Some simple coverage tests. | |
318 | # | |
319 | ||
320 | gdb_test "show debug compile" "Compile debugging is .*" | |
321 | gdb_test "show compile-args" \ | |
322 | "Compile command command-line arguments are .*" | |
323 | gdb_test "compile code -z" "Unknown argument.*" | |
324 | ||
325 | gdb_test "set lang java" \ | |
326 | "Warning: the current language does not match this frame." | |
27dc26ab | 327 | gdb_test "compile code globalvar" "No compiler support for language java\\." |
bb2ec1b3 TT |
328 | gdb_test_no_output "set lang auto" |
329 | ||
330 | gdb_test_no_output "compile code union union_type newdecl_u" | |
331 | gdb_test_no_output "compile code struct struct_type newdecl_s" | |
332 | gdb_test_no_output "compile code inttypedef newdecl_i" | |
333 | ||
334 | gdb_test "compile file" \ | |
335 | "You must provide a filename for this command.*" \ | |
336 | "Test compile file without a filename" | |
337 | gdb_test "compile file -r" \ | |
338 | "You must provide a filename with the raw option set.*" \ | |
339 | "Test compile file and raw option without a filename" | |
340 | gdb_test "compile file -z" \ | |
341 | "Unknown argument.*" \ | |
342 | "Test compile file with unknown argument" | |
343 | ||
344 | ||
345 | # LOC_CONST tests. | |
346 | ||
347 | if { $srcfile3 != "" } { | |
348 | gdb_test "p constvar" " = 3" | |
349 | gdb_test "info addr constvar" {Symbol "constvar" is constant\.} | |
350 | ||
351 | gdb_test "compile code globalvar = constvar;" | |
352 | gdb_test "print globalvar" " = 3" "print constvar value" | |
353 | } else { | |
354 | untested "print constvar value" | |
355 | } | |
356 | ||
357 | # Shared library tests. | |
358 | ||
359 | if {[skip_shlib_tests]} { | |
360 | untested "skipping shlib tests" | |
361 | return; | |
362 | } | |
363 | ||
364 | set libbin [standard_output_file ${testfile}-shlib.so] | |
365 | if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile2} $libbin {debug}] != "" | |
366 | || [build_executable $testfile ${testfile}-shlib $srcfile \ | |
367 | [list debug ldflags=$libbin]] == -1 } { | |
368 | return -1 | |
369 | } | |
370 | ||
371 | clean_restart ${testfile}-shlib | |
372 | if ![runto_main] { | |
373 | return -1 | |
374 | } | |
375 | ||
376 | gdb_test_no_output "compile code shlib_func ();" "call shared library function" | |
377 | gdb_test "p globalvar" " = 1" "expect 1" | |
378 | ||
379 | gdb_test_no_output "compile code shlibvar += 5;" "modify shared library variable" | |
380 | gdb_test "p shlibvar" " = 15" "expect 15" |