am 248f4d53: envsetup.sh: add functions to enable and generate core dumps

* commit '248f4d53b306bd3baddb1534d3d06076460e83d4':
  envsetup.sh: add functions to enable and generate core dumps
This commit is contained in:
Iliyan Malchev 2014-10-31 21:02:59 +00:00 committed by Android Git Automerger
commit 2b756f7946

View file

@ -890,6 +890,84 @@ function pid()
fi
}
# coredump-setup - enable core dumps globally for any process
# that has the core-file-size limit set correctly
#
# NOTE: You must call also coredump-enable for a specific process
# if its core-file-size limit is not set already.
# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
function coredump-setup()
{
echo "Getting root...";
adb root;
adb wait-for-device;
echo "Remounting root parition read-write...";
adb shell mount -w -o remount -t rootfs rootfs;
sleep 1;
adb wait-for-device;
adb shell mkdir -p /cores;
adb shell chmod 0777 /cores;
echo "Granting SELinux permission to dump in /cores...";
adb shell restorecon -R /cores;
echo "Set core pattern.";
adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
echo "Done."
}
# coredump-enable - enable core dumps for the specified process
# $1 = PID of process (e.g., $(pid mediaserver))
#
# NOTE: coredump-setup must have been called as well for a core
# dump to actually be generated.
function coredump-enable()
{
local PID=$1;
if [ -z "$PID" ]; then
printf "Expecting a PID!\n";
return;
fi;
echo "Setting core limit for $PID to infinite...";
adb shell prlimit $PID 4 -1 -1
}
# core - send SIGV and pull the core for process
# $1 = PID of process (e.g., $(pid mediaserver))
#
# NOTE: coredump-setup must be called once per boot for core dumps to be
# enabled globally.
function core()
{
local PID=$1;
if [ -z "$PID" ]; then
printf "Expecting a PID!\n";
return;
fi;
local CORENAME=core.$PID;
local COREPATH=/cores/$CORENAME;
local SIG=SEGV;
coredump-enable $1;
local done=0;
while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
printf "\tSending SIG%s to %d...\n" $SIG $PID;
adb shell kill -$SIG $PID;
sleep 1;
done;
adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
echo "Done: core is under $COREPATH on device.";
}
# systemstack - dump the current stack trace of all threads in the system process
# to the usual ANR traces file
function systemstack()