aboutsummaryrefslogtreecommitdiffstats
path: root/util/debug.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-08-10 20:30:40 +0100
committerMatthew Wild <mwild1@gmail.com>2013-08-10 20:30:40 +0100
commit51549fe050a1aec00284d1e2599c93010bc763c2 (patch)
treeeca9250ca7cd0e335bb1c71ab04f670baffb7d4f /util/debug.lua
parenta10c051fb26431f23f4086b8b20b02e32482b389 (diff)
downloadprosody-51549fe050a1aec00284d1e2599c93010bc763c2.tar.gz
prosody-51549fe050a1aec00284d1e2599c93010bc763c2.zip
util.debug: Fixes to make coroutine tracebacks work properly
Diffstat (limited to 'util/debug.lua')
-rw-r--r--util/debug.lua18
1 files changed, 10 insertions, 8 deletions
diff --git a/util/debug.lua b/util/debug.lua
index 1f1ec9df..52ba52d0 100644
--- a/util/debug.lua
+++ b/util/debug.lua
@@ -88,7 +88,7 @@ function get_traceback_table(thread, start_level)
for level = start_level, math.huge do
local info;
if thread then
- info = debug.getinfo(thread, level+1);
+ info = debug.getinfo(thread, level);
else
info = debug.getinfo(level+1);
end
@@ -97,7 +97,7 @@ function get_traceback_table(thread, start_level)
levels[(level-start_level)+1] = {
level = level;
info = info;
- locals = get_locals_table(level+1);
+ locals = not thread and get_locals_table(level+1);
upvalues = get_upvalues_table(info.func);
};
end
@@ -134,12 +134,12 @@ function _traceback(thread, message, level)
return nil; -- debug.traceback() does this
end
- level = level or 1;
+ level = level or 0;
message = message and (message.."\n") or "";
- -- +3 counts for this function, and the pcall() and wrapper above us
- local levels = get_traceback_table(thread, level+3);
+ -- +3 counts for this function, and the pcall() and wrapper above us, the +1... I don't know.
+ local levels = get_traceback_table(thread, level+(thread == nil and 4 or 0));
local last_source_desc;
@@ -171,9 +171,11 @@ function _traceback(thread, message, level)
nlevel = nlevel-1;
table.insert(lines, "\t"..(nlevel==0 and ">" or " ")..getstring(styles.level_num, "("..nlevel..") ")..line);
local npadding = (" "):rep(#tostring(nlevel));
- local locals_str = string_from_var_table(level.locals, optimal_line_length, "\t "..npadding);
- if locals_str then
- table.insert(lines, "\t "..npadding.."Locals: "..locals_str);
+ if level.locals then
+ local locals_str = string_from_var_table(level.locals, optimal_line_length, "\t "..npadding);
+ if locals_str then
+ table.insert(lines, "\t "..npadding.."Locals: "..locals_str);
+ end
end
local upvalues_str = string_from_var_table(level.upvalues, optimal_line_length, "\t "..npadding);
if upvalues_str then