From 68997879d34d202bdb88559f85fedbdbb51ef2f7 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Sun, 29 Aug 2021 20:55:45 +0100 Subject: [PATCH] Nasal/debug.nas: backtrace(): reinstate mechanism to truncate long filenames. Also made it configurable. --- Nasal/debug.nas | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Nasal/debug.nas b/Nasal/debug.nas index 774d32159..c3fd75eb9 100644 --- a/Nasal/debug.nas +++ b/Nasal/debug.nas @@ -305,7 +305,18 @@ var funcname = func(f) { return "-unknown-"; } -var backtrace = func(desc = nil, dump_vars = 1, skip_level = 0) { +# Write backtrace information. +# +# desc: +# Text to write in first line. +# dump_vars: +# If true, show info about variables. +# skip_level: +# How many top-level stack frames to skip. +# shorten: +# If greater than 10, max filename length before being trimmed. +# +var backtrace = func(desc = nil, dump_vars = 1, skip_level = 0, shorten = 50) { var d = (desc == nil) ? "" : " '" ~ desc ~ "'"; print(""); print(_title("### backtrace" ~ d ~ " ###")); @@ -314,6 +325,8 @@ var backtrace = func(desc = nil, dump_vars = 1, skip_level = 0) { if ((var v = caller(i)) == nil) return caller(i - 1); var filename = v[2]; var line = v[3]; + if (shorten >= 10 and size(filename) > shorten) + filename = substr(filename, 0, 5)~"[...]"~substr(filename, -(shorten-10)); print(_section(sprintf("#%-2d called from %s:%d (%s) (locals %s):", i - skip_level, filename, line, funcname(v[1]), id(v[0])))); if (dump_vars) dump(v[0]);