blob: 4975532213bc199d437c342b1696e00bcc721520 [file] [log] [blame]
[email protected]d43a9fb2012-08-21 00:09:191#!/bin/bash
[email protected]4cec25342012-06-28 23:37:312# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5#
[email protected]d43a9fb2012-08-21 00:09:196# Saves the gdb index for a given binary and its shared library dependencies.
[email protected]fdb9ecc2012-06-28 01:53:457
[email protected]d43a9fb2012-08-21 00:09:198set -e
[email protected]fdb9ecc2012-06-28 01:53:459
[email protected]d43a9fb2012-08-21 00:09:1910if [[ ! $# == 1 ]]; then
11 echo "Usage: $0 path-to-binary"
12 exit 1
13fi
[email protected]fdb9ecc2012-06-28 01:53:4514
[email protected]d43a9fb2012-08-21 00:09:1915FILENAME="$1"
16if [[ ! -f "$FILENAME" ]]; then
17 echo "Path $FILENAME does not exist."
18 exit 1
19fi
[email protected]fdb9ecc2012-06-28 01:53:4520
[email protected]d43a9fb2012-08-21 00:09:1921# We're good to go! Create temp directory for index files.
22DIRECTORY=$(mktemp -d)
23echo "Made temp directory $DIRECTORY."
[email protected]4cec25342012-06-28 23:37:3124
[email protected]d43a9fb2012-08-21 00:09:1925# Always remove directory on exit.
26trap "{ echo -n Removing temp directory $DIRECTORY...;
27 rm -rf $DIRECTORY; echo done; }" EXIT
[email protected]4cec25342012-06-28 23:37:3128
[email protected]d43a9fb2012-08-21 00:09:1929# Grab all the chromium shared library files.
30so_files=$(ldd "$FILENAME" 2>/dev/null \
[email protected]e4e06e32012-09-15 02:28:2031 | grep $(dirname "$FILENAME") \
[email protected]d43a9fb2012-08-21 00:09:1932 | sed "s/.*[ \t]\(.*\) (.*/\1/")
[email protected]4cec25342012-06-28 23:37:3133
[email protected]d43a9fb2012-08-21 00:09:1934# Add index to binary and the shared library dependencies.
35for file in "$FILENAME" $so_files; do
36 basename=$(basename "$file")
37 echo -n "Adding index to $basename..."
38 readelf_out=$(readelf -S "$file")
39 if [[ $readelf_out =~ "gdb_index" ]]; then
40 echo "already contains index. Skipped."
[email protected]4cec25342012-06-28 23:37:3141 else
[email protected]d43a9fb2012-08-21 00:09:1942 gdb -batch "$file" -ex "save gdb-index $DIRECTORY" -ex "quit"
43 objcopy --add-section .gdb_index="$DIRECTORY"/$basename.gdb-index \
44 --set-section-flags .gdb_index=readonly "$file" "$file"
45 echo "done."
[email protected]4cec25342012-06-28 23:37:3146 fi
[email protected]4cec25342012-06-28 23:37:3147done