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

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: clean-up pass 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..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
« 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