Skip to content

Commit d2d471f

Browse files
committed
run_qemu.sh: print a backtrace() on failure
Copied from thesofproject/sof-test@1aef6b9a18e7d1 where it has been successfully used for 5 years. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 5e9a8bf commit d2d471f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

run_qemu.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ cleanup()
256256
set +x
257257
}
258258

259+
backtrace()
260+
{
261+
( set +x
262+
for i in $(seq 1 $((${#FUNCNAME[@]}-1))); do
263+
264+
line_no=${BASH_LINENO[$((i-1))]} || true
265+
# BASH_LINENO doesn't always work
266+
if [ "$line_no" -gt 1 ]; then line_no=":$line_no"; else line_no=""; fi
267+
268+
printf ' %s() @ %s%s\n' "${FUNCNAME[i]}" "${BASH_SOURCE[i]}" "${line_no}"
269+
done
270+
)
271+
}
272+
259273
# In POSIX theory, the shell automatically saves for us the $? of the
260274
# "last command before the trap"; see special built-in 'exit' in
261275
# "2. Shell Command Language" on opengroup.org. However this is
@@ -265,6 +279,8 @@ cleanup()
265279
trap 'exit_handler $?' EXIT
266280
exit_handler()
267281
{
282+
test "$1" = 0 || >&2 backtrace
283+
268284
# 42 "breadcrumb" if forgotten and missing
269285
local err="${1-42}"
270286
# "set -e" can trigger _twice_ and abort the EXIT handler again!

0 commit comments

Comments
 (0)