1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/build/gdb-add-index Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +#!/bin/bash 1.5 +# Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.6 +# Use of this source code is governed by a BSD-style license that can be 1.7 +# found in the LICENSE file. 1.8 +# 1.9 +# Saves the gdb index for a given binary and its shared library dependencies. 1.10 + 1.11 +set -e 1.12 + 1.13 +if [[ ! $# == 1 ]]; then 1.14 + echo "Usage: $0 path-to-binary" 1.15 + exit 1 1.16 +fi 1.17 + 1.18 +FILENAME="$1" 1.19 +if [[ ! -f "$FILENAME" ]]; then 1.20 + echo "Path $FILENAME does not exist." 1.21 + exit 1 1.22 +fi 1.23 + 1.24 +# We're good to go! Create temp directory for index files. 1.25 +DIRECTORY=$(mktemp -d) 1.26 +echo "Made temp directory $DIRECTORY." 1.27 + 1.28 +# Always remove directory on exit. 1.29 +trap "{ echo -n Removing temp directory $DIRECTORY...; 1.30 + rm -rf $DIRECTORY; echo done; }" EXIT 1.31 + 1.32 +# Grab all the chromium shared library files. 1.33 +so_files=$(ldd "$FILENAME" 2>/dev/null \ 1.34 + | grep $(dirname "$FILENAME") \ 1.35 + | sed "s/.*[ \t]\(.*\) (.*/\1/") 1.36 + 1.37 +# Add index to binary and the shared library dependencies. 1.38 +for file in "$FILENAME" $so_files; do 1.39 + basename=$(basename "$file") 1.40 + echo -n "Adding index to $basename..." 1.41 + readelf_out=$(readelf -S "$file") 1.42 + if [[ $readelf_out =~ "gdb_index" ]]; then 1.43 + echo "already contains index. Skipped." 1.44 + else 1.45 + gdb -batch "$file" -ex "save gdb-index $DIRECTORY" -ex "quit" 1.46 + objcopy --add-section .gdb_index="$DIRECTORY"/$basename.gdb-index \ 1.47 + --set-section-flags .gdb_index=readonly "$file" "$file" 1.48 + echo "done." 1.49 + fi 1.50 +done