# Enhancement of eselect core lib to also show function names. # Generic cleanup of how array elements are set to make the code readable: # Get rid of lots of unnecessary $(()) and {}. # sourcefile setting should be 'n', not 'n-1' shopt -s extdebug # usage- first arg is the number of funcs on the stack to ignore. # defaults to 1 (ignoring dump_trace) # pulled from eselect. die() { local funcname="" sourcefile="" lineno="" n e s="yes" args newarg declare -i strip=1 if [[ -n $1 ]]; then strip=$(( $1 )) fi echo "Call stack: (most recent first)" 1>&2 for (( n = $strip, p = 0 ; n < ${#FUNCNAME[@]} ; ++n )) ; do funcname=${FUNCNAME[$n - 1]} sourcefile=$(basename ${BASH_SOURCE[$n]}) lineno=${BASH_LINENO[$n - 1]} # Display function arguments if [[ ! -z "${BASH_ARGV[@]}" ]]; then args= for (( j = ${BASH_ARGC[$n - 1]}; j > 0; j-- )); do newarg=${BASH_ARGV[$j + $p - 1]} args="${args:+${args} }'${newarg}'" done (( p += ${BASH_ARGC[$n - 1]} )) fi echo " ${funcname} ${args:+${args} }at ${sourcefile}:${lineno}" done }