summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-31 10:29:12 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-31 10:29:12 -0300
commit21dc77b2afa6f7185b6f96b80f54569b68c4dca3 (patch)
tree40993ba1b294c63ee69adfdfdea80e5102fabc76
parent2d3ebba537ce6257608b7cf3b5f65fff144b21e8 (diff)
downloadlua-21dc77b2afa6f7185b6f96b80f54569b68c4dca3.tar.gz
lua-21dc77b2afa6f7185b6f96b80f54569b68c4dca3.tar.bz2
lua-21dc77b2afa6f7185b6f96b80f54569b68c4dca3.zip
errors may happen before function start running (with pc=-1)
-rw-r--r--ldebug.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/ldebug.c b/ldebug.c
index 293138eb..93a35ff2 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.37 2000/08/28 17:57:04 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.38 2000/08/28 20:22:21 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*/
@@ -93,7 +93,10 @@ static int lua_nups (StkId f) {
93 93
94 94
95int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { 95int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) {
96 int refi = prefi ? *prefi : 0; 96 int refi;
97 if (lineinfo == NULL) return -1; /* no line info */
98 else if (pc == -1) return refline; /* function preamble */
99 refi = prefi ? *prefi : 0;
97 if (lineinfo[refi] < 0) 100 if (lineinfo[refi] < 0)
98 refline += -lineinfo[refi++]; 101 refline += -lineinfo[refi++];
99 LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info"); 102 LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info");
@@ -123,7 +126,7 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) {
123static int lua_currentpc (StkId f) { 126static int lua_currentpc (StkId f) {
124 CallInfo *ci = infovalue(f); 127 CallInfo *ci = infovalue(f);
125 LUA_ASSERT(ttype(f) == TAG_LMARK, "function has no pc"); 128 LUA_ASSERT(ttype(f) == TAG_LMARK, "function has no pc");
126 return (*ci->pc - 1) - ci->func->f.l->code; 129 return (*ci->pc - ci->func->f.l->code) - 1;
127} 130}
128 131
129 132
@@ -160,10 +163,11 @@ const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int localnum) {
160 const char *name; 163 const char *name;
161 StkId f = ar->_func; 164 StkId f = ar->_func;
162 Proto *fp = getluaproto(f); 165 Proto *fp = getluaproto(f);
166 L->top--; /* pop new value */
163 if (!fp) return NULL; /* `f' is not a Lua function? */ 167 if (!fp) return NULL; /* `f' is not a Lua function? */
164 name = luaF_getlocalname(fp, localnum, lua_currentpc(f)); 168 name = luaF_getlocalname(fp, localnum, lua_currentpc(f));
165 if (!name || name[0] == '*') return NULL; /* `*' starts private locals */ 169 if (!name || name[0] == '*') return NULL; /* `*' starts private locals */
166 *((f+1)+(localnum-1)) = *(--L->top); 170 *((f+1)+(localnum-1)) = *L->top;
167 return name; 171 return name;
168} 172}
169 173
@@ -376,6 +380,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) {
376 int pc = lua_currentpc(func); 380 int pc = lua_currentpc(func);
377 int stackpos = obj - (func+1); /* func+1 == function base */ 381 int stackpos = obj - (func+1); /* func+1 == function base */
378 Instruction i = luaG_symbexec(p, pc, stackpos); 382 Instruction i = luaG_symbexec(p, pc, stackpos);
383 LUA_ASSERT(pc != -1, "function must be active");
379 switch (GET_OPCODE(i)) { 384 switch (GET_OPCODE(i)) {
380 case OP_GETGLOBAL: { 385 case OP_GETGLOBAL: {
381 *name = p->kstr[GETARG_U(i)]->str; 386 *name = p->kstr[GETARG_U(i)]->str;
@@ -404,7 +409,10 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name) {
404 return NULL; /* not a Lua function */ 409 return NULL; /* not a Lua function */
405 else { 410 else {
406 Proto *p = infovalue(func)->func->f.l; 411 Proto *p = infovalue(func)->func->f.l;
407 Instruction i = p->code[lua_currentpc(func)]; 412 int pc = lua_currentpc(func);
413 Instruction i;
414 if (pc == -1) return NULL; /* function is not activated */
415 i = p->code[pc];
408 switch (GET_OPCODE(i)) { 416 switch (GET_OPCODE(i)) {
409 case OP_CALL: case OP_TAILCALL: 417 case OP_CALL: case OP_TAILCALL:
410 return getobjname(L, (func+1)+GETARG_A(i), name); 418 return getobjname(L, (func+1)+GETARG_A(i), name);