flatcar-scripts/cros_generate_stacks_bvt
Brian Harring 7f175a59e1 common.sh: output a backtrace and debug information on failure.
Currently, if set -e spots a nonzero exit we basically have
no real debug information- it just stops immediately without stating
where or why.  This forces our scripts to be stupidly verbose so
we can track roughly where they were, thus when they fail we can
use that information to localize the rough exit point.

Instead we should be traping that set -e induced exit and
outputing necessary debug information to run it down.  This includes
outputing the relevant stack trace, or at least what we can get of
it.

The 'die' function is now enhanced to automatically dump the trace
that lead to it.  For most consumers this is desired- however for
commandline parsing induced dies ("--board is missing" for example),
the trace is noise.  For those cases, a 'die_notrace' function was
added that retains the original non-backtrace behaviour.

Example output via instrumenting cros_generate_breakpad_symbols
w/ the failing command '/bin/false' (nonzero exit code).

Before:
./cros_generate_breakpad_symbols  monkeys --board=x86-alex
<no output at all, just exit code 1>

With this CL:
./cros_generate_breakpad_symbols  monkeys --board=x86-alex
ERROR   : script called: ./cros_generate_breakpad_symbols 'monkeys' '--board=x86-alex'
ERROR   : Backtrace:  (most recent call is last)
ERROR   :   file cros_generate_breakpad_symbols, line 207, called: main 'monkeys' '--board=x86-alex'
ERROR   :   file cros_generate_breakpad_symbols, line 163, called: die_err_trap '/bin/false' '1'
ERROR   :
ERROR   : Command failed:
ERROR   :   Command '/bin/false' exited with nonzero code: 1

BUG=chromium-os:30598
TEST=inject a failing command into a script, verify the output.
TEST=inject a 'command not found', verify the output
TEST=cbuildbot x86-generic-full --remote
TEST=cbuildbot arm-tegra2-full --remote
TEST=cbuildbot chromiumos-sdk --remote

Change-Id: I517ffde4d1bb7e2310a74f5a6455b53ba2dea86c
Reviewed-on: https://gerrit.chromium.org/gerrit/17225
Reviewed-by: Brian Harring <ferringb@chromium.org>
Tested-by: Brian Harring <ferringb@chromium.org>
Commit-Ready: Brian Harring <ferringb@chromium.org>
2012-05-07 17:19:41 -07:00

79 lines
1.9 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 generate stackdumps from BVT failures.
# This can only run inside the chroot since we need minidump_stackwalk.
. "$(dirname $0)/common.sh" || { echo "Unable to load common.sh"; exit 1; }
assert_inside_chroot "$@"
function usage() {
echo "Usage: $0 url_or_path_to_debug_tgz url_to_bvt_test_results"
}
if [ -z "$1" ] ; then
usage
die_notrace "The URL or path to symbols tarball (debug.tgz) is required"
fi
if [ -z "$2" ] ; then
usage
die_notrace "The URL to BVT test results is required"
fi
# Die on any errors.
switch_to_strict_mode
BREAKPAD_DIR="debug/breakpad"
STACKS_GENERATED=""
OUTPUT_DIR="$(mktemp -d)"
function extract_tarball() {
info "Extracting breakpad symbols from $1..."
tar zxf "$1" -C "${OUTPUT_DIR}" "${BREAKPAD_DIR}"
}
function generate_stacktrace() {
echo "$1.txt"
minidump_stackwalk "$1" "${OUTPUT_DIR}/${BREAKPAD_DIR}" \
>"$1.txt" 2>/dev/null
}
function find_and_generate_stacktraces() {
find "${OUTPUT_DIR}" -name "*.dmp" |
while read filename ; do
generate_stacktrace "${filename}"
done
}
function cleanup() {
if [ -n "${OUTPUT_DIR}" -a -z "${STACKS_GENERATED}" ] ; then
rm -rf "${OUTPUT_DIR}"
fi
}
trap cleanup INT TERM EXIT
info "Downloading minidumps from $2..."
wget -q -nv -r -l 10 -np -A "*.dmp" -P "${OUTPUT_DIR}" $2
if [[ -z "$(find "${OUTPUT_DIR}" -name "*.dmp")" ]] ; then
die "No minidumps found"
fi
if [[ -f "$1" ]] ; then
extract_tarball "$1"
else
info "Downloading symbols tarball from $1..."
wget -P "${OUTPUT_DIR}" "$1"
TARBALL="${OUTPUT_DIR}/$(basename $1)"
extract_tarball "$TARBALL"
rm -f "$TARBALL"
fi
info "Generating stack traces..."
STACKS_GENERATED=$(find_and_generate_stacktraces)
echo $STACKS_GENERATED