Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 | 2 |
| 3 # Add a .gdb_index section to a file. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | |
| 6 # | |
| 5 # Copyright (C) 2010 Free Software Foundation, Inc. | 7 # Copyright (C) 2010 Free Software Foundation, Inc. |
| 6 # This program is free software; you can redistribute it and/or modify | 8 # 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 | 9 # 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 | 10 # the Free Software Foundation; either version 3 of the License, or |
| 9 # (at your option) any later version. | 11 # (at your option) any later version. |
| 10 # | 12 # |
| 11 # This program is distributed in the hope that it will be useful, | 13 # This program is distributed in the hope that it will be useful, |
| 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 # GNU General Public License for more details. | 16 # GNU General Public License for more details. |
| 15 # | 17 # |
| 16 # You should have received a copy of the GNU General Public License | 18 # 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 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 20 |
| 19 file="$1" | 21 # This is a modification of gdb-add-index that recursively adds an index |
| 20 dir="${file%/*}" | 22 # to the shared libraries dependencies from the same build. |
| 21 | 23 |
| 22 # We don't care if gdb gives an error. | 24 target="$1" |
| 23 gdb -nx --batch-silent -ex "file $file" -ex "save gdb-index $dir" | 25 target_dir="${target%/*}" |
| 24 | 26 |
| 25 if test -f "${file}.gdb-index"; then | 27 OLDIFS=$IFS |
| 26 objcopy --add-section .gdb_index="${file}.gdb-index" --set-section-flags .gdb _index=readonly "$file" "$file" | 28 IFS=$'\n' |
| 27 rm -f "${file}.gdb-index" | |
| 28 fi | |
| 29 | 29 |
| 30 exit 0 | 30 shared_libraries=$( |
| 31 ldd -d "$target" | grep "$target_dir" | cut -d '>' -f2 | cut -d ' ' -f2 | |
| 32 ) | |
| 33 | |
| 34 # This function is basically the RedHat's gdb-add-index script and is why | |
| 35 # we have the FSF copyright above. | |
| 36 function index_one_file { | |
| 37 local file="$1" | |
| 38 local dir="${file%/*}" | |
| 39 | |
| 40 # We don't care if gdb gives an error. | |
| 41 gdb -nx --batch-silent -ex "file $file" -ex "save gdb-index $dir" | |
| 42 | |
| 43 if test -f "${file}.gdb-index"; then | |
| 44 objcopy --add-section .gdb_index="${file}.gdb-index" --set-section-flags \ | |
| 45 .gdb_index=readonly "$file" "$file" | |
| 46 rm -f "${file}.gdb-index" | |
|
cmp
2012/06/28 21:50:16
for lines 44-46, remove one space from indent
awong
2012/06/28 23:23:20
Fixed. Committing after clean try-bot run (I skip
| |
| 47 fi | |
| 48 } | |
| 49 | |
| 50 function maybe_index { | |
| 51 readelf -e "$1" | grep '.gdb_index' > /dev/null 2>&1 | |
| 52 if [[ "$?" != 0 ]]; then | |
| 53 echo "Adding .gdb_index to $1" | |
| 54 index_one_file "$1" | |
| 55 else | |
| 56 echo "Skipping $1 (already has .gdb_index)" | |
| 57 fi | |
| 58 } | |
| 59 | |
| 60 maybe_index "$target" | |
| 61 for lib in $shared_libraries; do | |
| 62 maybe_index "$lib" | |
| 63 done | |
| OLD | NEW |