In dump_trace(), fix BASH_ARGV and BASH_ARGC offsets so that they are always
authorZac Medico <zmedico@gentoo.org>
Tue, 8 Apr 2008 04:59:44 +0000 (04:59 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 8 Apr 2008 04:59:44 +0000 (04:59 -0000)
correct wrt eachother. Thanks to Betelgeuse for reporting. (trunk r9732:9734)

svn path=/main/branches/2.1.2/; revision=9751

bin/isolated-functions.sh

index 96594d8fef6fe110eeb13c0d7cfec3f4f7521760..737c5dfb4b069679ec05e7320540613c76829e08 100644 (file)
@@ -15,7 +15,7 @@ shopt -s extdebug
 #            [whitespacing for filenames],
 #            [whitespacing for line numbers])
 dump_trace() {
-       local funcname="" sourcefile="" lineno="" n e s="yes"
+       local funcname="" sourcefile="" lineno="" s="yes" n p
        declare -i strip=${1:-1}
        local filespacing=$2 linespacing=$3
 
@@ -23,14 +23,19 @@ dump_trace() {
        # that the user will not be interested in. Therefore, the stack trace
        # should only show calls that come after qa_call().
        (( n = ${#FUNCNAME[@]} - 1 ))
+       (( p = ${#BASH_ARGV[@]} ))
        while (( n > 0 )) ; do
                [ "${FUNCNAME[${n}]}" == "qa_call" ] && break
+               (( p -= ${BASH_ARGC[${n}]} ))
                (( n-- ))
        done
-       (( n == 0 )) && (( n = ${#FUNCNAME[@]} - 1 ))
+       if (( n == 0 )) ; then
+               (( n = ${#FUNCNAME[@]} - 1 ))
+               (( p = ${#BASH_ARGV[@]} ))
+       fi
 
        eerror "Call stack:"
-       for (( p = ${#BASH_ARGV[@]} ; n > ${strip} ; n-- )) ; do
+       while (( n > ${strip} )) ; do
                funcname=${FUNCNAME[${n} - 1]}
                sourcefile=$(basename ${BASH_SOURCE[${n}]})
                lineno=${BASH_LINENO[${n} - 1]}
@@ -44,6 +49,7 @@ dump_trace() {
                        (( p -= ${BASH_ARGC[${n} - 1]} ))
                fi
                eerror "  $(printf "%${filespacing}s" "${sourcefile}"), line $(printf "%${linespacing}s" "${lineno}"):  Called ${funcname}${args:+ ${args}}"
+               (( n-- ))
        done
 }