gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / break-interp.exp
index 4025083e715f8ef0fba8293dd79334596fffbb99..6b03c59c8175c43989ed6bf962288a711e64b558 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010 Free Software Foundation, Inc.
+# Copyright 2010-2020 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] || [use_gdb_stub]
+     || ![istarget *-linux*] || [skip_shlib_tests]} {
     continue
 }
 
 load_lib prelink-support.exp
 
 set test "break-interp"
-set binprefix ${objdir}/${subdir}/${test}
+set binprefix [standard_output_file ${test}]
 # Only to get the $interp_system name.
 set srcfile_test "start.c"
 set binfile_test ${test}-test
-set binfile_lib ${objdir}/${subdir}/${test}.so
+set binfile_lib ${binprefix}.so
 set srcfile "${test}-main.c"
 set srcfile_lib "${test}-lib.c"
 
-if [get_compiler_info ${binfile_lib}] {
+if [get_compiler_info] {
     return -1
 }
 
 # Use -soname so that the new library gets copied by build_executable_own_libs.
 
-if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug additional_flags=-Wl,-soname,${test}.so]] != ""} {
+if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug ldflags=-Wl,-soname,${test}.so]] != ""} {
     return -1
 }
 
@@ -82,7 +83,7 @@ gdb_test_multiple $test $test {
     }
 }
 
-set interp_system [section_get ${objdir}/${subdir}/$binfile_test .interp]
+set interp_system [section_get [standard_output_file $binfile_test] .interp]
 set interp_system_debug [system_debug_get $interp_system]
 verbose -log "$interp_system has debug $interp_system_debug"
 
@@ -108,12 +109,19 @@ proc strip_debug {dest} {
     }
 }
 
+# The marker function for the standard runtime linker interface is
+# _dl_debug_state.  The probes-based interface has no specific marker
+# function; the probe we will stop on (init_start) is in dl_main so we
+# check for that.
+
+set solib_bp {(_dl_debug_state|dl_main)}
+
 # Implementation of reach.
 
 proc reach_1 {func command displacement} {
-    global gdb_prompt expect_out
+    global gdb_prompt expect_out solib_bp
 
-    if {$func == "_dl_debug_state"} {
+    if {$func == $solib_bp} {
        # 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"
@@ -140,22 +148,22 @@ proc reach_1 {func command displacement} {
            }
            exp_continue
        }
-       -re "Breakpoint \[0-9\]+, \\.?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
-           if {$func == "_dl_debug_state"} {
+       -re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
+           if {$func == $solib_bp} {
                fail $test
            } else {
                pass $test
            }
        }
-       -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?$func \\(\\).*\r\n$gdb_prompt $" {
-           if {$func == "_dl_debug_state"} {
+       -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
+           if {$func == $solib_bp} {
                fail $test
            } else {
                pass $test
            }
        }
-       -re "Stopped due to shared library event\r\n$gdb_prompt $" {
-           if {$func == "_dl_debug_state"} {
+       -re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" {
+           if {$func == $solib_bp} {
                if {$debug_state_count == 0} {
                    # First stop does not yet relocate the _start function
                    # descriptor on ppc64.
@@ -174,7 +182,7 @@ proc reach_1 {func command displacement} {
        fail $test_displacement
     }
 
-    if {$func == "_dl_debug_state"} {
+    if {$func == $solib_bp} {
        gdb_test_no_output "set stop-on-solib-events 0"
     }
 }
@@ -183,162 +191,161 @@ proc reach_1 {func command displacement} {
 # 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
-
-    set pf_prefix $old_ldprefix
+#
+# The optional ITERATION parameter is used in order to make unique
+# test prefixes, when calling this proc with the same FUNC name
+# provide a unique ITERATION value for each call.
+proc reach {func command displacement {iteration 1}} {
+    set prefix "reach-$func"
+    if { $iteration > 1 } {
+       set prefix "$prefix-$iteration"
+    }
+    with_test_prefix $prefix {
+       reach_1 $func $command $displacement
+    }
 }
 
 proc test_core {file displacement} {
-    global srcdir subdir gdb_prompt expect_out
+    with_test_prefix "core" {
+       global srcdir subdir gdb_prompt expect_out
 
-    set corefile [core_find $file {} "segv"]
-    if {$corefile == ""} {
-       return
-    }
-
-    global pf_prefix
-    set old_ldprefix $pf_prefix
-    lappend pf_prefix "core:"
+       set corefile [core_find $file {} "segv"]
+       if {$corefile == ""} {
+           return
+       }
 
-    gdb_exit
-    gdb_start
-    # Clear it to never find any separate debug infos in $debug_root.
-    gdb_test_no_output "set debug-file-directory" \
-       "set debug-file-directory for core"
-    gdb_reinitialize_dir $srcdir/$subdir
-    gdb_load $file
+       gdb_exit
+       gdb_start
+       # Clear it to never find any separate debug infos in $debug_root.
+       gdb_test_no_output "set debug-file-directory" \
+           "set debug-file-directory for core"
+       gdb_reinitialize_dir $srcdir/$subdir
+       gdb_load $file
 
-    # Print the "PIE (Position Independent Executable) displacement" message.
-    gdb_test_no_output "set verbose on"
+       # Print the "PIE (Position Independent Executable) displacement" message.
+       gdb_test_no_output "set verbose on"
 
-    set test "core loaded"
-    set test_displacement "seen displacement message as $displacement"
-    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"
+       set test "core loaded"
+       set test_displacement "seen displacement message as $displacement"
+       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"
+               }
+               if {$displacement == $case || $displacement == "PRESENT"} {
+                   pass $test_displacement
+                   set displacement "FOUND-$displacement"
+               } else {
+                   fail $test_displacement
+               }
+               exp_continue
            }
-           if {$displacement == $case || $displacement == "PRESENT"} {
-               pass $test_displacement
-               set displacement "FOUND-$displacement"
-           } else {
-               fail $test_displacement
+           -re "Core was generated by .*\r\n#0 .*$gdb_prompt $" {
+               # Do not check the binary filename as it may be truncated.
+               pass $test
            }
-           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
        }
-    }
-    if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
-       fail $test_displacement
-    }
-
-    gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt"
+       gdb_test_no_output "set verbose off"
 
-    set pf_prefix $old_ldprefix
+       gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt"
+    }
 }
 
 proc test_attach_gdb {file pid displacement prefix} {
-    global gdb_prompt expect_out
+    with_test_prefix "$prefix" {
+       global gdb_prompt expect_out
 
-    global pf_prefix
-    set old_ldprefix $pf_prefix
-    lappend pf_prefix "$prefix:"
+       gdb_exit
+       gdb_start
 
-    gdb_exit
-    gdb_start
+       # Print the "PIE (Position Independent Executable) displacement" message.
+       gdb_test_no_output "set verbose on"
 
-    # Print the "PIE (Position Independent Executable) displacement" message.
-    gdb_test_no_output "set verbose on"
-
-    if {$file != ""} {
-       gdb_test "file $file" "Reading symbols from .*done\\." "file"
-    }
+       gdb_test "file $file" "Reading symbols from .*" "file"
 
-    set test "attach"
-    gdb_test_multiple "attach $pid" $test {
-       -re "Attaching to (program: .*, )?process $pid\r\n" {
-           # Missing "$gdb_prompt $" is intentional.
-           pass $test
+       set test "attach"
+       gdb_test_multiple "attach $pid" $test {
+           -re "Attaching to (program: .*, )?process $pid\r\n" {
+               # Missing "$gdb_prompt $" is intentional.
+               pass $test
+           }
        }
-    }
 
-    set test "attach final prompt"
-    set test_displacement "seen displacement message as $displacement"
-    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"
+       set test "attach final prompt"
+       set test_displacement "seen displacement message as $displacement"
+       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"
+               }
+               if {$displacement == $case || $displacement == "PRESENT"} {
+                   pass $test_displacement
+                   set displacement "FOUND-$displacement"
+               } else {
+                   fail $test_displacement
+               }
+               exp_continue
            }
-           if {$displacement == $case || $displacement == "PRESENT"} {
-               pass $test_displacement
-               set displacement "FOUND-$displacement"
-           } else {
-               fail $test_displacement
+           -re "$gdb_prompt $" {
+               pass $test
            }
-           exp_continue
        }
-       -re "$gdb_prompt $" {
-           pass $test
+       if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
+           fail $test_displacement
        }
-    }
-    if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
-       fail $test_displacement
-    }
-
-    gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "attach main bt"
-    gdb_exit
+       gdb_test_no_output "set verbose off"
 
-    set pf_prefix $old_ldprefix
+       gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "attach main bt"
+       gdb_exit
+    }
 }
 
 proc test_attach {file displacement {relink_args ""}} {
     global board_info
+    global exec
 
     gdb_exit
 
     set test "sleep function started"
 
     set command "${file} sleep"
-    set res [remote_spawn host $command];
-    if { $res < 0 || $res == "" } {
+    set test_spawn_id [remote_spawn host $command]
+    if { $test_spawn_id < 0 || $test_spawn_id == "" } {
        perror "Spawning $command failed."
        fail $test
        return
     }
-    set pid [exp_pid -i $res]
+    set pid [spawn_id_get_pid $test_spawn_id]
     gdb_expect {
        -re "sleeping\r\n" {
            pass $test
        }
        eof {
            fail "$test (eof)"
+           wait -i $test_spawn_id
            return
        }
        timeout {
            fail "$test (timeout)"
+           kill_wait_spawned_process $test_spawn_id
            return
        }
     }
 
     if {$relink_args == ""} {
-       test_attach_gdb "" $pid $displacement "attach"
+       test_attach_gdb $exec $pid $displacement "attach"
     } else {
        # These could be rather passed as arguments.
-       global exec interp_saved interp
+       global interp_saved interp
 
        foreach relink {YES NO} {
            # Formerly this test was testing only prelinking of $EXEC.  As the
@@ -352,6 +359,14 @@ proc test_attach {file displacement {relink_args ""}} {
            # test simplicity, we merged this test and the test above by not
            # restoring $INTERP after $EXEC prelink.  $INTERP gets restored
            # later below.
+           #
+           # `(wrong library or version mismatch?)' messages are printed for
+           # $binfile_lib on platforms converting REL->RELA relocations by
+           # prelink (such as on i386).  There is no reliable way to verify
+           # the library file matches the running library in such case but
+           # GDB at least attempts to set the right displacement.  We test
+           # `libfunc' is present in the backtrace and therefore the
+           # displacement has been guessed right.
 
            if [prelink$relink $relink_args [file tail $exec]] {
                # /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)".
@@ -361,11 +376,11 @@ proc test_attach {file displacement {relink_args ""}} {
        file_copy $interp_saved $interp
     }
 
-    remote_exec host "kill -9 $pid"
+    kill_wait_spawned_process $test_spawn_id
 }
 
 proc test_ld {file ifmain trynosym displacement} {
-    global srcdir subdir gdb_prompt expect_out
+    global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp
 
     # First test normal `file'-command loaded $FILE with symbols.
 
@@ -387,27 +402,37 @@ proc test_ld {file ifmain trynosym displacement} {
     if $ifmain {
        gdb_test_no_output "set args segv"
     } else {
-       global objdir binfile_test
+       global binfile_test
 
        # ld.so needs some executable to run to reach _dl_debug_state.
-       gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test"
+       gdb_test_no_output "set args [standard_output_file $binfile_test]" \
+           "set args OBJDIR/${subdir}/$binfile_test"
     }
 
-    reach "_dl_debug_state" "run" $displacement
+    reach $solib_bp "run" $displacement 1
 
-    gdb_test "bt" "#0 +\[^\r\n\]*\\m_dl_debug_state\\M.*" "dl bt"
+    with_test_prefix "first backtrace" {
+       gdb_test_no_output "set verbose off"
+       gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" "dl bt"
+       gdb_test_no_output "set verbose on"
+    }
 
     if $ifmain {
        reach "main" continue "NONE"
 
        reach "libfunc" continue "NONE"
 
-       gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt"
+       with_test_prefix "second backtrace" {
+           gdb_test_no_output "set verbose off"
+           gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt"
+           gdb_test_no_output "set verbose on"
+       }
     }
 
     # Try re-run if the new PIE displacement takes effect.
     gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
-    reach "_dl_debug_state" "run" $displacement
+    reach $solib_bp "run" $displacement 2
+    gdb_test_no_output "set verbose off"
 
     if $ifmain {
        test_core $file $displacement
@@ -419,93 +444,106 @@ proc test_ld {file ifmain trynosym displacement} {
        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.
-    gdb_test_no_output "set debug-file-directory"
-    gdb_reinitialize_dir $srcdir/$subdir
-
-    # Print the "PIE (Position Independent Executable) displacement" message.
-    gdb_test_no_output "set verbose on"
-
-    # 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 {
-       reach "_dl_debug_state" run $displacement
-
-       set test "info files"
-       set entrynohex ""
-       gdb_test_multiple $test $test {
-           -re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n.*$gdb_prompt $" {
-               set entrynohex $expect_out(1,string)
-               pass $test
-           }
-       }
-       # `info sym' cannot be tested for .opd as the binary may not have
-       # symbols.
-       if {[istarget powerpc64-*] && [is_lp64_target]} {
-           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
+    with_test_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.
+       gdb_test_no_output "set debug-file-directory"
+       gdb_reinitialize_dir $srcdir/$subdir
+
+       # Print the "PIE (Position Independent Executable)
+       # displacement" message.
+       gdb_test_no_output "set verbose on"
+
+       # 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 {
+           reach $solib_bp run $displacement 3
+
+           # Use two separate gdb_test_multiple statements to avoid timeouts due
+           # to slow processing of wildcard capturing long output
+           set test "info files"
+           set entrynohex ""
+           set info_line [join [list \
+                                    "\r\n" "\[\t\]" "0x\[0-9af\]+" " - " \
+                                    "0x\[0-9af\]+" " @ " "0x\[0-9af\]+"  \
+                                    " is " "\[^\r\n\]+"] ""]
+           gdb_test_multiple $test $test {
+               -re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n" {
+                   set entrynohex $expect_out(1,string)
+                   gdb_test_multiple "" $test {
+                       -re "\r\n$gdb_prompt $" {
+                           pass $test
+                       }
+                       -re $info_line {
+                           # Avoid timeout with check-read1
+                           exp_continue
+                       }
+                   }
                }
            }
-       }
-       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.
 
-       set test "ld.so exit"
-       set test_displacement "seen displacement message as $displacement"
-       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"
+           # `info sym' cannot be tested for .opd as the binary may not have
+           # symbols.
+           if {[istarget powerpc64-*] && [is_lp64_target]} {
+               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
+                   }
                }
-               if {$displacement == $case || $displacement == "PRESENT"} {
-                   pass $test_displacement
-                   set displacement "FOUND-$displacement"
-               } else {
-                   fail $test_displacement
+           }
+           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.
+
+           set test "ld.so exit"
+           set test_displacement "seen displacement message as $displacement"
+           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"
+                   }
+                   if {$displacement == $case || $displacement == "PRESENT"} {
+                       pass $test_displacement
+                       set displacement "FOUND-$displacement"
+                   } else {
+                       fail $test_displacement
+                   }
+                   exp_continue
+               }
+               -re "$inferior_exited_re (normally|with code \[0-9\]+).\r\n$gdb_prompt $" {
+                   # Do not check the binary filename as it may be truncated.
+                   pass $test
                }
-               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
            }
        }
-       if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
-           fail $test_displacement
-       }
+       gdb_test_no_output "set verbose off"
     }
-
-    set pf_prefix $old_ldprefix
 }
 
 # 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} {
+foreach_with_prefix ldprelink {NO YES} {
+    foreach_with_prefix 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"} {
@@ -528,9 +566,6 @@ foreach ldprelink {NO YES} {
        # 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"} {
            file_copy $interp_system $interp
            # Never call strip-debug before unprelink:
@@ -578,15 +613,17 @@ foreach ldprelink {NO YES} {
            file delete "${interp}.debug"
        }
 
-       if ![prelink$ldprelink $interp] {
+       if ![prelink$ldprelink $interp "[file tail $interp], second time"] {
            continue
        }
+
        if {$ldprelink == "NO"} {
            set displacement "NONZERO"
        } else {
-           # 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.
+           # 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"
        }
        test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement
@@ -594,13 +631,13 @@ foreach ldprelink {NO YES} {
        if ![file_copy $interp $interp_saved] {
            continue
        }
-       set old_binprefix $pf_prefix
-       foreach binprelink {NO YES} {
-           foreach binsepdebug {NO IN SEP} {
-               # "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} {
+
+       foreach_with_prefix binprelink {NO YES} {
+           foreach_with_prefix binsepdebug {NO IN SEP} {
+               # "ATTACH" is like "YES" but it is modified during
+               # run.  It cannot be used for problem
+               # reproducibility after the testcase ends.
+               foreach_with_prefix binpie {NO YES ATTACH} {
                    # This combination is not possible, non-PIE (fixed address)
                    # binary cannot be prelinked to any (other) address.
                    if {$binprelink == "YES" && $binpie == "NO"} {
@@ -610,21 +647,21 @@ foreach ldprelink {NO YES} {
                    set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}"
                    set exec $binprefix-$binname
 
-                   set pf_prefix $old_binprefix
-                   lappend pf_prefix "$binname:"
-
-                   set opts "additional_flags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]"
+                   set opts "ldflags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]"
                    if {$binsepdebug != "NO"} {
                        lappend opts {debug}
                    }
                    if {$binpie != "NO"} {
-                       lappend opts {additional_flags=-fPIE -pie}
+                       lappend opts {pie}
+                   } else {
+                       # Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled.
+                       lappend opts {nopie}
                    }
 
                    set dir ${exec}.d
                    set relink_args [build_executable_own_libs ${test}.exp [file tail $exec] $srcfile $opts $interp $dir]
                    if {$relink_args == ""} {
-                       continue;
+                       continue
                    }
 
                    if {$binsepdebug == "SEP"} {
@@ -636,45 +673,47 @@ foreach ldprelink {NO YES} {
                    } elseif {$binprelink == "NO"} {
                        set displacement "NONZERO"
                    } else {
-                       # 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.
+                       # 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"
                    }
 
                    if {[prelink$binprelink $relink_args [file tail $exec]]
-                       && [file_copy $interp_saved $interp]} {
-                       if {$binpie != "ATTACH"} {
-                           test_ld $exec 1 [expr {$binsepdebug == "NO"}] $displacement
-                       } else {
-                           # 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_copy $interp_saved $interp]} {
+                       # In order to make test names unique wrap the core of this if block
+                       # with a test prefix.  Some of the tests performed in the if
+                       # condition are repeated within this body.
+                       with_test_prefix "INNER" {
+                           if {$binpie != "ATTACH"} {
+                               test_ld $exec 1 [expr {$binsepdebug == "NO"}] $displacement
+                           } else {
+                               # 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
                                }
                            }
-                           file delete -force $dir
-                           # `file delete [glob "${exec}*"]' does not work.
-                           foreach f [glob "${exec}*"] {
-                               file delete $f
-                           }
                        }
                    }
                }
@@ -684,4 +723,3 @@ foreach ldprelink {NO YES} {
        file delete $interp_saved
     }
 }
-set pf_prefix $old_ldprefix
This page took 0.034891 seconds and 4 git commands to generate.