Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3772)

Unified Diff: build/add-index.sh

Issue 10843037: Rewrite the script to add gdb index to binary files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698