Browse Source

bash-back stacktrace1...

main
pvincent 2 weeks ago
parent
commit
00b57bf98c
  1. 30
      bin/bash-back
  2. 10
      lib/utility.bash
  3. 14
      useless.sh

30
bin/bash-back

@ -10,19 +10,33 @@ SCRIPT=$1
function exit { function exit {
code=${1:-0} code=${1:-0}
stack_lines=("${BASH_LINENO[@]}")
stack_functions=("${FUNCNAME[@]}")
stack_sources=("${BASH_SOURCE[@]}")
unset stack_lines[-1]
unset stack_lines[-1]
unset stack_functions[0]
unset stack_functions[-1]
stack_functions[-1]='<main>'
unset stack_sources[0]
unset stack_sources[-1]
stack_lines=("${stack_lines[@]}")
stack_functions=("${stack_functions[@]}")
stack_sources=("${stack_sources[@]}")
if [[ -s $TMP_ERROR ]]; then if [[ -s $TMP_ERROR ]]; then
content=$(<$TMP_ERROR)
last_error=$(tail -n1 $TMP_ERROR)
$DEBUG && >/dev/tty echo '---stderr---' $DEBUG && >/dev/tty echo '---stderr---'
>&4 echo "DETECTED: [$content]"
>&4 echo "ERROR $code: [$last_error]"
fi fi
stack_lines=("${BASH_LINENO[@]}")
stack_functions=("${FUNCNAME[@]}")
stack_sources=("${BASH_SOURCE[@]}")
for i in "${!stack_functions[@]}"; do
printf "%30s\t%s\n" "${stack_sources[$i]}:${stack_lines[$i]}" "${stack_functions[$i]}"
done
echo "${stack_lines[@]}"
echo "${stack_functions[@]}"
echo "${stack_sources[@]}"
# echo "${stack_lines[@]}"
# echo "${stack_functions[@]}"
# echo "${stack_sources[@]}"
cleanup ${code} cleanup ${code}
} }

10
lib/utility.bash

@ -0,0 +1,10 @@
function blabla {
echo IN blabla OUT
suite
}
function suite {
return 7
echo $nope
command_not_found
}

14
useless.sh

@ -3,10 +3,11 @@
function F2 { function F2 {
echo "stdout A" echo "stdout A"
# echo toto >>/tmp/toto # echo toto >>/tmp/toto
# $nope
grep titi toto
# exit 6
>&2 echo "This is stderr" >&2 echo "This is stderr"
blabla
exit 6
grep titi toto
$nope
echo "stdout B" echo "stdout B"
echo "stdout C" echo "stdout C"
# command_not_found # command_not_found
@ -17,6 +18,11 @@ function F1 {
F2 F2
} }
echo start of useless
function main {
F1 F1
}
. lib/utility.bash
echo start of useless
main
echo end of useless echo end of useless
Loading…
Cancel
Save