From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 154373858D33 for ; Thu, 23 May 2024 10:16:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 154373858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 154373858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716459389; cv=none; b=cv54Wn7XRjYyOvXQjCwwKXa6omSmD/2rjk8J6mkVV3Ntp4tPzYikil9F5wxrQBKrjdTBhIjYcsC/oDDI54WsZ1SzakHTcrgA0OefFb9FCrBE1swQBIgeIxEfokK/Q/7Ph1eG0+3FnqC89xw1KmmhANCnkxHaGIcts5CRakz65Xs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716459389; c=relaxed/simple; bh=5Y7J2yYZLG/cAPIxz8VFP6O5Kkvv8nzjGFrTDWtkJ88=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=SOUxBDikKO7TSrn81JSHWVUvPdohuD/wfUYlWsqACIXJs4sAj/IHY837abpY+2p3JcyTpbhxFiGsk8PJR/AGgBGyqwOudQQtdPWmXplkK2Tbls7mFxkNg97NQRS+qrSzIH1QViSdxXLepvtYZVzlbd9sudU9iZcLopAIwhqg0ro= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2F4F7200D2; Thu, 23 May 2024 10:16:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716459384; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G68L6OncXNOm1T8eeIZJv1TgB1+3qZSlLENbMN0w3io=; b=LRnCvz2tgCGPr03kO3BNCGG3RIdHcArhlvwBu4njrpN0iQ5PVt/VJ5shTrfw4kUwQ9tgRG ImCekB8WO/i4fKaeQtA8TFdv0NIupf0x4ZjPVmqbXiVAAHvvhSucV0stXDujm7QOQpaFyN +D87IpKd8NTNTi1D+7GIVM1b0rasjFg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716459384; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G68L6OncXNOm1T8eeIZJv1TgB1+3qZSlLENbMN0w3io=; b=XNwZTtmReWmDMwVhJKUjBHcJC6JSR7njpVH9yh+sb2cOe7oxVIO7OFH69wDo043Io/W0w8 JqektFUe3LhrCIBw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=LRnCvz2t; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=XNwZTtmR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716459384; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G68L6OncXNOm1T8eeIZJv1TgB1+3qZSlLENbMN0w3io=; b=LRnCvz2tgCGPr03kO3BNCGG3RIdHcArhlvwBu4njrpN0iQ5PVt/VJ5shTrfw4kUwQ9tgRG ImCekB8WO/i4fKaeQtA8TFdv0NIupf0x4ZjPVmqbXiVAAHvvhSucV0stXDujm7QOQpaFyN +D87IpKd8NTNTi1D+7GIVM1b0rasjFg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716459384; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G68L6OncXNOm1T8eeIZJv1TgB1+3qZSlLENbMN0w3io=; b=XNwZTtmReWmDMwVhJKUjBHcJC6JSR7njpVH9yh+sb2cOe7oxVIO7OFH69wDo043Io/W0w8 JqektFUe3LhrCIBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 171EE13A6B; Thu, 23 May 2024 10:16:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id f9MxBHgXT2acewAAD6G6ig (envelope-from ); Thu, 23 May 2024 10:16:24 +0000 Message-ID: Date: Thu, 23 May 2024 12:17:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] gdb/testsuite: tests for debug lookup within the sysroot To: Andrew Burgess , gdb-patches@sourceware.org References: Content-Language: en-US From: Tom de Vries In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -4.50 X-Rspamd-Action: no action X-Rspamd-Queue-Id: 2F4F7200D2 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.50 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email,gnu.org:url]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,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 List-Id: On 5/20/24 16:14, Andrew Burgess wrote: > Add tests for looking up debug information within the sysroot via both > build-id and gnu_debuglink. > > I wanted to ensure that the gnu_debuglink test couldn't make use of > build-ids, so I added the 'no-build-id' flag to gdb_compile. > > As these tests rely on setting the sysroot, if I'm running a > dynamically linked executable, GDB will try to find all shared > libraries within the sysroot. This would mean I'd have to figure out > and copy all shared libraries the executable uses, certainly possible, > but a bit of a pain. > > So instead, I've just compiled the test executable as a static binary. > Now there are no shared library dependencies. > Make sense. > I can now split the debug information out from the test binary, and > place it within the sysroot. When GDB is started and the executable > loaded, we can check that GDB is finding the debug information within > the sysroot. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30871 > --- > gdb/testsuite/gdb.base/sysroot-debug-lookup.c | 22 +++ > .../gdb.base/sysroot-debug-lookup.exp | 162 ++++++++++++++++++ > gdb/testsuite/lib/gdb.exp | 13 ++ > 3 files changed, 197 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/sysroot-debug-lookup.c > create mode 100644 gdb/testsuite/gdb.base/sysroot-debug-lookup.exp > > diff --git a/gdb/testsuite/gdb.base/sysroot-debug-lookup.c b/gdb/testsuite/gdb.base/sysroot-debug-lookup.c > new file mode 100644 > index 00000000000..e67331d3150 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/sysroot-debug-lookup.c > @@ -0,0 +1,22 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 1992-2024 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 > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +int > +main () > +{ > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp b/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp > new file mode 100644 > index 00000000000..e0377df0fa7 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp > @@ -0,0 +1,162 @@ > +# Copyright 2024 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 > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test GDB's ability to find debug information by looking within the > +# sysroot. > +# > +# We compile a static binary (to reduce what we need to copy into the > +# sysroot), split the debug information from the binary, and setup a > +# sysroot. > +# > +# The debug-file-directory is set to just '/debug', but we're > +# expecting GDB to actually look in '$SYSROOT/debug'. > +# > +# There's a test for using .build-id based lookup, and a test for > +# gnu_debuglink based lookup. > + > +require {!is_remote host} > + > +standard_testfile Consider using "standard_testfile main.c" and dropping gdb/testsuite/gdb.base/sysroot-debug-lookup.c. > + > +# Create a copy of BINFILE, split out the debug information, and then > +# setup a sysroot. Hide (by moving) the actual debug information file > +# and create a symlink to the hidden debug information from within the > +# sysroot. > +# > +# Start GDB, set the sysroot, and then load the executable, ensure GDB > +# finds the debug information, which must have happened by lookin in > +# the sysroot. > +proc_with_prefix lookup_via_build_id {} { > + set filename ${::binfile}_1 > + if { [build_executable "build exec" ${filename} $::srcfile \ > + {additional_flags=-static debug build-id}] } { > + return > + } > + > + # Split debug information into a .debug file, remove debug > + # information from FILENAME. Don't add a .gnu_debuglink to > + # FILENAME, we rely on the build-id. > + if {[gdb_gnu_strip_debug $filename { no-debuglink }] != 0} { > + unsupported "cannot split debug information from executable" > + return > + } > + > + set sysroot [standard_output_file "sysroot1"] > + set debug_dir "/debug" > + > + set debug_symlink \ > + $sysroot/$debug_dir/[build_id_debug_filename_get $filename] > + > + set build_id_dir [file dirname $debug_symlink] > + > + set debug_filename ${filename}_hidden_debug > + > + remote_exec build "mkdir -p $build_id_dir" > + remote_exec build "mv $filename.debug $debug_filename" > + remote_exec build "ln -sf $debug_filename $debug_symlink" > + > + clean_restart > + > + gdb_test_no_output "set sysroot $sysroot" "set sysroot" > + gdb_test_no_output "set debug-file-directory $debug_dir" > + > + gdb_file_cmd $filename > + > + gdb_assert { $::gdb_file_cmd_debug_info eq "debug" } > + > + set re [string_to_regexp "Reading symbols from $debug_filename..."] > + gdb_assert {[regexp $re $::gdb_file_cmd_msg]} Consider adding a friendlier test name, likewise in the other proc. Currently we get for a fail the not very meaningful: ... FAIL: $exp: lookup_via_build_id: [regexp $re $::gdb_file_cmd_msg] ... > +} > + > +# Create a copy of BINFILE, split out the debug information, and then > +# setup a sysroot. Hide (by moving) the actual debug information file > +# and create a symlink to the hidden debug information from within the > +# sysroot. > +# > +# Copy the executable into the sysroot and then start GDB, set the > +# sysroot, and load the executable. Check that GDB finds the debug > +# information, which must have happened by lookin in the sysroot. > +proc_with_prefix lookup_via_debuglink {} { > + set filename ${::binfile}_2 > + if { [build_executable "build exec" ${filename} $::srcfile \ > + {additional_flags=-static debug no-build-id}] } { > + return > + } > + > + # Split debug information into a .debug file, remove debug > + # information from FILENAME. > + if {[gdb_gnu_strip_debug $filename] != 0} { > + unsupported "cannot split debug information from executable" > + return > + } > + > + # We're going to setup the sysroot like this: > + # > + # sysroot2/ > + # bin/ > + # $FILENAME > + # debug/ > + # bin/ > + # $FILENAME.debug > + # > + # When looking up debug information via the debuglink, GDB will > + # only search in the sysroot if the original objfile was in the > + # sysroot. And GDB will resolve symlinks, so if the objfile is > + # symlinked to outside the sysroot, GDB will not search in the > + # sysroot for the debug information. > + # > + # So we have to copy the executable into the sysroot. > + # > + # We are OK to symlink the debug information to a file outside the > + # sysroot though. > + > + set sysroot [standard_output_file "sysroot2"] > + > + foreach path { bin debug/bin } { > + remote_exec build "mkdir -p $sysroot/$path" > + } > + > + # Copy the executable into the sysroot. > + set file_basename [file tail $filename] > + set exec_in_sysroot ${sysroot}/bin/${file_basename} > + remote_exec build "cp $filename $exec_in_sysroot" > + > + # Rename the debug file outside of the sysroot, this should stop > + # GDB finding this file "by accident". > + set debug_filename ${filename}_hidden_debug > + remote_exec build "mv $filename.debug $debug_filename" > + > + # Symlink the debug information into the sysroot. > + set debug_symlink \ > + ${sysroot}/debug/bin/${file_basename}.debug > + remote_exec build "ln -sf $debug_filename $debug_symlink" > + > + # Restart GDB and setup the sysroot and debug directory. > + clean_restart > + gdb_test_no_output "set sysroot $sysroot" "set sysroot" > + gdb_test_no_output "set debug-file-directory /debug" > + > + # Load the executable, we expect GDB to find the debug information > + # in the sysroot. > + gdb_file_cmd $exec_in_sysroot > + > + gdb_assert { $::gdb_file_cmd_debug_info eq "debug" } > + > + set re [string_to_regexp "Reading symbols from $debug_symlink..."] > + gdb_assert {[regexp $re $::gdb_file_cmd_msg]} > +} > + > +lookup_via_build_id > +lookup_via_debuglink > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > index a63c13f9cbc..a8e8b69d6ef 100644 > --- a/gdb/testsuite/lib/gdb.exp > +++ b/gdb/testsuite/lib/gdb.exp > @@ -5211,6 +5211,7 @@ proc quote_for_host { args } { > # debug information > # - text_segment=addr: Tell the linker to place the text segment at ADDR. > # - build-id: Ensure the final binary includes a build-id. > +# - no-build-id: Ensure the final binary does not include a build-id. > # - column-info/no-column-info: Enable/Disable generation of column table > # information. > # > @@ -5316,6 +5317,18 @@ proc gdb_compile {source dest type options} { > lappend new_options "additional_flags=-Wl,--build-id" > } > > + # If the 'no-build-id' option is used then disable the build-id. > + if {[lsearch -exact $options no-build-id] > 0} { > + lappend new_options "additional_flags=-Wl,--build-id=none" > + } > + > + # Sanity check. If both 'build-id' and 'no-build-id' are used > + # then what is expected from us! > + if {[lsearch -exact $options build-id] > 0 > + && [lsearch -exact $options no-build-id] > 0} { > + error "cannot use build-id and no-build-id options" > + } > + > # Treating .c input files as C++ is deprecated in Clang, so > # explicitly force C++ language. > if { !$getting_compiler_info I've added the target: prefix for the set sysroot commands, and ran into these three fails: ... FAIL: gdb.base/sysroot-debug-lookup.exp: lookup_via_build_id: [regexp $re $::gdb_file_cmd_msg] FAIL: gdb.base/sysroot-debug-lookup.exp: lookup_via_debuglink: $::gdb_file_cmd_debug_info eq "debug" FAIL: gdb.base/sysroot-debug-lookup.exp: lookup_via_debuglink: [regexp $re $::gdb_file_cmd_msg] ... The first one is just due to gdb mentioning an unresolved symlink. But I think the next one reproduces PR30866. So, IWBN to add this dimension to the test-case and add a kfail. Anyway, as is, LGTM. Approved-By: Tom de Vries Thanks, - Tom