| #!/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 attempt to resolve symbols using predefined remote |
| ## symbol servers for symbols that cannot be resolved |
| ## locally. |
| ## |
| ## --auth (C++ symbolizer) start the authentication process. |
| ## |
| ## Converts symbolizer 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, authentication for the symbol |
| ## server is needed. However, failed or missing authentication is silent. |
| ## To authenticate, run: |
| ## `fx symbolize --auth` |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| |
| function cpp_symbolizer { |
| fx-config-read |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/contrib/lib/symbol-index.sh || exit $? |
| ensure-symbol-index-registered || fx-warn "Failed to register ${FUCHSIA_DIR} in symbol-index!" |
| local symbolizer="${HOST_OUT_DIR}/symbolizer" |
| if [[ ! -x "${symbolizer}" ]]; then |
| fx-error "Cannot execute '${symbolizer}'. Try \`fx build\` first." |
| exit 1 |
| fi |
| local extra_args=() |
| for i in "${ids_txt[@]}"; do |
| extra_args+=(--ids-txt "${i}") |
| done |
| if [[ "${is_remote}" -eq 1 ]]; then |
| if [[ ! -f ~/.fuchsia/debug/googleapi_auth && ! -f ~/.config/gcloud/application_default_credentials.json ]]; then |
| fx-error "Please authenticate first using \`fx symbolize --auth\`." |
| exit 1 |
| fi |
| extra_args+=( |
| "--symbol-server" "gs://fuchsia-artifacts/debug" |
| "--symbol-server" "gs://fuchsia-artifacts-internal/debug" |
| "--symbol-server" "gs://fuchsia-artifacts-release/debug" |
| ) |
| fi |
| if [[ "${auth_mode}" -eq 1 ]]; then |
| extra_args+=(--auth) |
| fi |
| "${symbolizer}" "${extra_args[@]}" |
| } |
| |
| 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 ids_txt=() |
| declare is_remote=0 |
| declare auth_mode=0 |
| |
| while [[ $# -ne 0 ]]; do |
| case "$1" in |
| -h|--help) |
| fx-command-help |
| exit 0 |
| ;; |
| --auth) |
| auth_mode=1 |
| ;; |
| -i) |
| if [[ $# -lt 2 ]]; then |
| fx-error Invalid syntax |
| fx-command-help |
| return 1 |
| fi |
| ids_txt+=("$2") |
| shift |
| ;; |
| --remote-symbols|-r) |
| is_remote=1 |
| ;; |
| *) |
| fx-error Invalid syntax |
| fx-command-help |
| exit 1 |
| esac |
| shift |
| done |
| |
| cpp_symbolizer |