summaryrefslogtreecommitdiff
path: root/lib/dump.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dump.lua')
-rw-r--r--lib/dump.lua42
1 files changed, 18 insertions, 24 deletions
diff --git a/lib/dump.lua b/lib/dump.lua
index be456aa0..c12b0ba8 100644
--- a/lib/dump.lua
+++ b/lib/dump.lua
@@ -227,6 +227,19 @@ local function ctlsub(c)
227 end 227 end
228end 228end
229 229
230local function fmtfunc(func, pc)
231 local fi = funcinfo(func, pc)
232 if fi.loc then
233 return fi.loc
234 elseif fi.ffid then
235 return vmdef.ffnames[fi.ffid]
236 elseif fi.addr then
237 return format("C:%x", fi.addr)
238 else
239 return "(?)"
240 end
241end
242
230local function formatk(tr, idx) 243local function formatk(tr, idx)
231 local k, t, slot = tracek(tr, idx) 244 local k, t, slot = tracek(tr, idx)
232 local tn = type(k) 245 local tn = type(k)
@@ -240,12 +253,7 @@ local function formatk(tr, idx)
240 elseif tn == "string" then 253 elseif tn == "string" then
241 s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub)) 254 s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub))
242 elseif tn == "function" then 255 elseif tn == "function" then
243 local fi = funcinfo(k) 256 s = fmtfunc(k)
244 if fi.ffid then
245 s = vmdef.ffnames[fi.ffid]
246 else
247 s = fi.loc
248 end
249 elseif tn == "table" then 257 elseif tn == "table" then
250 s = format("{%p}", k) 258 s = format("{%p}", k)
251 elseif tn == "userdata" then 259 elseif tn == "userdata" then
@@ -428,14 +436,7 @@ local recdepth = 0
428-- Format trace error message. 436-- Format trace error message.
429local function fmterr(err, info) 437local function fmterr(err, info)
430 if type(err) == "number" then 438 if type(err) == "number" then
431 if type(info) == "function" then 439 if type(info) == "function" then info = fmtfunc(info) end
432 local fi = funcinfo(info)
433 if fi.ffid then
434 info = vmdef.ffnames[fi.ffid]
435 else
436 info = fi.loc
437 end
438 end
439 err = format(vmdef.traceerr[err], info) 440 err = format(vmdef.traceerr[err], info)
440 end 441 end
441 return err 442 return err
@@ -452,16 +453,14 @@ local function dump_trace(what, tr, func, pc, otr, oex)
452 if dumpmode.H then out:write('<pre class="ljdump">\n') end 453 if dumpmode.H then out:write('<pre class="ljdump">\n') end
453 out:write("---- TRACE ", tr, " ", what) 454 out:write("---- TRACE ", tr, " ", what)
454 if otr then out:write(" ", otr, "/", oex) end 455 if otr then out:write(" ", otr, "/", oex) end
455 local fi = funcinfo(func, pc) 456 out:write(" ", fmtfunc(func, pc), "\n")
456 out:write(" ", fi.loc, "\n")
457 recprefix = "" 457 recprefix = ""
458 reclevel = 0 458 reclevel = 0
459 elseif what == "stop" or what == "abort" then 459 elseif what == "stop" or what == "abort" then
460 out:write("---- TRACE ", tr, " ", what) 460 out:write("---- TRACE ", tr, " ", what)
461 recprefix = nil 461 recprefix = nil
462 if what == "abort" then 462 if what == "abort" then
463 local fi = funcinfo(func, pc) 463 out:write(" ", fmtfunc(func, pc), " -- ", fmterr(otr, oex), "\n")
464 out:write(" ", fi.loc, " -- ", fmterr(otr, oex), "\n")
465 else 464 else
466 local link = traceinfo(tr).link 465 local link = traceinfo(tr).link
467 if link == tr then 466 if link == tr then
@@ -487,12 +486,7 @@ local function dump_record(tr, func, pc, depth, callee)
487 local line = bcline(func, pc, recprefix) 486 local line = bcline(func, pc, recprefix)
488 if dumpmode.H then line = gsub(line, "[<>&]", html_escape) end 487 if dumpmode.H then line = gsub(line, "[<>&]", html_escape) end
489 if type(callee) == "function" then 488 if type(callee) == "function" then
490 local fi = funcinfo(callee) 489 out:write(sub(line, 1, -2), " ; ", fmtfunc(callee), "\n")
491 if fi.ffid then
492 out:write(sub(line, 1, -2), " ; ", vmdef.ffnames[fi.ffid], "\n")
493 else
494 out:write(sub(line, 1, -2), " ; ", fi.loc, "\n")
495 end
496 else 490 else
497 out:write(line) 491 out:write(line)
498 end 492 end