[PATCH 12/57][Arm][GAS] Add support for MVE instructions: vaddlv and vaddv
[binutils-gdb.git] / gdb / contrib / cc-with-tweaks.sh
blob7df16bc6c1ca03d7acc502b81752d6bbfe5e9a4e
1 #!/usr/bin/env bash
2 # Wrapper around gcc to tweak the output in various ways when running
3 # the testsuite.
5 # Copyright (C) 2010-2019 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.
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.
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/>.
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.
26 # Example usage:
28 # bash$ cd $objdir/gdb/testsuite
29 # bash$ runtest \
30 # CC_FOR_TARGET="/bin/bash $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS gcc" \
31 # CXX_FOR_TARGET="/bin/bash $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS g++"
33 # For documentation on Fission and dwp files:
34 # http://gcc.gnu.org/wiki/DebugFission
35 # http://gcc.gnu.org/wiki/DebugFissionDWP
36 # For documentation on index files: info -f gdb.info -n "Index Files"
37 # For information about 'dwz', see the announcement:
38 # http://gcc.gnu.org/ml/gcc/2012-04/msg00686.html
39 # (More documentation is to come.)
41 # ARGS determine what is done. They can be:
42 # -Z invoke objcopy --compress-debug-sections
43 # -z compress using dwz
44 # -m compress using dwz -m
45 # -i make an index (.gdb_index)
46 # -n make a dwarf5 index (.debug_names)
47 # -p create .dwp files (Fission), you need to also use gcc option -gsplit-dwarf
48 # If nothing is given, no changes are made
50 myname=cc-with-tweaks.sh
51 mydir=`dirname "$0"`
53 if [ -z "$GDB" ]
54 then
55 if [ -f ./gdb ]
56 then
57 GDB="./gdb -data-directory data-directory"
58 elif [ -f ../gdb ]
59 then
60 GDB="../gdb -data-directory ../data-directory"
61 elif [ -f ../../gdb ]
62 then
63 GDB="../../gdb -data-directory ../../data-directory"
64 else
65 echo "$myname: unable to find usable gdb" >&2
66 exit 1
70 OBJCOPY=${OBJCOPY:-objcopy}
71 READELF=${READELF:-readelf}
73 DWZ=${DWZ:-dwz}
74 DWP=${DWP:-dwp}
76 have_link=unknown
77 next_is_output_file=no
78 output_file=a.out
80 want_index=false
81 index_options=""
82 want_dwz=false
83 want_multi=false
84 want_dwp=false
85 want_objcopy_compress=false
87 while [ $# -gt 0 ]; do
88 case "$1" in
89 -Z) want_objcopy_compress=true ;;
90 -z) want_dwz=true ;;
91 -i) want_index=true ;;
92 -n) want_index=true; index_options=-dwarf-5;;
93 -m) want_multi=true ;;
94 -p) want_dwp=true ;;
95 *) break ;;
96 esac
97 shift
98 done
100 if [ "$want_index" = true ]
101 then
102 if [ -z "$GDB_ADD_INDEX" ]
103 then
104 if [ -f $mydir/gdb-add-index.sh ]
105 then
106 GDB_ADD_INDEX="$mydir/gdb-add-index.sh"
107 else
108 echo "$myname: unable to find usable contrib/gdb-add-index.sh" >&2
109 exit 1
114 for arg in "$@"
116 if [ "$next_is_output_file" = "yes" ]
117 then
118 output_file="$arg"
119 next_is_output_file=no
120 continue
123 # Poor man's gcc argument parser.
124 # We don't need to handle all arguments, we just need to know if we're
125 # doing a link and what the output file is.
126 # It's not perfect, but it seems to work well enough for the task at hand.
127 case "$arg" in
128 "-c") have_link=no ;;
129 "-E") have_link=no ;;
130 "-S") have_link=no ;;
131 "-o") next_is_output_file=yes ;;
132 esac
133 done
135 if [ "$next_is_output_file" = "yes" ]
136 then
137 echo "$myname: Unable to find output file" >&2
138 exit 1
141 if [ "$have_link" = "no" ]
142 then
143 "$@"
144 exit $?
147 index_file="${output_file}.gdb-index"
148 if [ "$want_index" = true ] && [ -f "$index_file" ]
149 then
150 echo "$myname: Index file $index_file exists, won't clobber." >&2
151 exit 1
154 output_dir="${output_file%/*}"
155 [ "$output_dir" = "$output_file" ] && output_dir="."
157 "$@"
158 rc=$?
159 [ $rc != 0 ] && exit $rc
160 if [ ! -f "$output_file" ]
161 then
162 echo "$myname: Internal error: $output_file missing." >&2
163 exit 1
166 if [ "$want_objcopy_compress" = true ]; then
167 $OBJCOPY --compress-debug-sections "$output_file"
168 rc=$?
169 [ $rc != 0 ] && exit $rc
172 if [ "$want_index" = true ]; then
173 # Filter out these messages which would stop dejagnu testcase run:
174 # echo "$myname: No index was created for $file" 1>&2
175 # echo "$myname: [Was there no debuginfo? Was there already an index?]" 1>&2
176 GDB=$GDB $GDB_ADD_INDEX $index_options "$output_file" 2>&1 \
177 | grep -v "^${GDB_ADD_INDEX##*/}: " >&2
178 rc=${PIPESTATUS[0]}
179 [ $rc != 0 ] && exit $rc
182 if [ "$want_dwz" = true ]; then
183 # Validate dwz's result by checking if the executable was modified.
184 cp "$output_file" "${output_file}.copy"
185 $DWZ "$output_file" > /dev/null
186 cmp "$output_file" "$output_file.copy" > /dev/null
187 cmp_rc=$?
188 rm -f "${output_file}.copy"
190 case $cmp_rc in
192 echo "$myname: dwz did not modify ${output_file}."
193 exit 1
196 # File was modified, great.
199 # Other cmp error, it presumably has already printed something on
200 # stderr.
201 exit 1
203 esac
204 elif [ "$want_multi" = true ]; then
205 # Remove the dwz output file if it exists, so we don't mistake it for a
206 # new file in case dwz fails.
207 rm -f "${output_file}.dwz"
209 cp $output_file ${output_file}.alt
210 $DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null
211 rm -f ${output_file}.alt
213 # Validate dwz's work by checking if the expected output file exists.
214 if [ ! -f "${output_file}.dwz" ]; then
215 echo "$myname: dwz file ${output_file}.dwz missing."
216 exit 1
220 if [ "$want_dwp" = true ]; then
221 dwo_files=$($READELF -wi "${output_file}" | grep _dwo_name | \
222 sed -e 's/^.*: //' | sort | uniq)
223 rc=0
224 if [ -n "$dwo_files" ]; then
225 $DWP -o "${output_file}.dwp" ${dwo_files} > /dev/null
226 rc=$?
227 [ $rc != 0 ] && exit $rc
228 rm -f ${dwo_files}
232 rm -f "$index_file"
233 exit $rc