diff options
| author | Mike Pall <mike> | 2010-02-15 17:36:29 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2010-02-15 17:36:29 +0100 |
| commit | 3452bfcf8cb2dc67819485c7b011e5c6a59310f8 (patch) | |
| tree | ef9296179854170d517ed02bdfc51f2003ceedf0 | |
| parent | b838cd8dca67c8ea251faf71408a9d4c45fd0daf (diff) | |
| download | luajit-3452bfcf8cb2dc67819485c7b011e5c6a59310f8.tar.gz luajit-3452bfcf8cb2dc67819485c7b011e5c6a59310f8.tar.bz2 luajit-3452bfcf8cb2dc67819485c7b011e5c6a59310f8.zip | |
Add generic function handling for debug modules.
Don't call record vmevent for non-Lua functions.
| -rw-r--r-- | lib/dump.lua | 42 | ||||
| -rw-r--r-- | lib/v.lua | 26 | ||||
| -rw-r--r-- | src/lib_jit.c | 7 | ||||
| -rw-r--r-- | src/lj_trace.c | 25 |
4 files changed, 52 insertions, 48 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 |
| 228 | end | 228 | end |
| 229 | 229 | ||
| 230 | local 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 | ||
| 241 | end | ||
| 242 | |||
| 230 | local function formatk(tr, idx) | 243 | local 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. |
| 429 | local function fmterr(err, info) | 437 | local 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 |
| @@ -73,17 +73,23 @@ local active, out | |||
| 73 | 73 | ||
| 74 | local startloc, startex | 74 | local startloc, startex |
| 75 | 75 | ||
| 76 | local function fmtfunc(func, pc) | ||
| 77 | local fi = funcinfo(func, pc) | ||
| 78 | if fi.loc then | ||
| 79 | return fi.loc | ||
| 80 | elseif fi.ffid then | ||
| 81 | return vmdef.ffnames[fi.ffid] | ||
| 82 | elseif fi.addr then | ||
| 83 | return format("C:%x", fi.addr) | ||
| 84 | else | ||
| 85 | return "(?)" | ||
| 86 | end | ||
| 87 | end | ||
| 88 | |||
| 76 | -- Format trace error message. | 89 | -- Format trace error message. |
| 77 | local function fmterr(err, info) | 90 | local function fmterr(err, info) |
| 78 | if type(err) == "number" then | 91 | if type(err) == "number" then |
| 79 | if type(info) == "function" then | 92 | if type(info) == "function" then info = fmtfunc(info) end |
| 80 | local fi = funcinfo(info) | ||
| 81 | if fi.ffid then | ||
| 82 | info = vmdef.ffnames[fi.ffid] | ||
| 83 | else | ||
| 84 | info = fi.loc | ||
| 85 | end | ||
| 86 | end | ||
| 87 | err = format(vmdef.traceerr[err], info) | 93 | err = format(vmdef.traceerr[err], info) |
| 88 | end | 94 | end |
| 89 | return err | 95 | return err |
| @@ -92,11 +98,11 @@ end | |||
| 92 | -- Dump trace states. | 98 | -- Dump trace states. |
| 93 | local function dump_trace(what, tr, func, pc, otr, oex) | 99 | local function dump_trace(what, tr, func, pc, otr, oex) |
| 94 | if what == "start" then | 100 | if what == "start" then |
| 95 | startloc = funcinfo(func, pc).loc | 101 | startloc = fmtfunc(func, pc) |
| 96 | startex = otr and "("..otr.."/"..oex..") " or "" | 102 | startex = otr and "("..otr.."/"..oex..") " or "" |
| 97 | else | 103 | else |
| 98 | if what == "abort" then | 104 | if what == "abort" then |
| 99 | local loc = funcinfo(func, pc).loc | 105 | local loc = fmtfunc(func, pc) |
| 100 | if loc ~= startloc then | 106 | if loc ~= startloc then |
| 101 | out:write(format("[TRACE --- %s%s -- %s at %s]\n", | 107 | out:write(format("[TRACE --- %s%s -- %s at %s]\n", |
| 102 | startex, startloc, fmterr(otr, oex), loc)) | 108 | startex, startloc, fmterr(otr, oex), loc)) |
diff --git a/src/lib_jit.c b/src/lib_jit.c index a5829dc3..0ee5ad0d 100644 --- a/src/lib_jit.c +++ b/src/lib_jit.c | |||
| @@ -197,9 +197,12 @@ LJLIB_CF(jit_util_funcinfo) | |||
| 197 | } else { | 197 | } else { |
| 198 | GCfunc *fn = funcV(L->base); | 198 | GCfunc *fn = funcV(L->base); |
| 199 | GCtab *t; | 199 | GCtab *t; |
| 200 | lua_createtable(L, 0, 2); /* Increment hash size if fields are added. */ | 200 | lua_createtable(L, 0, 4); /* Increment hash size if fields are added. */ |
| 201 | t = tabV(L->top-1); | 201 | t = tabV(L->top-1); |
| 202 | setintfield(L, t, "ffid", fn->c.ffid); | 202 | if (!iscfunc(fn)) |
| 203 | setintfield(L, t, "ffid", fn->c.ffid); | ||
| 204 | setnumV(lj_tab_setstr(L, t, lj_str_newlit(L, "addr")), | ||
| 205 | cast_num((intptr_t)fn->c.f)); | ||
| 203 | setintfield(L, t, "upvalues", fn->c.nupvalues); | 206 | setintfield(L, t, "upvalues", fn->c.nupvalues); |
| 204 | } | 207 | } |
| 205 | return 1; | 208 | return 1; |
diff --git a/src/lj_trace.c b/src/lj_trace.c index b5946346..7b366d54 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c | |||
| @@ -475,17 +475,18 @@ static TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud) | |||
| 475 | 475 | ||
| 476 | case LJ_TRACE_RECORD: | 476 | case LJ_TRACE_RECORD: |
| 477 | setvmstate(J2G(J), RECORD); | 477 | setvmstate(J2G(J), RECORD); |
| 478 | lj_vmevent_send(L, RECORD, | 478 | if (J->pt) |
| 479 | setintV(L->top++, J->curtrace); | 479 | lj_vmevent_send(L, RECORD, |
| 480 | setfuncV(L, L->top++, J->fn); | 480 | setintV(L->top++, J->curtrace); |
| 481 | setintV(L->top++, proto_bcpos(J->pt, J->pc)); | 481 | setfuncV(L, L->top++, J->fn); |
| 482 | setintV(L->top++, J->framedepth); | 482 | setintV(L->top++, proto_bcpos(J->pt, J->pc)); |
| 483 | if (bcmode_mm(bc_op(*J->pc)) == MM_call) { | 483 | setintV(L->top++, J->framedepth); |
| 484 | cTValue *o = &L->base[bc_a(*J->pc)]; | 484 | if (bcmode_mm(bc_op(*J->pc)) == MM_call) { |
| 485 | if (bc_op(*J->pc) == BC_ITERC) o -= 3; | 485 | cTValue *o = &L->base[bc_a(*J->pc)]; |
| 486 | copyTV(L, L->top++, o); | 486 | if (bc_op(*J->pc) == BC_ITERC) o -= 3; |
| 487 | } | 487 | copyTV(L, L->top++, o); |
| 488 | ); | 488 | } |
| 489 | ); | ||
| 489 | lj_record_ins(J); | 490 | lj_record_ins(J); |
| 490 | break; | 491 | break; |
| 491 | 492 | ||
| @@ -537,7 +538,7 @@ void lj_trace_ins(jit_State *J, const BCIns *pc) | |||
| 537 | /* Note: J->L must already be set. pc is the true bytecode PC here. */ | 538 | /* Note: J->L must already be set. pc is the true bytecode PC here. */ |
| 538 | J->pc = pc; | 539 | J->pc = pc; |
| 539 | J->fn = curr_func(J->L); | 540 | J->fn = curr_func(J->L); |
| 540 | J->pt = funcproto(J->fn); | 541 | J->pt = isluafunc(J->fn) ? funcproto(J->fn) : NULL; |
| 541 | while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0) | 542 | while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0) |
| 542 | J->state = LJ_TRACE_ERR; | 543 | J->state = LJ_TRACE_ERR; |
| 543 | } | 544 | } |
