mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 06:01:41 +02:00
Rather than trying to use an old/stale common.sh, use the common.sh from the invocation point- if invoked via /usr/lib/crosutils, use that common.sh. If invoked via src/scripts/, use that, etc. Trying to intermix it just introduces potential for bugs and invalidly freezes common.sh api, thus the efforts to revert this and ultimately revert the existing of a crosutils ebuild. BUG=chromium-os:27201 TEST=cbuildbot x86-generic-full Change-Id: I4c6c5fbade3d28c71752bd4c44dccad49af52ec0 Reviewed-on: https://gerrit.chromium.org/gerrit/18303 Reviewed-by: David James <davidjames@chromium.org> Commit-Ready: Brian Harring <ferringb@chromium.org> Tested-by: Brian Harring <ferringb@chromium.org>
156 lines
5.1 KiB
Bash
Executable File
156 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
# Script to upload all debug symbols required for crash reporting
|
|
# purposes. This script need only be used to upload release builds
|
|
# symbols or to debug crashes on non-release builds (in which case try
|
|
# to only upload the symbols for those executables involved).
|
|
|
|
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
|
|
. "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; }
|
|
|
|
# Script must be run inside the chroot
|
|
restart_in_chroot_if_needed "$@"
|
|
|
|
get_default_board
|
|
|
|
# Flags
|
|
DEFINE_string board "$DEFAULT_BOARD" "The board to build packages for."
|
|
DEFINE_string breakpad_root "" "Root directory for breakpad symbols."
|
|
DEFINE_boolean official_build ${FLAGS_FALSE} "Point to official symbol server."
|
|
DEFINE_boolean regenerate ${FLAGS_FALSE} "Regenerate all symbols."
|
|
DEFINE_integer strip_cfi 100000000 "Strip CFI data for files above this size."
|
|
DEFINE_boolean verbose ${FLAGS_FALSE} "Be verbose."
|
|
DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts."
|
|
|
|
SYM_UPLOAD="sym_upload"
|
|
|
|
ANY_ERRORS=0
|
|
|
|
OUT_DIR=$(mktemp -d "/tmp/err.XXXX")
|
|
|
|
function cleanup() {
|
|
rm -rf "${OUT_DIR}"
|
|
}
|
|
|
|
function really_upload() {
|
|
if [ ${FLAGS_yes} -eq ${FLAGS_TRUE} ]; then
|
|
return 0
|
|
fi
|
|
echo "Uploading symbols for an entire Chromium OS build is really only "
|
|
echo "necessary for release builds and in a few cases for developers "
|
|
echo "to debug problems. It will take considerable time to run. For "
|
|
echo "developer debugging purposes, consider instead passing specific files "
|
|
echo "to upload."
|
|
read -p "Are you sure you want to upload all build symbols (y/N)? " SURE
|
|
SURE="${SURE:0:1}" # Get just the first character
|
|
if [ "${SURE}" != "y" ]; then
|
|
echo "Ok, better safe than sorry."
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
# Upload the given symbol file to given URL.
|
|
function upload_file() {
|
|
local symbol_file="$1"
|
|
local upload_url="$2"
|
|
local upload_file="${symbol_file}"
|
|
if [ ${FLAGS_strip_cfi} -ne 0 ]; then
|
|
local symbol_size="$(stat -c%s ${symbol_file})"
|
|
if [ ${symbol_size} -gt ${FLAGS_strip_cfi} ]; then
|
|
# Call frame info is unnecessary for 32b x86 targets with frame
|
|
# pointer used (as all of ours have) and it accounts for over
|
|
# half the size of the symbols uploaded. To buy us more time
|
|
# for the server team to increase the current 160MB, remove this
|
|
# data unless the user requests it.
|
|
if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then
|
|
info "Stripping CFI for ${symbol_file} due to size ${symbol_size} > \
|
|
${FLAGS_strip_cfi}."
|
|
fi
|
|
upload_file="${OUT_DIR}/stripped.sym"
|
|
sed '/^STACK CFI/d' < "${symbol_file}" > "${upload_file}"
|
|
fi
|
|
fi
|
|
if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then
|
|
info "Uploading ${symbol_file}"
|
|
fi
|
|
"${SYM_UPLOAD}" "${upload_file}" "${upload_url}" > "${OUT_DIR}/stdout" \
|
|
2> "${OUT_DIR}/stderr"
|
|
if ! grep -q "Successfully sent the symbol file." "${OUT_DIR}/stdout"; then
|
|
error "Unable to upload symbols in ${symbol_file}:"
|
|
cat "${OUT_DIR}/stderr"
|
|
ANY_ERRORS=1
|
|
return 1
|
|
fi
|
|
if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then
|
|
size=$(wc -c "${upload_file}" | cut -d' ' -f1)
|
|
info "Successfully uploaded ${size}B."
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
function main() {
|
|
trap cleanup EXIT
|
|
|
|
# Parse command line
|
|
FLAGS_HELP="usage: $0 [flags] [<files...>]"
|
|
FLAGS "$@" || exit 1
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
set -e
|
|
|
|
[ -n "$FLAGS_board" ] || die "--board is required."
|
|
|
|
SYSROOT="/build/${FLAGS_board}"
|
|
|
|
local upload_url=""
|
|
if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then
|
|
upload_url="http://clients2.google.com/cr/symbol"
|
|
else
|
|
upload_url="http://clients2.google.com/cr/staging_symbol"
|
|
warn "This is an unofficial build, uploading to staging server."
|
|
fi
|
|
info "Uploading symbols to ${upload_url} from ${SYSROOT}."
|
|
|
|
DEFAULT_BREAKPAD_ROOT="${SYSROOT}/usr/lib/debug/breakpad"
|
|
if [ -z "${FLAGS_breakpad_root}" ]; then
|
|
FLAGS_breakpad_root="${DEFAULT_BREAKPAD_ROOT}"
|
|
else
|
|
if [ ${FLAGS_regenerate} -eq ${FLAGS_TRUE} ]; then
|
|
warn "Assuming --noregenerate when --breakpad_root is specified"
|
|
FLAGS_regenerate=${FLAGS_FALSE}
|
|
fi
|
|
fi
|
|
|
|
if [ -z "${FLAGS_ARGV}" ]; then
|
|
if [ ${FLAGS_regenerate} -eq ${FLAGS_TRUE} ]; then
|
|
really_upload || exit 1
|
|
info "Clearing ${DEFAULT_BREAKPAD_ROOT}"
|
|
sudo rm -rf "${DEFAULT_BREAKPAD_ROOT}"
|
|
info "Generating all breakpad symbol files."
|
|
local verbosity=""
|
|
local generate_script="${SCRIPTS_DIR}/cros_generate_breakpad_symbols"
|
|
[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ] && verbosity="--verbose"
|
|
if ! "${generate_script}" --board=${FLAGS_board} ${verbosity}; then
|
|
error "Some errors while generating symbols; uploading anyway"
|
|
ANY_ERRORS=1
|
|
fi
|
|
fi
|
|
|
|
info "Uploading all breakpad symbol files."
|
|
for sym_file in $(find "${FLAGS_breakpad_root}" -name \*.sym); do
|
|
! upload_file "${sym_file}" "${upload_url}"
|
|
done
|
|
else
|
|
error "Unexpected args ${FLAGS_ARGV}"
|
|
fi
|
|
|
|
[ ${ANY_ERRORS} -ne 0 ] && die "Encountered problems"
|
|
return 0
|
|
}
|
|
|
|
main "$@"
|