* hppa.h (pa_opcodes): Use "cX" completer instead of "cx" in fstqx
[external/binutils.git] / gdb / contrib / cc-with-tweaks.sh
1 #! /bin/sh
2 # Wrapper around gcc to tweak the output in various ways when running
3 # the testsuite.
4
5 # Copyright (C) 2010-2012 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 # This program requires gdb and objcopy in addition to gcc.
20 # The default values are gdb from the build tree and objcopy from $PATH.
21 # They may be overridden by setting environment variables GDB and OBJCOPY
22 # respectively.  Note that GDB should contain the gdb binary as well as the
23 # -data-directory flag, e.g., "foo/gdb -data-directory foo/data-directory".
24 # We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
25 #
26 # Example usage:
27 #
28 # bash$ cd $objdir/gdb/testsuite
29 # bash$ runtest \
30 #   CC_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS gcc" \
31 #   CXX_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS g++"
32 #
33 # For documentation on index files: info -f gdb.info -n "Index Files"
34 # For information about 'dwz', see the announcement:
35 #     http://gcc.gnu.org/ml/gcc/2012-04/msg00686.html
36 # (More documentation is to come.)
37
38 # ARGS determine what is done.  They can be:
39 # -z compress using dwz
40 # -m compress using dwz -m
41 # -i make an index
42 # If nothing is given, no changes are made
43
44 myname=cc-with-tweaks.sh
45
46 if [ -z "$GDB" ]
47 then
48     if [ -f ./gdb ]
49     then
50         GDB="./gdb -data-directory data-directory"
51     elif [ -f ../gdb ]
52     then
53         GDB="../gdb -data-directory ../data-directory"
54     elif [ -f ../../gdb ]
55     then
56         GDB="../../gdb -data-directory ../../data-directory"
57     else
58         echo "$myname: unable to find usable gdb" >&2
59         exit 1
60     fi
61 fi
62
63 OBJCOPY=${OBJCOPY:-objcopy}
64
65 DWZ=${DWZ:-dwz}
66
67 have_link=unknown
68 next_is_output_file=no
69 output_file=a.out
70
71 want_index=false
72 want_dwz=false
73 want_multi=false
74
75 while [ $# -gt 0 ]; do
76     case "$1" in
77         -z) want_dwz=true ;;
78         -i) want_index=true ;;
79         -m) want_multi=true ;;
80         *) break ;;
81     esac
82     shift
83 done
84
85 for arg in "$@"
86 do
87     if [ "$next_is_output_file" = "yes" ]
88     then
89         output_file="$arg"
90         next_is_output_file=no
91         continue
92     fi
93
94     # Poor man's gcc argument parser.
95     # We don't need to handle all arguments, we just need to know if we're
96     # doing a link and what the output file is.
97     # It's not perfect, but it seems to work well enough for the task at hand.
98     case "$arg" in
99     "-c") have_link=no ;;
100     "-E") have_link=no ;;
101     "-S") have_link=no ;;
102     "-o") next_is_output_file=yes ;;
103     esac
104 done
105
106 if [ "$next_is_output_file" = "yes" ]
107 then
108     echo "$myname: Unable to find output file" >&2
109     exit 1
110 fi
111
112 if [ "$have_link" = "no" ]
113 then
114     "$@"
115     exit $?
116 fi
117
118 index_file="${output_file}.gdb-index"
119 if [ "$want_index" = true ] && [ -f "$index_file" ]
120 then
121     echo "$myname: Index file $index_file exists, won't clobber." >&2
122     exit 1
123 fi
124
125 output_dir="${output_file%/*}"
126 [ "$output_dir" = "$output_file" ] && output_dir="."
127
128 "$@"
129 rc=$?
130 [ $rc != 0 ] && exit $rc
131 if [ ! -f "$output_file" ]
132 then
133     echo "$myname: Internal error: $output_file missing." >&2
134     exit 1
135 fi
136
137 if [ "$want_index" = true ]; then
138     $GDB --batch-silent -nx -ex "set auto-load no" -ex "file $output_file" -ex "save gdb-index $output_dir"
139     rc=$?
140     [ $rc != 0 ] && exit $rc
141
142     # GDB might not always create an index.  Cope.
143     if [ -f "$index_file" ]
144     then
145         $OBJCOPY --add-section .gdb_index="$index_file" \
146             --set-section-flags .gdb_index=readonly \
147             "$output_file" "$output_file"
148         rc=$?
149     else
150         rc=0
151     fi
152     [ $rc != 0 ] && exit $rc
153 fi
154
155 if [ "$want_dwz" = true ]; then
156     $DWZ "$output_file" > /dev/null 2>&1
157 elif [ "$want_multi" = true ]; then
158     cp $output_file ${output_file}.alt
159     $DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null 2>&1
160 fi
161
162 rm -f "$index_file"
163 exit $rc