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

* commit '2b756f79461c3cc5c227dc83e6dd3f360ad3f247':
  envsetup.sh: add functions to enable and generate core dumps
This commit is contained in:
Iliyan Malchev 2014-10-31 22:59:59 +00:00 committed by Android Git Automerger
commit 2e835e714c
1 changed files with 78 additions and 0 deletions

View File

@ -890,6 +890,84 @@ function pid()
fi 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 # systemstack - dump the current stack trace of all threads in the system process
# to the usual ANR traces file # to the usual ANR traces file
function systemstack() function systemstack()