diff options
author | Gvozden Neskovic <[email protected]> | 2016-07-24 21:55:48 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-07-25 11:47:21 -0700 |
commit | 20da056688ef9b41ed4c0a9ee9ff4cd36949c3d8 (patch) | |
tree | 3e7ca6788e89e9c140096dba97c63899eb0112e4 /scripts/zloop.sh | |
parent | f4bc1bbe11042de49226c69f0334c77af30024b4 (diff) |
zloop: print backtrace from core files
Find the core file by using `/proc/sys/kernel/core_pattern`
Signed-off-by: Gvozden Neskovic <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #4874
Diffstat (limited to 'scripts/zloop.sh')
-rwxr-xr-x | scripts/zloop.sh | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/scripts/zloop.sh b/scripts/zloop.sh index 2550eab45..8125229a8 100755 --- a/scripts/zloop.sh +++ b/scripts/zloop.sh @@ -63,9 +63,25 @@ function or_die fi } +# core file helpers +origcorepattern="$(cat /proc/sys/kernel/core_pattern)" +coreglob="$(egrep -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*" + +if [[ $coreglob = "*" ]]; then + echo "Setting core file pattern..." + echo "core" > /proc/sys/kernel/core_pattern + coreglob="$(egrep -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*" +fi + +function core_file +{ + printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)" +} + function store_core { - if [[ $ztrc -ne 0 ]] || [[ -f core ]]; then + core="$(core_file)" + if [[ $ztrc -ne 0 ]] || [[ -f "$core" ]]; then coreid=$(date "+zloop-%y%m%d-%H%M%S") foundcrashes=$(($foundcrashes + 1)) @@ -82,7 +98,7 @@ function store_core or_die mv $workdir/zpool.cache $dest/vdev/ # check for core - if [[ -f core ]]; then + if [[ -f "$core" ]]; then corestatus=$($GDB --batch --quiet \ -ex "set print thread-events off" \ -ex "printf \"*\n* Backtrace \n*\n\"" \ @@ -95,14 +111,14 @@ function store_core -ex "thread apply all bt" \ -ex "printf \"*\n* Backtraces (full) \n*\n\"" \ -ex "thread apply all bt full" \ - -ex "quit" $ZTEST core | grep -v "New LWP") + -ex "quit" $ZTEST "$core" | grep -v "New LWP") # Dump core + logs to stored directory echo "$corestatus" >>$dest/status - or_die mv core $dest/ + or_die mv "$core" $dest/ # Record info in cores logfile - echo "*** core @ $coredir/$coreid/core:" | \ + echo "*** core @ $coredir/$coreid/$core:" | \ tee -a ztest.cores echo "$corestatus" | tee -a ztest.cores echo "" | tee -a ztest.cores @@ -135,8 +151,9 @@ shift $((OPTIND - 1)) # enable core dumps ulimit -c unlimited -if [[ -f core ]]; then - echo "There's a core dump here you might want to look at first." +if [[ -f "$(core_file)" ]]; then + echo -n "There's a core dump here you might want to look at first... " + echo "$(core_file)" exit 1 fi @@ -206,6 +223,9 @@ done echo "zloop finished, $foundcrashes crashes found" +#restore core pattern +echo "$origcorepattern" > /proc/sys/kernel/core_pattern + uptime >>ztest.out if [[ $foundcrashes -gt 0 ]]; then |