diff options
Diffstat (limited to 'src/jit/dump.lua')
-rw-r--r-- | src/jit/dump.lua | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/jit/dump.lua b/src/jit/dump.lua index 6a2632c3..0cb38b58 100644 --- a/src/jit/dump.lua +++ b/src/jit/dump.lua | |||
@@ -55,7 +55,7 @@ | |||
55 | 55 | ||
56 | -- Cache some library functions and objects. | 56 | -- Cache some library functions and objects. |
57 | local jit = require("jit") | 57 | local jit = require("jit") |
58 | assert(jit.version_num == 20005, "LuaJIT core/library version mismatch") | 58 | assert(jit.version_num == 20100, "LuaJIT core/library version mismatch") |
59 | local jutil = require("jit.util") | 59 | local jutil = require("jit.util") |
60 | local vmdef = require("jit.vmdef") | 60 | local vmdef = require("jit.vmdef") |
61 | local funcinfo, funcbc = jutil.funcinfo, jutil.funcbc | 61 | local funcinfo, funcbc = jutil.funcinfo, jutil.funcbc |
@@ -63,7 +63,7 @@ local traceinfo, traceir, tracek = jutil.traceinfo, jutil.traceir, jutil.tracek | |||
63 | local tracemc, tracesnap = jutil.tracemc, jutil.tracesnap | 63 | local tracemc, tracesnap = jutil.tracemc, jutil.tracesnap |
64 | local traceexitstub, ircalladdr = jutil.traceexitstub, jutil.ircalladdr | 64 | local traceexitstub, ircalladdr = jutil.traceexitstub, jutil.ircalladdr |
65 | local bit = require("bit") | 65 | local bit = require("bit") |
66 | local band, shr = bit.band, bit.rshift | 66 | local band, shr, tohex = bit.band, bit.rshift, bit.tohex |
67 | local sub, gsub, format = string.sub, string.gsub, string.format | 67 | local sub, gsub, format = string.sub, string.gsub, string.format |
68 | local byte, rep = string.byte, string.rep | 68 | local byte, rep = string.byte, string.rep |
69 | local type, tostring = type, tostring | 69 | local type, tostring = type, tostring |
@@ -85,12 +85,13 @@ local nexitsym = 0 | |||
85 | local function fillsymtab_tr(tr, nexit) | 85 | local function fillsymtab_tr(tr, nexit) |
86 | local t = {} | 86 | local t = {} |
87 | symtabmt.__index = t | 87 | symtabmt.__index = t |
88 | if jit.arch == "mips" or jit.arch == "mipsel" then | 88 | if jit.arch:sub(1, 4) == "mips" then |
89 | t[traceexitstub(tr, 0)] = "exit" | 89 | t[traceexitstub(tr, 0)] = "exit" |
90 | return | 90 | return |
91 | end | 91 | end |
92 | for i=0,nexit-1 do | 92 | for i=0,nexit-1 do |
93 | local addr = traceexitstub(tr, i) | 93 | local addr = traceexitstub(tr, i) |
94 | if addr < 0 then addr = addr + 2^32 end | ||
94 | t[addr] = tostring(i) | 95 | t[addr] = tostring(i) |
95 | end | 96 | end |
96 | local addr = traceexitstub(tr, nexit) | 97 | local addr = traceexitstub(tr, nexit) |
@@ -104,7 +105,10 @@ local function fillsymtab(tr, nexit) | |||
104 | local ircall = vmdef.ircall | 105 | local ircall = vmdef.ircall |
105 | for i=0,#ircall do | 106 | for i=0,#ircall do |
106 | local addr = ircalladdr(i) | 107 | local addr = ircalladdr(i) |
107 | if addr ~= 0 then t[addr] = ircall[i] end | 108 | if addr ~= 0 then |
109 | if addr < 0 then addr = addr + 2^32 end | ||
110 | t[addr] = ircall[i] | ||
111 | end | ||
108 | end | 112 | end |
109 | end | 113 | end |
110 | if nexitsym == 1000000 then -- Per-trace exit stubs. | 114 | if nexitsym == 1000000 then -- Per-trace exit stubs. |
@@ -118,6 +122,7 @@ local function fillsymtab(tr, nexit) | |||
118 | nexit = 1000000 | 122 | nexit = 1000000 |
119 | break | 123 | break |
120 | end | 124 | end |
125 | if addr < 0 then addr = addr + 2^32 end | ||
121 | t[addr] = tostring(i) | 126 | t[addr] = tostring(i) |
122 | end | 127 | end |
123 | nexitsym = nexit | 128 | nexitsym = nexit |
@@ -136,6 +141,7 @@ local function dump_mcode(tr) | |||
136 | local mcode, addr, loop = tracemc(tr) | 141 | local mcode, addr, loop = tracemc(tr) |
137 | if not mcode then return end | 142 | if not mcode then return end |
138 | if not disass then disass = require("jit.dis_"..jit.arch) end | 143 | if not disass then disass = require("jit.dis_"..jit.arch) end |
144 | if addr < 0 then addr = addr + 2^32 end | ||
139 | out:write("---- TRACE ", tr, " mcode ", #mcode, "\n") | 145 | out:write("---- TRACE ", tr, " mcode ", #mcode, "\n") |
140 | local ctx = disass.create(mcode, addr, dumpwrite) | 146 | local ctx = disass.create(mcode, addr, dumpwrite) |
141 | ctx.hexdump = 0 | 147 | ctx.hexdump = 0 |
@@ -270,8 +276,7 @@ local litname = { | |||
270 | ["CONV "] = setmetatable({}, { __index = function(t, mode) | 276 | ["CONV "] = setmetatable({}, { __index = function(t, mode) |
271 | local s = irtype[band(mode, 31)] | 277 | local s = irtype[band(mode, 31)] |
272 | s = irtype[band(shr(mode, 5), 31)].."."..s | 278 | s = irtype[band(shr(mode, 5), 31)].."."..s |
273 | if band(mode, 0x400) ~= 0 then s = s.." trunc" | 279 | if band(mode, 0x800) ~= 0 then s = s.." sext" end |
274 | elseif band(mode, 0x800) ~= 0 then s = s.." sext" end | ||
275 | local c = shr(mode, 14) | 280 | local c = shr(mode, 14) |
276 | if c == 2 then s = s.." index" elseif c == 3 then s = s.." check" end | 281 | if c == 2 then s = s.." index" elseif c == 3 then s = s.." check" end |
277 | t[mode] = s | 282 | t[mode] = s |
@@ -280,6 +285,8 @@ local litname = { | |||
280 | ["FLOAD "] = vmdef.irfield, | 285 | ["FLOAD "] = vmdef.irfield, |
281 | ["FREF "] = vmdef.irfield, | 286 | ["FREF "] = vmdef.irfield, |
282 | ["FPMATH"] = vmdef.irfpm, | 287 | ["FPMATH"] = vmdef.irfpm, |
288 | ["BUFHDR"] = { [0] = "RESET", "APPEND" }, | ||
289 | ["TOSTR "] = { [0] = "INT", "NUM", "CHAR" }, | ||
283 | } | 290 | } |
284 | 291 | ||
285 | local function ctlsub(c) | 292 | local function ctlsub(c) |
@@ -303,15 +310,17 @@ local function fmtfunc(func, pc) | |||
303 | end | 310 | end |
304 | end | 311 | end |
305 | 312 | ||
306 | local function formatk(tr, idx) | 313 | local function formatk(tr, idx, sn) |
307 | local k, t, slot = tracek(tr, idx) | 314 | local k, t, slot = tracek(tr, idx) |
308 | local tn = type(k) | 315 | local tn = type(k) |
309 | local s | 316 | local s |
310 | if tn == "number" then | 317 | if tn == "number" then |
311 | if k == 2^52+2^51 then | 318 | if band(sn or 0, 0x30000) ~= 0 then |
319 | s = band(sn, 0x20000) ~= 0 and "contpc" or "ftsz" | ||
320 | elseif k == 2^52+2^51 then | ||
312 | s = "bias" | 321 | s = "bias" |
313 | else | 322 | else |
314 | s = format("%+.14g", k) | 323 | s = format(0 < k and k < 0x1p-1026 and "%+a" or "%+.14g", k) |
315 | end | 324 | end |
316 | elseif tn == "string" then | 325 | elseif tn == "string" then |
317 | s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub)) | 326 | s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub)) |
@@ -329,6 +338,8 @@ local function formatk(tr, idx) | |||
329 | elseif t == 21 then -- int64_t | 338 | elseif t == 21 then -- int64_t |
330 | s = sub(tostring(k), 1, -3) | 339 | s = sub(tostring(k), 1, -3) |
331 | if sub(s, 1, 1) ~= "-" then s = "+"..s end | 340 | if sub(s, 1, 1) ~= "-" then s = "+"..s end |
341 | elseif sn == 0x1057fff then -- SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL) | ||
342 | return "----" -- Special case for LJ_FR2 slot 1. | ||
332 | else | 343 | else |
333 | s = tostring(k) -- For primitives. | 344 | s = tostring(k) -- For primitives. |
334 | end | 345 | end |
@@ -347,7 +358,7 @@ local function printsnap(tr, snap) | |||
347 | n = n + 1 | 358 | n = n + 1 |
348 | local ref = band(sn, 0xffff) - 0x8000 -- REF_BIAS | 359 | local ref = band(sn, 0xffff) - 0x8000 -- REF_BIAS |
349 | if ref < 0 then | 360 | if ref < 0 then |
350 | out:write(formatk(tr, ref)) | 361 | out:write(formatk(tr, ref, sn)) |
351 | elseif band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM | 362 | elseif band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM |
352 | out:write(colorize(format("%04d/%04d", ref, ref+1), 14)) | 363 | out:write(colorize(format("%04d/%04d", ref, ref+1), 14)) |
353 | else | 364 | else |
@@ -545,7 +556,7 @@ local function dump_trace(what, tr, func, pc, otr, oex) | |||
545 | if what == "start" then | 556 | if what == "start" then |
546 | if dumpmode.H then out:write('<pre class="ljdump">\n') end | 557 | if dumpmode.H then out:write('<pre class="ljdump">\n') end |
547 | out:write("---- TRACE ", tr, " ", what) | 558 | out:write("---- TRACE ", tr, " ", what) |
548 | if otr then out:write(" ", otr, "/", oex) end | 559 | if otr then out:write(" ", otr, "/", oex == -1 and "stitch" or oex) end |
549 | out:write(" ", fmtfunc(func, pc), "\n") | 560 | out:write(" ", fmtfunc(func, pc), "\n") |
550 | elseif what == "stop" or what == "abort" then | 561 | elseif what == "stop" or what == "abort" then |
551 | out:write("---- TRACE ", tr, " ", what) | 562 | out:write("---- TRACE ", tr, " ", what) |
@@ -608,7 +619,7 @@ local function dump_texit(tr, ex, ngpr, nfpr, ...) | |||
608 | end | 619 | end |
609 | else | 620 | else |
610 | for i=1,ngpr do | 621 | for i=1,ngpr do |
611 | out:write(format(" %08x", regs[i])) | 622 | out:write(" ", tohex(regs[i])) |
612 | if i % 8 == 0 then out:write("\n") end | 623 | if i % 8 == 0 then out:write("\n") end |
613 | end | 624 | end |
614 | end | 625 | end |
@@ -693,9 +704,9 @@ local function dumpon(opt, outfile) | |||
693 | end | 704 | end |
694 | 705 | ||
695 | -- Public module functions. | 706 | -- Public module functions. |
696 | module(...) | 707 | return { |
697 | 708 | on = dumpon, | |
698 | on = dumpon | 709 | off = dumpoff, |
699 | off = dumpoff | 710 | start = dumpon -- For -j command line option. |
700 | start = dumpon -- For -j command line option. | 711 | } |
701 | 712 | ||