From patchwork Wed Aug 12 18:24:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 8161 Received: (qmail 101395 invoked by alias); 12 Aug 2015 18:24:23 -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 101386 invoked by uid 89); 12 Aug 2015 18:24:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f73.google.com Received: from mail-pa0-f73.google.com (HELO mail-pa0-f73.google.com) (209.85.220.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 12 Aug 2015 18:24:20 +0000 Received: by pacum4 with SMTP id um4so2038871pac.1 for ; Wed, 12 Aug 2015 11:24:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to :content-type; bh=8Uw4oY3ty0sCgsHGRGFyNHtdo4dpR3v2vKKabflzf0w=; b=TYIh25JOs58h24OCr3kIQh5KaZrGgFR5+GV5B1CoPgQSdNOKm3HTvHs1hvqeCUva2O iHUJugaLLTh1ajECsmKyjxg04fvWdnrEMfN5RtbCfqNSr8gI+7iusca56lPQCPZ14Isj tPQPKb9Ic6HerE64ZKj0xflkJEGfJvx12XyMXmn9InTQY3M90JPKyexb2wZSNFP5GwfA kKdJmUySxS/804fonoUEJrgxCDOKWStPc8kb4PmscEeuYA+BETovbjk4vVzAnbou1c29 Ylh+F1sDYyMEoA6ITwutvI2Y11lS6qjiQzsajiNIq1dOwEAh/eRbcN/SRqF7uANqqI5b fc/w== X-Gm-Message-State: ALoCoQnfqyiAQ9KZCivuyq+XS0hQ0UlkRKfDLEdpFF66R/ygO+GdDrrmxmfFBdCynctrWJuiqrBhyAQ/e26SNSa0IgtSgAB/2z6v28MhrGxtKkKR9SuHB8h3tuie10NkdI1sRqzX97akZK2+a7lz2uEhA0eKEEmOLv/cCWgDXy/ajSwJB9rrLmI= MIME-Version: 1.0 X-Received: by 10.66.63.69 with SMTP id e5mr30519042pas.34.1439403858701; Wed, 12 Aug 2015 11:24:18 -0700 (PDT) Message-ID: <001a113803b2aff208051d215382@google.com> Date: Wed, 12 Aug 2015 18:24:18 +0000 Subject: [PATCH 2/2] Try both make_relative_prefix{, ignore_links} for relocatability From: Doug Evans To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi. This patch is the testcase. It's pretty simple, but it does do things a little differently. Adding bindir to the output of "show config" is reasonable regardless: We tell the user that certain dirs are relocatable, but we don't provide the necessary information to answer the question "Relocatable relative to what?". 2015-08-12 Doug Evans * top.c (print_gdb_configuration): Print BINDIR. testsuite/ * gdb.base/relocatable.exp: New file. + + start_and_check_data_dir ${install_bindir}/gdb \ + "${install_dir}${datadir}" + } +} diff --git a/gdb/top.c b/gdb/top.c index 061b52f..247650d 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1285,6 +1285,9 @@ This GDB was configured as follows:\n\ configure --host=%s --target=%s\n\ "), host_name, target_name); fprintf_filtered (stream, _("\ + --bindir=%s\n\ +"), BINDIR); + fprintf_filtered (stream, _("\ --with-auto-load-dir=%s\n\ --with-auto-load-safe-path=%s\n\ "), AUTO_LOAD_DIR, AUTO_LOAD_SAFE_PATH); diff --git a/gdb/testsuite/gdb.base/relocatable.exp b/gdb/testsuite/gdb.base/relocatable.exp new file mode 100644 index 0000000..ea35f29 --- /dev/null +++ b/gdb/testsuite/gdb.base/relocatable.exp @@ -0,0 +1,161 @@ +# Copyright 2015 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 handling of relocatability. +# This only works if gdb was configured to be relocatable. +# We can't rebuild gdb just for this test, but we can check whether +# the built gdb is relocatable and if so then run the tests. + +# It's not clear what systems this test will work on. +# For now pick the ones we know will work. +if {![istarget *-*-linux*] + || [is_remote host]} { + return 0 +} + +gdb_exit +gdb_start +set config [capture_command_output "show config" ""] + +regsub "^.*(--bindir=\[\^\r\n\]+).*$" $config "\\1" bindir_text +regsub "^.*(--with-gdb-datadir=\[\^\r\n\]+).*$" $config "\\1" datadir_text + +verbose -log "bindir_text: $bindir_text" +verbose -log "datadir_text: $datadir_text" + +if { [string first " (relocatable)" $datadir_text] < 0 } { + unsupported "gdb not relocatable" + return 0 +} + +regsub "^--bindir=" $bindir_text "" bindir +regsub "^--with-gdb-datadir=" $datadir_text "" datadir +regsub " \\(relocatable\\)" $datadir "" datadir + +verbose -log "bindir: $bindir" +verbose -log "datadir: $datadir" + +set env_program "env" ;# TODO: gdb_find_env +set make_program "make" ;# TODO: gdb_find_make + +# Run "make install" to install gdb in INSTALL_DIR. +# The result is zero for success, non-zero for failure. + +proc make_install { install_dir } { + global env_program + global make_program + + file delete -force -- $install_dir + + # If invoked from make check-parallel, several env vars are set up which + # will confuse this make, so unset them. + set env_options "-u MAKELEVEL -u MAKEFLAGS -u MFLAGS -u MAKEOVERRIDES" + + # We don't need to install the docs or gdbserver, just gdb. + # And we don't want to cause a rebuild of gdb, so use install-only. + set make_options "-C .. install-only SUBDIRS=data-directory DESTDIR=$install_dir" + + set cmd "$env_program $env_options $make_program $make_options" + verbose -log "Executing: $cmd" + set result [catch "exec $cmd" output] + + verbose -log "result is $result" + verbose -log "output is $output" + + set test "make install" + if { $result != 0 } { + fail $test + } else { + pass $test + } + return $result +} + +proc start_and_check_data_dir { gdb_path expected_data_dir } { + global GDB INTERNAL_GDBFLAGS + save_vars { GDB INTERNAL_GDBFLAGS } { + set GDB $gdb_path + # We want this gdb to find its installed data-directory, so don't + # pass it one. + regsub -- "-data-directory \[^ \]+" $INTERNAL_GDBFLAGS "" INTERNAL_GDBFLAGS + gdb_exit + gdb_start + set datadir_in_gdb [capture_command_output "show data-dir" ""] + regsub "^GDB's data directory is \"" $datadir_in_gdb "" datadir_in_gdb + regsub "\".\[\r\n\]+$" $datadir_in_gdb "" datadir_in_gdb + set test "data-dir updated correctly" + if { $datadir_in_gdb == $expected_data_dir } { + pass $test + } else { + fail $test + } + } +} + +# Move all files (and directories) from from_dir to to_dir and leave behind +# symlinks pointing to the new location. + +proc move_and_leave_symlinks { from_dir to_dir } { + file delete -force -- $to_dir + file mkdir $to_dir + set files [glob -tails -directory $from_dir *] + foreach f $files { + file copy -- "${from_dir}/$f" "${to_dir}" + file delete -force -- "${from_dir}/$f" + file link -symbolic "${from_dir}/$f" "${to_dir}/$f" + } +} + +# First test the case where gdb is a symlink to its installed copy. +# This exercises make_relative_prefix (where we need to call lrealname +# on gdb's argv[0] in order to establish our location). + +with_test_prefix "realpath_symlinks" { + set install_dir [standard_output_file make_relative_prefix] + + if { [make_install $install_dir] == 0 } { + set linked_gdb [standard_output_file ${install_dir}/gdb] + file delete -force -- "${linked_gdb}" + file link -symbolic "${linked_gdb}" ".${bindir}/gdb" + + start_and_check_data_dir $linked_gdb "${install_dir}${datadir}" + } +} + +# Second test is having the install tree being a set of symlinks pointing +# to (essentially) random places +# This exercises make_relative_prefix_ignore_links (where calling lrealname on +# gdb's argv[0] is the wrong thing to do). + +with_test_prefix "ignore_symlinks" { + set install_dir [standard_output_file make_relative_prefix_ignore_links] + + if { [make_install $install_dir] == 0 } { + # Now that we've created an install tree, move bindir and datadir to + # "random" places and create symlinks in their place. + + set install_bindir "${install_dir}${bindir}" + set install_datadir "${install_dir}${datadir}" + + set random_bindir "${install_dir}/random1/bindir" + set random_datadir "${install_dir}/random2/datadir" + + move_and_leave_symlinks $install_bindir $random_bindir + move_and_leave_symlinks $install_datadir $random_datadir