OLD | NEW |
---|---|
(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 if [[ ! $# == 1 ]]; then | |
11 echo "Usage: $0 path-to-binary" | |
12 exit | |
13 fi | |
14 | |
15 FILENAME="$1" | |
16 if [[ ! -f "$FILENAME" ]]; then | |
17 echo "Path $FILENAME does not exist." | |
18 exit | |
19 fi | |
20 | |
21 # Check to make sure ldd and gdb exist. | |
22 command -v ldd &>/dev/null | |
23 if [[ $? -gt 0 ]]; then | |
24 echo "ldd not found." | |
25 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.
| |
26 fi | |
27 command -v gdb &>/dev/null | |
28 if [[ $? -gt 0 ]]; then | |
29 echo "gdb not found." | |
30 exit | |
31 fi | |
32 | |
33 # GDB version check. | |
34 gdb_version_string=$(gdb --version \ | |
35 | head -n 1 \ | |
36 | sed "s/.*GDB) \([0-9]*\)\.\([0-9]*\).*/\1 \2/") | |
37 gdb_version=($gdb_version_string) | |
38 | |
39 if [[ ${gdb_version[0]} -lt 7 ]] || [[ ${gdb_version[1]} -lt 3 ]]; then | |
40 echo "Needs gdb version 7.3 or higher to use gdb_index."; | |
41 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.
| |
42 fi | |
43 | |
44 # We're good to go! Create temp directory for index files. | |
45 DIRECTORY=$(mktemp -d) | |
46 echo "Made temp directory $DIRECTORY." | |
47 | |
48 # Always remove directory on exit. | |
49 trap "{ echo -n Removing temp directory $DIRECTORY...; | |
50 rm -rf $DIRECTORY; echo done; }" EXIT | |
51 | |
52 # Grab all the chromium shared library files. | |
53 so_files=$(ldd "$FILENAME" 2>/dev/null \ | |
54 | grep $(pwd) \ | |
55 | sed "s/.*[ \t]\(.*\) (.*/\1/") | |
56 | |
57 # Add index to binary and the shared library dependencies. | |
58 for file in "$FILENAME" $so_files; do | |
59 basename=$(basename "$file") | |
60 echo -n "Adding index to $basename..." | |
61 readelf_out=$(readelf -S "$file") | |
62 if [[ $readelf_out =~ "gdb_index" ]]; then | |
63 echo "already contains index. Skipped." | |
64 else | |
65 gdb -batch "$file" -ex "save gdb-index $DIRECTORY" -ex "quit" | |
66 objcopy --add-section .gdb_index="$DIRECTORY"/$basename.gdb-index \ | |
67 --set-section-flags .gdb_index=readonly "$file" "$file" | |
68 echo "done." | |
69 fi | |
70 done | |
OLD | NEW |