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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/bash
2 # 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 #
6 # Saves the gdb index for a given binary and its shared library dependencies.
7
8 set -e
9
10 # Adds a gdb index to the given binary.
11 # $1: path to the binary
12 # $2: temp directory to store .gdb-index files
13 function add_index_to_binary {
14 local basename=$(basename $1)
15 echo -n "Adding index to $basename..."
16 local readelf_out=$(readelf -S $1)
17 if [[ $readelf_out =~ "gdb_index" ]]; then
18 echo "already contains index. Skipped."
19 else
20 gdb -batch $1 -ex "save gdb-index $2" -ex "quit"
21 objcopy --add-section .gdb_index=$2/$basename.gdb-index \
22 --set-section-flags .gdb_index=readonly $1 $1
23 echo "done."
24 fi
25
26 # Grab all the chromium shared library files.
27 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.
28 | grep $(pwd) \
29 | sed "s/.*[ \t]\(.*\) (.*/\1/")
30
31 for file in $so_files; do
32 add_index_to_binary $file $2
33 done
34 }
35
36 # Removes the temp directory holding .gdb-index files.
37 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.
38 echo -n "Removing temp directory $DIRECTORY..."
39 rm -rf $DIRECTORY
40 echo "done."
41 exit
42 }
43 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.
44
45 if [[ ! $# == 1 ]]; then
46 echo "Usage: $0 path-to-binary"
47 exit
48 fi
49
50 FILENAME="$1"
51 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.
52 echo "Path $FILENAME does not exist."
53 exit
54 fi
55
56 # 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
57 command -v ldd &>/dev/null
58 if [[ $? -gt 0 ]]; then
59 "ldd not found."
60 exit
61 fi
62
63 # Create temp directory for index files.
64 DIRECTORY=$(mktemp -d)
65 echo "Made temp directory $DIRECTORY..."
66
67 add_index_to_binary $FILENAME $DIRECTORY
OLDNEW
« 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