From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gYi8KylytWn8NSkAWB0awg (envelope-from ) for ; Sat, 14 Mar 2026 10:35:21 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B3tWv/rc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AD2EC1E0DD; Sat, 14 Mar 2026 10:35:21 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 710791E08D for ; Sat, 14 Mar 2026 10:35:20 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 0021A4C31890 for ; Sat, 14 Mar 2026 14:35:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0021A4C31890 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B3tWv/rc Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id E20FB4C318B0 for ; Sat, 14 Mar 2026 14:32:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E20FB4C318B0 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E20FB4C318B0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773498755; cv=none; b=D3X0SVhz2lA15dBakVjJv4DYWgjT3c6Q+QhhimYIOUJGtyJt+ULFfxLBxy73O9VIdMh/DOT6dgPbZE6wUxF5RV3/WUS+74FVG1lVh0GJevjGPSe4juUoKg7PMGgxE9Rf82GAQ3YNuVlljJscLfa9tyBvlFl6vG4ZE7+LopSkrBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773498755; c=relaxed/simple; bh=+a20FszpIIQWxNn5kN6PZd3tplBBTlHXnSevyBtVTQE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=K0qX12LE9x894VBFlY9x5vvDXj13UVqPvis3ITCUym2YWgGCp8oYegFkbXVQS3RJ57fdCQh03G7QC6SG1bXZXMPJqBT+vgLeTXIzpHJZKAYJaw6r+E0daQRGgT9vwnhzlJZb2YMTpNhiWOXPCt/x9j9WDPujcCKvzfQelUcSEGM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E20FB4C318B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773498754; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p2G2pnrdxpmbcNKy5GZ8TMavRQdcO3kW5pWRhCi6DbY=; b=B3tWv/rcbig8zzZyrhfYF01vTrCEfQuzuCIKN9B/ekgshvClXhJWw/OiwDMCSyR55EPmxf qR4ZTXy+Zv5TVapp1rIljUrhIZ11bO53v/ubBldemTaUQPWtID9gWrKTqJeT9CKeTvkpYE r7AFQSrnfFZuvcNYRmKNKlyxVo1duro= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-3NAQS36zPFCsxZsDgr5_8g-1; Sat, 14 Mar 2026 10:32:33 -0400 X-MC-Unique: 3NAQS36zPFCsxZsDgr5_8g-1 X-Mimecast-MFC-AGG-ID: 3NAQS36zPFCsxZsDgr5_8g_1773498752 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-439b484ee04so3218555f8f.1 for ; Sat, 14 Mar 2026 07:32:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773498752; x=1774103552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p2G2pnrdxpmbcNKy5GZ8TMavRQdcO3kW5pWRhCi6DbY=; b=nw3eAiCeMZHC+wPCmL8m32OPmRKEQcgwgTcqVLwaN1Lz1oWukERKT22+DR4EfJLKTr Dq6f3GKp30It7mEROP4PIi+haLeMzeiRT8CpWhGK4XQiViKVyugdRBVaYpLnOBVNkhQs 1MeAie0sEVVGWEuVt4H49hZ+W050c1DzjOvThkTaB20DT6wHSbHGqMcmAWLk8tIWM8z7 d833oSwjszxHVYwRCi66q2CUsWiuJbKKBkp0YyA2TUXuh4O899L2wo91vCAOXBWo4ZNt 9vWHQWrsysKjh5/un48YgsbfDIPAl97xeJ6V4W4FYbbi+mXXts1ScPDk98B5VrAXrzgL KtJg== X-Gm-Message-State: AOJu0YzwO1I+unn5Is79k0yttKa75aRzXNRrFLL8oZMFV099OLq4hTAP j4PxsyNt4PiuhqzI4VBP7cZ+10jHkwuDN/XVgry0DiZ175DJZSskg2KXIRDWyQ+nhf4IkQPVS+k 9CrCwCScw9XtwCvgGiVHrD9/QKflZFbWsQUzBMp0qX45UmcOZcFT2pVmDstZssUxZcVRdkM9Ec/ ocg5y1Wkq6/H9AxBILBZugNGQbWYisAg799iMHhAMQimurYTc= X-Gm-Gg: ATEYQzx7HzEKKv+tGDNXJaYEoM/V2VazYcnkJoySQvt/JNO689mCbOdXn3/eQLqfRIz vaNuYjiJ2beWV5EWgAOHhHAoJzQKXEfZVLO4IWgA1qgWx2WJXsYOPEqasAbzhLVs6NHkDI71Rss b3b5Y4gzVqgL6wikdosmScLU7a2+miM6qUWAnN8LVYVMcudl5SihG2po5HOD++P/Z7TPpmbvHkb O8TpvI5Lnxf7sVB0D/vUFCYNhZ+dWBrAHo42zfFfwLnHw1pCFD3OWHoBRE6dmD3MydxwSxvmNdl yhgq5h8k8MuCb2Ay4vNwivu3gvC0GtIJQPAH0kr5WwI8Pa8tQZFWaCH5Yea/ZczfLkI/Z7sA1tT byBTgaduW4ZhGo8Hop4ZdwM1KNiHDXM27mM1NlwdIputvvQ== X-Received: by 2002:a5d:5d11:0:b0:439:c153:ae3d with SMTP id ffacd0b85a97d-439fdf34566mr20548806f8f.6.1773498751564; Sat, 14 Mar 2026 07:32:31 -0700 (PDT) X-Received: by 2002:a5d:5d11:0:b0:439:c153:ae3d with SMTP id ffacd0b85a97d-439fdf34566mr20548754f8f.6.1773498750856; Sat, 14 Mar 2026 07:32:30 -0700 (PDT) Received: from localhost (92.40.185.182.threembb.co.uk. [92.40.185.182]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439fe2187aasm23277328f8f.30.2026.03.14.07.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Mar 2026 07:32:29 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/5] gdb/testsuite: restructure gdb.base/corefile-buildid.exp Date: Sat, 14 Mar 2026 14:32:19 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: K525Z7gQGI1lidHhoCx2X4l3hpZ77jg6iOysjkmYY6c_1773498752 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Restructure the gdb.base/corefile-buildid.exp test. Previously this test focused on testing that GDB could find the executable for a core file based on the executable's build-id. The test did include building an executable that made use of shared libraries, but the test never tried to confirm that GDB could find these shared libraries based on their build-id, only the executable was being tested. This rewrite extends the test so that, for the shared library using executable, both of the shared libraries are moved into the debug directory, we then check that they are found when the core file is opened. As the debug directory is indexed by build-id, this indicates that GDB can find the shared libraries for a core file based on the build-id of the shared libraries. The existing executable lookup tests are unchanged, this is just adding additional testing. --- gdb/testsuite/gdb.base/corefile-buildid.exp | 263 +++++++++++++++----- 1 file changed, 196 insertions(+), 67 deletions(-) diff --git a/gdb/testsuite/gdb.base/corefile-buildid.exp b/gdb/testsuite/gdb.base/corefile-buildid.exp index 45c613b528f..1dec651e03c 100644 --- a/gdb/testsuite/gdb.base/corefile-buildid.exp +++ b/gdb/testsuite/gdb.base/corefile-buildid.exp @@ -52,22 +52,33 @@ proc create_core_file { progname } { } -# Build a non-shared executable. +# Build a non-shared executable. MODE is a suffix used to generate +# the executable name (which should be based on global TESTFILE). +# Returns an empty list if anything goes wrong, otherwise, returns a +# list containing the absolute filename of the executable. -proc build_corefile_buildid_exec { progname } { - return [expr {[build_executable "build non-shared exec" $progname $::srcfile] != -1}] +proc build_corefile_buildid_exec { mode } { + set progname $::testfile-$mode + if {[build_executable "build non-shared exec" $progname $::srcfile] == -1} { + return {} + } + return [list [standard_output_file $progname]] } -# Build a shared executable. +# Build a shared executable. MODE is a suffix used to generate the +# executable name (which should be based on global TESTFILE). Returns +# an empty list if anything goes wrong, otherwise, returns a list +# containing the absolute filename of the executable (first) followed +# by all the additional shared libraries. -proc build_corefile_buildid_shared { progname } { +proc build_corefile_buildid_shared { mode } { # Compile DSO. + set progname $::testfile-$mode set objdso [standard_output_file $::testfile-shlib-shr.so] if {[build_executable "build dso" $objdso $::srcfile2 {debug shlib}] == -1} { - return false + return {} } - # Compile shared library. set srclib $::srcfile3 set libname lib$::testfile.so @@ -76,16 +87,16 @@ proc build_corefile_buildid_shared { progname } { set opts [list debug shlib_load shlib \ additional_flags=-DSHLIB_NAME=\"$dlopen_lib\"] if {[build_executable "build solib" $objlib $::srcfile3 $opts] == -1} { - return false + return {} } # Compile main program. set opts [list debug shlib=$objlib additional_flags=-DTEST_SHARED] if {[build_executable "build shared exec" $progname $::srcfile $opts] == -1} { - return false + return {} } - return true + return [list [standard_output_file $progname] $objdso $objlib] } # Append DEBUGDIR to the debug-file-directory path. @@ -145,18 +156,84 @@ proc check_exec_file {file} { } } -# Test whether gdb can find an exec file from a core file's build-id. -# The executable (and separate debuginfo if SEPDEBUG is true) is -# copied to the .build-id directory. -# -# SUFFIX is appended to the .builid-id parent directory name to -# keep all tests separate. -# SYMLINK specifies whether build-id files should be copied or symlinked. -# SHARED is a boolean indicating whether we are testing the shared -# library core dump test case. +# A convenience procedure to check if "info sharedlibrary" mentions the +# files in the list EXPECTED_FILES. Each filename in EXPECTED_FILES is an +# absolute filename for a shared library GDB should have found when loading +# the core file. -proc locate_exec_from_core_build_id {corefile buildid \ - dirname progname \ +proc check_shlib_files { expected_files } { + set shlibs {} + set missing_shlib false + gdb_test_multiple "info sharedlibrary" "" { + -re "^info sharedlibrary\r\n" { + exp_continue + } + + -re "^From\\s+To\\s\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^$::hex\\s+$::hex\\s+(?:Yes|No)\\s+(?:\\(\\*\\)\\s+)?(\[^\r\n\]+)\r\n" { + set filename $expect_out(1,string) + lappend shlibs $filename + exp_continue + } + + -re "^\\s+(?:Yes|No)\\s+(?:\\(\\*\\)\\s+)?(\[^\r\n\]+)\r\n" { + # This shared library wasn't loaded correctly; GDB + # probably failed to find the library file. Don't add + # this to the shlibs list as we want this library to + # appear as missing. + set missing_shlib true + exp_continue + } + + -re "^\\(\\*\\): Shared library is missing debugging information\\.\r\n" { + exp_continue + } + + -re "^$::gdb_prompt $" { + # This proc is only called for the shared library test + # case, in which case there should be at least two shared + # libraries loaded. + gdb_assert { !$missing_shlib && [llength $shlibs] >= 2 } \ + $gdb_test_name + } + } + + set count 0 + foreach filename $expected_files { + incr count + gdb_assert { [lsearch -exact $shlibs $filename] != -1 } \ + "found shlib $count" + } +} + +# Test whether gdb can find an exec file from a COREFILE's +# build-id(s). The basenames of the executable, and any shared +# libraries built by this test script, that are used by the +# executable, are in the list FILENAMES. These files can all be found +# in the directory DIRNAME. +# +# This function creates a debug directory and either copies, or +# symlinks FILENAMES into the debug directory using the file's +# build-id as the new filename within the newly created debug +# directory. +# +# SEPDEBUG is a boolean, when true every file in FILENAMES has a +# separate debug file, the same filename with ".debug" appended. When +# false, the debug information is contained within the file. +# +# SYMLINK is a boolean and indicates whether build-id files should be +# copied or symlinked from DIRNAME. +# +# SHARED is a boolean indicating whether we are testing the shared +# library core dump test case. We carry out more checks when running +# the shared library case, checking that GDB managed to load all the +# shared libraries correctly too. + +proc locate_exec_from_core_build_id {corefile \ + dirname filenames \ sepdebug symlink shared} { clean_restart @@ -177,78 +254,130 @@ proc locate_exec_from_core_build_id {corefile buildid \ } else { set d "${d}_not-stripped" } - set debugdir [standard_output_file $d] - remote_exec build \ - "mkdir -p [file join $debugdir [file dirname $buildid]]" - set files_list {} - lappend files_list [file join $dirname [file tail $progname]] \ - $buildid - if {$sepdebug} { - lappend files_list [file join $dirname [file tail $progname]].debug \ - "$buildid.debug" - } + # The following loop does two jobs. The primary task is to either + # copy or symlink the files within DIRNAME into DEBUGDIR. Within + # DEBUGDIR files are placed into a tree based on their build-id. + # + # As this loop is calculating build-ids anyway, the build-ids are + # recorded in the ALL_BUILDIDS list, retaining the order that + # items are found in FILENAMES. + set all_buildids {} + foreach filename $filenames { + # Get the build-id for FILENAME without ".debug" on the end. + # This will have the format: '.build-id/xx/xxxxx' + set buildid [build_id_debug_filename_get \ + [file join $dirname $filename] ""] + if {$buildid == ""} { + untested "no build-id for $filename" + return + } + verbose -log "build-id for $filename is $buildid" + lappend all_buildids $buildid - foreach {target name} $files_list { - set t [file join $dirname [file tail $target]] - if {$symlink} { - remote_exec build "ln -s $t [file join $debugdir $name]" - } else { - remote_exec build "cp $t [file join $debugdir $name]" + # Create the sub-directory of DEBUGDIR based on BUILDID. + remote_exec build \ + "mkdir -p [file join $debugdir [file dirname $buildid]]" + + # Build a list of source target filename pairs. + set files_list {} + lappend files_list $filename $buildid + if {$sepdebug} { + lappend files_list ${filename}.debug ${buildid}.debug + } + + # Copy the source file from DIRNAME into DEBUGDIR. + foreach {target name} $files_list { + set t [file join $dirname $target] + set n [file join $debugdir $name] + if {$symlink} { + remote_exec build "ln -s $t $n" + } else { + remote_exec build "cp $t $n" + } } } # Append the debugdir to the separate debug directory search path. append_debug_dir $debugdir + # Load the core file. gdb_test "core-file $corefile" "Program terminated with .*" \ "load core file" + + # What do we expect the name of the executable to appear as? if {$symlink} { - set expected_file [file join $dirname [file tail $progname]] + set expected_file [file join $dirname [lindex $filenames 0]] } else { - set expected_file $buildid + set expected_file [file join $debugdir [lindex $all_buildids 0]] + } + check_exec_file $expected_file + + # Check that all of the expected shared libraries have been found. + if {$shared} { + if {$symlink} { + set expected_files [lmap item [lrange $filenames 1 end] { + file join $dirname $item + }] + } else { + set expected_files [lmap item [lrange $all_buildids 1 end] { + file join $debugdir $item + }] + } + check_shlib_files $expected_files } - check_exec_file [file join $debugdir $expected_file] } foreach_with_prefix mode { exec shared } { - # Build the executable. - set progname ${binfile}-$mode + # Build the executable and optionally, any shared libraries. set build_proc build_corefile_buildid_${mode} - if { ![$build_proc $progname] } { - return -1 + set build_artefacts [$build_proc $mode] + if { [llength $build_artefacts] == 0 } { + return } - # Generate a corefile. + # Generate a corefile. The executable is the first item in + # BUILD_ARTEFACTS. + set progname [lindex $build_artefacts 0] set corefile [create_core_file $progname] if { $corefile eq "" } { - return -1 - } - - # Get the build-id filename without ".debug" on the end. This - # will have the format: '.build-id/xx/xxxxx' - set buildid [build_id_debug_filename_get $progname ""] - if {$buildid == ""} { - untested "binary has no build-id" return } - verbose -log "build-id is $buildid" - # Create a directory for the non-stripped test. - set combined_dirname [standard_output_file ${mode}_non-stripped] + # Create a directory for the non-stripped test, copy every build + # artefact into this directory. + set combined_dirname [standard_output_file ${mode}_not-stripped] remote_exec build "mkdir -p $combined_dirname" - remote_exec build "cp $progname $combined_dirname" - - # Create a directory for the stripped test. - if {[gdb_gnu_strip_debug [standard_output_file $progname] no-debuglink] != 0} { - untested "could not strip executable for [join $suffix \ ]" - return + foreach filename $build_artefacts { + remote_exec build "cp $filename $combined_dirname" } + + # Split the debug from each build artefact. + foreach filename $build_artefacts { + if {[gdb_gnu_strip_debug $filename no-debuglink] != 0} { + untested "could not strip debug from [file tail $filename]" + return + } + } + + # Create a directory for the stripped test, move the now stripped + # binary, and the stripped out debug information for every build + # artefact, into this new directory. set sepdebug_dirname [standard_output_file ${mode}_stripped] remote_exec build "mkdir -p $sepdebug_dirname" - remote_exec build "mv $progname $sepdebug_dirname" - remote_exec build "mv ${progname}.debug $sepdebug_dirname" + foreach filename $build_artefacts { + remote_exec build "mv $filename $sepdebug_dirname" + remote_exec build "mv ${filename}.debug $sepdebug_dirname" + } + + # The build artefacts are all absolute filenames, but now they + # have been copied or moved into the two holding areas created + # above, it is more useful to have BUILD_ARTEFACTS contain just + # the basenames. Update the list now. + set build_artefacts [lmap filename $build_artefacts { + file tail $filename + }] # Now do the actual testing part. Fill out a debug directory with # build-id related files (copies or symlinks) and then load the @@ -262,9 +391,9 @@ foreach_with_prefix mode { exec shared } { } foreach_with_prefix symlink { false true } { - locate_exec_from_core_build_id $corefile $buildid \ - $dirname $progname \ - $sepdebug $symlink [expr {$mode eq "shared"}] + locate_exec_from_core_build_id $corefile $dirname \ + $build_artefacts $sepdebug $symlink \ + [expr {$mode eq "shared"}] } } } -- 2.25.4