From 6396ccabe3af33f8a8b32b6644afe971a3fa6dbf Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 18 May 2013 12:34:41 +0200 Subject: [PATCH] Enhance backtrace with called binary. So it is easier to find out which command has been executed. --- functions.list | 10 ++++++++++ functions.util | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/functions.list b/functions.list index 3110357f..062df27e 100644 --- a/functions.list +++ b/functions.list @@ -119,3 +119,13 @@ function list_join() { print "${ret:${#delim}}" } + +function list_reverse() { + local reversed arg + for arg in $@; do + reversed="${arg} ${reversed}" + done + + print "${reversed}" + return ${EXIT_OK} +} diff --git a/functions.util b/functions.util index b975b6a0..2eef4a7a 100644 --- a/functions.util +++ b/functions.util @@ -260,7 +260,14 @@ function backtrace() { local i source for i in $(seq ${start} ${#BASH_SOURCE[*]}); do [ -z "${FUNCNAME[${i}]}" ] && continue - [ "${FUNCNAME[${i}]}" == "main" ] && continue + + # Print called binary with arguments. + if [ "${FUNCNAME[${i}]}" == "main" ]; then + local args="$(list_reverse ${BASH_ARGV[*]})" + printf -v source "%20s" "$0" + error_log " ${source} ${args}" + continue + fi source=${BASH_SOURCE[$(( ${i} + 1 ))]} error_log " $(printf "%20s" "'${FUNCNAME[${i}]}'") called from ${source:-}:${BASH_LINENO[${i}]}" -- 2.39.2