| #!/bin/bash |
| # Copyright 2018 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| #### CATEGORY=Run, inspect and debug |
| ### symbolize backtraces and program locations provided as input on stdin |
| |
| ## usage: fx symbolize [-i IDS_TXT_FILE] [-r | --remote-symbols] |
| ## |
| ## -i IDS_TXT_FILE specify an ids.txt file to be used |
| ## |
| ## --remote-symbols|-r attemp to resolve symbols using predefined remote |
| ## symbol servers for symbols that cannot be resolved |
| ## locally. |
| ## |
| ## Converts sybmolizer markup found in stdin to human readable using |
| ## local symbols (and remote if the --remote-symbols option is used). |
| ## This command is usually used on log output from either zx_log or syslog. |
| ## Anything that is not valid symbolizer markup is left alone. This is similar |
| ## to how c++filt works for demangling C++ symbols. |
| ## |
| ## By default, `fx log` and `fx klog` automatically pipe their results into |
| ## this command. |
| ## |
| ## Authentication: |
| ## If the `--remote-symbols` option is specified, `fx symbolize` will fail if the |
| ## current user is not authenticated with `gcloud` or if they don't have enough |
| ## privileges on the symbol servers. To ensure that the current user is |
| ## properly authenticated, run: |
| ## `gcloud auth application-default login` |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| |
| function symbolize { |
| fx-config-read |
| local symbolize="${HOST_OUT_DIR}/symbolize" |
| if [[ ! -x "${symbolize}" ]]; then |
| fx-error "Cannot execute '${symbolize}'. Try \`fx build\` first." |
| exit 1 |
| fi |
| local llvm_symbolizer="${PREBUILT_CLANG_DIR}/bin/llvm-symbolizer" |
| local toolchain_dir="${PREBUILT_CLANG_DIR}/lib/debug/.build-id" |
| local prebuilt_dir="${FUCHSIA_DIR}/prebuilt/.build-id" |
| local out_dir="${FUCHSIA_BUILD_DIR}/.build-id" |
| local zircon_dir="${ZIRCON_BUILDROOT}/.build-id" |
| if [[ "${is_remote}" -eq 1 ]]; then |
| trap '_code=$?; set +x; exit-with-warning ${_code}' ERR |
| fi |
| "$symbolize" -llvm-symbolizer "$llvm_symbolizer" \ |
| -ids-rel "${extra_args[@]}" \ |
| -build-id-dir "$prebuilt_dir" -build-id-dir "$toolchain_dir" \ |
| -build-id-dir "$out_dir" -build-id-dir "$zircon_dir" |
| } |
| |
| function exit-with-warning { |
| local error_code="$1" |
| if [[ "${error_code}" -ne 0 ]]; then |
| fx-error "If you are having trouble with authentication, make sure you are" \ |
| "authenticated in gcloud and you have permission to access" \ |
| "the remote symbols servers.\nSee \`fx help symbolize\` for more information" |
| fi |
| exit ${error_code} |
| } |
| |
| declare extra_args=() |
| declare is_remote=0 |
| |
| while [[ $# -ne 0 ]]; do |
| case "$1" in |
| -h|--help) |
| fx-command-help |
| exit 0 |
| ;; |
| -i) |
| if [[ $# -lt 2 ]]; then |
| fx-error Invalid syntax |
| fx-command-help |
| return 1 |
| fi |
| extra_args+=( "-ids" "$2") |
| shift |
| ;; |
| --remote-symbols|-r) |
| is_remote=1 |
| ;; |
| *) |
| fx-error Invalid syntax |
| fx-command-help |
| exit 1 |
| esac |
| shift |
| done |
| |
| if [[ "${is_remote}" -eq 1 ]]; then |
| extra_args+=( |
| "-symbol-cache" "$HOME/.fuchsia-symbol-cache" |
| "-symbol-server" "gs://fuchsia-artifacts/debug" |
| "-symbol-server" "gs://fuchsia-artifacts-internal/debug" |
| "-symbol-server" "gs://fuchsia-artifacts-release/debug" |
| ) |
| fi |
| |
| symbolize |