Software /
code /
prosody
Annotate
util/debug.lua @ 4521:4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 22 Mar 2012 15:09:37 +0000 |
parent | 4520:2d85ac26799c |
child | 4522:29f75c2af90e |
rev | line source |
---|---|
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Variables ending with these names will not |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- have their values printed ('password' includes |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- 'new_password', etc.) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local censored_names = { |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 password = true; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 passwd = true; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 pass = true; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 pwd = true; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 }; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local function get_locals_table(level) |
4465
41c4252526bd
util.debug: Adjust level within get_locals_table() to account for the additional depth of this function itself
Matthew Wild <mwild1@gmail.com>
parents:
4418
diff
changeset
|
12 level = level + 1; -- Skip this function itself |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local locals = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 for local_num = 1, math.huge do |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local name, value = debug.getlocal(level, local_num); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 if not name then break; end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 table.insert(locals, { name = name, value = value }); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 return locals; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local function get_upvalues_table(func) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local upvalues = {}; |
4418
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
24 if func then |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
25 for upvalue_num = 1, math.huge do |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
26 local name, value = debug.getupvalue(func, upvalue_num); |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
27 if not name then break; end |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
28 table.insert(upvalues, { name = name, value = value }); |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
29 end |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 return upvalues; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local function string_from_var_table(var_table, max_line_len, indent_str) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local var_string = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local col_pos = 0; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 max_line_len = max_line_len or math.huge; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 indent_str = "\n"..(indent_str or ""); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 for _, var in ipairs(var_table) do |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 local name, value = var.name, var.value; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 if name:sub(1,1) ~= "(" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 if type(value) == "string" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 if censored_names[name:match("%a+$")] then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 value = "<hidden>"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 value = ("%q"):format(value); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 value = tostring(value); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 if #value > max_line_len then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 value = value:sub(1, max_line_len-3).."…"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 local str = ("%s = %s"):format(name, tostring(value)); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 col_pos = col_pos + #str; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 if col_pos > max_line_len then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 table.insert(var_string, indent_str); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 col_pos = 0; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 table.insert(var_string, str); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 if #var_string == 0 then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 return nil; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 return "{ "..table.concat(var_string, ", "):gsub(indent_str..", ", indent_str).." }"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 function get_traceback_table(thread, start_level) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 local levels = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 for level = start_level, math.huge do |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 local info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 if thread then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 info = debug.getinfo(thread, level); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 info = debug.getinfo(level); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 if not info then break; end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 levels[(level-start_level)+1] = { |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 level = level; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 info = info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 locals = get_locals_table(level); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 upvalues = get_upvalues_table(info.func); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 }; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 return levels; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 |
4520
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
91 function debug.traceback(...) |
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
92 local ok, ret = pcall(debug._traceback, ...); |
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
93 if not ok then |
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
94 return "Error in error handling: "..ret; |
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
95 end |
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
96 return ret; |
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
97 end |
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
98 |
2d85ac26799c
util.debug: Add catch for an "error in error handling"
Matthew Wild <mwild1@gmail.com>
parents:
4519
diff
changeset
|
99 function debug._traceback(thread, message, level) |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 if type(thread) ~= "thread" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 thread, message, level = coroutine.running(), thread, message; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 if level and type(message) ~= "string" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 return nil, "invalid message"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 elseif not level then |
4519
510f4ba7080f
util.debug: Attempt to get debug.traceback() parameter handling correct (again)
Matthew Wild <mwild1@gmail.com>
parents:
4465
diff
changeset
|
106 if type(message) == "number" then |
510f4ba7080f
util.debug: Attempt to get debug.traceback() parameter handling correct (again)
Matthew Wild <mwild1@gmail.com>
parents:
4465
diff
changeset
|
107 level, message = message, nil; |
510f4ba7080f
util.debug: Attempt to get debug.traceback() parameter handling correct (again)
Matthew Wild <mwild1@gmail.com>
parents:
4465
diff
changeset
|
108 else |
510f4ba7080f
util.debug: Attempt to get debug.traceback() parameter handling correct (again)
Matthew Wild <mwild1@gmail.com>
parents:
4465
diff
changeset
|
109 level = 2; |
510f4ba7080f
util.debug: Attempt to get debug.traceback() parameter handling correct (again)
Matthew Wild <mwild1@gmail.com>
parents:
4465
diff
changeset
|
110 end |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 message = message and (message.."\n") or ""; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 local levels = get_traceback_table(thread, level+2); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 |
4521
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
117 local last_source_desc; |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
118 |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 local lines = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 for nlevel, level in ipairs(levels) do |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 local info = level.info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 local line = "..."; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 local func_type = info.namewhat.." "; |
4521
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
124 local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown"; |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 if func_type == " " then func_type = ""; end; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 if info.short_src == "[C]" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 line = "[ C ] "..func_type.."C function "..(info.name and ("%q"):format(info.name) or "(unknown name)") |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 elseif info.what == "main" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 line = "[Lua] "..info.short_src.." line "..info.currentline; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 local name = info.name or " "; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 if name ~= " " then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 name = ("%q"):format(name); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 if func_type == "global " or func_type == "local " then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 func_type = func_type.."function "; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 line = "[Lua] "..info.short_src.." line "..info.currentline.." in "..func_type..name.." defined on line "..info.linedefined; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 end |
4521
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
140 if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
141 if last_source_desc then |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
142 local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc)/2)); |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
143 table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
144 end |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
145 last_source_desc = source_desc; |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
146 end |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 nlevel = nlevel-1; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 table.insert(lines, "\t"..(nlevel==0 and ">" or " ").."("..nlevel..") "..line); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 local npadding = (" "):rep(#tostring(nlevel)); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 local locals_str = string_from_var_table(level.locals, 65, "\t "..npadding); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 if locals_str then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 table.insert(lines, "\t "..npadding.."Locals: "..locals_str); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 local upvalues_str = string_from_var_table(level.upvalues, 65, "\t "..npadding); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 if upvalues_str then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 end |
4521
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
159 |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
160 local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc) / 2)); |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
161 table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); |
4c7495f7f543
util.debug: Add markers in the output when crossing source file boundaries
Matthew Wild <mwild1@gmail.com>
parents:
4520
diff
changeset
|
162 |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 return message.."stack traceback:\n"..table.concat(lines, "\n"); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 end |