mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Add generic function handling for debug modules.
Don't call record vmevent for non-Lua functions.
This commit is contained in:
parent
b838cd8dca
commit
3452bfcf8c
42
lib/dump.lua
42
lib/dump.lua
@ -227,6 +227,19 @@ local function ctlsub(c)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
local function formatk(tr, idx)
|
local function formatk(tr, idx)
|
||||||
local k, t, slot = tracek(tr, idx)
|
local k, t, slot = tracek(tr, idx)
|
||||||
local tn = type(k)
|
local tn = type(k)
|
||||||
@ -240,12 +253,7 @@ local function formatk(tr, idx)
|
|||||||
elseif tn == "string" then
|
elseif tn == "string" then
|
||||||
s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub))
|
s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub))
|
||||||
elseif tn == "function" then
|
elseif tn == "function" then
|
||||||
local fi = funcinfo(k)
|
s = fmtfunc(k)
|
||||||
if fi.ffid then
|
|
||||||
s = vmdef.ffnames[fi.ffid]
|
|
||||||
else
|
|
||||||
s = fi.loc
|
|
||||||
end
|
|
||||||
elseif tn == "table" then
|
elseif tn == "table" then
|
||||||
s = format("{%p}", k)
|
s = format("{%p}", k)
|
||||||
elseif tn == "userdata" then
|
elseif tn == "userdata" then
|
||||||
@ -428,14 +436,7 @@ local recdepth = 0
|
|||||||
-- Format trace error message.
|
-- Format trace error message.
|
||||||
local function fmterr(err, info)
|
local function fmterr(err, info)
|
||||||
if type(err) == "number" then
|
if type(err) == "number" then
|
||||||
if type(info) == "function" then
|
if type(info) == "function" then info = fmtfunc(info) end
|
||||||
local fi = funcinfo(info)
|
|
||||||
if fi.ffid then
|
|
||||||
info = vmdef.ffnames[fi.ffid]
|
|
||||||
else
|
|
||||||
info = fi.loc
|
|
||||||
end
|
|
||||||
end
|
|
||||||
err = format(vmdef.traceerr[err], info)
|
err = format(vmdef.traceerr[err], info)
|
||||||
end
|
end
|
||||||
return err
|
return err
|
||||||
@ -452,16 +453,14 @@ local function dump_trace(what, tr, func, pc, otr, oex)
|
|||||||
if dumpmode.H then out:write('<pre class="ljdump">\n') end
|
if dumpmode.H then out:write('<pre class="ljdump">\n') end
|
||||||
out:write("---- TRACE ", tr, " ", what)
|
out:write("---- TRACE ", tr, " ", what)
|
||||||
if otr then out:write(" ", otr, "/", oex) end
|
if otr then out:write(" ", otr, "/", oex) end
|
||||||
local fi = funcinfo(func, pc)
|
out:write(" ", fmtfunc(func, pc), "\n")
|
||||||
out:write(" ", fi.loc, "\n")
|
|
||||||
recprefix = ""
|
recprefix = ""
|
||||||
reclevel = 0
|
reclevel = 0
|
||||||
elseif what == "stop" or what == "abort" then
|
elseif what == "stop" or what == "abort" then
|
||||||
out:write("---- TRACE ", tr, " ", what)
|
out:write("---- TRACE ", tr, " ", what)
|
||||||
recprefix = nil
|
recprefix = nil
|
||||||
if what == "abort" then
|
if what == "abort" then
|
||||||
local fi = funcinfo(func, pc)
|
out:write(" ", fmtfunc(func, pc), " -- ", fmterr(otr, oex), "\n")
|
||||||
out:write(" ", fi.loc, " -- ", fmterr(otr, oex), "\n")
|
|
||||||
else
|
else
|
||||||
local link = traceinfo(tr).link
|
local link = traceinfo(tr).link
|
||||||
if link == tr then
|
if link == tr then
|
||||||
@ -487,12 +486,7 @@ local function dump_record(tr, func, pc, depth, callee)
|
|||||||
local line = bcline(func, pc, recprefix)
|
local line = bcline(func, pc, recprefix)
|
||||||
if dumpmode.H then line = gsub(line, "[<>&]", html_escape) end
|
if dumpmode.H then line = gsub(line, "[<>&]", html_escape) end
|
||||||
if type(callee) == "function" then
|
if type(callee) == "function" then
|
||||||
local fi = funcinfo(callee)
|
out:write(sub(line, 1, -2), " ; ", fmtfunc(callee), "\n")
|
||||||
if fi.ffid then
|
|
||||||
out:write(sub(line, 1, -2), " ; ", vmdef.ffnames[fi.ffid], "\n")
|
|
||||||
else
|
|
||||||
out:write(sub(line, 1, -2), " ; ", fi.loc, "\n")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
out:write(line)
|
out:write(line)
|
||||||
end
|
end
|
||||||
|
26
lib/v.lua
26
lib/v.lua
@ -73,17 +73,23 @@ local active, out
|
|||||||
|
|
||||||
local startloc, startex
|
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.
|
-- Format trace error message.
|
||||||
local function fmterr(err, info)
|
local function fmterr(err, info)
|
||||||
if type(err) == "number" then
|
if type(err) == "number" then
|
||||||
if type(info) == "function" then
|
if type(info) == "function" then info = fmtfunc(info) end
|
||||||
local fi = funcinfo(info)
|
|
||||||
if fi.ffid then
|
|
||||||
info = vmdef.ffnames[fi.ffid]
|
|
||||||
else
|
|
||||||
info = fi.loc
|
|
||||||
end
|
|
||||||
end
|
|
||||||
err = format(vmdef.traceerr[err], info)
|
err = format(vmdef.traceerr[err], info)
|
||||||
end
|
end
|
||||||
return err
|
return err
|
||||||
@ -92,11 +98,11 @@ end
|
|||||||
-- Dump trace states.
|
-- Dump trace states.
|
||||||
local function dump_trace(what, tr, func, pc, otr, oex)
|
local function dump_trace(what, tr, func, pc, otr, oex)
|
||||||
if what == "start" then
|
if what == "start" then
|
||||||
startloc = funcinfo(func, pc).loc
|
startloc = fmtfunc(func, pc)
|
||||||
startex = otr and "("..otr.."/"..oex..") " or ""
|
startex = otr and "("..otr.."/"..oex..") " or ""
|
||||||
else
|
else
|
||||||
if what == "abort" then
|
if what == "abort" then
|
||||||
local loc = funcinfo(func, pc).loc
|
local loc = fmtfunc(func, pc)
|
||||||
if loc ~= startloc then
|
if loc ~= startloc then
|
||||||
out:write(format("[TRACE --- %s%s -- %s at %s]\n",
|
out:write(format("[TRACE --- %s%s -- %s at %s]\n",
|
||||||
startex, startloc, fmterr(otr, oex), loc))
|
startex, startloc, fmterr(otr, oex), loc))
|
||||||
|
@ -197,9 +197,12 @@ LJLIB_CF(jit_util_funcinfo)
|
|||||||
} else {
|
} else {
|
||||||
GCfunc *fn = funcV(L->base);
|
GCfunc *fn = funcV(L->base);
|
||||||
GCtab *t;
|
GCtab *t;
|
||||||
lua_createtable(L, 0, 2); /* Increment hash size if fields are added. */
|
lua_createtable(L, 0, 4); /* Increment hash size if fields are added. */
|
||||||
t = tabV(L->top-1);
|
t = tabV(L->top-1);
|
||||||
setintfield(L, t, "ffid", fn->c.ffid);
|
if (!iscfunc(fn))
|
||||||
|
setintfield(L, t, "ffid", fn->c.ffid);
|
||||||
|
setnumV(lj_tab_setstr(L, t, lj_str_newlit(L, "addr")),
|
||||||
|
cast_num((intptr_t)fn->c.f));
|
||||||
setintfield(L, t, "upvalues", fn->c.nupvalues);
|
setintfield(L, t, "upvalues", fn->c.nupvalues);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -475,17 +475,18 @@ static TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud)
|
|||||||
|
|
||||||
case LJ_TRACE_RECORD:
|
case LJ_TRACE_RECORD:
|
||||||
setvmstate(J2G(J), RECORD);
|
setvmstate(J2G(J), RECORD);
|
||||||
lj_vmevent_send(L, RECORD,
|
if (J->pt)
|
||||||
setintV(L->top++, J->curtrace);
|
lj_vmevent_send(L, RECORD,
|
||||||
setfuncV(L, L->top++, J->fn);
|
setintV(L->top++, J->curtrace);
|
||||||
setintV(L->top++, proto_bcpos(J->pt, J->pc));
|
setfuncV(L, L->top++, J->fn);
|
||||||
setintV(L->top++, J->framedepth);
|
setintV(L->top++, proto_bcpos(J->pt, J->pc));
|
||||||
if (bcmode_mm(bc_op(*J->pc)) == MM_call) {
|
setintV(L->top++, J->framedepth);
|
||||||
cTValue *o = &L->base[bc_a(*J->pc)];
|
if (bcmode_mm(bc_op(*J->pc)) == MM_call) {
|
||||||
if (bc_op(*J->pc) == BC_ITERC) o -= 3;
|
cTValue *o = &L->base[bc_a(*J->pc)];
|
||||||
copyTV(L, L->top++, o);
|
if (bc_op(*J->pc) == BC_ITERC) o -= 3;
|
||||||
}
|
copyTV(L, L->top++, o);
|
||||||
);
|
}
|
||||||
|
);
|
||||||
lj_record_ins(J);
|
lj_record_ins(J);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -537,7 +538,7 @@ void lj_trace_ins(jit_State *J, const BCIns *pc)
|
|||||||
/* Note: J->L must already be set. pc is the true bytecode PC here. */
|
/* Note: J->L must already be set. pc is the true bytecode PC here. */
|
||||||
J->pc = pc;
|
J->pc = pc;
|
||||||
J->fn = curr_func(J->L);
|
J->fn = curr_func(J->L);
|
||||||
J->pt = funcproto(J->fn);
|
J->pt = isluafunc(J->fn) ? funcproto(J->fn) : NULL;
|
||||||
while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0)
|
while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0)
|
||||||
J->state = LJ_TRACE_ERR;
|
J->state = LJ_TRACE_ERR;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user