From patchwork Mon May 20 14:14:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 90487 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 004D7384AB57 for ; Mon, 20 May 2024 14:15:00 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id EAD9F3858D35 for ; Mon, 20 May 2024 14:14:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAD9F3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 EAD9F3858D35 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=1716214471; cv=none; b=QwwxA37UTAgWfY0nPcwpKSwKpaA5yAGUsJmsRHu2nqPzF9iBKu18/lYtmJIOS21zMOOpFFrbWDvPKJqM5c9ApUthIVySMydHBJd8vHgh51HZS5AHC1hBYHiFXBOktgwEUrwRbOWWGcfr6SRM0l9e8HNOFOA/RkCWb52C9/NxTy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716214471; c=relaxed/simple; bh=m/Adpxy6oK9Iwd+BpCbQuj9+E42lD0JVaTjHeXN0ZiE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=PHHCfUDIwSpSmlF39M5u8VG5OKpY4ibjNaeUy5sCN1WKtyU5L+g9FfkOFcLCJRXqp2EnN932kBmr26Dj7kGF0HfWXBxgumQTteOEolhJ7tXSGHbo9pBYJjwy7KgXaWRjB8oIemW5H/SIOKVq9bO2NMgRy+eCT86F27rty7E+iFQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716214469; 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=xcgoyfX0EoHwfEfAftm4mkwjWUjtYnGjB6Jz+p+NtZs=; b=NU1QIf6ZpY8xBGJeJb5UzXMRV5tCJBBSuBtueWRXwuDu9I7AFSgSKX92memTuxWsVleQ5c AP8TjO6fggNIhDRkgnMEF+tpMsxm7qonod+MvqDUj5rrX4qfRKVQ1JxhKDjMCgAiI89VuC 9GN++bVTkDZU2KG4ZeN1WhitnQOFNV8= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-263-oTw5rSiRN6-2wFC2PNkA_w-1; Mon, 20 May 2024 10:14:28 -0400 X-MC-Unique: oTw5rSiRN6-2wFC2PNkA_w-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a51fdbd06c8so767960966b.3 for ; Mon, 20 May 2024 07:14:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716214467; x=1716819267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xcgoyfX0EoHwfEfAftm4mkwjWUjtYnGjB6Jz+p+NtZs=; b=YY4jgEjl66Pj1H7DvYVVl3Iv+FoY1D06e0VUMT/Ih77bTqmeDkY1A1odSXyDmPYNx9 pBSFTHpqHwGn40IRVwUnakuE3dl5DOUTwSYXHJUuQ9AH54ywh9OeBx+hBrttQ4q07Hhe b5XwrhBpPbxgOInE2qJ5QejwnrWbc1vJ/Ey/IrYPDnAerKi3H9ObQp08i9AdCx6TKnkr Pj393opg+4RfVljWaMYvyYd03Wc9fJuEWoegKR8WizRoIeVe7CFTHu6K2SGwu4f1amzO XOKWsijfcP3RSsDRIutwF1rAM99DtNxrj5tZLwGOoc+I/SYffk4JRqCXj3TncRly0IUq N4gA== X-Gm-Message-State: AOJu0YwO1hq2zHgxKoAD78eAO4+nB1WCToPBIZyQmMcEoEZPP3etzyK8 ScrSU4fkPCGtoA3Xp3v0CtfSIvh/Cgibg9DBdgcHYFTGOBV6Q2UsgzLhCM5CZVhie6ZF9+2Xzvt XuYNmUqoGiYHgbAjNWXa15068E9R1y8f5/nCd6jUgUkqNnsCpmRvqxAuOf4HydX3IPfPHBz0wHq CgBQBwNTmvSFoHWLRDfacsI0yHb/bmX+hn5fz/qubaoG0= X-Received: by 2002:a17:906:17c5:b0:a5a:1b57:426f with SMTP id a640c23a62f3a-a5a2d54c10fmr1787960366b.13.1716214466551; Mon, 20 May 2024 07:14:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJ7HggiTyMaILYimPsZjiQyPgwIP9slDdT4/QL3usC+ict77aqSHhJhhSBpCplU1n6C4jWjw== X-Received: by 2002:a17:906:17c5:b0:a5a:1b57:426f with SMTP id a640c23a62f3a-a5a2d54c10fmr1787958966b.13.1716214465776; Mon, 20 May 2024 07:14:25 -0700 (PDT) Received: from localhost ([31.111.84.240]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a179c7e8fsm1447703566b.122.2024.05.20.07.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 07:14:25 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb/testsuite: make gdb_gnu_strip_debug consistent Date: Mon, 20 May 2024 15:14:22 +0100 Message-Id: <5671b0171ba648906c19ec6e585668b35bb1d541.1716214388.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org While writing a test I realised that the default behaviour of gdb_gnu_strip_debug doesn't match its comment. The comment says that the function takes a FILENAME, and splits the file into FILENAME.stripped and FILENAME.debug, leaving FILENAME unchanged. The comment says that a .gnu_debuglink will be added to FILENAME.stripped. However, this is not true, FILENAME.stripped is created, with no debug information. FILENAME.debug is created containing the debug information. But, when adding the .gnu_debuglink we take FILENAME.stripped as the input, and then overwrite FILENAME with the output. As a result, FILENAME.stripped does not include a .gnu_debuglink, while FILENAME contains the .gnu_debuglink and no debug information! The users of gdb_gnu_strip_debug can be split into two groups, those who are using the .gnu_debuglink, these tests are all written assuming that FILENAME is updated. Then there are some tests that rely on gdb_gnu_strip_debug's ability to split out the debug information, these tests are then going to do a lookup based on the build-id. These tests use the FILENAME.stripped output file. This all seems too confused to me. As most used of gdb_gnu_strip_debug assume that FILENAME is updated, I propose that we just make that the actual, advertised behaviour of this proc. So now, gdb_gnu_strip_debug will take FILENAME, and will split the debug information out into FILENAME.debug. The debug information will then be stripped from FILENAME, and by default a .gnu_debuglink will be added to FILENAME pointing to FILENAME.debug. I've updated the two tests that actually relied on FILENAME.stripped to instead just use FILENAME. One of the tests was doing a build-id based lookup, but was still allowing the .gnu_debuglink to be added to FILENAME, I've updated this test to pass the no-debuglink flag to gdb_gnu_strip_debug, which stops the .gnu_debuglink from being added. All of the tests that call gdb_gnu_strip_debug still pass for me. Acked-By: Tom de Vries --- gdb/testsuite/gdb.base/corefile-buildid.exp | 18 +++---------- .../build-id-no-debug-warning.exp | 19 ++++---------- gdb/testsuite/lib/gdb.exp | 25 ++++++++++++------- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/gdb/testsuite/gdb.base/corefile-buildid.exp b/gdb/testsuite/gdb.base/corefile-buildid.exp index 130198611ec..e1b9804d891 100644 --- a/gdb/testsuite/gdb.base/corefile-buildid.exp +++ b/gdb/testsuite/gdb.base/corefile-buildid.exp @@ -172,11 +172,9 @@ proc locate_exec_from_core_build_id {corefile buildid suffix \ "mkdir -p [file join $debugdir [file dirname $buildid]]" set files_list {} + lappend files_list $binfile $buildid if {$sepdebug} { - lappend files_list "$binfile.stripped" $buildid lappend files_list "$binfile.debug" "$buildid.debug" - } else { - lappend files_list $binfile $buildid } if {$shared} { global sharedir @@ -200,12 +198,7 @@ proc locate_exec_from_core_build_id {corefile buildid suffix \ gdb_test "core-file $corefile" "Program terminated with .*" \ "load core file" if {$symlink} { - if {$sepdebug} { - set expected_file [file join $builddir \ - [file tail "$binfile.stripped"]] - } else { - set expected_file [file join $builddir [file tail $binfile]] - } + set expected_file [file join $builddir [file tail $binfile]] } else { set expected_file $buildid } @@ -245,15 +238,12 @@ proc do_corefile_buildid_tests {args} { if {$sepdebug} { # Strip debuginfo into its own file. - if {[gdb_gnu_strip_debug [standard_output_file $program_to_run]] \ - != 0} { + if {[gdb_gnu_strip_debug [standard_output_file $program_to_run] \ + no-debuglink] != 0} { untested "could not strip executable for [join $suffix \ ]" return } - # Run the stripped program instead of the original. - set program_to_run [file join $builddir \ - [file tail "$binfile.stripped"]] lappend suffix "sepdebug" } diff --git a/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp b/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp index b86622543ef..aa1c263e800 100644 --- a/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp +++ b/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp @@ -30,14 +30,11 @@ if {[build_executable "build executable" ${testfile} ${srcfile} \ return -1 } -# Split BINFILE into BINFILE.stripped and BINFILE.debug, the first is -# the executable with the debug information removed, and the second is -# the debug information. +# Split debug information from BINFILE into BINFILE.debug. # -# However, by passing the "no-debuglink" flag we prevent this proc -# from adding a .gnu_debuglink section to the executable. Any lookup -# of the debug information by GDB will need to be done based on the -# build-id. +# By passing the "no-debuglink" flag we prevent this proc from adding +# a .gnu_debuglink section to BINFILE. Any lookup of the debug +# information by GDB will need to be done based on the build-id. if {[gdb_gnu_strip_debug $binfile no-debuglink]} { unsupported "cannot produce separate debug info files" return -1 @@ -59,12 +56,6 @@ set debuginfod_debugdir [standard_output_file "debug"] remote_exec build "mkdir $debuginfod_debugdir" remote_exec build "mv $debugfile $debuginfod_debugdir" -# This is BINFILE with the debug information removed. We are going to -# place this in the BUILD_ID_DEBUG_FILE location, this would usually -# represent a mistake by the user, and will trigger a warning from -# GDB, this is the warning we are checking for. -set stripped_binfile [standard_output_file "${binfile}.stripped"] - # Create the .build-id/PREFIX directory name from # .build-id/PREFIX/SUFFIX.debug filename. set debugdir [file dirname ${build_id_debug_file}] @@ -76,7 +67,7 @@ remote_exec build "mkdir -p $debugdir" # information, which will point back at this file, which also doesn't # have debug information, which could cause a loop. But GDB will spot # this and give a warning. -remote_exec build "mv ${stripped_binfile} ${build_id_debug_file}" +remote_exec build "mv ${binfile} ${build_id_debug_file}" # Now start GDB. clean_restart diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 0d78691c381..a63c13f9cbc 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -8017,10 +8017,11 @@ proc build_id_debug_filename_get { filename } { } # DEST should be a file compiled with debug information. This proc -# creates two new files DEST.debug which contains the debug -# information extracted from DEST, and DEST.stripped, which is a copy -# of DEST with the debug information removed. A '.gnu_debuglink' -# section will be added to DEST.stripped that points to DEST.debug. +# creates DEST.debug which contains the debug information extracted +# from DEST, and DEST is updated with the debug information removed. +# +# By default a '.gnu_debuglink' section will be added to DEST that +# points to DEST.debug. # # If ARGS is passed, it is a list of optional flags. The currently # supported flags are: @@ -8028,7 +8029,7 @@ proc build_id_debug_filename_get { filename } { # - no-main : remove the symbol entry for main from the separate # debug file DEST.debug, # - no-debuglink : don't add the '.gnu_debuglink' section to -# DEST.stripped. +# DEST. # # Function returns zero on success. Function will return non-zero failure code # on some targets not supporting separate debug info (such as i386-msdos). @@ -8087,20 +8088,26 @@ proc gdb_gnu_strip_debug { dest args } { # Unless the "no-debuglink" flag is passed, then link the two # previous output files together, adding the .gnu_debuglink # section to the stripped_file, containing a pointer to the - # debug_file, save the new file in dest. + # debug_file. if {[lsearch -exact $args "no-debuglink"] == -1} { - set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output] + set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${stripped_file}-tmp" output] verbose "result is $result" verbose "output is $output" if {$result == 1} { return 1 } + file delete "${stripped_file}" + file rename "${stripped_file}-tmp" "${stripped_file}" } # Workaround PR binutils/10802: # Preserve the 'x' bit also for PIEs (Position Independent Executables). - set perm [file attributes ${stripped_file} -permissions] - file attributes ${dest} -permissions $perm + set perm [file attributes ${dest} -permissions] + file attributes ${stripped_file} -permissions $perm + + # Move the stripped_file back into dest. + file delete ${dest} + file rename ${stripped_file} ${dest} return 0 }