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