aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-30 16:28:40 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-30 16:28:40 -0200
commitbcdbdaccc37aacdb8305f5012c2963e4cb343005 (patch)
treec6e0ad8afa371840f49d92b3f1455f3e57cbccc6
parent5cafe5af02bfe2188ba0b69f5a7a8fe44c38ed24 (diff)
downloadlua-bcdbdaccc37aacdb8305f5012c2963e4cb343005.tar.gz
lua-bcdbdaccc37aacdb8305f5012c2963e4cb343005.tar.bz2
lua-bcdbdaccc37aacdb8305f5012c2963e4cb343005.zip
more debug information (still with bug for tag methods...)
-rw-r--r--ldebug.c38
-rw-r--r--ldo.c14
-rw-r--r--ldo.h4
-rw-r--r--liolib.c7
-rw-r--r--lobject.c4
-rw-r--r--lvm.c4
6 files changed, 41 insertions, 30 deletions
diff --git a/ldebug.c b/ldebug.c
index 2557d221..5d0b811e 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.2 1999/12/23 18:19:57 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.3 1999/12/29 16:31:15 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*/
@@ -45,9 +45,9 @@ int lua_setdebug (lua_State *L, int debug) {
45} 45}
46 46
47 47
48lua_Function lua_stackedfunction (lua_State *L, int level) { 48static lua_Function aux_stackedfunction (lua_State *L, int level, StkId top) {
49 int i; 49 int i;
50 for (i = (L->top-1)-L->stack; i>=0; i--) { 50 for (i = (top-1)-L->stack; i>=0; i--) {
51 if (is_T_MARK(L->stack[i].ttype)) { 51 if (is_T_MARK(L->stack[i].ttype)) {
52 if (level == 0) 52 if (level == 0)
53 return L->stack+i; 53 return L->stack+i;
@@ -58,10 +58,15 @@ lua_Function lua_stackedfunction (lua_State *L, int level) {
58} 58}
59 59
60 60
61const char *luaG_getname (lua_State *L, const char **name) { 61lua_Function lua_stackedfunction (lua_State *L, int level) {
62 lua_Function f = lua_stackedfunction(L, 0); 62 return aux_stackedfunction(L, level, L->top);
63}
64
65
66static const char *luaG_getname (lua_State *L, const char **name, StkId top) {
67 lua_Function f = aux_stackedfunction(L, 0, top);
63 if (f == LUA_NOOBJECT || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL) 68 if (f == LUA_NOOBJECT || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL)
64 return NULL; /* no name available */ 69 return ""; /* no name available */
65 else { 70 else {
66 int i = (f+2)->value.i; 71 int i = (f+2)->value.i;
67 if (ttype(f) == LUA_T_LCLMARK) 72 if (ttype(f) == LUA_T_LCLMARK)
@@ -69,14 +74,7 @@ const char *luaG_getname (lua_State *L, const char **name) {
69 LUA_ASSERT(L, ttype(f) == LUA_T_LMARK, "must be a Lua function"); 74 LUA_ASSERT(L, ttype(f) == LUA_T_LMARK, "must be a Lua function");
70 LUA_ASSERT(L, ttype(&tfvalue(f)->consts[i]) == LUA_T_STRING, ""); 75 LUA_ASSERT(L, ttype(&tfvalue(f)->consts[i]) == LUA_T_STRING, "");
71 *name = tsvalue(&tfvalue(f)->consts[i])->str; 76 *name = tsvalue(&tfvalue(f)->consts[i])->str;
72 switch (ttype(f+2)) { 77 return luaO_typename(f+2);
73 case LUA_T_NGLOBAL: return "global";
74 case LUA_T_NLOCAL: return "local";
75 case LUA_T_NDOT: return "field";
76 default:
77 LUA_INTERNALERROR(L, "invalid tag for NAME");
78 return NULL; /* unreacheable; to avoid warnings */
79 }
80 } 78 }
81} 79}
82 80
@@ -162,8 +160,14 @@ static int checkfunc (lua_State *L, TObject *o) {
162 160
163 161
164const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { 162const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) {
165 /* try to find a name for given function */
166 GlobalVar *g; 163 GlobalVar *g;
164 if (is_T_MARK(ttype(o))) { /* `o' is an active function? */
165 /* look for caller debug information */
166 const char *kind = luaG_getname(L, name, o);
167 if (*kind) return kind;
168 /* else go through */
169 }
170 /* try to find a name for given function */
167 luaA_setnormalized(L->top, o); /* to be used by `checkfunc' */ 171 luaA_setnormalized(L->top, o); /* to be used by `checkfunc' */
168 for (g=L->rootglobal; g; g=g->next) { 172 for (g=L->rootglobal; g; g=g->next) {
169 if (checkfunc(L, &g->value)) { 173 if (checkfunc(L, &g->value)) {
@@ -180,8 +184,8 @@ const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) {
180static void call_index_error (lua_State *L, TObject *o, const char *tp, 184static void call_index_error (lua_State *L, TObject *o, const char *tp,
181 const char *v) { 185 const char *v) {
182 const char *name; 186 const char *name;
183 const char *kind = luaG_getname(L, &name); 187 const char *kind = luaG_getname(L, &name, L->top);
184 if (kind) { /* is there a name? */ 188 if (*kind) { /* is there a name? */
185 luaL_verror(L, "%.10s `%.30s' is not a %.10s", kind, name, tp); 189 luaL_verror(L, "%.10s `%.30s' is not a %.10s", kind, name, tp);
186 } 190 }
187 else { 191 else {
diff --git a/ldo.c b/ldo.c
index d2bdd440..fb0a4b71 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.61 1999/12/27 17:33:22 roberto Exp roberto $ 2** $Id: ldo.c,v 1.62 1999/12/29 16:31:15 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -114,8 +114,8 @@ void luaD_lineHook (lua_State *L, int line) {
114} 114}
115 115
116 116
117static void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook, 117void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook,
118 int isreturn) { 118 int isreturn) {
119 if (L->allowhooks) { 119 if (L->allowhooks) {
120 struct C_Lua_Stack oldCLS = L->Cstack; 120 struct C_Lua_Stack oldCLS = L->Cstack;
121 StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; 121 StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top;
@@ -156,6 +156,8 @@ static StkId callC (lua_State *L, lua_CFunction f, StkId base) {
156 L->Cstack.num = numarg; 156 L->Cstack.num = numarg;
157 L->Cstack.lua2C = base; 157 L->Cstack.lua2C = base;
158 L->Cstack.base = L->top; 158 L->Cstack.base = L->top;
159 if (L->callhook)
160 luaD_callHook(L, base-1, L->callhook, 0);
159 (*f)(L); /* do the actual call */ 161 (*f)(L); /* do the actual call */
160 firstResult = L->Cstack.base; 162 firstResult = L->Cstack.base;
161 L->Cstack = oldCLS; 163 L->Cstack = oldCLS;
@@ -194,8 +196,6 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) {
194void luaD_call (lua_State *L, StkId func, int nResults) { 196void luaD_call (lua_State *L, StkId func, int nResults) {
195 StkId firstResult; 197 StkId firstResult;
196 lua_CHFunction callhook = L->callhook; 198 lua_CHFunction callhook = L->callhook;
197 if (callhook)
198 luaD_callHook(L, func, callhook, 0);
199 retry: /* for `function' tag method */ 199 retry: /* for `function' tag method */
200 switch (ttype(func)) { 200 switch (ttype(func)) {
201 case LUA_T_CPROTO: 201 case LUA_T_CPROTO:
@@ -224,10 +224,10 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
224 luaG_callerror(L, func); 224 luaG_callerror(L, func);
225 luaD_openstack(L, func); 225 luaD_openstack(L, func);
226 *func = *im; /* tag method is the new function to be called */ 226 *func = *im; /* tag method is the new function to be called */
227 goto retry; /* retry the call (without calling callhook again) */ 227 goto retry; /* retry the call */
228 } 228 }
229 } 229 }
230 if (callhook) /* same hook that was used at entry */ 230 if (callhook) /* same hook that was active at entry */
231 luaD_callHook(L, NULL, callhook, 1); /* `return' hook */ 231 luaD_callHook(L, NULL, callhook, 1); /* `return' hook */
232 /* adjust the number of results */ 232 /* adjust the number of results */
233 if (nResults == MULT_RET) 233 if (nResults == MULT_RET)
diff --git a/ldo.h b/ldo.h
index 0193b797..bd15f039 100644
--- a/ldo.h
+++ b/ldo.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.h,v 1.14 1999/12/06 11:41:28 roberto Exp roberto $ 2** $Id: ldo.h,v 1.15 1999/12/21 18:04:41 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -26,6 +26,8 @@
26void luaD_init (lua_State *L, int stacksize); 26void luaD_init (lua_State *L, int stacksize);
27void luaD_adjusttop (lua_State *L, StkId base, int extra); 27void luaD_adjusttop (lua_State *L, StkId base, int extra);
28void luaD_openstack (lua_State *L, StkId pos); 28void luaD_openstack (lua_State *L, StkId pos);
29void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook,
30 int isreturn);
29void luaD_lineHook (lua_State *L, int line); 31void luaD_lineHook (lua_State *L, int line);
30void luaD_call (lua_State *L, StkId func, int nResults); 32void luaD_call (lua_State *L, StkId func, int nResults);
31void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults); 33void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults);
diff --git a/liolib.c b/liolib.c
index df8e5c53..b58bcaff 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.53 1999/12/27 13:04:53 roberto Exp roberto $ 2** $Id: liolib.c,v 1.54 1999/12/28 11:52:49 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -546,9 +546,12 @@ static void errorfb (lua_State *L) {
546 break; /* buffer is full */ 546 break; /* buffer is full */
547 } 547 }
548 switch (*lua_getobjname(L, func, &name)) { 548 switch (*lua_getobjname(L, func, &name)) {
549 case 'g': 549 case 'g': case 'l':
550 sprintf(buff+strlen(buff), "function `%.50s'", name); 550 sprintf(buff+strlen(buff), "function `%.50s'", name);
551 break; 551 break;
552 case 'f':
553 sprintf(buff+strlen(buff), "method `%.50s'", name);
554 break;
552 case 't': 555 case 't':
553 sprintf(buff+strlen(buff), "`%.50s' tag method", name); 556 sprintf(buff+strlen(buff), "`%.50s' tag method", name);
554 break; 557 break;
diff --git a/lobject.c b/lobject.c
index e55d9694..6aa92d0a 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.27 1999/12/14 18:31:20 roberto Exp roberto $ 2** $Id: lobject.c,v 1.28 1999/12/23 18:19:57 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,7 +16,7 @@
16const char *const luaO_typenames[] = { /* ORDER LUA_T */ 16const char *const luaO_typenames[] = { /* ORDER LUA_T */
17 "userdata", "number", "string", "table", "function", "function", "nil", 17 "userdata", "number", "string", "table", "function", "function", "nil",
18 "function", "function", "function", "function", "function", "function", 18 "function", "function", "function", "function", "function", "function",
19 "line", NULL 19 "line", "global", "local", "field", NULL
20}; 20};
21 21
22 22
diff --git a/lvm.c b/lvm.c
index e2da0801..360e6869 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.76 1999/12/27 17:33:22 roberto Exp roberto $ 2** $Id: lvm.c,v 1.77 1999/12/29 16:31:15 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*/
@@ -297,6 +297,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
297 register StkId top; /* keep top local, for performance */ 297 register StkId top; /* keep top local, for performance */
298 register const Byte *pc = tf->code; 298 register const Byte *pc = tf->code;
299 const TObject *consts = tf->consts; 299 const TObject *consts = tf->consts;
300 if (L->callhook)
301 luaD_callHook(L, base-1, L->callhook, 0);
300 luaD_checkstack(L, (*pc++)+EXTRA_STACK); 302 luaD_checkstack(L, (*pc++)+EXTRA_STACK);
301 if (*pc < ZEROVARARG) 303 if (*pc < ZEROVARARG)
302 luaD_adjusttop(L, base, *(pc++)); 304 luaD_adjusttop(L, base, *(pc++));