OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Script to upload all debug symbols required for crash reporting | 6 # Script to upload all debug symbols required for crash reporting |
7 # purposes. This script need only be used to upload release builds | 7 # purposes. This script need only be used to upload release builds |
8 # symbols or to debug crashes on non-release builds (in which case try | 8 # symbols or to debug crashes on non-release builds (in which case try |
9 # to only upload the symbols for those executables involved). | 9 # to only upload the symbols for those executables involved). |
10 # | 10 # |
(...skipping 12 matching lines...) Expand all Loading... |
23 # Flags | 23 # Flags |
24 DEFINE_string board "$DEFAULT_BOARD" "The board to build packages for." | 24 DEFINE_string board "$DEFAULT_BOARD" "The board to build packages for." |
25 DEFINE_boolean dryrun ${FLAGS_FALSE} "Run without actually uploading." | 25 DEFINE_boolean dryrun ${FLAGS_FALSE} "Run without actually uploading." |
26 DEFINE_boolean verbose ${FLAGS_FALSE} "Be verbose." | 26 DEFINE_boolean verbose ${FLAGS_FALSE} "Be verbose." |
27 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts." | 27 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts." |
28 | 28 |
29 DUMP_SYMS="dump_syms.i386" | 29 DUMP_SYMS="dump_syms.i386" |
30 SYM_UPLOAD="sym_upload.i386" | 30 SYM_UPLOAD="sym_upload.i386" |
31 | 31 |
32 CUMULATIVE_SIZE=0 | 32 CUMULATIVE_SIZE=0 |
| 33 ANY_ERRORS=0 |
33 | 34 |
34 SYM_FILE=$(mktemp "/tmp/sym.XXXX") | 35 SYM_FILE=$(mktemp "/tmp/sym.XXXX") |
35 ERR_FILE=$(mktemp "/tmp/err.XXXX") | 36 ERR_FILE=$(mktemp "/tmp/err.XXXX") |
36 | 37 |
37 function cleanup() { | 38 function cleanup() { |
38 rm -f "${SYM_FILE}" "${ERR_FILE}" | 39 rm -f "${SYM_FILE}" "${ERR_FILE}" |
39 } | 40 } |
40 | 41 |
41 function is_official() { | 42 function is_official() { |
42 if [ ${CHROMEOS_OFFICIAL:-0} = 1 ]; then | 43 if [ ${CHROMEOS_OFFICIAL:-0} = 1 ]; then |
(...skipping 30 matching lines...) Expand all Loading... |
73 echo "to upload." | 74 echo "to upload." |
74 read -p "Are you sure you want to upload all build symbols (y/N)? " SURE | 75 read -p "Are you sure you want to upload all build symbols (y/N)? " SURE |
75 SURE="${SURE:0:1}" # Get just the first character | 76 SURE="${SURE:0:1}" # Get just the first character |
76 if [ "${SURE}" != "y" ]; then | 77 if [ "${SURE}" != "y" ]; then |
77 echo "Ok, better safe than sorry." | 78 echo "Ok, better safe than sorry." |
78 return 1 | 79 return 1 |
79 fi | 80 fi |
80 return 0 | 81 return 0 |
81 } | 82 } |
82 | 83 |
| 84 # Dump given debug and text file to SYM_FILE. Returns 1 if any errors, even |
| 85 # if they can be ignored, but only sets ANY_ERRORS if the error should not |
| 86 # be ignored (and we should not proceed to upload). |
83 function dump_file { | 87 function dump_file { |
84 local debug_file="$1" | 88 local debug_file="$1" |
85 local text_file="$2" | 89 local text_file="$2" |
86 # Dump symbols as root in order to read all files. | 90 # Dump symbols as root in order to read all files. |
87 if ! sudo "${DUMP_SYMS}" "${debug_file}" "${text_file}" > "${SYM_FILE}" \ | 91 if ! sudo "${DUMP_SYMS}" "${debug_file}" "${text_file}" > "${SYM_FILE}" \ |
88 2> "${ERR_FILE}"; then | 92 2> "${ERR_FILE}"; then |
89 # A lot of files (like kernel files) contain no debug information, do | 93 # A lot of files (like kernel files) contain no debug information, do |
90 # not consider such occurrences as errors. | 94 # not consider such occurrences as errors. |
91 if grep -q "file contains no debugging information" "${ERR_FILE}"; then | 95 if grep -q "file contains no debugging information" "${ERR_FILE}"; then |
92 warn "No symbols found for ${text_file}" | 96 warn "No symbols found for ${text_file}" |
93 return 0 | 97 return 1 |
94 fi | 98 fi |
95 error "Unable to dump symbols for ${text_file}:" | 99 error "Unable to dump symbols for ${text_file}:" |
96 cat "${ERR_FILE}" | 100 cat "${ERR_FILE}" |
| 101 ANY_ERRORS=1 |
97 return 1 | 102 return 1 |
98 fi | 103 fi |
99 if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then | 104 if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then |
100 local file_id=$(head -1 ${SYM_FILE} | cut -d' ' -f4) | 105 local file_id=$(head -1 ${SYM_FILE} | cut -d' ' -f4) |
101 local module_name=$(head -1 ${SYM_FILE} | cut -d' ' -f5) | 106 local module_name=$(head -1 ${SYM_FILE} | cut -d' ' -f5) |
102 # Show file upload success and symbol info for easier lookup | 107 # Show file upload success and symbol info for easier lookup |
103 info "Dumped symbols from ${text_file} for ${module_name}|${file_id}." | 108 info "Dumped symbols from ${text_file} for ${module_name}|${file_id}." |
104 fi | 109 fi |
105 # Sanity check: if we've created the same named file in the /usr/lib/debug | 110 # Sanity check: if we've created the same named file in the /usr/lib/debug |
106 # directory during the src_compile stage of an ebuild, verify our sym file | 111 # directory during the src_compile stage of an ebuild, verify our sym file |
107 # is the same. | 112 # is the same. |
108 local installed_sym="${DEBUG_ROOT}"/$(basename "${text_file}").sym | 113 local installed_sym="${DEBUG_ROOT}"/$(basename "${text_file}").sym |
109 if [ -e "${installed_sym}" ]; then | 114 if [ -e "${installed_sym}" ]; then |
110 if ! diff "${installed_sym}" "${SYM_FILE}"; then | 115 if ! diff "${installed_sym}" "${SYM_FILE}"; then |
111 error "${installed_sym} differ from current sym file:" | 116 error "${installed_sym} differ from current sym file:" |
112 diff "${installed_sym}" "${SYM_FILE}" | 117 diff "${installed_sym}" "${SYM_FILE}" |
| 118 ANY_ERRORS=1 |
113 return 1 | 119 return 1 |
114 fi | 120 fi |
115 fi | 121 fi |
116 size=$(wc -c "${SYM_FILE}" | cut -d' ' -f1) | 122 size=$(wc -c "${SYM_FILE}" | cut -d' ' -f1) |
117 CUMULATIVE_SIZE=$((CUMULATIVE_SIZE + $size)) | 123 CUMULATIVE_SIZE=$((CUMULATIVE_SIZE + $size)) |
118 return 0 | 124 return 0 |
119 } | 125 } |
120 | 126 |
121 # Upload the current symbol file to given URL. | 127 # Upload the current symbol file to given URL. |
122 function upload_file { | 128 function upload_file { |
123 local upload_url="$1" | 129 local upload_url="$1" |
124 if ! "${SYM_UPLOAD}" "${SYM_FILE}" "${upload_url}" > /dev/null \ | 130 if ! "${SYM_UPLOAD}" "${SYM_FILE}" "${upload_url}" > /dev/null \ |
125 2> "${ERR_FILE}"; then | 131 2> "${ERR_FILE}"; then |
126 error "Unable to upload symbols in ${SYM_FILE}:" | 132 error "Unable to upload symbols in ${SYM_FILE}:" |
127 cat "${ERR_FILE}" | 133 cat "${ERR_FILE}" |
| 134 ANY_ERRORS=1 |
128 return 1 | 135 return 1 |
129 fi | 136 fi |
130 if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then | 137 if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then |
131 size=$(wc -c "${SYM_FILE}" | cut -d' ' -f1) | 138 size=$(wc -c "${SYM_FILE}" | cut -d' ' -f1) |
132 info "Successfully uploaded ${size}B." | 139 info "Successfully uploaded ${size}B." |
133 fi | 140 fi |
134 return 0 | 141 return 0 |
135 } | 142 } |
136 | 143 |
137 # Convert and then upload the given debug file to the given URL. | 144 # Convert and then upload the given debug file to the given URL. No |
| 145 # return value. |
138 function process_file { | 146 function process_file { |
139 local debug_file="$1" | 147 local debug_file="$1" |
140 local upload_url="$2" | 148 local upload_url="$2" |
141 local text_file="$(get_text_for_debug ${debug_file})" | 149 local text_file="$(get_text_for_debug ${debug_file})" |
142 if [ "${text_file##*.}" == "ko" ]; then | 150 if [ "${text_file##*.}" == "ko" ]; then |
143 # Skip kernel objects. We can't use their symbols and they sometimes | 151 # Skip kernel objects. We can't use their symbols and they sometimes |
144 # have objects with empty text sections which trigger errors in dump_sym. | 152 # have objects with empty text sections which trigger errors in dump_sym. |
145 if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then | 153 if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then |
146 info "Skipping kernel object: ${text_file}" | 154 info "Skipping kernel object: ${text_file}" |
147 fi | 155 fi |
148 return 0 | 156 return 0 |
149 fi | 157 fi |
150 if [ "${text_file#${AUTOTEST_ROOT}}" != "${text_file}" ]; then | 158 if [ "${text_file#${AUTOTEST_ROOT}}" != "${text_file}" ]; then |
151 # Skip autotest files, they are not part of the image to debug | 159 # Skip autotest files, they are not part of the image to debug |
152 # and some cause trouble to dump_syms because they are built | 160 # and some cause trouble to dump_syms because they are built |
153 # externally (with different build options). | 161 # externally (with different build options). |
154 if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then | 162 if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then |
155 info "Skipping autotest file: ${text_file}" | 163 info "Skipping autotest file: ${text_file}" |
156 fi | 164 fi |
157 return 0 | 165 return 0 |
158 fi | 166 fi |
159 if [ ! -f "${text_file}" ]; then | 167 if [ ! -f "${text_file}" ]; then |
160 # Allow files to not exist, for instance if they are in the INSTALL_MASK. | 168 # Allow files to not exist, for instance if they are in the INSTALL_MASK. |
161 warn "Binary does not exist: ${text_file}" | 169 warn "Binary does not exist: ${text_file}" |
162 return 0 | 170 return 0 |
163 fi | 171 fi |
164 | 172 |
165 dump_file "${debug_file}" "${text_file}" || return 1 | 173 dump_file "${debug_file}" "${text_file}" || return 0 |
166 | 174 |
167 [ ${FLAGS_dryrun} -eq ${FLAGS_TRUE} ] && return 0 | 175 [ ${FLAGS_dryrun} -eq ${FLAGS_TRUE} ] && return 0 |
168 | 176 |
169 upload_file "${upload_url}" | 177 upload_file "${upload_url}" |
170 } | 178 } |
171 | 179 |
172 function main() { | 180 function main() { |
173 trap cleanup EXIT | 181 trap cleanup EXIT |
174 | 182 |
175 # Parse command line | 183 # Parse command line |
(...skipping 17 matching lines...) Expand all Loading... |
193 fi | 201 fi |
194 info "Uploading symbols to ${upload_url} from ${SYSROOT}." | 202 info "Uploading symbols to ${upload_url} from ${SYSROOT}." |
195 else | 203 else |
196 warn "Will not upload symbols due to --nodryrun." | 204 warn "Will not upload symbols due to --nodryrun." |
197 fi | 205 fi |
198 | 206 |
199 DEBUG_ROOT="${SYSROOT}/usr/lib/debug" | 207 DEBUG_ROOT="${SYSROOT}/usr/lib/debug" |
200 AUTOTEST_ROOT="${SYSROOT}/usr/local/autotest" | 208 AUTOTEST_ROOT="${SYSROOT}/usr/local/autotest" |
201 CUMULATIVE_SIZE=0 | 209 CUMULATIVE_SIZE=0 |
202 | 210 |
203 local any_errors=0 | |
204 if [ -z "${FLAGS_ARGV}" ]; then | 211 if [ -z "${FLAGS_ARGV}" ]; then |
205 if [ ${FLAGS_dryrun} -eq ${FLAGS_FALSE} ]; then | 212 if [ ${FLAGS_dryrun} -eq ${FLAGS_FALSE} ]; then |
206 really_upload || exit 1 | 213 really_upload || exit 1 |
207 fi | 214 fi |
208 for debug_file in $(find "${DEBUG_ROOT}" -name \*.debug); do | 215 for debug_file in $(find "${DEBUG_ROOT}" -name \*.debug); do |
209 if ! process_file "${debug_file}" "${upload_url}"; then | 216 ! process_file "${debug_file}" "${upload_url}" |
210 any_errors=1 | |
211 fi | |
212 done | 217 done |
213 else | 218 else |
214 for either_file in ${FLAGS_ARGV}; do | 219 for either_file in ${FLAGS_ARGV}; do |
215 either_file=${either_file#\'} | 220 either_file=${either_file#\'} |
216 either_file=${either_file%\'} | 221 either_file=${either_file%\'} |
217 if [ ! -f "${either_file}" ]; then | 222 if [ ! -f "${either_file}" ]; then |
218 error "Specified file ${either_file} does not exist" | 223 error "Specified file ${either_file} does not exist" |
219 any_errors=1 | 224 ANY_ERRORS=1 |
220 continue | 225 continue |
221 fi | 226 fi |
222 if [ "${either_file##*.}" == "debug" ]; then | 227 if [ "${either_file##*.}" == "debug" ]; then |
223 debug_file="${either_file}" | 228 debug_file="${either_file}" |
224 else | 229 else |
225 debug_file="$(get_debug_for_text ${either_file})" | 230 debug_file="$(get_debug_for_text ${either_file})" |
226 fi | 231 fi |
227 if ! process_file "${debug_file}" "${upload_url}"; then | 232 ! process_file "${debug_file}" "${upload_url}"; |
228 any_errors=1 | |
229 fi | |
230 done | 233 done |
231 fi | 234 fi |
232 | 235 |
233 if [ ${FLAGS_dryrun} -eq ${FLAGS_TRUE} ]; then | 236 if [ ${FLAGS_dryrun} -eq ${FLAGS_TRUE} ]; then |
234 warn "Did not actually upload, pass --nodryrun to upload" | 237 warn "Did not actually upload, pass --nodryrun to upload" |
235 info "Would have uploaded ${CUMULATIVE_SIZE}B of debug information" | 238 info "Would have uploaded ${CUMULATIVE_SIZE}B of debug information" |
236 else | 239 else |
237 info "Uploaded ${CUMULATIVE_SIZE}B of debug information" | 240 info "Uploaded ${CUMULATIVE_SIZE}B of debug information" |
238 fi | 241 fi |
239 [ ${any_errors} -ne 0 ] && die "Encountered problems" | 242 |
| 243 [ ${ANY_ERRORS} -ne 0 ] && die "Encountered problems" |
| 244 return 0 |
240 } | 245 } |
241 | 246 |
242 main "$@" | 247 main "$@" |
OLD | NEW |