Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 896a5466 authored by Josh Gao's avatar Josh Gao
Browse files

Move pid, stacks from envsetup.sh to dedicated scripts.

Make it so that these can be used in other scripts by moving them from
functions defined in envsetup.sh to standalone scripts.

Test: stacks zygote64
Change-Id: Id8e5ce5b4da80e57f4226eb34edaf82b87393834
parent ab1e09a6
Loading
Loading
Loading
Loading
+0 −53
Original line number Diff line number Diff line
@@ -974,28 +974,6 @@ function qpid() {
    fi
}

function pid()
{
    local prepend=''
    local append=''
    if [ "$1" = "--exact" ]; then
        prepend=' '
        append='$'
        shift
    fi
    local EXE="$1"
    if [ "$EXE" ] ; then
        local PID=`adb shell ps \
            | tr -d '\r' \
            | \grep "$prepend$EXE$append" \
            | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
        echo "$PID"
    else
        echo "usage: pid [--exact] <process name>"
        return 255
    fi
}

# coredump_setup - enable core dumps globally for any process
#                  that has the core-file-size limit set correctly
#
@@ -1082,37 +1060,6 @@ function systemstack()
    stacks system_server
}

function stacks()
{
    if [[ $1 =~ ^[0-9]+$ ]] ; then
        local PID="$1"
    elif [ "$1" ] ; then
        local PIDLIST="$(pid $1)"
        if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
            local PID="$PIDLIST"
        elif [ "$PIDLIST" ] ; then
            echo "more than one process: $1"
        else
            echo "no such process: $1"
        fi
    else
        echo "usage: stacks [pid|process name]"
    fi

    if [ "$PID" ] ; then
        # Use `debuggerd -j` on java processes.
        if adb shell readlink /proc/$PID/exe | egrep -q '^/system/bin/app_process' ; then
            # But not the zygote.
            if ! adb shell cat /proc/$PID/cmdline | egrep -q '^zygote'; then
                adb shell debuggerd -j $PID
                return
            fi
        fi

        adb shell debuggerd -b $PID
    fi
}

# Read the ELF header from /proc/$PID/exe to determine if the process is
# 64-bit.
function is64bit()