| OLD | NEW |
| 1 #! /bin/sh | 1 #! /bin/sh |
| 2 # Wrapper around gcc to add the .gdb_index section when running the testsuite. | 2 # Wrapper around gcc to run 'dwz' when running the testsuite. |
| 3 | 3 |
| 4 # Copyright (C) 2010-2012 Free Software Foundation, Inc. | 4 # Copyright (C) 2010-2012 Free Software Foundation, Inc. |
| 5 # This program is free software; you can redistribute it and/or modify | 5 # This program is free software; you can redistribute it and/or modify |
| 6 # it under the terms of the GNU General Public License as published by | 6 # it under the terms of the GNU General Public License as published by |
| 7 # the Free Software Foundation; either version 3 of the License, or | 7 # the Free Software Foundation; either version 3 of the License, or |
| 8 # (at your option) any later version. | 8 # (at your option) any later version. |
| 9 # | 9 # |
| 10 # This program is distributed in the hope that it will be useful, | 10 # This program is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
| 14 # | 14 # |
| 15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
| 16 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 |
| 18 # This program requires gdb and objcopy in addition to gcc. | 18 # This program requires dwz in addition to gcc. |
| 19 # The default values are gdb from the build tree and objcopy from $PATH. | |
| 20 # They may be overridden by setting environment variables GDB and OBJCOPY | |
| 21 # respectively. | |
| 22 # We assume the current directory is either $obj/gdb or $obj/gdb/testsuite. | |
| 23 # | 19 # |
| 24 # Example usage: | 20 # Example usage: |
| 25 # | 21 # |
| 26 # bash$ cd $objdir/gdb/testsuite | 22 # bash$ cd $objdir/gdb/testsuite |
| 27 # bash$ runtest \ | 23 # bash$ runtest \ |
| 28 # CC_FOR_TARGET="/bin/sh $srcdir/cc-with-index.sh gcc" \ | 24 # CC_FOR_TARGET="/bin/sh $srcdir/cc-with-dwz.sh gcc" \ |
| 29 # CXX_FOR_TARGET="/bin/sh $srcdir/cc-with-index.sh g++" | 25 # CXX_FOR_TARGET="/bin/sh $srcdir/cc-with-dwz.sh g++" |
| 30 # | 26 # |
| 31 # For documentation on index files: info -f gdb.info -n "Index Files" | |
| 32 | 27 |
| 33 myname=cc-with-index.sh | 28 myname=cc-with-dwz.sh |
| 34 | 29 |
| 35 if [ -z "$GDB" ] | 30 DWZ=${DWZ:-dwz} |
| 36 then | |
| 37 if [ -f ./gdb ] | |
| 38 then | |
| 39 » GDB="./gdb" | |
| 40 elif [ -f ../gdb ] | |
| 41 then | |
| 42 » GDB="../gdb" | |
| 43 elif [ -f ../../gdb ] | |
| 44 then | |
| 45 » GDB="../../gdb" | |
| 46 else | |
| 47 » echo "$myname: unable to find usable gdb" >&2 | |
| 48 » exit 1 | |
| 49 fi | |
| 50 fi | |
| 51 | |
| 52 OBJCOPY=${OBJCOPY:-objcopy} | |
| 53 | 31 |
| 54 have_link=unknown | 32 have_link=unknown |
| 55 next_is_output_file=no | 33 next_is_output_file=no |
| 56 output_file=a.out | 34 output_file=a.out |
| 57 | 35 |
| 58 for arg in "$@" | 36 for arg in "$@" |
| 59 do | 37 do |
| 60 if [ "$next_is_output_file" = "yes" ] | 38 if [ "$next_is_output_file" = "yes" ] |
| 61 then | 39 then |
| 62 output_file="$arg" | 40 output_file="$arg" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 81 echo "$myname: Unable to find output file" >&2 | 59 echo "$myname: Unable to find output file" >&2 |
| 82 exit 1 | 60 exit 1 |
| 83 fi | 61 fi |
| 84 | 62 |
| 85 if [ "$have_link" = "no" ] | 63 if [ "$have_link" = "no" ] |
| 86 then | 64 then |
| 87 "$@" | 65 "$@" |
| 88 exit $? | 66 exit $? |
| 89 fi | 67 fi |
| 90 | 68 |
| 91 index_file="${output_file}.gdb-index" | |
| 92 if [ -f "$index_file" ] | |
| 93 then | |
| 94 echo "$myname: Index file $index_file exists, won't clobber." >&2 | |
| 95 exit 1 | |
| 96 fi | |
| 97 | |
| 98 output_dir="${output_file%/*}" | |
| 99 [ "$output_dir" = "$output_file" ] && output_dir="." | |
| 100 | |
| 101 "$@" | 69 "$@" |
| 102 rc=$? | 70 rc=$? |
| 103 [ $rc != 0 ] && exit $rc | 71 [ $rc != 0 ] && exit $rc |
| 104 if [ ! -f "$output_file" ] | 72 if [ ! -f "$output_file" ] |
| 105 then | 73 then |
| 106 echo "$myname: Internal error: $output_file missing." >&2 | 74 echo "$myname: Internal error: $output_file missing." >&2 |
| 107 exit 1 | 75 exit 1 |
| 108 fi | 76 fi |
| 109 | 77 |
| 110 $GDB --batch-silent -nx -ex "file $output_file" -ex "save gdb-index $output_dir" | 78 $DWZ "$output_file" > /dev/null 2>&1 |
| 111 rc=$? | |
| 112 [ $rc != 0 ] && exit $rc | |
| 113 | 79 |
| 114 # GDB might not always create an index. Cope. | 80 exit 0 |
| 115 if [ -f "$index_file" ] | |
| 116 then | |
| 117 $OBJCOPY --add-section .gdb_index="$index_file" \ | |
| 118 » --set-section-flags .gdb_index=readonly \ | |
| 119 » "$output_file" "$output_file" | |
| 120 rc=$? | |
| 121 else | |
| 122 rc=0 | |
| 123 fi | |
| 124 | |
| 125 rm -f "$index_file" | |
| 126 exit $rc | |
| OLD | NEW |