From patchwork Fri Mar 6 22:32:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 38515 Received: (qmail 124952 invoked by alias); 6 Mar 2020 22:32:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 124158 invoked by uid 89); 6 Mar 2020 22:32:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_SOFTFAIL autolearn=ham version=3.3.1 spammy=sk:ldpreli, sk:BINprel, sk:binprel, sk:LDpreli X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Mar 2020 22:32:21 +0000 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 1hev1NKYNeLrd0VF (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 06 Mar 2020 17:32:18 -0500 (EST) Received: from smarchi-efficios.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by smtp.ebox.ca (Postfix) with ESMTP id 829D9441B21; Fri, 6 Mar 2020 17:32:18 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: use foreach_with_prefix in gdb.base/break-interp.exp Date: Fri, 6 Mar 2020 17:32:18 -0500 Message-Id: <20200306223218.20320-1-simon.marchi@efficios.com> MIME-Version: 1.0 Use foreach_with_prefix, instead of foreach and with_test_prefix separately. Since allows removing some indentation levels, and formats the test names a bit nicer, in my opinion (or at least, it's more consistent with the rest of the testsuite): - PASS: gdb.base/break-interp.exp: LDprelinkNOdebugNO: BINprelinkNOdebugNOpieNO: INNER: core: set verbose on + PASS: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=NO: binpie=NO: INNER: set verbose on Note: this patch is better viewed with "git show -w" to ignore whitespace changes. gdb/testsuite/ChangeLog: * gdb.base/break-interp.exp: Use foreach_with_prefix. --- gdb/testsuite/gdb.base/break-interp.exp | 270 ++++++++++++------------ 1 file changed, 133 insertions(+), 137 deletions(-) diff --git a/gdb/testsuite/gdb.base/break-interp.exp b/gdb/testsuite/gdb.base/break-interp.exp index 6f1af0e5b184..4dabf49aae2f 100644 --- a/gdb/testsuite/gdb.base/break-interp.exp +++ b/gdb/testsuite/gdb.base/break-interp.exp @@ -530,8 +530,8 @@ proc test_ld {file ifmain trynosym displacement} { # Create separate binaries for each testcase - to make the possible reported # problem reproducible after the whole test run finishes. -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"} { @@ -554,164 +554,160 @@ foreach ldprelink {NO YES} { # possibly unprelinked ld.so to test all the combinations for GDB. set interp_saved ${interp}-saved - with_test_prefix "$ldname" { - if {$ldsepdebug == "NO"} { - file_copy $interp_system $interp - # 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 == ""} { - file_copy $interp_system $interp - } elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} { - file_copy $interp_system $interp - file_copy $interp_system_debug "${interp}.debug" - # 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 == ""} { - file_copy $interp_system $interp - # 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 != ""} { - file_copy $interp_system $interp - file_copy $interp_system_debug "${interp}.debug" - } - - if {$ldsepdebug == "SEP"} { - if ![prelinkNO "${interp}.debug"] { - continue - } - } else { - file delete "${interp}.debug" + if {$ldsepdebug == "NO"} { + file_copy $interp_system $interp + # Never call strip-debug before unprelink: + # prelink: ...: Section .note.gnu.build-id created after prelinking + if ![prelinkNO $interp] { + continue } - - if ![prelink$ldprelink $interp "$interp, second time"] { + strip_debug $interp + } elseif {$ldsepdebug == "IN" && $interp_system_debug == ""} { + file_copy $interp_system $interp + } elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} { + file_copy $interp_system $interp + file_copy $interp_system_debug "${interp}.debug" + # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u + if {![prelinkNO $interp] || ![prelinkNO "${interp}.debug"]} { continue } - - if {$ldprelink == "NO"} { - set displacement "NONZERO" + 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 { - # 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" + pass $test } - test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement + } elseif {$ldsepdebug == "SEP" && $interp_system_debug == ""} { + file_copy $interp_system $interp + # 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 != ""} { + file_copy $interp_system $interp + file_copy $interp_system_debug "${interp}.debug" + } - if ![file_copy $interp $interp_saved] { + if {$ldsepdebug == "SEP"} { + if ![prelinkNO "${interp}.debug"] { continue } + } else { + file delete "${interp}.debug" + } - 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} { - # This combination is not possible, non-PIE (fixed address) - # binary cannot be prelinked to any (other) address. - if {$binprelink == "YES" && $binpie == "NO"} { - continue - } + if ![prelink$ldprelink $interp "$interp, second time"] { + continue + } - set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}" - set exec $binprefix-$binname + 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. + set displacement "PRESENT" + } + test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement - with_test_prefix "$binname" { - set opts "ldflags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]" - if {$binsepdebug != "NO"} { - lappend opts {debug} - } - if {$binpie != "NO"} { - lappend opts {pie} - } else { - # Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled. - lappend opts {nopie} - } + if ![file_copy $interp $interp_saved] { + continue + } - set dir ${exec}.d - set relink_args [build_executable_own_libs ${test}.exp [file tail $exec] $srcfile $opts $interp $dir] - if {$relink_args == ""} { - continue - } + 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"} { + continue + } - if {$binsepdebug == "SEP"} { - gdb_gnu_strip_debug $exec - } + set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}" + set exec $binprefix-$binname - if {$binpie == "NO"} { - set displacement "NONE" - } elseif {$binprelink == "NO"} { - set displacement "NONZERO" + set opts "ldflags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]" + if {$binsepdebug != "NO"} { + lappend opts {debug} + } + if {$binpie != "NO"} { + 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 + } + + if {$binsepdebug == "SEP"} { + gdb_gnu_strip_debug $exec + } + + if {$binpie == "NO"} { + set displacement "NONE" + } 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. + set displacement "PRESENT" + } + + if {[prelink$binprelink $relink_args [file tail $exec]] + && [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 { - # 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 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. - if {[prelink$binprelink $relink_args [file tail $exec]] - && [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 - } + 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 $interp_saved } + + file delete $interp_saved } }