Index: build/add-index.sh |
diff --git a/build/add-index.sh b/build/add-index.sh |
new file mode 100755 |
index 0000000000000000000000000000000000000000..1a2bde841af46cbb64263472ff1db9d4253971c8 |
--- /dev/null |
+++ b/build/add-index.sh |
@@ -0,0 +1,67 @@ |
+#!/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 |
+ |
+# Adds a gdb index to the given binary. |
+# $1: path to the binary |
+# $2: temp directory to store .gdb-index files |
+function add_index_to_binary { |
+ local basename=$(basename $1) |
+ echo -n "Adding index to $basename..." |
+ local readelf_out=$(readelf -S $1) |
+ if [[ $readelf_out =~ "gdb_index" ]]; then |
+ echo "already contains index. Skipped." |
+ else |
+ gdb -batch $1 -ex "save gdb-index $2" -ex "quit" |
+ objcopy --add-section .gdb_index=$2/$basename.gdb-index \ |
+ --set-section-flags .gdb_index=readonly $1 $1 |
+ echo "done." |
+ fi |
+ |
+ # Grab all the chromium shared library files. |
+ local so_files=$(ldd $1 2>/dev/null \ |
Ami GONE FROM CHROMIUM
2012/08/02 18:16:52
This will recursively process the .so's that the .
vrk (LEFT CHROMIUM)
2012/08/02 22:51:32
Done.
|
+ | grep $(pwd) \ |
+ | sed "s/.*[ \t]\(.*\) (.*/\1/") |
+ |
+ for file in $so_files; do |
+ add_index_to_binary $file $2 |
+ done |
+} |
+ |
+# Removes the temp directory holding .gdb-index files. |
+function rm_directory { |
Ami GONE FROM CHROMIUM
2012/08/02 18:16:52
s/rm_/rm_tmp_/
vrk (LEFT CHROMIUM)
2012/08/02 22:51:32
Inlined instead.
|
+ echo -n "Removing temp directory $DIRECTORY..." |
+ rm -rf $DIRECTORY |
+ echo "done." |
+ exit |
+} |
+trap rm_directory EXIT |
Ami GONE FROM CHROMIUM
2012/08/02 18:16:52
Only register this after the mktemp -d?
vrk (LEFT CHROMIUM)
2012/08/02 22:51:32
Done.
|
+ |
+if [[ ! $# == 1 ]]; then |
+ echo "Usage: $0 path-to-binary" |
+ exit |
+fi |
+ |
+FILENAME="$1" |
+if [[ ! -f $FILENAME ]]; then |
Ami GONE FROM CHROMIUM
2012/08/02 18:16:52
""-quote $FILENAME everywhere to avoid spaces chan
vrk (LEFT CHROMIUM)
2012/08/02 22:51:32
Done.
|
+ echo "Path $FILENAME does not exist." |
+ exit |
+fi |
+ |
+# Check to make sure ldd exists. |
Ami GONE FROM CHROMIUM
2012/08/02 18:16:52
Why check for ldd's existence but not gdb's?
Are y
vrk (LEFT CHROMIUM)
2012/08/02 22:51:32
Ah, I just thought gdb was more likely to already
|
+command -v ldd &>/dev/null |
+if [[ $? -gt 0 ]]; then |
+ "ldd not found." |
+ exit |
+fi |
+ |
+# Create temp directory for index files. |
+DIRECTORY=$(mktemp -d) |
+echo "Made temp directory $DIRECTORY..." |
+ |
+add_index_to_binary $FILENAME $DIRECTORY |