blob: 8f255ac54375556412f7f9b6a76b04d6ba679831 [file] [log] [blame]
#!/bin/bash
# Copyright 2017 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
### listen for kernel logs
## usage: fx klog [--raw] [-r | --remote-symbols]
##
## --experimental use the experimental C++ symbolizer
##
## --legacy use the legacy Go symbolizer
##
## --raw do not attempt to symbolize the log
##
## --remote-symbols|-r attemp to resolve symbols using predefined remote
## symbol servers for symbols that cannot be resolved
## locally. See `fx help symbolize` for more
## information on remote symbol servers.
##
## This command delegates to the Zircon `loglistener` binary.
## It will listen to the device specified with `fx -d DEVICE klog` or
## `fx set-device`, otherwise one of the devices on the link-local network.
set -e
set -o pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
fx-config-read
declare is_raw=0
declare is_remote=0
declare symbolizer=( "fx-command-run" "symbolize" )
while [[ $# -ne 0 ]]; do
case "$1" in
-h|--help)
fx-command-help
exit 0
;;
--raw)
is_raw=1
;;
--remote-symbols|-r)
is_remote=1
symbolizer+=("-r")
;;
--experimental|--legacy)
symbolizer+=("$1")
;;
*)
fx-error Invalid syntax
fx-command-help
exit 1
esac
shift
done
if (( is_raw )) && (( is_remote )); then
fx-error "Invalid syntax: --raw and -r cannot be used together"
fx-command-help
exit 1
fi
device="$(get-device-name)" || exit $?
if (( is_raw )); then
exec "${FUCHSIA_BUILD_DIR}/host-tools/loglistener" "${device}"
else
"${FUCHSIA_BUILD_DIR}/host-tools/loglistener" "${device}" | "${symbolizer[@]}"
fi