From 39b2d58c39fd0cd554b27ed071926bc439338964 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 8 Jul 2002 15:21:33 -0300 Subject: new interface for debug hooks --- lvm.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'lvm.c') diff --git a/lvm.c b/lvm.c index 0e643f7f..20674c61 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.243 2002/06/24 15:07:21 roberto Exp roberto $ +** $Id: lvm.c,v 1.244 2002/07/05 18:27:39 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -69,17 +69,28 @@ int luaV_tostring (lua_State *L, TObject *obj) { static void traceexec (lua_State *L) { - CallInfo *ci = L->ci; - Proto *p = ci_func(ci)->l.p; - int newline = getline(p, pcRel(*ci->pc, p)); - if (pcRel(*ci->pc, p) == 0) /* tracing may be starting now? */ - ci->savedpc = *ci->pc; /* initialize `savedpc' */ - /* calls linehook when enters a new line or jumps back (loop) */ - if (*ci->pc <= ci->savedpc || newline != getline(p, pcRel(ci->savedpc, p))) { - luaD_lineHook(L, newline); - ci = L->ci; /* previous call may reallocate `ci' */ + int mask = L->hookmask; + if (mask >= LUA_MASKCOUNT) { /* instruction hook set? */ + if (L->hookcount == 0) { + luaD_callhook(L, LUA_HOOKCOUNT, -1); + resethookcount(L); + return; + } + } + if (mask & LUA_MASKLINE) { + CallInfo *ci = L->ci; + Proto *p = ci_func(ci)->l.p; + int newline = getline(p, pcRel(*ci->pc, p)); + if (pcRel(*ci->pc, p) == 0) /* tracing may be starting now? */ + ci->savedpc = *ci->pc; /* initialize `savedpc' */ + /* calls linehook when enters a new line or jumps back (loop) */ + if (*ci->pc <= ci->savedpc || + newline != getline(p, pcRel(ci->savedpc, p))) { + luaD_callhook(L, LUA_HOOKLINE, newline); + ci = L->ci; /* previous call may reallocate `ci' */ + } + ci->savedpc = *ci->pc; } - ci->savedpc = *ci->pc; } @@ -370,8 +381,9 @@ StkId luaV_execute (lua_State *L) { for (;;) { const Instruction i = *pc++; StkId ra; - if (L->linehook) - traceexec(L); + if (L->hookmask >= LUA_MASKLINE && + (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) + traceexec(L); ra = RA(i); lua_assert(L->top <= L->stack + L->stacksize && L->top >= L->ci->base); lua_assert(L->top == L->ci->top || -- cgit v1.2.3-55-g6feb