]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/testsuite/gdb.base/attach-pie-misread.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / attach-pie-misread.exp
index 334272bf3c8cf1988204998defbd3f2b3c5f5681..aa7710a3971e0664bebf1bdbcd5ed1ddc8fccb60 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010 Free Software Foundation, Inc.
+# Copyright 2010-2018 Free Software Foundation, Inc.
 
 # 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
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # This test only works on GNU/Linux.
-if { ![isnative] || [is_remote host] || ![istarget *-linux*] || [skip_shlib_tests]} {
+if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub]
+     || ![istarget *-linux*] || [skip_shlib_tests]} {
     continue
 }
 
-set test "attach-pie-misread"
-set srcfile ${test}.c
-set genfile ${objdir}/${subdir}/${test}-gen.h
-set executable ${test}
-set binfile ${objdir}/${subdir}/${executable}
+load_lib prelink-support.exp
 
-if {[build_executable ${test}.exp $executable $srcfile [list "additional_flags=-fPIE -pie"]] == -1} {
+standard_testfile .c
+set genfile [standard_output_file ${testfile}-gen.h]
+set executable $testfile
+
+if {[build_executable_own_libs ${testfile}.exp $executable $srcfile [list additional_flags=-fPIE ldflags=-pie]] == ""} {
     return -1
 }
 
@@ -35,7 +36,7 @@ if {[build_executable ${test}.exp $executable $srcfile [list "additional_flags=-
 #   DYNAMIC        0x134f618 0x000000000194f618 0x000000000194f618 0x000200 0x000200 RW  0x8
 #
 proc read_phdr {binfile test} {
-    set readelf_program [transform readelf]
+    set readelf_program [gdb_find_readelf]
     set command "exec $readelf_program -Wl $binfile"
     verbose -log "command is $command"
     set result [catch $command output]
@@ -94,7 +95,8 @@ if {$result == 0} {
     fail $test
 }
 
-if {[build_executable ${test}.exp $executable $srcfile [list "additional_flags=-fPIE -pie -DGEN=\"$genfile\""]] == -1} {
+set prelink_args [build_executable_own_libs ${test}.exp $executable $srcfile [list "additional_flags=-fPIE -DGEN=\"$genfile\"" "ldflags=-pie"]]
+if {$prelink_args == ""} {
     return -1
 }
 
@@ -104,20 +106,8 @@ file delete -- $genfile
 set phdr [read_phdr $binfile "readelf rebuilt with stub_size"]
 set dynamic_vaddr_prelinkno [lindex $phdr 0]
 
-set command "exec /usr/sbin/prelink -q -N --no-exec-shield -R $binfile"
-verbose -log "command is $command"
-set result [catch $command output]
-verbose -log "result is $result"
-verbose -log "output is $output"
-
-set test "prelink -R"
-if {$result == 0 && $output == ""} {
-    pass $test
-} elseif {$result == 1 && [regexp {^(couldn't execute "/usr/sbin/prelink[^\r\n]*": no such file or directory\n?)*$} $output]} {
-    untested attach-pie-misread.exp
+if ![prelink_yes $prelink_args] {
     return -1
-} else {
-    fail $test
 }
 
 set phdr [read_phdr $binfile "readelf with prelink -R"]
@@ -136,38 +126,40 @@ if {$first_offset == 0} {
 set test "start inferior"
 gdb_exit
 
-set res [remote_spawn host $binfile];
-if { $res < 0 || $res == "" } {
+set test_spawn_id [remote_spawn host $binfile]
+if { $test_spawn_id < 0 || $test_spawn_id == "" } {
     perror "Spawning $binfile failed."
     fail $test
     return
 }
-set pid [exp_pid -i $res]
+set testpid [spawn_id_get_pid $test_spawn_id]
 gdb_expect {
     -re "sleeping\r\n" {
        pass $test
     }
     eof {
        fail "$test (eof)"
-       remote_exec host "kill -9 $pid"
+       wait -i $test_spawn_id
        return
     }
     timeout {
        fail "$test (timeout)"
-       remote_exec host "kill -9 $pid"
+       kill_wait_spawned_process $test_spawn_id
        return
     }
 }
 
 # Due to alignments it was reproducible with 1 on x86_64 but 2 on i686.
-foreach align_mult {1 2} {
-    set old_ldprefix $pf_prefix
-    lappend pf_prefix "shift-by-$align_mult:"
+foreach align_mult {1 2} { with_test_prefix "shift-by-$align_mult" {
 
     # FIXME: We believe there is enough room under FIRST_OFFSET.
     set shifted_offset [format 0x%x [expr "$first_offset - $align_mult * $align_max"]]
     verbose -log "shifted_offset is $shifted_offset"
 
+    # For normal prelink (prelink_yes call), we need to supply $prelink_args.
+    # For the prelink `-r' option below, $prelink_args is not required.
+    # Moreover, if it was used, the problem would not longer be reproducible
+    # as the libraries would also get relocated.
     set command "exec /usr/sbin/prelink -q -N --no-exec-shield -r $shifted_offset $binfile"
     verbose -log "command is $command"
     set result [catch $command output]
@@ -184,8 +176,8 @@ foreach align_mult {1 2} {
     clean_restart $executable
 
     set test "attach"
-    gdb_test_multiple "attach $pid" $test {
-       -re "Attaching to program: .*, process $pid\r\n" {
+    gdb_test_multiple "attach $testpid" $test {
+       -re "Attaching to program: .*, process $testpid\r\n" {
            # Missing "$gdb_prompt $" is intentional.
            pass $test
        }
@@ -202,8 +194,6 @@ foreach align_mult {1 2} {
     }
 
     gdb_test "detach" "Detaching from program: .*"
+}}
 
-    set pf_prefix $old_ldprefix
-}
-
-remote_exec host "kill -9 $pid"
+kill_wait_spawned_process $test_spawn_id