From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12864 invoked by alias); 5 Oct 2010 04:28:46 -0000 Received: (qmail 12855 invoked by uid 22791); 5 Oct 2010 04:28:45 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,TW_BJ,TW_JC,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Oct 2010 04:28:40 +0000 Received: from wpaz37.hot.corp.google.com (wpaz37.hot.corp.google.com [172.24.198.101]) by smtp-out.google.com with ESMTP id o954STZw015708; Mon, 4 Oct 2010 21:28:29 -0700 Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.18.118.116]) by wpaz37.hot.corp.google.com with ESMTP id o954SRoK024582; Mon, 4 Oct 2010 21:28:28 -0700 Received: by ruffy.mtv.corp.google.com (Postfix, from userid 67641) id 9640724619A; Mon, 4 Oct 2010 21:28:27 -0700 (PDT) To: tromey@redhat.com, gdb-patches@sourceware.org Subject: [commit] cc-with-index.sh Message-Id: <20101005042827.9640724619A@ruffy.mtv.corp.google.com> Date: Tue, 05 Oct 2010 04:28:00 -0000 From: dje@google.com (Doug Evans) X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00043.txt.bz2 I need a way to run the testsuite with index files, so I wrote this script to help. Tom, feel free to replace it with something else. 2010-10-04 Doug Evans * cc-with-index.sh: New file. Index: cc-with-index.sh =================================================================== RCS file: cc-with-index.sh diff -N cc-with-index.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ cc-with-index.sh 5 Oct 2010 04:25:54 -0000 @@ -0,0 +1,122 @@ +#! /bin/sh +# Wrapper around gcc to add the .gdb_index section when running the testsuite. + +# Copyright (C) 2010 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 . + +# This program requires gdb and objcopy in addition to gcc. +# The default values are gdb from the build tree and objdump from $PATH. +# They may be overridden by setting environment variables GDB and OBJDUMP +# respectively. +# We assume the current directory is either $obj/gdb or $obj/gdb/testsuite. +# +# Example usage: +# +# bash$ cd $objdir/gdb/testsuite +# bash$ runtest \ +# CC_FOR_TARGET="/bin/sh $srcdir/cc-with-index.sh gcc" \ +# CXX_FOR_TARGET="/bin/sh $srcdir/cc-with-index.sh g++" +# +# For documentation on index files: info -f gdb.info -n "Index Files" + +myname=cc-with-index.sh + +if [ -z "$GDB" ] +then + if [ -f ./gdb ] + then + GDB="./gdb" + elif [ -f ../gdb ] + then + GDB="../gdb" + else + echo "$myname: unable to find usable gdb" >&2 + exit 1 + fi +fi + +OBJCOPY=${OBJCOPY:-objcopy} + +have_link=unknown +next_is_output_file=no + +for arg in "$@" +do + if [ "$next_is_output_file" = "yes" ] + then + output_file="$arg" + next_is_output_file=no + continue + fi + + # Poor man's gcc argument parser. + # We don't need to handle all arguments, we just need to know if we're + # doing a link and what the output file is. + # It's not perfect, but it seems to work well enough for the task at hand. + case "$arg" in + "-c") have_link=no ;; + "-E") have_link=no ;; + "-S") have_link=no ;; + "-o") next_is_output_file=yes ;; + esac +done + +if [ "$next_is_output_file" = "yes" ] +then + echo "$myname: Unable to find output file" >&2 + exit 1 +fi + +if [ "$have_link" = "no" ] +then + "$@" + exit $? +fi + +index_file="${output_file}.gdb-index" +if [ -f "$index_file" ] +then + echo "$myname: Index file $index_file exists, won't clobber." >&2 + exit 1 +fi + +output_dir="${output_file%/*}" +[ "$output_dir" = "$output_file" ] && output_dir="." + +"$@" +rc=$? +[ $rc != 0 ] && exit $rc +if [ ! -f "$output_file" ] +then + echo "$myname: Internal error: $output_file missing." >&2 + exit 1 +fi + +$GDB --batch-silent -nx -ex "file $output_file" -ex "save gdb-index $output_dir" +rc=$? +[ $rc != 0 ] && exit $rc + +# GDB might not always create an index. Cope. +if [ -f "$index_file" ] +then + $OBJCOPY --add-section .gdb_index="$index_file" \ + --set-section-flags .gdb_index=readonly \ + "$output_file" "$output_file" + rc=$? +else + rc=0 +fi + +rm -f "$index_file" +exit $rc