commit 6c7334a9ac4b424a4fd52bfeb4d674bc7cfa4eb3
parent 8e1e61860643baeb443efcdbf51bc25b0c006a88
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 10 Apr 2002 09:10:45 -0300
line trace uses `savedpc' to save last `pc' seen
Diffstat:
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/ldebug.c b/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 1.106 2002/04/04 17:21:31 roberto Exp roberto $
+** $Id: ldebug.c,v 1.107 2002/04/09 19:47:44 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -37,9 +37,9 @@ static int isLmark (CallInfo *ci) {
static int currentpc (lua_State *L, CallInfo *ci) {
if (ci->pc == NULL) return -1; /* function is not an active Lua function */
if (ci == L->ci || ci->pc != (ci+1)->pc) /* no other function using `pc'? */
- return (*ci->pc - ci_func(ci)->l.p->code) - 1;
- else /* function's pc is saved */
- return (ci->savedpc - ci_func(ci)->l.p->code) - 1;
+ ci->savedpc = *ci->pc; /* may not be saved; save it */
+ /* function's pc is saved */
+ return pcRel(ci->savedpc, ci_func(ci)->l.p);
}
@@ -69,7 +69,7 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) {
oldhook = L->linehook;
L->linehook = func;
for (ci = L->base_ci; ci <= L->ci; ci++)
- ci->lastpc = currentpc(L, ci);
+ currentpc(L, ci); /* update `savedpc' */
lua_unlock(L);
return oldhook;
}
diff --git a/ldebug.h b/ldebug.h
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.h,v 1.17 2002/03/19 12:45:25 roberto Exp roberto $
+** $Id: ldebug.h,v 1.18 2002/03/25 17:47:14 roberto Exp roberto $
** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h
*/
@@ -12,6 +12,8 @@
#include "luadebug.h"
+#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
+
void luaG_typeerror (lua_State *L, const TObject *o, const char *opname);
void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2);
diff --git a/lstate.h b/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.80 2002/03/25 17:47:14 roberto Exp roberto $
+** $Id: lstate.h,v 1.81 2002/03/26 20:46:10 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -91,7 +91,6 @@ typedef struct CallInfo {
StkId top; /* top for this function (when it's a Lua function) */
const Instruction **pc; /* points to `pc' variable in `luaV_execute' */
StkId *pb; /* points to `base' variable in `luaV_execute' */
- int lastpc; /* last pc traced */
int yield_results;
} CallInfo;
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.223 2002/03/25 17:47:14 roberto Exp roberto $
+** $Id: lvm.c,v 1.224 2002/04/09 19:47:44 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -64,15 +64,16 @@ int luaV_tostring (lua_State *L, TObject *obj) {
static void traceexec (lua_State *L) {
CallInfo *ci = L->ci;
- int *lineinfo = ci_func(ci)->l.p->lineinfo;
- int pc = cast(int, *ci->pc - ci_func(ci)->l.p->code) - 1;
- int newline = lineinfo[pc];
- if (pc == 0) /* tracing may be starting now? */
- ci->lastpc = 0; /* initialize `lastpc' */
+ Proto *p = ci_func(ci)->l.p;
+ int newline = p->lineinfo[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 (pc <= ci->lastpc || newline != lineinfo[ci->lastpc])
+ if (*ci->pc <= ci->savedpc || newline != p->lineinfo[pcRel(ci->savedpc, p)]) {
luaD_lineHook(L, newline);
- L->ci->lastpc = pc;
+ ci = L->ci; /* previous call may reallocate `ci' */
+ }
+ ci->savedpc = *ci->pc;
}