diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.89 2012/01/20 22:05:50 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.90 2012/08/16 17:34:28 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 | */ |
@@ -578,3 +578,36 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { | |||
578 | luaG_errormsg(L); | 578 | luaG_errormsg(L); |
579 | } | 579 | } |
580 | 580 | ||
581 | |||
582 | void luaG_traceexec (lua_State *L) { | ||
583 | CallInfo *ci = L->ci; | ||
584 | lu_byte mask = L->hookmask; | ||
585 | int counthook = ((mask & LUA_MASKCOUNT) && L->hookcount == 0); | ||
586 | if (counthook) | ||
587 | resethookcount(L); /* reset count */ | ||
588 | if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */ | ||
589 | ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */ | ||
590 | return; /* do not call hook again (VM yielded, so it did not move) */ | ||
591 | } | ||
592 | if (counthook) | ||
593 | luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */ | ||
594 | if (mask & LUA_MASKLINE) { | ||
595 | Proto *p = ci_func(ci)->p; | ||
596 | int npc = pcRel(ci->u.l.savedpc, p); | ||
597 | int newline = getfuncline(p, npc); | ||
598 | if (npc == 0 || /* call linehook when enter a new function, */ | ||
599 | ci->u.l.savedpc <= L->oldpc || /* when jump back (loop), or when */ | ||
600 | newline != getfuncline(p, pcRel(L->oldpc, p))) /* enter a new line */ | ||
601 | luaD_hook(L, LUA_HOOKLINE, newline); /* call line hook */ | ||
602 | } | ||
603 | L->oldpc = ci->u.l.savedpc; | ||
604 | if (L->status == LUA_YIELD) { /* did hook yield? */ | ||
605 | if (counthook) | ||
606 | L->hookcount = 1; /* undo decrement to zero */ | ||
607 | ci->u.l.savedpc--; /* undo increment (resume will increment it again) */ | ||
608 | ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */ | ||
609 | ci->func = L->top - 1; /* protect stack below results */ | ||
610 | luaD_throw(L, LUA_YIELD); | ||
611 | } | ||
612 | } | ||
613 | |||