2011-01-01 15:34:07 +00:00
|
|
|
# Copyright 2010, 2011 Free Software Foundation, Inc.
|
2010-01-14 20:48:26 +00:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# This test only works on GNU/Linux.
|
2010-01-14 21:04:53 +00:00
|
|
|
if { ![isnative] || [is_remote host] || ![istarget *-linux*] || [skip_shlib_tests]} {
|
2010-01-14 20:48:26 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2010-07-05 18:01:53 +00:00
|
|
|
load_lib prelink-support.exp
|
|
|
|
|
2010-01-14 20:48:26 +00:00
|
|
|
set test "break-interp"
|
|
|
|
set binprefix ${objdir}/${subdir}/${test}
|
|
|
|
# Only to get the $interp_system name.
|
|
|
|
set srcfile_test "start.c"
|
|
|
|
set binfile_test ${test}-test
|
2010-01-14 21:04:53 +00:00
|
|
|
set binfile_lib ${objdir}/${subdir}/${test}.so
|
|
|
|
set srcfile "${test}-main.c"
|
|
|
|
set srcfile_lib "${test}-lib.c"
|
|
|
|
|
|
|
|
if [get_compiler_info ${binfile_lib}] {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2010-07-05 18:01:53 +00:00
|
|
|
# Use -soname so that the new library gets copied by build_executable_own_libs.
|
2010-01-14 21:04:53 +00:00
|
|
|
|
2010-10-12 18:12:49 +00:00
|
|
|
if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug ldflags=-Wl,-soname,${test}.so]] != ""} {
|
2010-01-14 21:04:53 +00:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2010-01-14 20:48:26 +00:00
|
|
|
if {[build_executable ${test}.exp $binfile_test ${srcfile_test} {}] == -1} {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Note: The separate debug info file content build-id/crc32 are not verified
|
|
|
|
# contrary to the GDB search algorithm skipping non-matching ones.
|
|
|
|
proc system_debug_get {exec} {
|
|
|
|
global debug_root
|
|
|
|
|
|
|
|
set exec_build_id_debug [build_id_debug_filename_get $exec]
|
|
|
|
set debug_base "[file tail $exec].debug"
|
|
|
|
set exec_dir [file dirname $exec]
|
|
|
|
|
|
|
|
# isfile returns 1 even for symlinks to files.
|
|
|
|
set retval $debug_root/$exec_build_id_debug
|
|
|
|
if [file isfile $retval] {
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
set retval $exec_dir/$debug_base
|
|
|
|
if [file isfile $retval] {
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
set retval $exec_dir/.debug/$debug_base
|
|
|
|
if [file isfile $retval] {
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
set retval $debug_root/$exec_dir/$debug_base
|
|
|
|
if [file isfile $retval] {
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
set debug_root ""
|
|
|
|
set test "show debug-file-directory"
|
|
|
|
gdb_test_multiple $test $test {
|
|
|
|
-re "The directory where separate debug symbols are searched for is \"(.*)\".\r\n$gdb_prompt $" {
|
|
|
|
set debug_root $expect_out(1,string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set interp_system [section_get ${objdir}/${subdir}/$binfile_test .interp]
|
|
|
|
set interp_system_debug [system_debug_get $interp_system]
|
|
|
|
verbose -log "$interp_system has debug $interp_system_debug"
|
|
|
|
|
2010-07-05 18:01:53 +00:00
|
|
|
proc prelinkNO {arg {name ""}} {
|
|
|
|
return [prelink_no $arg $name]
|
2010-01-14 20:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proc prelinkYES {arg {name ""}} {
|
2010-07-05 18:01:53 +00:00
|
|
|
return [prelink_yes $arg $name]
|
2010-01-14 20:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proc strip_debug {dest} {
|
|
|
|
set test "strip [file tail $dest]"
|
|
|
|
set strip_program [transform strip]
|
|
|
|
set command "exec $strip_program --strip-debug $dest"
|
|
|
|
verbose -log "command is $command"
|
|
|
|
if [catch $command] {
|
|
|
|
fail $test
|
|
|
|
return 0
|
|
|
|
} else {
|
|
|
|
pass $test
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:47:47 +00:00
|
|
|
# Implementation of reach.
|
|
|
|
|
|
|
|
proc reach_1 {func command displacement} {
|
2010-03-11 22:07:03 +00:00
|
|
|
global gdb_prompt expect_out
|
|
|
|
|
2010-10-11 08:47:47 +00:00
|
|
|
if {$func == "_dl_debug_state"} {
|
|
|
|
# Breakpoint on _dl_debug_state can have problems due to its overlap
|
|
|
|
# with the existing internal breakpoint from GDB.
|
|
|
|
gdb_test_no_output "set stop-on-solib-events 1"
|
|
|
|
} elseif {! [gdb_breakpoint $func allow-pending]} {
|
|
|
|
return
|
|
|
|
}
|
2010-01-14 20:48:26 +00:00
|
|
|
|
2010-10-11 08:47:47 +00:00
|
|
|
set test "reach"
|
|
|
|
set test_displacement "seen displacement message as $displacement"
|
|
|
|
set debug_state_count 0
|
|
|
|
gdb_test_multiple $command $test {
|
|
|
|
-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
|
|
|
|
# Missing "$gdb_prompt $" is intentional.
|
|
|
|
if {$expect_out(1,string) == "0x0"} {
|
|
|
|
set case "ZERO"
|
|
|
|
} else {
|
|
|
|
set case "NONZERO"
|
2010-03-11 22:07:03 +00:00
|
|
|
}
|
2010-10-11 08:47:47 +00:00
|
|
|
if {$displacement == $case || $displacement == "PRESENT"} {
|
|
|
|
pass $test_displacement
|
|
|
|
set displacement "FOUND-$displacement"
|
|
|
|
} else {
|
|
|
|
fail $test_displacement
|
|
|
|
}
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re "Breakpoint \[0-9\]+, \\.?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
|
|
|
|
if {$func == "_dl_debug_state"} {
|
|
|
|
fail $test
|
|
|
|
} else {
|
2010-01-14 20:48:26 +00:00
|
|
|
pass $test
|
|
|
|
}
|
2010-10-11 08:47:47 +00:00
|
|
|
}
|
|
|
|
-re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?$func \\(\\).*\r\n$gdb_prompt $" {
|
|
|
|
if {$func == "_dl_debug_state"} {
|
|
|
|
fail $test
|
|
|
|
} else {
|
2010-01-14 20:48:26 +00:00
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
2010-10-11 08:47:47 +00:00
|
|
|
-re "Stopped due to shared library event\r\n$gdb_prompt $" {
|
|
|
|
if {$func == "_dl_debug_state"} {
|
|
|
|
if {$debug_state_count == 0} {
|
|
|
|
# First stop does not yet relocate the _start function
|
|
|
|
# descriptor on ppc64.
|
|
|
|
set debug_state_count 1
|
|
|
|
send_gdb "continue\n"
|
|
|
|
exp_continue
|
|
|
|
} else {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fail $test
|
|
|
|
}
|
2010-03-11 22:07:03 +00:00
|
|
|
}
|
2010-01-14 20:48:26 +00:00
|
|
|
}
|
2010-10-11 08:47:47 +00:00
|
|
|
if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
|
|
|
|
fail $test_displacement
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$func == "_dl_debug_state"} {
|
|
|
|
gdb_test_no_output "set stop-on-solib-events 0"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# `runto' does not check we stopped really at the function we specified.
|
|
|
|
# DISPLACEMENT can be "NONE" for no message to be present, "ZERO" for
|
|
|
|
# displacement of 0 bytes to be present, "NONZERO" for displacement of non-0
|
|
|
|
# bytes to be present and "PRESENT" if both "ZERO" and "NONZERO" are valid.
|
|
|
|
proc reach {func command displacement} {
|
|
|
|
global pf_prefix
|
|
|
|
set old_ldprefix $pf_prefix
|
|
|
|
lappend pf_prefix "reach-$func:"
|
|
|
|
|
|
|
|
reach_1 $func $command $displacement
|
2010-03-11 22:07:03 +00:00
|
|
|
|
|
|
|
set pf_prefix $old_ldprefix
|
2010-01-14 20:48:26 +00:00
|
|
|
}
|
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
proc test_core {file displacement} {
|
|
|
|
global srcdir subdir gdb_prompt expect_out
|
2010-01-14 21:09:05 +00:00
|
|
|
|
2010-01-14 21:12:00 +00:00
|
|
|
set corefile [core_find $file {} "segv"]
|
2010-01-14 21:09:05 +00:00
|
|
|
if {$corefile == ""} {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
global pf_prefix
|
|
|
|
set old_ldprefix $pf_prefix
|
|
|
|
lappend pf_prefix "core:"
|
|
|
|
|
2010-01-14 21:09:05 +00:00
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
# Clear it to never find any separate debug infos in $debug_root.
|
2010-06-01 21:29:21 +00:00
|
|
|
gdb_test_no_output "set debug-file-directory" \
|
|
|
|
"set debug-file-directory for core"
|
2010-01-14 21:09:05 +00:00
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_load $file
|
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
# Print the "PIE (Position Independent Executable) displacement" message.
|
2010-06-01 21:29:21 +00:00
|
|
|
gdb_test_no_output "set verbose on"
|
2010-03-11 22:07:03 +00:00
|
|
|
|
|
|
|
set test "core loaded"
|
2010-03-28 19:08:24 +00:00
|
|
|
set test_displacement "seen displacement message as $displacement"
|
2010-03-11 22:07:03 +00:00
|
|
|
gdb_test_multiple "core-file $corefile" $test {
|
|
|
|
-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
|
|
|
|
# Missing "$gdb_prompt $" is intentional.
|
|
|
|
if {$expect_out(1,string) == "0x0"} {
|
|
|
|
set case "ZERO"
|
|
|
|
} else {
|
|
|
|
set case "NONZERO"
|
|
|
|
}
|
2010-10-11 08:45:12 +00:00
|
|
|
if {$displacement == $case || $displacement == "PRESENT"} {
|
2010-03-11 22:07:03 +00:00
|
|
|
pass $test_displacement
|
|
|
|
set displacement "FOUND-$displacement"
|
2010-07-05 18:00:40 +00:00
|
|
|
} else {
|
2010-03-11 22:07:03 +00:00
|
|
|
fail $test_displacement
|
|
|
|
}
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re "Core was generated by .*\r\n#0 .*$gdb_prompt $" {
|
|
|
|
# Do not check the binary filename as it may be truncated.
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
|
|
|
|
fail $test_displacement
|
|
|
|
}
|
2010-01-14 21:09:05 +00:00
|
|
|
|
|
|
|
gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt"
|
2010-03-11 22:07:03 +00:00
|
|
|
|
|
|
|
set pf_prefix $old_ldprefix
|
2010-01-14 21:09:05 +00:00
|
|
|
}
|
|
|
|
|
2010-07-05 17:57:50 +00:00
|
|
|
proc test_attach_gdb {file pid displacement prefix} {
|
|
|
|
global gdb_prompt expect_out
|
2010-01-14 21:12:00 +00:00
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
global pf_prefix
|
|
|
|
set old_ldprefix $pf_prefix
|
2010-07-05 17:57:50 +00:00
|
|
|
lappend pf_prefix "$prefix:"
|
2010-03-11 22:07:03 +00:00
|
|
|
|
2010-01-14 21:12:00 +00:00
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
2010-03-11 22:07:03 +00:00
|
|
|
|
|
|
|
# Print the "PIE (Position Independent Executable) displacement" message.
|
2010-06-01 21:29:21 +00:00
|
|
|
gdb_test_no_output "set verbose on"
|
2010-03-11 22:07:03 +00:00
|
|
|
|
2010-07-05 17:57:50 +00:00
|
|
|
if {$file != ""} {
|
|
|
|
gdb_test "file $file" "Reading symbols from .*done\\." "file"
|
|
|
|
}
|
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
set test "attach"
|
|
|
|
gdb_test_multiple "attach $pid" $test {
|
2010-07-05 17:57:50 +00:00
|
|
|
-re "Attaching to (program: .*, )?process $pid\r\n" {
|
2010-03-11 22:07:03 +00:00
|
|
|
# Missing "$gdb_prompt $" is intentional.
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set test "attach final prompt"
|
2010-03-28 19:08:24 +00:00
|
|
|
set test_displacement "seen displacement message as $displacement"
|
2010-03-11 22:07:03 +00:00
|
|
|
gdb_test_multiple "" $test {
|
|
|
|
-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
|
|
|
|
# Missing "$gdb_prompt $" is intentional.
|
|
|
|
if {$expect_out(1,string) == "0x0"} {
|
|
|
|
set case "ZERO"
|
|
|
|
} else {
|
|
|
|
set case "NONZERO"
|
|
|
|
}
|
2010-10-11 08:45:12 +00:00
|
|
|
if {$displacement == $case || $displacement == "PRESENT"} {
|
2010-03-11 22:07:03 +00:00
|
|
|
pass $test_displacement
|
|
|
|
set displacement "FOUND-$displacement"
|
2010-07-05 18:00:40 +00:00
|
|
|
} else {
|
2010-03-11 22:07:03 +00:00
|
|
|
fail $test_displacement
|
|
|
|
}
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
|
|
|
|
fail $test_displacement
|
|
|
|
}
|
|
|
|
|
2010-01-14 21:12:00 +00:00
|
|
|
gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "attach main bt"
|
|
|
|
gdb_exit
|
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
set pf_prefix $old_ldprefix
|
2010-01-14 21:12:00 +00:00
|
|
|
}
|
|
|
|
|
2010-07-05 17:57:50 +00:00
|
|
|
proc test_attach {file displacement {relink_args ""}} {
|
|
|
|
global board_info
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
|
|
|
|
set test "sleep function started"
|
|
|
|
|
|
|
|
set command "${file} sleep"
|
|
|
|
set res [remote_spawn host $command];
|
|
|
|
if { $res < 0 || $res == "" } {
|
|
|
|
perror "Spawning $command failed."
|
|
|
|
fail $test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
set pid [exp_pid -i $res]
|
|
|
|
gdb_expect {
|
|
|
|
-re "sleeping\r\n" {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
eof {
|
|
|
|
fail "$test (eof)"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "$test (timeout)"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$relink_args == ""} {
|
|
|
|
test_attach_gdb "" $pid $displacement "attach"
|
|
|
|
} else {
|
|
|
|
# These could be rather passed as arguments.
|
|
|
|
global exec interp_saved interp
|
|
|
|
|
|
|
|
foreach relink {YES NO} {
|
2010-07-05 17:58:56 +00:00
|
|
|
# Formerly this test was testing only prelinking of $EXEC. As the
|
|
|
|
# prelink command automatically prelinks all of $EXEC's libraries,
|
|
|
|
# even $INTERP got prelinked. Therefore, we formerly had to
|
2010-07-05 18:01:53 +00:00
|
|
|
# `[file_copy $interp_saved $interp]' to make $INTERP not affected
|
|
|
|
# by this prelinking of $EXEC.
|
2010-07-05 17:58:56 +00:00
|
|
|
#
|
|
|
|
# But now we need to test even prelinking of $INTERP. We could
|
|
|
|
# create a separate test to test just the $INTERP prelinking. For
|
|
|
|
# test simplicity, we merged this test and the test above by not
|
|
|
|
# restoring $INTERP after $EXEC prelink. $INTERP gets restored
|
|
|
|
# later below.
|
|
|
|
|
|
|
|
if [prelink$relink $relink_args [file tail $exec]] {
|
2010-07-05 17:57:50 +00:00
|
|
|
# /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)".
|
|
|
|
test_attach_gdb $exec $pid $displacement "attach-relink$relink"
|
|
|
|
}
|
|
|
|
}
|
2010-07-05 18:01:53 +00:00
|
|
|
file_copy $interp_saved $interp
|
2010-07-05 17:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
remote_exec host "kill -9 $pid"
|
|
|
|
}
|
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
proc test_ld {file ifmain trynosym displacement} {
|
|
|
|
global srcdir subdir gdb_prompt expect_out
|
2010-01-14 20:48:26 +00:00
|
|
|
|
|
|
|
# First test normal `file'-command loaded $FILE with symbols.
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
# Clear it to never find any separate debug infos in $debug_root.
|
2010-06-01 21:29:21 +00:00
|
|
|
gdb_test_no_output "set debug-file-directory"
|
2010-01-14 20:48:26 +00:00
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_load $file
|
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
# Print the "PIE (Position Independent Executable) displacement" message.
|
2010-06-01 21:29:21 +00:00
|
|
|
gdb_test_no_output "set verbose on"
|
2010-03-11 22:07:03 +00:00
|
|
|
|
2010-07-05 18:04:33 +00:00
|
|
|
# We want to test the re-run of a PIE in the case where the executable
|
|
|
|
# is loaded with a different displacement, but disable-randomization
|
|
|
|
# prevents that from happening. So turn it off.
|
|
|
|
gdb_test "set disable-randomization off"
|
|
|
|
|
2010-10-11 08:47:47 +00:00
|
|
|
if $ifmain {
|
|
|
|
gdb_test_no_output "set args segv"
|
|
|
|
} else {
|
|
|
|
global objdir binfile_test
|
|
|
|
|
|
|
|
# ld.so needs some executable to run to reach _dl_debug_state.
|
2011-02-07 13:35:42 +00:00
|
|
|
gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test" "set args OBJDIR/${subdir}/$binfile_test"
|
2010-10-11 08:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reach "_dl_debug_state" "run" $displacement
|
2010-01-14 21:04:53 +00:00
|
|
|
|
2010-10-11 08:47:47 +00:00
|
|
|
gdb_test "bt" "#0 +\[^\r\n\]*\\m_dl_debug_state\\M.*" "dl bt"
|
2010-01-14 21:04:53 +00:00
|
|
|
|
2010-01-14 20:48:26 +00:00
|
|
|
if $ifmain {
|
2010-07-05 18:00:40 +00:00
|
|
|
reach "main" continue "NONE"
|
2010-01-14 21:04:53 +00:00
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
reach "libfunc" continue "NONE"
|
2010-01-14 21:04:53 +00:00
|
|
|
|
|
|
|
gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt"
|
2010-07-05 18:04:33 +00:00
|
|
|
}
|
2010-01-14 21:09:05 +00:00
|
|
|
|
2010-07-05 18:04:33 +00:00
|
|
|
# Try re-run if the new PIE displacement takes effect.
|
|
|
|
gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
|
2010-10-11 08:47:47 +00:00
|
|
|
reach "_dl_debug_state" "run" $displacement
|
2010-07-05 18:04:33 +00:00
|
|
|
|
|
|
|
if $ifmain {
|
2010-03-11 22:07:03 +00:00
|
|
|
test_core $file $displacement
|
2010-01-14 21:12:00 +00:00
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
test_attach $file $displacement
|
2010-01-14 20:48:26 +00:00
|
|
|
}
|
2010-01-14 21:01:25 +00:00
|
|
|
|
|
|
|
if !$trynosym {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
global pf_prefix
|
|
|
|
set old_ldprefix $pf_prefix
|
|
|
|
lappend pf_prefix "symbol-less:"
|
|
|
|
|
|
|
|
# Test also `exec-file'-command loaded $FILE - therefore without symbols.
|
|
|
|
# SYMBOL_OBJFILE is not available and only EXEC_BFD must be used.
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
# Clear it to never find any separate debug infos in $debug_root.
|
2010-06-01 21:29:21 +00:00
|
|
|
gdb_test_no_output "set debug-file-directory"
|
2010-01-14 21:01:25 +00:00
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
|
2010-03-11 22:07:03 +00:00
|
|
|
# Print the "PIE (Position Independent Executable) displacement" message.
|
2010-06-01 21:29:21 +00:00
|
|
|
gdb_test_no_output "set verbose on"
|
2010-03-11 22:07:03 +00:00
|
|
|
|
2010-01-14 21:01:25 +00:00
|
|
|
# Test no (error) message has been printed by `exec-file'.
|
|
|
|
set escapedfile [string_to_regexp $file]
|
|
|
|
gdb_test "exec-file $file" "exec-file $escapedfile" "load"
|
|
|
|
|
|
|
|
if $ifmain {
|
2010-10-11 08:47:47 +00:00
|
|
|
reach "_dl_debug_state" run $displacement
|
2010-01-14 21:01:25 +00:00
|
|
|
|
2010-10-12 18:41:06 +00:00
|
|
|
# Use two separate gdb_test_multiple statements to avoid timeouts due
|
|
|
|
# to slow processing of wildcard capturing long output
|
2010-01-14 21:01:25 +00:00
|
|
|
set test "info files"
|
|
|
|
set entrynohex ""
|
2010-10-12 18:41:06 +00:00
|
|
|
gdb_test_multiple $test $test {
|
2010-10-12 17:17:36 +00:00
|
|
|
-re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n" {
|
2010-03-11 22:07:03 +00:00
|
|
|
set entrynohex $expect_out(1,string)
|
2010-10-12 18:41:06 +00:00
|
|
|
gdb_test_multiple "" $test {
|
|
|
|
-re "\r\n$gdb_prompt $" {
|
|
|
|
pass $test
|
|
|
|
}
|
2010-10-12 17:17:36 +00:00
|
|
|
}
|
2010-01-14 21:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-12 17:17:36 +00:00
|
|
|
|
2010-09-09 20:00:49 +00:00
|
|
|
# `info sym' cannot be tested for .opd as the binary may not have
|
|
|
|
# symbols.
|
2010-09-10 20:29:25 +00:00
|
|
|
if {[istarget powerpc64-*] && [is_lp64_target]} {
|
2010-09-09 20:00:49 +00:00
|
|
|
set test "convert entry point"
|
|
|
|
gdb_test_multiple "p *(void(*)(void) *) 0x$entrynohex" $test {
|
|
|
|
-re " =( \\(\[^0-9\]*\\))? 0x(\[0-9a-f\]+)( < \[^\r\n\]*)?\r\n$gdb_prompt $" {
|
|
|
|
set entrynohex $expect_out(2,string)
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-14 21:01:25 +00:00
|
|
|
if {$entrynohex != ""} {
|
|
|
|
gdb_test "break *0x$entrynohex" "" "break at entry point"
|
|
|
|
gdb_test "continue" "\r\nBreakpoint \[0-9\]+, 0x0*$entrynohex in .*" "entry point reached"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# There is no symbol to break at ld.so. Moreover it can exit with an
|
|
|
|
# error code.
|
2010-03-11 22:07:03 +00:00
|
|
|
|
|
|
|
set test "ld.so exit"
|
2010-03-28 19:08:24 +00:00
|
|
|
set test_displacement "seen displacement message as $displacement"
|
2010-03-11 22:07:03 +00:00
|
|
|
gdb_test_multiple "run" $test {
|
|
|
|
-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
|
|
|
|
# Missing "$gdb_prompt $" is intentional.
|
|
|
|
if {$expect_out(1,string) == "0x0"} {
|
|
|
|
set case "ZERO"
|
|
|
|
} else {
|
|
|
|
set case "NONZERO"
|
|
|
|
}
|
2010-10-11 08:45:12 +00:00
|
|
|
if {$displacement == $case || $displacement == "PRESENT"} {
|
2010-03-11 22:07:03 +00:00
|
|
|
pass $test_displacement
|
|
|
|
set displacement "FOUND-$displacement"
|
2010-07-05 18:00:40 +00:00
|
|
|
} else {
|
2010-03-11 22:07:03 +00:00
|
|
|
fail $test_displacement
|
|
|
|
}
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re "Program exited (normally|with code \[0-9\]+)\\.\r\n$gdb_prompt $" {
|
|
|
|
# Do not check the binary filename as it may be truncated.
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
|
|
|
|
fail $test_displacement
|
|
|
|
}
|
2010-01-14 21:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set pf_prefix $old_ldprefix
|
2010-01-14 20:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create separate binaries for each testcase - to make the possible reported
|
|
|
|
# problem reproducible after the whole test run finishes.
|
|
|
|
|
|
|
|
set old_ldprefix $pf_prefix
|
|
|
|
foreach ldprelink {NO YES} {
|
|
|
|
foreach ldsepdebug {NO IN SEP} {
|
|
|
|
# Skip running the ldsepdebug test if we do not have system separate
|
|
|
|
# debug info available.
|
|
|
|
if {$interp_system_debug == "" && $ldsepdebug == "SEP"} {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
set ldname "LDprelink${ldprelink}debug${ldsepdebug}"
|
|
|
|
set interp $binprefix-$ldname
|
|
|
|
|
|
|
|
# prelink needs to always prelink all the dependencies to do any file
|
|
|
|
# modifications of its files. ld.so also needs all the dependencies to
|
|
|
|
# be prelinked to omit the relocation process. In-memory file offsets
|
|
|
|
# are not dependent whether ld.so went the prelink way or through the
|
|
|
|
# relocation process.
|
|
|
|
#
|
|
|
|
# For GDB we are not interested whether prelink succeeds as it is
|
|
|
|
# transparent to GDB. GDB is being tested for differences of file
|
|
|
|
# offsets vs. in-memory offsets. So we have to prelink even ld.so for
|
|
|
|
# the BIN modification to happen but we need to restore the original
|
|
|
|
# possibly unprelinked ld.so to test all the combinations for GDB.
|
|
|
|
set interp_saved ${interp}-saved
|
|
|
|
|
|
|
|
set pf_prefix $old_ldprefix
|
|
|
|
lappend pf_prefix "$ldname:"
|
|
|
|
|
|
|
|
if {$ldsepdebug == "NO"} {
|
2010-07-05 18:01:53 +00:00
|
|
|
file_copy $interp_system $interp
|
2010-01-14 20:48:26 +00:00
|
|
|
# Never call strip-debug before unprelink:
|
|
|
|
# prelink: ...: Section .note.gnu.build-id created after prelinking
|
|
|
|
if ![prelinkNO $interp] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
strip_debug $interp
|
|
|
|
} elseif {$ldsepdebug == "IN" && $interp_system_debug == ""} {
|
2010-07-05 18:01:53 +00:00
|
|
|
file_copy $interp_system $interp
|
2010-01-14 20:48:26 +00:00
|
|
|
} elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} {
|
2010-07-05 18:01:53 +00:00
|
|
|
file_copy $interp_system $interp
|
|
|
|
file_copy $interp_system_debug "${interp}.debug"
|
2010-01-14 20:48:26 +00:00
|
|
|
# eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u
|
|
|
|
if {![prelinkNO $interp] || ![prelinkNO "${interp}.debug"]} {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
set test "eu-unstrip unprelinked:[file tail $interp_system] + [file tail $interp_system_debug] to [file tail $interp]"
|
|
|
|
set command "exec eu-unstrip -o $interp $interp ${interp}.debug"
|
|
|
|
verbose -log "command is $command"
|
|
|
|
if [catch $command] {
|
|
|
|
setup_xfail *-*-*
|
|
|
|
fail $test
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
} elseif {$ldsepdebug == "SEP" && $interp_system_debug == ""} {
|
2010-07-05 18:01:53 +00:00
|
|
|
file_copy $interp_system $interp
|
2010-01-14 20:48:26 +00:00
|
|
|
# eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u
|
|
|
|
if ![prelinkNO $interp] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
gdb_gnu_strip_debug $interp
|
|
|
|
} elseif {$ldsepdebug == "SEP" && $interp_system_debug != ""} {
|
2010-07-05 18:01:53 +00:00
|
|
|
file_copy $interp_system $interp
|
|
|
|
file_copy $interp_system_debug "${interp}.debug"
|
2010-01-14 20:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if {$ldsepdebug == "SEP"} {
|
|
|
|
if ![prelinkNO "${interp}.debug"] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
file delete "${interp}.debug"
|
|
|
|
}
|
|
|
|
|
|
|
|
if ![prelink$ldprelink $interp] {
|
|
|
|
continue
|
|
|
|
}
|
2010-03-11 22:07:03 +00:00
|
|
|
if {$ldprelink == "NO"} {
|
|
|
|
set displacement "NONZERO"
|
|
|
|
} else {
|
2010-10-11 08:45:12 +00:00
|
|
|
# x86* kernel loads prelinked PIE binary at its prelinked address
|
|
|
|
# but ppc* kernel loads it at a random address. prelink normally
|
|
|
|
# skips PIE binaries during the system scan.
|
|
|
|
set displacement "PRESENT"
|
2010-03-11 22:07:03 +00:00
|
|
|
}
|
|
|
|
test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement
|
2010-01-14 20:48:26 +00:00
|
|
|
|
2010-07-05 18:01:53 +00:00
|
|
|
if ![file_copy $interp $interp_saved] {
|
2010-01-14 20:48:26 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
set old_binprefix $pf_prefix
|
|
|
|
foreach binprelink {NO YES} {
|
|
|
|
foreach binsepdebug {NO IN SEP} {
|
2010-07-05 17:57:50 +00:00
|
|
|
# "ATTACH" is like "YES" but it is modified during run.
|
|
|
|
# It cannot be used for problem reproducibility after the
|
|
|
|
# testcase ends.
|
|
|
|
foreach binpie {NO YES ATTACH} {
|
2010-01-14 20:48:26 +00:00
|
|
|
# This combination is not possible, non-PIE (fixed address)
|
|
|
|
# binary cannot be prelinked to any (other) address.
|
|
|
|
if {$binprelink == "YES" && $binpie == "NO"} {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}"
|
|
|
|
set exec $binprefix-$binname
|
|
|
|
|
|
|
|
set pf_prefix $old_binprefix
|
|
|
|
lappend pf_prefix "$binname:"
|
|
|
|
|
2010-10-12 18:12:49 +00:00
|
|
|
set opts "ldflags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]"
|
2010-01-14 20:48:26 +00:00
|
|
|
if {$binsepdebug != "NO"} {
|
|
|
|
lappend opts {debug}
|
|
|
|
}
|
2010-07-05 17:57:50 +00:00
|
|
|
if {$binpie != "NO"} {
|
2010-01-14 20:48:26 +00:00
|
|
|
lappend opts {additional_flags=-fPIE -pie}
|
|
|
|
}
|
2010-07-05 18:01:53 +00:00
|
|
|
|
|
|
|
set dir ${exec}.d
|
|
|
|
set relink_args [build_executable_own_libs ${test}.exp [file tail $exec] $srcfile $opts $interp $dir]
|
|
|
|
if {$relink_args == ""} {
|
2010-01-14 20:48:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-07-05 18:01:53 +00:00
|
|
|
|
2010-01-14 20:48:26 +00:00
|
|
|
if {$binsepdebug == "SEP"} {
|
|
|
|
gdb_gnu_strip_debug $exec
|
|
|
|
}
|
|
|
|
|
2010-07-05 17:57:50 +00:00
|
|
|
if {$binpie == "NO"} {
|
|
|
|
set displacement "NONE"
|
|
|
|
} elseif {$binprelink == "NO"} {
|
|
|
|
set displacement "NONZERO"
|
|
|
|
} else {
|
2010-10-11 08:45:12 +00:00
|
|
|
# x86* kernel loads prelinked PIE binary at its
|
|
|
|
# prelinked address but ppc* kernel loads it at
|
|
|
|
# a random address. prelink normally skips PIE
|
|
|
|
# binaries during the system scan.
|
|
|
|
set displacement "PRESENT"
|
2010-07-05 17:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if {[prelink$binprelink $relink_args [file tail $exec]]
|
2010-07-05 18:01:53 +00:00
|
|
|
&& [file_copy $interp_saved $interp]} {
|
2010-07-05 17:57:50 +00:00
|
|
|
if {$binpie != "ATTACH"} {
|
|
|
|
test_ld $exec 1 [expr {$binsepdebug == "NO"}] $displacement
|
2010-03-11 22:07:03 +00:00
|
|
|
} else {
|
2010-07-05 17:57:50 +00:00
|
|
|
# If the file has been randomly prelinked it must
|
|
|
|
# be "NONZERO". We could see "ZERO" only if it was
|
|
|
|
# unprelinked and it is now running at the same
|
|
|
|
# address - which is 0 but executable can never run
|
|
|
|
# at address 0.
|
|
|
|
|
|
|
|
set displacement "NONZERO"
|
|
|
|
test_attach $exec $displacement $relink_args
|
|
|
|
|
|
|
|
# ATTACH means that executables and libraries have
|
|
|
|
# been modified after they have been run. They
|
|
|
|
# cannot be reused for problem reproducibility after
|
|
|
|
# the testcase ends in the ATTACH case. Therefore
|
|
|
|
# they are rather deleted not to confuse after the
|
|
|
|
# run finishes.
|
|
|
|
set exec_debug [system_debug_get $exec]
|
|
|
|
if {$exec_debug != ""} {
|
|
|
|
# `file delete [glob "${exec_debug}*"]' does not work.
|
|
|
|
foreach f [glob "${exec_debug}*"] {
|
|
|
|
file delete $f
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file delete -force $dir
|
|
|
|
# `file delete [glob "${exec}*"]' does not work.
|
|
|
|
foreach f [glob "${exec}*"] {
|
|
|
|
file delete $f
|
|
|
|
}
|
2010-03-11 22:07:03 +00:00
|
|
|
}
|
2010-01-14 20:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file delete $interp_saved
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set pf_prefix $old_ldprefix
|