#!/bin/bash # Copyright (C) 2018 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -e . "${0%/*}"/bash_util.bash function usage() { cat 1>&2 <<"EOF" $script_name: print stacktrace of an android process. Usage: $script_name PID_OR_PROCESS_NAME EOF exit 1 } pid="$(resolve_pid "$1" || usage)" info "Dumping stacktrace from pid $pid ..." # Send sigquit to initiate stacktrace. ts="$(get_last_logcat_timestamp)" do_adb shell kill -s sigquit "$pid" # Watch logcat to catch finish, and then obtain the filename. # First, set up a timer for timeout. ( sleep 10 warn "Timed out waiting for tombstoned. (wrong PID?)" kill -s usr1 $$ ) & timer_pid=$! trap 'exit 0' USR1 # --------- beginning of main # 06-14 00:12:57.384 1058 925 925 E /system/bin/tombstoned: Traces for pid 1204 written to: /data/anr/trace_01 info "Waiting for tombstoned to finish writing..." log="$(do_adb logcat -T "$ts" -e "Traces for pid $pid written to" -m 1 | sed -e 1d)" # Remoe the header file="${log## }" # Remove everything until the last space. do_adb shell cat "$file" || true # Somehow this returns 1? # Success, kill the timer process. kill "$timer_pid"