blob: 7f4bb5ad56e807d703b73bd78a61e8bdff59e1b6 [file] [log] [blame]
Josh Gao3dffb842018-06-14 16:12:12 -07001#!/bin/bash
2# Copyright (C) 2018 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Get backtraces for a process.
17if [[ $1 =~ ^[0-9]+$ ]] ; then
18 PID="$1"
19elif [ "$1" ] ; then
20 PIDLIST="$(pid $1)"
21 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
22 PID="$PIDLIST"
23 elif [ "$PIDLIST" ] ; then
24 echo "more than one process: $1"
25 else
26 echo "no such process: $1"
27 fi
28else
29 echo "usage: stacks [pid|process name]"
30fi
31
32if [ "$PID" ] ; then
33 # Use `debuggerd -j` on java processes.
34 if adb shell readlink /proc/$PID/exe | egrep -q '^/system/bin/app_process' ; then
35 # But not the zygote.
36 if ! adb shell cat /proc/$PID/cmdline | egrep -q '^zygote'; then
37 adb shell debuggerd -j $PID
38 exit $?
39 fi
40 fi
41
42 adb shell debuggerd -b $PID
43fi