aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/ldebug.c b/ldebug.c
index 996e8cb1..c07a37f8 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.155 2018/02/17 19:29:29 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.156 2018/03/16 15:33:34 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*/
@@ -783,17 +783,24 @@ static int changedline (Proto *p, int oldpc, int newpc) {
783} 783}
784 784
785 785
786void luaG_traceexec (lua_State *L) { 786int luaG_traceexec (lua_State *L, const Instruction *pc) {
787 CallInfo *ci = L->ci; 787 CallInfo *ci = L->ci;
788 lu_byte mask = L->hookmask; 788 lu_byte mask = L->hookmask;
789 int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT)); 789 int counthook;
790 if (!(mask & (LUA_MASKLINE | LUA_MASKCOUNT))) { /* no hooks? */
791 ci->u.l.trap = 0; /* don't need to stop again */
792 return 0; /* turn off 'trap' */
793 }
794 pc++; /* reference is always next instruction */
795 ci->u.l.savedpc = pc; /* save 'pc' */
796 counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
790 if (counthook) 797 if (counthook)
791 resethookcount(L); /* reset count */ 798 resethookcount(L); /* reset count */
792 else if (!(mask & LUA_MASKLINE)) 799 else if (!(mask & LUA_MASKLINE))
793 return; /* no line hook and count != 0; nothing to be done */ 800 return 1; /* no line hook and count != 0; nothing to be done now */
794 if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */ 801 if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
795 ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */ 802 ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
796 return; /* do not call hook again (VM yielded, so it did not move) */ 803 return 1; /* do not call hook again (VM yielded, so it did not move) */
797 } 804 }
798 if (!isIT(*(ci->u.l.savedpc - 1))) 805 if (!isIT(*(ci->u.l.savedpc - 1)))
799 L->top = ci->top; /* prepare top */ 806 L->top = ci->top; /* prepare top */
@@ -801,15 +808,14 @@ void luaG_traceexec (lua_State *L) {
801 luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */ 808 luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */
802 if (mask & LUA_MASKLINE) { 809 if (mask & LUA_MASKLINE) {
803 Proto *p = ci_func(ci)->p; 810 Proto *p = ci_func(ci)->p;
804 const Instruction *npc = ci->u.l.savedpc; 811 int npci = pcRel(pc, p);
805 int npci = pcRel(npc, p);
806 if (npci == 0 || /* call linehook when enter a new function, */ 812 if (npci == 0 || /* call linehook when enter a new function, */
807 npc <= L->oldpc || /* when jump back (loop), or when */ 813 pc <= L->oldpc || /* when jump back (loop), or when */
808 changedline(p, pcRel(L->oldpc, p), npci)) { /* enter new line */ 814 changedline(p, pcRel(L->oldpc, p), npci)) { /* enter new line */
809 int newline = luaG_getfuncline(p, npci); /* new line */ 815 int newline = luaG_getfuncline(p, npci);
810 luaD_hook(L, LUA_HOOKLINE, newline, 0, 0); /* call line hook */ 816 luaD_hook(L, LUA_HOOKLINE, newline, 0, 0); /* call line hook */
811 } 817 }
812 L->oldpc = npc; 818 L->oldpc = pc; /* 'pc' of last call to line hook */
813 } 819 }
814 if (L->status == LUA_YIELD) { /* did hook yield? */ 820 if (L->status == LUA_YIELD) { /* did hook yield? */
815 if (counthook) 821 if (counthook)
@@ -818,5 +824,6 @@ void luaG_traceexec (lua_State *L) {
818 ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */ 824 ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
819 luaD_throw(L, LUA_YIELD); 825 luaD_throw(L, LUA_YIELD);
820 } 826 }
827 return 1; /* keep 'trap' on */
821} 828}
822 829