diff options
author | vrk@chromium.org <vrk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-03 02:56:36 +0000 |
---|---|---|
committer | vrk@chromium.org <vrk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-03 02:56:36 +0000 |
commit | 8df3fe463deb067aff64e37ca2fb893f2209b14f (patch) | |
tree | 5e2d988e1e44629998170190863c05d0d3bcfd54 /build | |
parent | 6cf945691358f42a74fcab27021d376199f932df (diff) | |
download | chromium_src-8df3fe463deb067aff64e37ca2fb893f2209b14f.zip chromium_src-8df3fe463deb067aff64e37ca2fb893f2209b14f.tar.gz chromium_src-8df3fe463deb067aff64e37ca2fb893f2209b14f.tar.bz2 |
Rewrite script to add gdb index to binary files
This is a clean rewrite of ajwong@'s add-gdb-index script.
BUG=NONE
Review URL: https://chromiumcodereview.appspot.com/10843037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149791 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rwxr-xr-x | build/add-index.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/build/add-index.sh b/build/add-index.sh new file mode 100755 index 0000000..fa3e726 --- /dev/null +++ b/build/add-index.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Saves the gdb index for a given binary and its shared library dependencies. + +set -e + +if [[ ! $# == 1 ]]; then + echo "Usage: $0 path-to-binary" + exit 1 +fi + +FILENAME="$1" +if [[ ! -f "$FILENAME" ]]; then + echo "Path $FILENAME does not exist." + exit 1 +fi + +# We're good to go! Create temp directory for index files. +DIRECTORY=$(mktemp -d) +echo "Made temp directory $DIRECTORY." + +# Always remove directory on exit. +trap "{ echo -n Removing temp directory $DIRECTORY...; + rm -rf $DIRECTORY; echo done; }" EXIT + +# Grab all the chromium shared library files. +so_files=$(ldd "$FILENAME" 2>/dev/null \ + | grep $(pwd) \ + | sed "s/.*[ \t]\(.*\) (.*/\1/") + +# Add index to binary and the shared library dependencies. +for file in "$FILENAME" $so_files; do + basename=$(basename "$file") + echo -n "Adding index to $basename..." + readelf_out=$(readelf -S "$file") + if [[ $readelf_out =~ "gdb_index" ]]; then + echo "already contains index. Skipped." + else + gdb -batch "$file" -ex "save gdb-index $DIRECTORY" -ex "quit" + objcopy --add-section .gdb_index="$DIRECTORY"/$basename.gdb-index \ + --set-section-flags .gdb_index=readonly "$file" "$file" + echo "done." + fi +done |