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