This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathextract-debug-symbols.sh
More file actions
executable file
·105 lines (81 loc) · 2.23 KB
/
extract-debug-symbols.sh
File metadata and controls
executable file
·105 lines (81 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
set -e
os="$1"
suffix="$2"
shift 2
inputs="$@"
OBJCOPY="${OBJCOPY:-objcopy}"
OBJDUMP="${OBJDUMP:-objdump}"
STRIP="${STRIP:-strip}"
function extract_linux_or_android {
for input in "$@" ; do
output="${input}${suffix}"
# The --preserve-dates flag for strip and objcopy only has whole
# second resolution, so save the timestamps in a separate file
# instead.
touch -m -r "$input" "$input.timestamps"
# Extract a copy of the debugging information
$OBJCOPY --only-keep-debug "$input" "$output"
if [ "$os" == "android" -a "$BUILDTYPE" == "Debug" ] ; then
echo Skipping strip-debug for ${input}
else
# Because we export symbols from the engine, only debug symbols
# should be stripped.
$STRIP -x --strip-debug "$input"
fi
# Add a hint for the debugger so it can find the debug info
$OBJCOPY --remove-section=.gnu_debuglink "$input"
$OBJCOPY --add-gnu-debuglink="$output" "$input"
# Restore the original modification time
touch -m -r "$input.timestamps" "$input"
rm "$input.timestamps" 2>&1
done
}
function extract_emscripten {
for input in "$@" ; do
touch "${input}${suffix}"
done
}
function extract_mac_or_ios {
for input in "$@" ; do
output="${input}${suffix}"
# If this is an app bundle, find the executable name
if [ -f "${input}/Contents/Info.plist" ] ; then
executable=$(/usr/libexec/PlistBuddy -c "Print CFBundleExecutable" "${input}/Contents/Info.plist")
if [ $? -eq 0 ] ; then
real_input="${input}/Contents/MacOS/${executable}"
else
echo >&2 Cannot find executable for bundle "${input}" \(no CFBundleExecutable key in plist\)
exit 1
fi
else
real_input="${input}"
fi
# If the OS is iOS and this is a debug build, do nothing
if [ "$os" == "ios" -a "$BUILDTYPE" == "Debug" ] ; then
echo Creating empty debug symbols file for ${input}
touch "${output}"
else
# Extract a copy of the debugging information
echo Extracting debug symbols for ${input}
dsymutil --out "${output}" "${real_input}"
# Strip the executable
$STRIP -x -S "$real_input"
fi
done
}
case $os in
linux|android)
extract_linux_or_android ${inputs}
;;
mac|ios)
extract_mac_or_ios ${inputs}
;;
emscripten)
extract_emscripten ${inputs}
;;
*)
echo OS "$os" not supported by this script
exit 1
;;
esac