aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-04-10 09:11:07 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-04-10 09:11:07 -0300
commit6c7334a9ac4b424a4fd52bfeb4d674bc7cfa4eb3 (patch)
treef6e3f9fb0bdbf3169426798b12391f8355d52432
parent8e1e61860643baeb443efcdbf51bc25b0c006a88 (diff)
downloadlua-6c7334a9ac4b424a4fd52bfeb4d674bc7cfa4eb3.tar.gz
lua-6c7334a9ac4b424a4fd52bfeb4d674bc7cfa4eb3.tar.bz2
lua-6c7334a9ac4b424a4fd52bfeb4d674bc7cfa4eb3.zip
line trace uses `savedpc' to save last `pc' seen
-rw-r--r--ldebug.c10
-rw-r--r--ldebug.h4
-rw-r--r--lstate.h3
-rw-r--r--lvm.c17
4 files changed, 18 insertions, 16 deletions
diff --git a/ldebug.c b/ldebug.c
index eb282db7..b34e6fff 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.106 2002/04/04 17:21:31 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.107 2002/04/09 19:47:44 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -37,9 +37,9 @@ static int isLmark (CallInfo *ci) {
37static int currentpc (lua_State *L, CallInfo *ci) { 37static int currentpc (lua_State *L, CallInfo *ci) {
38 if (ci->pc == NULL) return -1; /* function is not an active Lua function */ 38 if (ci->pc == NULL) return -1; /* function is not an active Lua function */
39 if (ci == L->ci || ci->pc != (ci+1)->pc) /* no other function using `pc'? */ 39 if (ci == L->ci || ci->pc != (ci+1)->pc) /* no other function using `pc'? */
40 return (*ci->pc - ci_func(ci)->l.p->code) - 1; 40 ci->savedpc = *ci->pc; /* may not be saved; save it */
41 else /* function's pc is saved */ 41 /* function's pc is saved */
42 return (ci->savedpc - ci_func(ci)->l.p->code) - 1; 42 return pcRel(ci->savedpc, ci_func(ci)->l.p);
43} 43}
44 44
45 45
@@ -69,7 +69,7 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) {
69 oldhook = L->linehook; 69 oldhook = L->linehook;
70 L->linehook = func; 70 L->linehook = func;
71 for (ci = L->base_ci; ci <= L->ci; ci++) 71 for (ci = L->base_ci; ci <= L->ci; ci++)
72 ci->lastpc = currentpc(L, ci); 72 currentpc(L, ci); /* update `savedpc' */
73 lua_unlock(L); 73 lua_unlock(L);
74 return oldhook; 74 return oldhook;
75} 75}
diff --git a/ldebug.h b/ldebug.h
index 36b866df..4590aeba 100644
--- a/ldebug.h
+++ b/ldebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.h,v 1.17 2002/03/19 12:45:25 roberto Exp roberto $ 2** $Id: ldebug.h,v 1.18 2002/03/25 17:47:14 roberto Exp roberto $
3** Auxiliary functions from Debug Interface module 3** Auxiliary functions from Debug Interface module
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,6 +12,8 @@
12#include "luadebug.h" 12#include "luadebug.h"
13 13
14 14
15#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
16
15void luaG_typeerror (lua_State *L, const TObject *o, const char *opname); 17void luaG_typeerror (lua_State *L, const TObject *o, const char *opname);
16void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 18void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
17void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2); 19void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2);
diff --git a/lstate.h b/lstate.h
index a7ec7e2c..3bb3fa5d 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.80 2002/03/25 17:47:14 roberto Exp roberto $ 2** $Id: lstate.h,v 1.81 2002/03/26 20:46:10 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -91,7 +91,6 @@ typedef struct CallInfo {
91 StkId top; /* top for this function (when it's a Lua function) */ 91 StkId top; /* top for this function (when it's a Lua function) */
92 const Instruction **pc; /* points to `pc' variable in `luaV_execute' */ 92 const Instruction **pc; /* points to `pc' variable in `luaV_execute' */
93 StkId *pb; /* points to `base' variable in `luaV_execute' */ 93 StkId *pb; /* points to `base' variable in `luaV_execute' */
94 int lastpc; /* last pc traced */
95 int yield_results; 94 int yield_results;
96} CallInfo; 95} CallInfo;
97 96
diff --git a/lvm.c b/lvm.c
index bb1b9852..9079b32b 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.223 2002/03/25 17:47:14 roberto Exp roberto $ 2** $Id: lvm.c,v 1.224 2002/04/09 19:47:44 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -64,15 +64,16 @@ int luaV_tostring (lua_State *L, TObject *obj) {
64 64
65static void traceexec (lua_State *L) { 65static void traceexec (lua_State *L) {
66 CallInfo *ci = L->ci; 66 CallInfo *ci = L->ci;
67 int *lineinfo = ci_func(ci)->l.p->lineinfo; 67 Proto *p = ci_func(ci)->l.p;
68 int pc = cast(int, *ci->pc - ci_func(ci)->l.p->code) - 1; 68 int newline = p->lineinfo[pcRel(*ci->pc, p)];
69 int newline = lineinfo[pc]; 69 if (pcRel(*ci->pc, p) == 0) /* tracing may be starting now? */
70 if (pc == 0) /* tracing may be starting now? */ 70 ci->savedpc = *ci->pc; /* initialize `savedpc' */
71 ci->lastpc = 0; /* initialize `lastpc' */
72 /* calls linehook when enters a new line or jumps back (loop) */ 71 /* calls linehook when enters a new line or jumps back (loop) */
73 if (pc <= ci->lastpc || newline != lineinfo[ci->lastpc]) 72 if (*ci->pc <= ci->savedpc || newline != p->lineinfo[pcRel(ci->savedpc, p)]) {
74 luaD_lineHook(L, newline); 73 luaD_lineHook(L, newline);
75 L->ci->lastpc = pc; 74 ci = L->ci; /* previous call may reallocate `ci' */
75 }
76 ci->savedpc = *ci->pc;
76} 77}
77 78
78 79