diff options
author | Matthew Wild <mwild1@gmail.com> | 2012-03-22 15:09:37 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2012-03-22 15:09:37 +0000 |
commit | 4c94b7dbf1148040551c000f0fa5cf31713f1fc2 (patch) | |
tree | 12cd9c12535d191e42071625b5332e292238bee5 /util | |
parent | 553666c3f2d7da937658e5f695ca4d29a4c1851d (diff) | |
download | prosody-4c94b7dbf1148040551c000f0fa5cf31713f1fc2.tar.gz prosody-4c94b7dbf1148040551c000f0fa5cf31713f1fc2.zip |
util.debug: Add markers in the output when crossing source file boundaries
Diffstat (limited to 'util')
-rw-r--r-- | util/debug.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/util/debug.lua b/util/debug.lua index 9fd0f9dd..6df249c0 100644 --- a/util/debug.lua +++ b/util/debug.lua @@ -114,11 +114,14 @@ function debug._traceback(thread, message, level) local levels = get_traceback_table(thread, level+2); + local last_source_desc; + local lines = {}; for nlevel, level in ipairs(levels) do local info = level.info; local line = "..."; local func_type = info.namewhat.." "; + local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown"; if func_type == " " then func_type = ""; end; if info.short_src == "[C]" then line = "[ C ] "..func_type.."C function "..(info.name and ("%q"):format(info.name) or "(unknown name)") @@ -134,6 +137,13 @@ function debug._traceback(thread, message, level) end line = "[Lua] "..info.short_src.." line "..info.currentline.." in "..func_type..name.." defined on line "..info.linedefined; end + if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous + if last_source_desc then + local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc)/2)); + table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); + end + last_source_desc = source_desc; + end nlevel = nlevel-1; table.insert(lines, "\t"..(nlevel==0 and ">" or " ").."("..nlevel..") "..line); local npadding = (" "):rep(#tostring(nlevel)); @@ -146,5 +156,9 @@ function debug._traceback(thread, message, level) table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); end end + + local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc) / 2)); + table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); + return message.."stack traceback:\n"..table.concat(lines, "\n"); end |