aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/ldebug.c b/ldebug.c
index 5ca78bd1..2db0910c 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.134 2017/11/01 18:20:48 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.135 2017/11/02 11:28:56 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*/
@@ -43,7 +43,7 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
43 43
44 44
45static int currentpc (CallInfo *ci) { 45static int currentpc (CallInfo *ci) {
46 lua_assert(isLua(ci)); 46 lua_assert(isLua(ci->func));
47 return pcRel(ci->u.l.savedpc, ci_func(ci)->p); 47 return pcRel(ci->u.l.savedpc, ci_func(ci)->p);
48} 48}
49 49
@@ -120,7 +120,7 @@ LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
120 mask = 0; 120 mask = 0;
121 func = NULL; 121 func = NULL;
122 } 122 }
123 if (isLua(L->ci)) 123 if (isLua(L->func))
124 L->oldpc = L->ci->u.l.savedpc; 124 L->oldpc = L->ci->u.l.savedpc;
125 L->hook = func; 125 L->hook = func;
126 L->basehookcount = count; 126 L->basehookcount = count;
@@ -172,7 +172,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
172 StkId *pos) { 172 StkId *pos) {
173 const char *name = NULL; 173 const char *name = NULL;
174 StkId base; 174 StkId base;
175 if (isLua(ci)) { 175 if (isLua(ci->func)) {
176 base = ci->func + 1; 176 base = ci->func + 1;
177 name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci)); 177 name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
178 } 178 }
@@ -277,12 +277,12 @@ static void collectvalidlines (lua_State *L, Closure *f) {
277static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { 277static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
278 if (ci == NULL) /* no 'ci'? */ 278 if (ci == NULL) /* no 'ci'? */
279 return NULL; /* no info */ 279 return NULL; /* no info */
280 else if (ci->callstatus & CIST_FIN) { /* is this a finalizer? */ 280 else if (callstatus(ci->func) & CIST_FIN) { /* is this a finalizer? */
281 *name = "__gc"; 281 *name = "__gc";
282 return "metamethod"; /* report it as such */ 282 return "metamethod"; /* report it as such */
283 } 283 }
284 /* calling function is a known Lua function? */ 284 /* calling function is a known Lua function? */
285 else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous)) 285 else if (!(callstatus(ci->func) & CIST_TAIL) && isLua(ci->previous->func))
286 return funcnamefromcode(L, ci->previous, name); 286 return funcnamefromcode(L, ci->previous, name);
287 else return NULL; /* no way to find a name */ 287 else return NULL; /* no way to find a name */
288} 288}
@@ -298,7 +298,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
298 break; 298 break;
299 } 299 }
300 case 'l': { 300 case 'l': {
301 ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1; 301 ar->currentline = (ci && isLua(ci->func)) ? currentline(ci) : -1;
302 break; 302 break;
303 } 303 }
304 case 'u': { 304 case 'u': {
@@ -314,7 +314,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
314 break; 314 break;
315 } 315 }
316 case 't': { 316 case 't': {
317 ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0; 317 ar->istailcall = (ci) ? callstatus(ci->func) & CIST_TAIL : 0;
318 break; 318 break;
319 } 319 }
320 case 'n': { 320 case 'n': {
@@ -549,7 +549,7 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
549 Proto *p = ci_func(ci)->p; /* calling function */ 549 Proto *p = ci_func(ci)->p; /* calling function */
550 int pc = currentpc(ci); /* calling instruction index */ 550 int pc = currentpc(ci); /* calling instruction index */
551 Instruction i = p->code[pc]; /* calling instruction */ 551 Instruction i = p->code[pc]; /* calling instruction */
552 if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */ 552 if (callstatus(ci->func) & CIST_HOOKED) { /* was it called inside a hook? */
553 *name = "?"; 553 *name = "?";
554 return "hook"; 554 return "hook";
555 } 555 }
@@ -635,7 +635,7 @@ static const char *varinfo (lua_State *L, const TValue *o) {
635 const char *name = NULL; /* to avoid warnings */ 635 const char *name = NULL; /* to avoid warnings */
636 CallInfo *ci = L->ci; 636 CallInfo *ci = L->ci;
637 const char *kind = NULL; 637 const char *kind = NULL;
638 if (isLua(ci)) { 638 if (isLua(L->func)) {
639 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ 639 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
640 if (!kind && isinstack(L, o)) /* no? try a register */ 640 if (!kind && isinstack(L, o)) /* no? try a register */
641 kind = getobjname(ci_func(ci)->p, currentpc(ci), 641 kind = getobjname(ci_func(ci)->p, currentpc(ci),
@@ -719,7 +719,7 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
719 va_start(argp, fmt); 719 va_start(argp, fmt);
720 msg = luaO_pushvfstring(L, fmt, argp); /* format message */ 720 msg = luaO_pushvfstring(L, fmt, argp); /* format message */
721 va_end(argp); 721 va_end(argp);
722 if (isLua(ci)) /* if Lua function, add source:line information */ 722 if (isLua(L->func)) /* if Lua function, add source:line information */
723 luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci)); 723 luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci));
724 luaG_errormsg(L); 724 luaG_errormsg(L);
725} 725}
@@ -740,14 +740,15 @@ static int changedline (Proto *p, int oldpc, int newpc) {
740 740
741void luaG_traceexec (lua_State *L) { 741void luaG_traceexec (lua_State *L) {
742 CallInfo *ci = L->ci; 742 CallInfo *ci = L->ci;
743 StkId func = L->func;
743 lu_byte mask = L->hookmask; 744 lu_byte mask = L->hookmask;
744 int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT)); 745 int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
745 if (counthook) 746 if (counthook)
746 resethookcount(L); /* reset count */ 747 resethookcount(L); /* reset count */
747 else if (!(mask & LUA_MASKLINE)) 748 else if (!(mask & LUA_MASKLINE))
748 return; /* no line hook and count != 0; nothing to be done */ 749 return; /* no line hook and count != 0; nothing to be done */
749 if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */ 750 if (callstatus(func) & CIST_HOOKYIELD) { /* called hook last time? */
750 ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */ 751 callstatus(func) &= ~CIST_HOOKYIELD; /* erase mark */
751 return; /* do not call hook again (VM yielded, so it did not move) */ 752 return; /* do not call hook again (VM yielded, so it did not move) */
752 } 753 }
753 if (counthook) 754 if (counthook)
@@ -767,7 +768,7 @@ void luaG_traceexec (lua_State *L) {
767 if (counthook) 768 if (counthook)
768 L->hookcount = 1; /* undo decrement to zero */ 769 L->hookcount = 1; /* undo decrement to zero */
769 ci->u.l.savedpc--; /* undo increment (resume will increment it again) */ 770 ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
770 ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */ 771 callstatus(func) |= CIST_HOOKYIELD; /* mark that it yielded */
771 luaD_throw(L, LUA_YIELD); 772 luaD_throw(L, LUA_YIELD);
772 } 773 }
773} 774}