]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | # Copyright 2010-2023 Free Software Foundation, Inc. |
b8040f19 JK |
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 | # This test only works on GNU/Linux. | |
079670b9 | 17 | if { ![isnative] || [is_remote host] || [use_gdb_stub] |
3a3dad98 | 18 | || ![istarget *-linux*] || [skip_shlib_tests]} { |
cdd42066 | 19 | return |
b8040f19 JK |
20 | } |
21 | ||
5e3b36f8 JK |
22 | load_lib prelink-support.exp |
23 | ||
b8040f19 | 24 | set test "break-interp" |
a64d2530 | 25 | set binprefix [standard_output_file ${test}] |
b8040f19 JK |
26 | # Only to get the $interp_system name. |
27 | set srcfile_test "start.c" | |
28 | set binfile_test ${test}-test | |
a64d2530 | 29 | set binfile_lib ${binprefix}.so |
06a6f270 JK |
30 | set srcfile "${test}-main.c" |
31 | set srcfile_lib "${test}-lib.c" | |
32 | ||
5e3b36f8 | 33 | # Use -soname so that the new library gets copied by build_executable_own_libs. |
06a6f270 | 34 | |
d8b34041 | 35 | if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug ldflags=-Wl,-soname,${test}.so]] != ""} { |
06a6f270 JK |
36 | return -1 |
37 | } | |
38 | ||
b8040f19 JK |
39 | if {[build_executable ${test}.exp $binfile_test ${srcfile_test} {}] == -1} { |
40 | return -1 | |
41 | } | |
42 | ||
b8040f19 JK |
43 | # Note: The separate debug info file content build-id/crc32 are not verified |
44 | # contrary to the GDB search algorithm skipping non-matching ones. | |
45 | proc system_debug_get {exec} { | |
46 | global debug_root | |
47 | ||
48 | set exec_build_id_debug [build_id_debug_filename_get $exec] | |
49 | set debug_base "[file tail $exec].debug" | |
50 | set exec_dir [file dirname $exec] | |
51 | ||
52 | # isfile returns 1 even for symlinks to files. | |
53 | set retval $debug_root/$exec_build_id_debug | |
54 | if [file isfile $retval] { | |
55 | return $retval | |
56 | } | |
57 | set retval $exec_dir/$debug_base | |
58 | if [file isfile $retval] { | |
59 | return $retval | |
60 | } | |
61 | set retval $exec_dir/.debug/$debug_base | |
62 | if [file isfile $retval] { | |
63 | return $retval | |
64 | } | |
65 | set retval $debug_root/$exec_dir/$debug_base | |
66 | if [file isfile $retval] { | |
67 | return $retval | |
68 | } | |
69 | return "" | |
70 | } | |
71 | ||
72 | gdb_exit | |
73 | gdb_start | |
74 | set debug_root "" | |
75 | set test "show debug-file-directory" | |
76 | gdb_test_multiple $test $test { | |
77 | -re "The directory where separate debug symbols are searched for is \"(.*)\".\r\n$gdb_prompt $" { | |
78 | set debug_root $expect_out(1,string) | |
79 | } | |
80 | } | |
81 | ||
a64d2530 | 82 | set interp_system [section_get [standard_output_file $binfile_test] .interp] |
50810961 TV |
83 | clean_restart $interp_system |
84 | set dl_main_found 0 | |
85 | gdb_test_multiple "info addr dl_main" "" { | |
86 | -re -wrap "Symbol \"dl_main\" is a function at address $hex\\." { | |
87 | set dl_main_found 1 | |
88 | } | |
215b6d10 TV |
89 | -re -wrap "Symbol \"dl_main\" is at $hex in a file compiled without debugging\\." { |
90 | set dl_main_found 1 | |
91 | } | |
50810961 TV |
92 | -re -wrap "No symbol \"dl_main\" in current context\\." { |
93 | } | |
94 | } | |
95 | ||
b8040f19 JK |
96 | set interp_system_debug [system_debug_get $interp_system] |
97 | verbose -log "$interp_system has debug $interp_system_debug" | |
98 | ||
5e3b36f8 JK |
99 | proc prelinkNO {arg {name ""}} { |
100 | return [prelink_no $arg $name] | |
b8040f19 JK |
101 | } |
102 | ||
103 | proc prelinkYES {arg {name ""}} { | |
5e3b36f8 | 104 | return [prelink_yes $arg $name] |
b8040f19 JK |
105 | } |
106 | ||
107 | proc strip_debug {dest} { | |
108 | set test "strip [file tail $dest]" | |
109 | set strip_program [transform strip] | |
110 | set command "exec $strip_program --strip-debug $dest" | |
111 | verbose -log "command is $command" | |
112 | if [catch $command] { | |
113 | fail $test | |
114 | return 0 | |
115 | } else { | |
116 | pass $test | |
117 | return 1 | |
118 | } | |
119 | } | |
120 | ||
a29a3fb7 GB |
121 | # The marker function for the standard runtime linker interface is |
122 | # _dl_debug_state. The probes-based interface has no specific marker | |
123 | # function; the probe we will stop on (init_start) is in dl_main so we | |
124 | # check for that. | |
125 | ||
126 | set solib_bp {(_dl_debug_state|dl_main)} | |
127 | ||
d3d7896d JK |
128 | # Implementation of reach. |
129 | ||
130 | proc reach_1 {func command displacement} { | |
a29a3fb7 | 131 | global gdb_prompt expect_out solib_bp |
ccf26247 | 132 | |
a29a3fb7 | 133 | if {$func == $solib_bp} { |
d3d7896d JK |
134 | # Breakpoint on _dl_debug_state can have problems due to its overlap |
135 | # with the existing internal breakpoint from GDB. | |
136 | gdb_test_no_output "set stop-on-solib-events 1" | |
137 | } elseif {! [gdb_breakpoint $func allow-pending]} { | |
138 | return | |
139 | } | |
b8040f19 | 140 | |
d3d7896d JK |
141 | set test "reach" |
142 | set test_displacement "seen displacement message as $displacement" | |
143 | set debug_state_count 0 | |
144 | gdb_test_multiple $command $test { | |
145 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
146 | # Missing "$gdb_prompt $" is intentional. | |
147 | if {$expect_out(1,string) == "0x0"} { | |
148 | set case "ZERO" | |
149 | } else { | |
150 | set case "NONZERO" | |
ccf26247 | 151 | } |
d3d7896d JK |
152 | if {$displacement == $case || $displacement == "PRESENT"} { |
153 | pass $test_displacement | |
154 | set displacement "FOUND-$displacement" | |
155 | } else { | |
156 | fail $test_displacement | |
157 | } | |
158 | exp_continue | |
159 | } | |
900e11f9 | 160 | -re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" { |
a29a3fb7 | 161 | if {$func == $solib_bp} { |
d3d7896d JK |
162 | fail $test |
163 | } else { | |
b8040f19 JK |
164 | pass $test |
165 | } | |
d3d7896d | 166 | } |
900e11f9 | 167 | -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" { |
a29a3fb7 | 168 | if {$func == $solib_bp} { |
d3d7896d JK |
169 | fail $test |
170 | } else { | |
b8040f19 JK |
171 | pass $test |
172 | } | |
173 | } | |
edcc5120 | 174 | -re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" { |
a29a3fb7 | 175 | if {$func == $solib_bp} { |
d3d7896d JK |
176 | if {$debug_state_count == 0} { |
177 | # First stop does not yet relocate the _start function | |
178 | # descriptor on ppc64. | |
179 | set debug_state_count 1 | |
180 | send_gdb "continue\n" | |
181 | exp_continue | |
182 | } else { | |
183 | pass $test | |
184 | } | |
185 | } else { | |
186 | fail $test | |
187 | } | |
ccf26247 | 188 | } |
b8040f19 | 189 | } |
d3d7896d JK |
190 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
191 | fail $test_displacement | |
192 | } | |
193 | ||
a29a3fb7 | 194 | if {$func == $solib_bp} { |
d3d7896d JK |
195 | gdb_test_no_output "set stop-on-solib-events 0" |
196 | } | |
197 | } | |
198 | ||
199 | # `runto' does not check we stopped really at the function we specified. | |
200 | # DISPLACEMENT can be "NONE" for no message to be present, "ZERO" for | |
201 | # displacement of 0 bytes to be present, "NONZERO" for displacement of non-0 | |
202 | # bytes to be present and "PRESENT" if both "ZERO" and "NONZERO" are valid. | |
2b74ba5a AB |
203 | # |
204 | # The optional ITERATION parameter is used in order to make unique | |
205 | # test prefixes, when calling this proc with the same FUNC name | |
206 | # provide a unique ITERATION value for each call. | |
207 | proc reach {func command displacement {iteration 1}} { | |
208 | set prefix "reach-$func" | |
209 | if { $iteration > 1 } { | |
210 | set prefix "$prefix-$iteration" | |
211 | } | |
212 | with_test_prefix $prefix { | |
6a5870ce PA |
213 | reach_1 $func $command $displacement |
214 | } | |
b8040f19 JK |
215 | } |
216 | ||
0a251e08 YQ |
217 | proc test_core {file displacement} { |
218 | with_test_prefix "core" { | |
219 | global srcdir subdir gdb_prompt expect_out | |
61f0d762 | 220 | |
0a251e08 YQ |
221 | set corefile [core_find $file {} "segv"] |
222 | if {$corefile == ""} { | |
223 | return | |
224 | } | |
ccf26247 | 225 | |
0a251e08 YQ |
226 | gdb_exit |
227 | gdb_start | |
228 | # Clear it to never find any separate debug infos in $debug_root. | |
229 | gdb_test_no_output "set debug-file-directory" \ | |
230 | "set debug-file-directory for core" | |
231 | gdb_reinitialize_dir $srcdir/$subdir | |
232 | gdb_load $file | |
233 | ||
234 | # Print the "PIE (Position Independent Executable) displacement" message. | |
235 | gdb_test_no_output "set verbose on" | |
236 | ||
237 | set test "core loaded" | |
238 | set test_displacement "seen displacement message as $displacement" | |
239 | gdb_test_multiple "core-file $corefile" $test { | |
240 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
241 | # Missing "$gdb_prompt $" is intentional. | |
242 | if {$expect_out(1,string) == "0x0"} { | |
243 | set case "ZERO" | |
244 | } else { | |
245 | set case "NONZERO" | |
246 | } | |
247 | if {$displacement == $case || $displacement == "PRESENT"} { | |
248 | pass $test_displacement | |
249 | set displacement "FOUND-$displacement" | |
250 | } else { | |
251 | fail $test_displacement | |
252 | } | |
253 | exp_continue | |
ccf26247 | 254 | } |
0a251e08 YQ |
255 | -re "Core was generated by .*\r\n#0 .*$gdb_prompt $" { |
256 | # Do not check the binary filename as it may be truncated. | |
257 | pass $test | |
ccf26247 | 258 | } |
ccf26247 | 259 | } |
0a251e08 YQ |
260 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
261 | fail $test_displacement | |
ccf26247 | 262 | } |
1c6c46a0 | 263 | gdb_test_no_output "set verbose off" |
0a251e08 YQ |
264 | |
265 | gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt" | |
ccf26247 | 266 | } |
0a251e08 | 267 | } |
61f0d762 | 268 | |
0a251e08 YQ |
269 | proc test_attach_gdb {file pid displacement prefix} { |
270 | with_test_prefix "$prefix" { | |
271 | global gdb_prompt expect_out | |
ccf26247 | 272 | |
0a251e08 YQ |
273 | gdb_exit |
274 | gdb_start | |
bbfba9ed | 275 | |
0a251e08 YQ |
276 | # Print the "PIE (Position Independent Executable) displacement" message. |
277 | gdb_test_no_output "set verbose on" | |
ccf26247 | 278 | |
3453e7e4 | 279 | gdb_test "file $file" "Reading symbols from .*" "file" |
ccf26247 | 280 | |
0a251e08 YQ |
281 | set test "attach" |
282 | gdb_test_multiple "attach $pid" $test { | |
283 | -re "Attaching to (program: .*, )?process $pid\r\n" { | |
284 | # Missing "$gdb_prompt $" is intentional. | |
285 | pass $test | |
286 | } | |
ccf26247 | 287 | } |
ccf26247 | 288 | |
0a251e08 YQ |
289 | set test "attach final prompt" |
290 | set test_displacement "seen displacement message as $displacement" | |
291 | gdb_test_multiple "" $test { | |
292 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
293 | # Missing "$gdb_prompt $" is intentional. | |
294 | if {$expect_out(1,string) == "0x0"} { | |
295 | set case "ZERO" | |
296 | } else { | |
297 | set case "NONZERO" | |
298 | } | |
299 | if {$displacement == $case || $displacement == "PRESENT"} { | |
300 | pass $test_displacement | |
301 | set displacement "FOUND-$displacement" | |
302 | } else { | |
303 | fail $test_displacement | |
304 | } | |
305 | exp_continue | |
ccf26247 | 306 | } |
0a251e08 YQ |
307 | -re "$gdb_prompt $" { |
308 | pass $test | |
ccf26247 | 309 | } |
ccf26247 | 310 | } |
0a251e08 YQ |
311 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
312 | fail $test_displacement | |
ccf26247 | 313 | } |
1c6c46a0 | 314 | gdb_test_no_output "set verbose off" |
ccf26247 | 315 | |
0a251e08 YQ |
316 | gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "attach main bt" |
317 | gdb_exit | |
318 | } | |
319 | } | |
bbfba9ed | 320 | |
0a1e94c7 JK |
321 | proc test_attach {file displacement {relink_args ""}} { |
322 | global board_info | |
4a2d9c08 | 323 | global exec |
0a1e94c7 JK |
324 | |
325 | gdb_exit | |
326 | ||
327 | set test "sleep function started" | |
328 | ||
329 | set command "${file} sleep" | |
2c8c5d37 PA |
330 | set test_spawn_id [remote_spawn host $command] |
331 | if { $test_spawn_id < 0 || $test_spawn_id == "" } { | |
0a1e94c7 JK |
332 | perror "Spawning $command failed." |
333 | fail $test | |
334 | return | |
335 | } | |
2c8c5d37 | 336 | set pid [spawn_id_get_pid $test_spawn_id] |
0a1e94c7 JK |
337 | gdb_expect { |
338 | -re "sleeping\r\n" { | |
339 | pass $test | |
340 | } | |
341 | eof { | |
342 | fail "$test (eof)" | |
2c8c5d37 | 343 | wait -i $test_spawn_id |
0a1e94c7 JK |
344 | return |
345 | } | |
346 | timeout { | |
347 | fail "$test (timeout)" | |
2c8c5d37 | 348 | kill_wait_spawned_process $test_spawn_id |
0a1e94c7 JK |
349 | return |
350 | } | |
351 | } | |
352 | ||
353 | if {$relink_args == ""} { | |
4a2d9c08 | 354 | test_attach_gdb $exec $pid $displacement "attach" |
0a1e94c7 JK |
355 | } else { |
356 | # These could be rather passed as arguments. | |
4a2d9c08 | 357 | global interp_saved interp |
0a1e94c7 JK |
358 | |
359 | foreach relink {YES NO} { | |
3cd07d20 JK |
360 | # Formerly this test was testing only prelinking of $EXEC. As the |
361 | # prelink command automatically prelinks all of $EXEC's libraries, | |
362 | # even $INTERP got prelinked. Therefore, we formerly had to | |
5e3b36f8 JK |
363 | # `[file_copy $interp_saved $interp]' to make $INTERP not affected |
364 | # by this prelinking of $EXEC. | |
3cd07d20 JK |
365 | # |
366 | # But now we need to test even prelinking of $INTERP. We could | |
367 | # create a separate test to test just the $INTERP prelinking. For | |
368 | # test simplicity, we merged this test and the test above by not | |
369 | # restoring $INTERP after $EXEC prelink. $INTERP gets restored | |
370 | # later below. | |
02835898 JK |
371 | # |
372 | # `(wrong library or version mismatch?)' messages are printed for | |
373 | # $binfile_lib on platforms converting REL->RELA relocations by | |
374 | # prelink (such as on i386). There is no reliable way to verify | |
375 | # the library file matches the running library in such case but | |
376 | # GDB at least attempts to set the right displacement. We test | |
377 | # `libfunc' is present in the backtrace and therefore the | |
378 | # displacement has been guessed right. | |
3cd07d20 JK |
379 | |
380 | if [prelink$relink $relink_args [file tail $exec]] { | |
0a1e94c7 JK |
381 | # /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)". |
382 | test_attach_gdb $exec $pid $displacement "attach-relink$relink" | |
383 | } | |
384 | } | |
5e3b36f8 | 385 | file_copy $interp_saved $interp |
0a1e94c7 JK |
386 | } |
387 | ||
2c8c5d37 | 388 | kill_wait_spawned_process $test_spawn_id |
0a1e94c7 JK |
389 | } |
390 | ||
ccf26247 | 391 | proc test_ld {file ifmain trynosym displacement} { |
a29a3fb7 | 392 | global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp |
50810961 | 393 | global hex dl_main_found |
b8040f19 JK |
394 | |
395 | # First test normal `file'-command loaded $FILE with symbols. | |
396 | ||
397 | gdb_exit | |
398 | gdb_start | |
399 | # Clear it to never find any separate debug infos in $debug_root. | |
27d3a1a2 | 400 | gdb_test_no_output "set debug-file-directory" |
b8040f19 JK |
401 | gdb_reinitialize_dir $srcdir/$subdir |
402 | gdb_load $file | |
403 | ||
ccf26247 | 404 | # Print the "PIE (Position Independent Executable) displacement" message. |
27d3a1a2 | 405 | gdb_test_no_output "set verbose on" |
ccf26247 | 406 | |
4e5799b6 JK |
407 | # We want to test the re-run of a PIE in the case where the executable |
408 | # is loaded with a different displacement, but disable-randomization | |
409 | # prevents that from happening. So turn it off. | |
410 | gdb_test "set disable-randomization off" | |
411 | ||
d3d7896d JK |
412 | if $ifmain { |
413 | gdb_test_no_output "set args segv" | |
414 | } else { | |
a64d2530 | 415 | global binfile_test |
d3d7896d JK |
416 | |
417 | # ld.so needs some executable to run to reach _dl_debug_state. | |
a64d2530 TT |
418 | gdb_test_no_output "set args [standard_output_file $binfile_test]" \ |
419 | "set args OBJDIR/${subdir}/$binfile_test" | |
d3d7896d JK |
420 | } |
421 | ||
2b74ba5a | 422 | reach $solib_bp "run" $displacement 1 |
06a6f270 | 423 | |
1b83d09c AB |
424 | with_test_prefix "first backtrace" { |
425 | gdb_test_no_output "set verbose off" | |
50810961 TV |
426 | gdb_test_multiple "bt" "dl bt" { |
427 | -re -wrap "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" { | |
428 | pass $gdb_test_name | |
429 | } | |
430 | -re -wrap "#0 ($hex) .*" { | |
431 | if { $dl_main_found } { | |
432 | fail $gdb_test_name | |
433 | } else { | |
434 | set pc $expect_out(1,string) | |
435 | regsub "0x0*" $pc "" pc | |
83572821 | 436 | gdb_test "p /x 0x$pc" ".*" "p /x \$pc" |
50810961 TV |
437 | gdb_test_multiple "info probes stap rtld" $gdb_test_name { |
438 | -re -wrap "(?:init_start|init_complete) +0x0*$pc .*" { | |
439 | pass $gdb_test_name | |
440 | } | |
441 | -re -wrap "" { | |
442 | fail $gdb_test_name | |
443 | } | |
444 | } | |
445 | } | |
446 | } | |
447 | } | |
1b83d09c AB |
448 | gdb_test_no_output "set verbose on" |
449 | } | |
06a6f270 | 450 | |
b8040f19 | 451 | if $ifmain { |
86e4bafc | 452 | reach "main" continue "NONE" |
06a6f270 | 453 | |
ccf26247 | 454 | reach "libfunc" continue "NONE" |
06a6f270 | 455 | |
1b83d09c AB |
456 | with_test_prefix "second backtrace" { |
457 | gdb_test_no_output "set verbose off" | |
458 | gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt" | |
459 | gdb_test_no_output "set verbose on" | |
460 | } | |
4e5799b6 | 461 | } |
61f0d762 | 462 | |
4e5799b6 JK |
463 | # Try re-run if the new PIE displacement takes effect. |
464 | gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y" | |
2b74ba5a | 465 | reach $solib_bp "run" $displacement 2 |
1c6c46a0 | 466 | gdb_test_no_output "set verbose off" |
4e5799b6 JK |
467 | |
468 | if $ifmain { | |
ccf26247 | 469 | test_core $file $displacement |
bbfba9ed | 470 | |
ccf26247 | 471 | test_attach $file $displacement |
b8040f19 | 472 | } |
51bee8e9 JK |
473 | |
474 | if !$trynosym { | |
475 | return | |
476 | } | |
477 | ||
11337c2f PA |
478 | with_test_prefix "symbol-less" { |
479 | # Test also `exec-file'-command loaded $FILE - therefore | |
480 | # without symbols. SYMBOL_OBJFILE is not available and only | |
481 | # EXEC_BFD must be used. | |
482 | ||
483 | gdb_exit | |
484 | gdb_start | |
485 | # Clear it to never find any separate debug infos in $debug_root. | |
486 | gdb_test_no_output "set debug-file-directory" | |
487 | gdb_reinitialize_dir $srcdir/$subdir | |
488 | ||
489 | # Print the "PIE (Position Independent Executable) | |
490 | # displacement" message. | |
491 | gdb_test_no_output "set verbose on" | |
492 | ||
493 | # Test no (error) message has been printed by `exec-file'. | |
494 | set escapedfile [string_to_regexp $file] | |
495 | gdb_test "exec-file $file" "exec-file $escapedfile" "load" | |
496 | ||
497 | if $ifmain { | |
2b74ba5a | 498 | reach $solib_bp run $displacement 3 |
11337c2f PA |
499 | |
500 | # Use two separate gdb_test_multiple statements to avoid timeouts due | |
501 | # to slow processing of wildcard capturing long output | |
502 | set test "info files" | |
503 | set entrynohex "" | |
117eb594 TV |
504 | set info_line [join [list \ |
505 | "\r\n" "\[\t\]" "0x\[0-9af\]+" " - " \ | |
506 | "0x\[0-9af\]+" " @ " "0x\[0-9af\]+" \ | |
507 | " is " "\[^\r\n\]+"] ""] | |
11337c2f PA |
508 | gdb_test_multiple $test $test { |
509 | -re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n" { | |
510 | set entrynohex $expect_out(1,string) | |
511 | gdb_test_multiple "" $test { | |
512 | -re "\r\n$gdb_prompt $" { | |
513 | pass $test | |
514 | } | |
117eb594 TV |
515 | -re $info_line { |
516 | # Avoid timeout with check-read1 | |
517 | exp_continue | |
518 | } | |
93c17e06 | 519 | } |
e0cc584e | 520 | } |
51bee8e9 | 521 | } |
e0cc584e | 522 | |
11337c2f PA |
523 | # `info sym' cannot be tested for .opd as the binary may not have |
524 | # symbols. | |
525 | if {[istarget powerpc64-*] && [is_lp64_target]} { | |
526 | set test "convert entry point" | |
527 | gdb_test_multiple "p *(void(*)(void) *) 0x$entrynohex" $test { | |
528 | -re " =( \\(\[^0-9\]*\\))? 0x(\[0-9a-f\]+)( < \[^\r\n\]*)?\r\n$gdb_prompt $" { | |
529 | set entrynohex $expect_out(2,string) | |
530 | pass $test | |
531 | } | |
4569eed2 JK |
532 | } |
533 | } | |
11337c2f PA |
534 | if {$entrynohex != ""} { |
535 | gdb_test "break *0x$entrynohex" "" "break at entry point" | |
536 | gdb_test "continue" "\r\nBreakpoint \[0-9\]+, 0x0*$entrynohex in .*" "entry point reached" | |
537 | } | |
538 | } else { | |
539 | # There is no symbol to break at ld.so. Moreover it can | |
540 | # exit with an error code. | |
541 | ||
542 | set test "ld.so exit" | |
543 | set test_displacement "seen displacement message as $displacement" | |
544 | gdb_test_multiple "run" $test { | |
545 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
546 | # Missing "$gdb_prompt $" is intentional. | |
547 | if {$expect_out(1,string) == "0x0"} { | |
548 | set case "ZERO" | |
549 | } else { | |
550 | set case "NONZERO" | |
551 | } | |
552 | if {$displacement == $case || $displacement == "PRESENT"} { | |
553 | pass $test_displacement | |
554 | set displacement "FOUND-$displacement" | |
555 | } else { | |
556 | fail $test_displacement | |
557 | } | |
558 | exp_continue | |
ccf26247 | 559 | } |
11337c2f PA |
560 | -re "$inferior_exited_re (normally|with code \[0-9\]+).\r\n$gdb_prompt $" { |
561 | # Do not check the binary filename as it may be truncated. | |
562 | pass $test | |
ccf26247 | 563 | } |
ccf26247 | 564 | } |
11337c2f PA |
565 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
566 | fail $test_displacement | |
ccf26247 JK |
567 | } |
568 | } | |
1c6c46a0 | 569 | gdb_test_no_output "set verbose off" |
51bee8e9 | 570 | } |
b8040f19 JK |
571 | } |
572 | ||
573 | # Create separate binaries for each testcase - to make the possible reported | |
574 | # problem reproducible after the whole test run finishes. | |
575 | ||
3f512721 SM |
576 | foreach_with_prefix ldprelink {NO YES} { |
577 | foreach_with_prefix ldsepdebug {NO IN SEP} { | |
b8040f19 JK |
578 | # Skip running the ldsepdebug test if we do not have system separate |
579 | # debug info available. | |
580 | if {$interp_system_debug == "" && $ldsepdebug == "SEP"} { | |
581 | continue | |
582 | } | |
583 | ||
584 | set ldname "LDprelink${ldprelink}debug${ldsepdebug}" | |
585 | set interp $binprefix-$ldname | |
586 | ||
587 | # prelink needs to always prelink all the dependencies to do any file | |
588 | # modifications of its files. ld.so also needs all the dependencies to | |
589 | # be prelinked to omit the relocation process. In-memory file offsets | |
590 | # are not dependent whether ld.so went the prelink way or through the | |
591 | # relocation process. | |
592 | # | |
593 | # For GDB we are not interested whether prelink succeeds as it is | |
594 | # transparent to GDB. GDB is being tested for differences of file | |
595 | # offsets vs. in-memory offsets. So we have to prelink even ld.so for | |
596 | # the BIN modification to happen but we need to restore the original | |
597 | # possibly unprelinked ld.so to test all the combinations for GDB. | |
598 | set interp_saved ${interp}-saved | |
599 | ||
3f512721 SM |
600 | if {$ldsepdebug == "NO"} { |
601 | file_copy $interp_system $interp | |
602 | # Never call strip-debug before unprelink: | |
603 | # prelink: ...: Section .note.gnu.build-id created after prelinking | |
604 | if ![prelinkNO $interp] { | |
605 | continue | |
b8040f19 | 606 | } |
3f512721 SM |
607 | strip_debug $interp |
608 | } elseif {$ldsepdebug == "IN" && $interp_system_debug == ""} { | |
609 | file_copy $interp_system $interp | |
610 | } elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} { | |
611 | file_copy $interp_system $interp | |
612 | file_copy $interp_system_debug "${interp}.debug" | |
613 | # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u | |
614 | if {![prelinkNO $interp] || ![prelinkNO "${interp}.debug"]} { | |
b8040f19 JK |
615 | continue |
616 | } | |
3f512721 SM |
617 | set test "eu-unstrip unprelinked:[file tail $interp_system] + [file tail $interp_system_debug] to [file tail $interp]" |
618 | set command "exec eu-unstrip -o $interp $interp ${interp}.debug" | |
619 | verbose -log "command is $command" | |
620 | if [catch $command] { | |
621 | setup_xfail *-*-* | |
622 | fail $test | |
623 | continue | |
11337c2f | 624 | } else { |
3f512721 | 625 | pass $test |
11337c2f | 626 | } |
3f512721 SM |
627 | } elseif {$ldsepdebug == "SEP" && $interp_system_debug == ""} { |
628 | file_copy $interp_system $interp | |
629 | # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u | |
630 | if ![prelinkNO $interp] { | |
631 | continue | |
632 | } | |
633 | gdb_gnu_strip_debug $interp | |
634 | } elseif {$ldsepdebug == "SEP" && $interp_system_debug != ""} { | |
635 | file_copy $interp_system $interp | |
636 | file_copy $interp_system_debug "${interp}.debug" | |
637 | } | |
b8040f19 | 638 | |
3f512721 SM |
639 | if {$ldsepdebug == "SEP"} { |
640 | if ![prelinkNO "${interp}.debug"] { | |
b8040f19 JK |
641 | continue |
642 | } | |
3f512721 SM |
643 | } else { |
644 | file delete "${interp}.debug" | |
645 | } | |
b8040f19 | 646 | |
1b83d09c | 647 | if ![prelink$ldprelink $interp "[file tail $interp], second time"] { |
3f512721 SM |
648 | continue |
649 | } | |
b8040f19 | 650 | |
3f512721 SM |
651 | if {$ldprelink == "NO"} { |
652 | set displacement "NONZERO" | |
653 | } else { | |
654 | # x86* kernel loads prelinked PIE binary at its | |
655 | # prelinked address but ppc* kernel loads it at a | |
656 | # random address. prelink normally skips PIE binaries | |
657 | # during the system scan. | |
658 | set displacement "PRESENT" | |
659 | } | |
660 | test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement | |
b8040f19 | 661 | |
3f512721 SM |
662 | if ![file_copy $interp $interp_saved] { |
663 | continue | |
664 | } | |
5e3b36f8 | 665 | |
3f512721 SM |
666 | foreach_with_prefix binprelink {NO YES} { |
667 | foreach_with_prefix binsepdebug {NO IN SEP} { | |
668 | # "ATTACH" is like "YES" but it is modified during | |
669 | # run. It cannot be used for problem | |
670 | # reproducibility after the testcase ends. | |
671 | foreach_with_prefix binpie {NO YES ATTACH} { | |
672 | # This combination is not possible, non-PIE (fixed address) | |
673 | # binary cannot be prelinked to any (other) address. | |
674 | if {$binprelink == "YES" && $binpie == "NO"} { | |
675 | continue | |
676 | } | |
5e3b36f8 | 677 | |
3f512721 SM |
678 | set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}" |
679 | set exec $binprefix-$binname | |
b8040f19 | 680 | |
3f512721 SM |
681 | set opts "ldflags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]" |
682 | if {$binsepdebug != "NO"} { | |
683 | lappend opts {debug} | |
684 | } | |
685 | if {$binpie != "NO"} { | |
686 | lappend opts {pie} | |
687 | } else { | |
688 | # Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled. | |
689 | lappend opts {nopie} | |
690 | } | |
691 | ||
692 | set dir ${exec}.d | |
693 | set relink_args [build_executable_own_libs ${test}.exp [file tail $exec] $srcfile $opts $interp $dir] | |
694 | if {$relink_args == ""} { | |
695 | continue | |
696 | } | |
697 | ||
698 | if {$binsepdebug == "SEP"} { | |
699 | gdb_gnu_strip_debug $exec | |
700 | } | |
701 | ||
702 | if {$binpie == "NO"} { | |
703 | set displacement "NONE" | |
704 | } elseif {$binprelink == "NO"} { | |
705 | set displacement "NONZERO" | |
706 | } else { | |
707 | # x86* kernel loads prelinked PIE binary at its prelinked | |
708 | # address but ppc* kernel loads it at a random address. | |
709 | # prelink normally skips PIE binaries during the system scan. | |
710 | set displacement "PRESENT" | |
711 | } | |
712 | ||
713 | if {[prelink$binprelink $relink_args [file tail $exec]] | |
714 | && [file_copy $interp_saved $interp]} { | |
715 | # In order to make test names unique wrap the core of this if block | |
716 | # with a test prefix. Some of the tests performed in the if | |
717 | # condition are repeated within this body. | |
718 | with_test_prefix "INNER" { | |
719 | if {$binpie != "ATTACH"} { | |
720 | test_ld $exec 1 [expr {$binsepdebug == "NO"}] $displacement | |
11337c2f | 721 | } else { |
3f512721 SM |
722 | # If the file has been randomly prelinked it must be |
723 | # "NONZERO". We could see "ZERO" only if it was unprelinked | |
724 | # and it is now running at the same address - which is 0 but | |
725 | # executable can never run at address 0. | |
0a1e94c7 | 726 | |
3f512721 SM |
727 | set displacement "NONZERO" |
728 | test_attach $exec $displacement $relink_args | |
729 | ||
730 | # ATTACH means that executables and libraries have been | |
731 | # modified after they have been run. They cannot be reused | |
732 | # for problem reproducibility after the testcase ends in | |
733 | # the ATTACH case. Therefore they are rather deleted not | |
734 | # to confuse after the run finishes. | |
735 | set exec_debug [system_debug_get $exec] | |
736 | if {$exec_debug != ""} { | |
737 | # `file delete [glob "${exec_debug}*"]' does not work. | |
738 | foreach f [glob "${exec_debug}*"] { | |
739 | file delete $f | |
11337c2f | 740 | } |
0a1e94c7 | 741 | } |
3f512721 SM |
742 | file delete -force $dir |
743 | # `file delete [glob "${exec}*"]' does not work. | |
744 | foreach f [glob "${exec}*"] { | |
745 | file delete $f | |
746 | } | |
0a1e94c7 | 747 | } |
ccf26247 | 748 | } |
b8040f19 JK |
749 | } |
750 | } | |
751 | } | |
11337c2f | 752 | } |
3f512721 SM |
753 | |
754 | file delete $interp_saved | |
b8040f19 JK |
755 | } |
756 | } |