Index: build/add-index.sh |
diff --git a/build/add-index.sh b/build/add-index.sh |
new file mode 100755 |
index 0000000000000000000000000000000000000000..397339139af558b15454982b84db8bc525351b76 |
--- /dev/null |
+++ b/build/add-index.sh |
@@ -0,0 +1,70 @@ |
+#!/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 |
+fi |
+ |
+FILENAME="$1" |
+if [[ ! -f "$FILENAME" ]]; then |
+ echo "Path $FILENAME does not exist." |
+ exit |
+fi |
+ |
+# Check to make sure ldd and gdb exist. |
+command -v ldd &>/dev/null |
+if [[ $? -gt 0 ]]; then |
+ echo "ldd not found." |
+ exit |
Ami GONE FROM CHROMIUM
2012/08/02 23:01:15
each of the error exits here and below should exit
vrk (LEFT CHROMIUM)
2012/08/02 23:24:55
Done.
|
+fi |
+command -v gdb &>/dev/null |
+if [[ $? -gt 0 ]]; then |
+ echo "gdb not found." |
+ exit |
+fi |
+ |
+# GDB version check. |
+gdb_version_string=$(gdb --version \ |
+ | head -n 1 \ |
+ | sed "s/.*GDB) \([0-9]*\)\.\([0-9]*\).*/\1 \2/") |
+gdb_version=($gdb_version_string) |
+ |
+if [[ ${gdb_version[0]} -lt 7 ]] || [[ ${gdb_version[1]} -lt 3 ]]; then |
+ echo "Needs gdb version 7.3 or higher to use gdb_index."; |
+ exit |
Ami GONE FROM CHROMIUM
2012/08/02 23:01:15
You're checking ldd & gdb, but assuming readelf an
vrk (LEFT CHROMIUM)
2012/08/02 23:24:55
Done.
|
+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 |