Commit d43a9fbd authored by ajwong@chromium.org's avatar ajwong@chromium.org

Replace gdb-add-index with cleanroom rewrite from vrk@

This CL takes add-index.sh and overwrites gdb-add-index.

BUG=none


Review URL: https://chromiumcodereview.appspot.com/10827427

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152443 0039d316-1c4b-4281-b951-d872f2087c98
parent aa172edf
#!/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
#!/bin/sh #!/bin/bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# #
# Copyright (C) 2010 Free Software Foundation, Inc. # Saves the gdb index for a given binary and its shared library dependencies.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by set -e
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version. if [[ ! $# == 1 ]]; then
# echo "Usage: $0 path-to-binary"
# This program is distributed in the hope that it will be useful, exit 1
# but WITHOUT ANY WARRANTY; without even the implied warranty of fi
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. FILENAME="$1"
# if [[ ! -f "$FILENAME" ]]; then
# You should have received a copy of the GNU General Public License echo "Path $FILENAME does not exist."
# along with this program. If not, see <http://www.gnu.org/licenses/>. exit 1
fi
# This is a modification of gdb-add-index that recursively adds an index
# to the shared libraries dependencies from the same build. # We're good to go! Create temp directory for index files.
DIRECTORY=$(mktemp -d)
target="$1" echo "Made temp directory $DIRECTORY."
target_dir="${target%/*}"
# Always remove directory on exit.
OLDIFS=$IFS trap "{ echo -n Removing temp directory $DIRECTORY...;
IFS=$'\n' rm -rf $DIRECTORY; echo done; }" EXIT
shared_libraries=$( # Grab all the chromium shared library files.
ldd -d "$target" | grep "$target_dir" | cut -d '>' -f2 | cut -d ' ' -f2 so_files=$(ldd "$FILENAME" 2>/dev/null \
) | grep $(pwd) \
| sed "s/.*[ \t]\(.*\) (.*/\1/")
# This function is basically the RedHat's gdb-add-index script and is why
# we have the FSF copyright above. # Add index to binary and the shared library dependencies.
function index_one_file { for file in "$FILENAME" $so_files; do
local file="$1" basename=$(basename "$file")
local dir="${file%/*}" echo -n "Adding index to $basename..."
readelf_out=$(readelf -S "$file")
# We don't care if gdb gives an error. if [[ $readelf_out =~ "gdb_index" ]]; then
gdb -nx --batch-silent -ex "file $file" -ex "save gdb-index $dir" echo "already contains index. Skipped."
if test -f "${file}.gdb-index"; then
objcopy --add-section .gdb_index="${file}.gdb-index" --set-section-flags \
.gdb_index=readonly "$file" "$file"
rm -f "${file}.gdb-index"
fi
}
function maybe_index {
readelf -e "$1" | grep '.gdb_index' > /dev/null 2>&1
if [[ "$?" != 0 ]]; then
echo "Adding .gdb_index to $1"
index_one_file "$1"
else else
echo "Skipping $1 (already has .gdb_index)" 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 fi
}
maybe_index "$target"
for lib in $shared_libraries; do
maybe_index "$lib"
done done
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment