Comparison

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
comparison
equal deleted inserted replaced
4520:2d85ac26799c 4521:4c7495f7f543
112 112
113 message = message and (message.."\n") or ""; 113 message = message and (message.."\n") or "";
114 114
115 local levels = get_traceback_table(thread, level+2); 115 local levels = get_traceback_table(thread, level+2);
116 116
117 local last_source_desc;
118
117 local lines = {}; 119 local lines = {};
118 for nlevel, level in ipairs(levels) do 120 for nlevel, level in ipairs(levels) do
119 local info = level.info; 121 local info = level.info;
120 local line = "..."; 122 local line = "...";
121 local func_type = info.namewhat.." "; 123 local func_type = info.namewhat.." ";
124 local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown";
122 if func_type == " " then func_type = ""; end; 125 if func_type == " " then func_type = ""; end;
123 if info.short_src == "[C]" then 126 if info.short_src == "[C]" then
124 line = "[ C ] "..func_type.."C function "..(info.name and ("%q"):format(info.name) or "(unknown name)") 127 line = "[ C ] "..func_type.."C function "..(info.name and ("%q"):format(info.name) or "(unknown name)")
125 elseif info.what == "main" then 128 elseif info.what == "main" then
126 line = "[Lua] "..info.short_src.." line "..info.currentline; 129 line = "[Lua] "..info.short_src.." line "..info.currentline;
132 if func_type == "global " or func_type == "local " then 135 if func_type == "global " or func_type == "local " then
133 func_type = func_type.."function "; 136 func_type = func_type.."function ";
134 end 137 end
135 line = "[Lua] "..info.short_src.." line "..info.currentline.." in "..func_type..name.." defined on line "..info.linedefined; 138 line = "[Lua] "..info.short_src.." line "..info.currentline.." in "..func_type..name.." defined on line "..info.linedefined;
136 end 139 end
140 if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous
141 if last_source_desc then
142 local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc)/2));
143 table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ "));
144 end
145 last_source_desc = source_desc;
146 end
137 nlevel = nlevel-1; 147 nlevel = nlevel-1;
138 table.insert(lines, "\t"..(nlevel==0 and ">" or " ").."("..nlevel..") "..line); 148 table.insert(lines, "\t"..(nlevel==0 and ">" or " ").."("..nlevel..") "..line);
139 local npadding = (" "):rep(#tostring(nlevel)); 149 local npadding = (" "):rep(#tostring(nlevel));
140 local locals_str = string_from_var_table(level.locals, 65, "\t "..npadding); 150 local locals_str = string_from_var_table(level.locals, 65, "\t "..npadding);
141 if locals_str then 151 if locals_str then
144 local upvalues_str = string_from_var_table(level.upvalues, 65, "\t "..npadding); 154 local upvalues_str = string_from_var_table(level.upvalues, 65, "\t "..npadding);
145 if upvalues_str then 155 if upvalues_str then
146 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); 156 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str);
147 end 157 end
148 end 158 end
159
160 local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc) / 2));
161 table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ "));
162
149 return message.."stack traceback:\n"..table.concat(lines, "\n"); 163 return message.."stack traceback:\n"..table.concat(lines, "\n");
150 end 164 end