From 783001ec079bac46e51ab2ce7969d117f8af05fc Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Thu, 8 Feb 2007 04:38:21 +0000 Subject: die requires diefunc and dump_trace too; duh; also move extdebug into isolated-functions.sh svn path=/main/trunk/; revision=5930 --- bin/isolated-functions.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'bin/isolated-functions.sh') diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh index d9fafbcb6..41595ea30 100755 --- a/bin/isolated-functions.sh +++ b/bin/isolated-functions.sh @@ -10,6 +10,37 @@ alias assert='_pipestatus="${PIPESTATUS[*]}"; [[ "${_pipestatus// /}" -eq 0 ]] | alias save_IFS='[ "${IFS:-unset}" != "unset" ] && old_IFS="${IFS}"' alias restore_IFS='if [ "${old_IFS:-unset}" != "unset" ]; then IFS="${old_IFS}"; unset old_IFS; else unset IFS; fi' +shopt -s extdebug + +# usage- first arg is the number of funcs on the stack to ignore. +# defaults to 1 (ignoring dump_trace) +dump_trace() { + local funcname="" sourcefile="" lineno="" n e s="yes" + + declare -i strip=1 + + if [[ -n $1 ]]; then + strip=$(( $1 )) + fi + + echo "Call stack:" + for (( n = ${#FUNCNAME[@]} - 1, p = ${#BASH_ARGV[@]} ; n > $strip ; n-- )) ; do + funcname=${FUNCNAME[${n} - 1]} + sourcefile=$(basename ${BASH_SOURCE[${n}]}) + lineno=${BASH_LINENO[${n} - 1]} + # Display function arguments + args= + if [[ -n "${BASH_ARGV[@]}" ]]; then + for (( j = 1 ; j <= ${BASH_ARGC[${n} - 1]} ; ++j )); do + newarg=${BASH_ARGV[$(( p - j - 1 ))]} + args="${args:+${args} }'${newarg}'" + done + (( p -= ${BASH_ARGC[${n} - 1]} )) + fi + echo " ${sourcefile}, line ${lineno}: Called ${funcname}${args:+ ${args}}" + done +} + diefunc() { local funcname="$1" lineno="$2" exitcode="$3" shift 3 -- cgit v1.2.3-1-g7c22