MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / luaG_traceexec

Function luaG_traceexec

xrepo/packages/l/lua/port/lua/src/ldebug.c:874–917  ·  view source on GitHub ↗

** Traces the execution of a Lua function. Called before the execution ** of each opcode, when debug is on. 'L->oldpc' stores the last ** instruction traced, to detect line changes. When entering a new ** function, 'npci' will be zero and will test as a new line whatever ** the value of 'oldpc'. Some exceptional conditions may return to ** a function without setting 'oldpc'. In that case, 'oldpc'

Source from the content-addressed store, hash-verified

872** 'L->top' before calling anything that can run the GC.
873*/
874int luaG_traceexec (lua_State *L, const Instruction *pc) {
875 CallInfo *ci = L->ci;
876 lu_byte mask = L->hookmask;
877 const Proto *p = ci_func(ci)->p;
878 int counthook;
879 if (!(mask & (LUA_MASKLINE | LUA_MASKCOUNT))) { /* no hooks? */
880 ci->u.l.trap = 0; /* don't need to stop again */
881 return 0; /* turn off 'trap' */
882 }
883 pc++; /* reference is always next instruction */
884 ci->u.l.savedpc = pc; /* save 'pc' */
885 counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
886 if (counthook)
887 resethookcount(L); /* reset count */
888 else if (!(mask & LUA_MASKLINE))
889 return 1; /* no line hook and count != 0; nothing to be done now */
890 if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
891 ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
892 return 1; /* do not call hook again (VM yielded, so it did not move) */
893 }
894 if (!isIT(*(ci->u.l.savedpc - 1))) /* top not being used? */
895 L->top = ci->top; /* correct top */
896 if (counthook)
897 luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */
898 if (mask & LUA_MASKLINE) {
899 /* 'L->oldpc' may be invalid; use zero in this case */
900 int oldpc = (L->oldpc < p->sizecode) ? L->oldpc : 0;
901 int npci = pcRel(pc, p);
902 if (npci <= oldpc || /* call hook when jump back (loop), */
903 changedline(p, oldpc, npci)) { /* or when enter new line */
904 int newline = luaG_getfuncline(p, npci);
905 luaD_hook(L, LUA_HOOKLINE, newline, 0, 0); /* call line hook */
906 }
907 L->oldpc = npci; /* 'pc' of last call to line hook */
908 }
909 if (L->status == LUA_YIELD) { /* did hook yield? */
910 if (counthook)
911 L->hookcount = 1; /* undo decrement to zero */
912 ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
913 ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
914 luaD_throw(L, LUA_YIELD);
915 }
916 return 1; /* keep 'trap' on */
917}
918

Callers 1

lvm.cFile · 0.85

Calls 4

luaD_hookFunction · 0.85
changedlineFunction · 0.85
luaG_getfunclineFunction · 0.85
luaD_throwFunction · 0.70

Tested by

no test coverage detected