From 3452bfcf8cb2dc67819485c7b011e5c6a59310f8 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 15 Feb 2010 17:36:29 +0100 Subject: Add generic function handling for debug modules. Don't call record vmevent for non-Lua functions. --- lib/v.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'lib/v.lua') diff --git a/lib/v.lua b/lib/v.lua index 93f1cbb2..649bbf8d 100644 --- a/lib/v.lua +++ b/lib/v.lua @@ -73,17 +73,23 @@ local active, out local startloc, startex +local function fmtfunc(func, pc) + local fi = funcinfo(func, pc) + if fi.loc then + return fi.loc + elseif fi.ffid then + return vmdef.ffnames[fi.ffid] + elseif fi.addr then + return format("C:%x", fi.addr) + else + return "(?)" + end +end + -- Format trace error message. local function fmterr(err, info) if type(err) == "number" then - if type(info) == "function" then - local fi = funcinfo(info) - if fi.ffid then - info = vmdef.ffnames[fi.ffid] - else - info = fi.loc - end - end + if type(info) == "function" then info = fmtfunc(info) end err = format(vmdef.traceerr[err], info) end return err @@ -92,11 +98,11 @@ end -- Dump trace states. local function dump_trace(what, tr, func, pc, otr, oex) if what == "start" then - startloc = funcinfo(func, pc).loc + startloc = fmtfunc(func, pc) startex = otr and "("..otr.."/"..oex..") " or "" else if what == "abort" then - local loc = funcinfo(func, pc).loc + local loc = fmtfunc(func, pc) if loc ~= startloc then out:write(format("[TRACE --- %s%s -- %s at %s]\n", startex, startloc, fmterr(otr, oex), loc)) -- cgit v1.2.3-55-g6feb