2010-10-05 04:28:15 +00:00
|
|
|
#! /bin/sh
|
2012-07-18 20:04:44 +00:00
|
|
|
# Wrapper around gcc to tweak the output in various ways when running
|
|
|
|
# the testsuite.
|
2010-10-05 04:28:15 +00:00
|
|
|
|
2012-01-04 08:17:56 +00:00
|
|
|
# Copyright (C) 2010-2012 Free Software Foundation, Inc.
|
2010-10-05 04:28:15 +00:00
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# This program requires gdb and objcopy in addition to gcc.
|
2011-06-08 00:15:54 +00:00
|
|
|
# The default values are gdb from the build tree and objcopy from $PATH.
|
|
|
|
# They may be overridden by setting environment variables GDB and OBJCOPY
|
2012-09-14 08:03:34 +00:00
|
|
|
# respectively. Note that GDB should contain the gdb binary as well as the
|
|
|
|
# -data-directory flag, e.g., "foo/gdb -data-directory foo/data-directory".
|
2010-10-05 04:28:15 +00:00
|
|
|
# We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
|
|
|
|
#
|
|
|
|
# Example usage:
|
|
|
|
#
|
|
|
|
# bash$ cd $objdir/gdb/testsuite
|
|
|
|
# bash$ runtest \
|
2012-07-25 20:14:20 +00:00
|
|
|
# CC_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS gcc" \
|
|
|
|
# CXX_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS g++"
|
2010-10-05 04:28:15 +00:00
|
|
|
#
|
|
|
|
# For documentation on index files: info -f gdb.info -n "Index Files"
|
2012-07-18 20:04:44 +00:00
|
|
|
# For information about 'dwz', see the announcement:
|
|
|
|
# http://gcc.gnu.org/ml/gcc/2012-04/msg00686.html
|
|
|
|
# (More documentation is to come.)
|
2010-10-05 04:28:15 +00:00
|
|
|
|
2012-07-18 20:04:44 +00:00
|
|
|
# ARGS determine what is done. They can be:
|
2012-11-08 19:52:42 +00:00
|
|
|
# -Z invoke objcopy --compress-debug-sections
|
2012-07-18 20:04:44 +00:00
|
|
|
# -z compress using dwz
|
|
|
|
# -m compress using dwz -m
|
|
|
|
# -i make an index
|
|
|
|
# If nothing is given, no changes are made
|
|
|
|
|
|
|
|
myname=cc-with-tweaks.sh
|
2010-10-05 04:28:15 +00:00
|
|
|
|
|
|
|
if [ -z "$GDB" ]
|
|
|
|
then
|
|
|
|
if [ -f ./gdb ]
|
|
|
|
then
|
2012-09-14 08:03:34 +00:00
|
|
|
GDB="./gdb -data-directory data-directory"
|
2010-10-05 04:28:15 +00:00
|
|
|
elif [ -f ../gdb ]
|
|
|
|
then
|
2012-09-14 08:03:34 +00:00
|
|
|
GDB="../gdb -data-directory ../data-directory"
|
2011-06-08 01:40:58 +00:00
|
|
|
elif [ -f ../../gdb ]
|
|
|
|
then
|
2012-09-14 08:03:34 +00:00
|
|
|
GDB="../../gdb -data-directory ../../data-directory"
|
2010-10-05 04:28:15 +00:00
|
|
|
else
|
|
|
|
echo "$myname: unable to find usable gdb" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
OBJCOPY=${OBJCOPY:-objcopy}
|
2012-11-05 15:50:22 +00:00
|
|
|
READELF=${READELF:-readelf}
|
2010-10-05 04:28:15 +00:00
|
|
|
|
2012-07-18 20:04:44 +00:00
|
|
|
DWZ=${DWZ:-dwz}
|
2012-11-05 15:50:22 +00:00
|
|
|
DWP=${DWP:-dwp}
|
2012-07-18 20:04:44 +00:00
|
|
|
|
2010-10-05 04:28:15 +00:00
|
|
|
have_link=unknown
|
|
|
|
next_is_output_file=no
|
2010-10-07 19:34:52 +00:00
|
|
|
output_file=a.out
|
2010-10-05 04:28:15 +00:00
|
|
|
|
2012-07-18 20:04:44 +00:00
|
|
|
want_index=false
|
|
|
|
want_dwz=false
|
|
|
|
want_multi=false
|
2012-11-05 15:50:22 +00:00
|
|
|
want_dwp=false
|
2012-11-08 19:52:42 +00:00
|
|
|
want_objcopy_compress=false
|
2012-07-18 20:04:44 +00:00
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
2012-11-08 19:52:42 +00:00
|
|
|
-Z) want_objcopy_compress=true ;;
|
2012-07-18 20:04:44 +00:00
|
|
|
-z) want_dwz=true ;;
|
|
|
|
-i) want_index=true ;;
|
|
|
|
-m) want_multi=true ;;
|
2012-11-05 15:50:22 +00:00
|
|
|
-p) want_dwp=true ;;
|
2012-07-18 20:04:44 +00:00
|
|
|
*) break ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2010-10-05 04:28:15 +00:00
|
|
|
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"
|
2012-07-18 20:04:44 +00:00
|
|
|
if [ "$want_index" = true ] && [ -f "$index_file" ]
|
2010-10-05 04:28:15 +00:00
|
|
|
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
|
|
|
|
|
2012-11-08 19:52:42 +00:00
|
|
|
if [ "$want_objcopy_compress" = true ]; then
|
|
|
|
$OBJCOPY --compress-debug-sections "$output_file"
|
|
|
|
rc=$?
|
|
|
|
[ $rc != 0 ] && exit $rc
|
|
|
|
fi
|
|
|
|
|
2012-07-18 20:04:44 +00:00
|
|
|
if [ "$want_index" = true ]; then
|
|
|
|
$GDB --batch-silent -nx -ex "set auto-load no" -ex "file $output_file" -ex "save gdb-index $output_dir"
|
2010-10-05 04:28:15 +00:00
|
|
|
rc=$?
|
2012-07-18 20:04:44 +00:00
|
|
|
[ $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
|
|
|
|
[ $rc != 0 ] && exit $rc
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$want_dwz" = true ]; then
|
|
|
|
$DWZ "$output_file" > /dev/null 2>&1
|
|
|
|
elif [ "$want_multi" = true ]; then
|
|
|
|
cp $output_file ${output_file}.alt
|
|
|
|
$DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null 2>&1
|
2010-10-05 04:28:15 +00:00
|
|
|
fi
|
|
|
|
|
2012-11-05 15:50:22 +00:00
|
|
|
if [ "$want_dwp" = true ]; then
|
|
|
|
dwo_files=$($READELF -wi "${output_file}" | grep _dwo_name | \
|
|
|
|
sed -e 's/^.*: //' | sort | uniq)
|
|
|
|
$DWP -o "${output_file}.dwp" ${dwo_files} > /dev/null
|
|
|
|
rm -f ${dwo_files}
|
|
|
|
fi
|
|
|
|
|
2010-10-05 04:28:15 +00:00
|
|
|
rm -f "$index_file"
|
|
|
|
exit $rc
|