summaryrefslogtreecommitdiffstats
path: root/bin/isolated-functions.sh
diff options
context:
space:
mode:
authorAlec Warner <antarus@gentoo.org>2007-02-08 04:38:21 +0000
committerAlec Warner <antarus@gentoo.org>2007-02-08 04:38:21 +0000
commit783001ec079bac46e51ab2ce7969d117f8af05fc (patch)
treec52419f82e2d0dbb306232ba61e4ef152e830380 /bin/isolated-functions.sh
parent9e59455b3ec09e1dbe6a1eece39ec1185a64284d (diff)
downloadportage-783001ec079bac46e51ab2ce7969d117f8af05fc.tar.gz
portage-783001ec079bac46e51ab2ce7969d117f8af05fc.tar.bz2
portage-783001ec079bac46e51ab2ce7969d117f8af05fc.zip
die requires diefunc and dump_trace too; duh; also move extdebug into isolated-functions.sh
svn path=/main/trunk/; revision=5930
Diffstat (limited to 'bin/isolated-functions.sh')
-rwxr-xr-xbin/isolated-functions.sh31
1 files changed, 31 insertions, 0 deletions
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