From 652e9ca6e0b74222e645262c38350731c74b2fab Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 16 Jun 2017 17:34:44 +1000 Subject: src/ldo.js: Add call debug hook --- src/ldo.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ldo.js b/src/ldo.js index ed1213e..426422a 100644 --- a/src/ldo.js +++ b/src/ldo.js @@ -9,6 +9,7 @@ const ldebug = require('./ldebug.js'); const lfunc = require('./lfunc.js'); const llimit = require('./llimit.js'); const lobject = require('./lobject.js'); +const lopcodes= require('./lopcodes.js'); const lparser = require('./lparser.js'); const lstate = require('./lstate.js'); const lstring = require('./lstring.js'); @@ -173,7 +174,8 @@ const luaD_precall = function(L, off, nresults) { ci.l_code = p.code; ci.l_savedpc = 0; ci.callstatus = lstate.CIST_LUA; - + if (L.hookmask & defs.LUA_MASKCALL) + callhook(L, ci); return false; } default: @@ -272,6 +274,18 @@ const luaD_hook = function(L, event, line) { } }; +const callhook = function(L, ci) { + let hook = defs.LUA_HOOKCALL; + ci.l_savedpc++; /* hooks assume 'pc' is already incremented */ + if ((ci.previous.callstatus & lstate.CIST_LUA) && + ci.previous.l_code[ci.previous.l_savedpc - 1].opcode == lopcodes.OpCodesI.OP_TAILCALL) { + ci.callstatus |= lstate.CIST_TAIL; + hook = defs.LUA_HOOKTAILCALL; + } + luaD_hook(L, hook, -1); + ci.l_savedpc--; /* correct 'pc' */ +}; + const adjust_varargs = function(L, p, actual) { let nfixargs = p.numparams; /* move fixed parameters to final position */ -- cgit v1.2.3-70-g09d2