MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaG_traceexec

Function luaG_traceexec

third-party/lua-5.4.6/src/ldebug.c:928–970  ·  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

926** 'L->top.p' before calling anything that can run the GC.
927*/
928int luaG_traceexec (lua_State *L, const Instruction *pc) {
929 CallInfo *ci = L->ci;
930 lu_byte mask = L->hookmask;
931 const Proto *p = ci_func(ci)->p;
932 int counthook;
933 if (!(mask & (LUA_MASKLINE | LUA_MASKCOUNT))) { /* no hooks? */
934 ci->u.l.trap = 0; /* don't need to stop again */
935 return 0; /* turn off 'trap' */
936 }
937 pc++; /* reference is always next instruction */
938 ci->u.l.savedpc = pc; /* save 'pc' */
939 counthook = (mask & LUA_MASKCOUNT) && (--L->hookcount == 0);
940 if (counthook)
941 resethookcount(L); /* reset count */
942 else if (!(mask & LUA_MASKLINE))
943 return 1; /* no line hook and count != 0; nothing to be done now */
944 if (ci->callstatus & CIST_HOOKYIELD) { /* hook yielded last time? */
945 ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
946 return 1; /* do not call hook again (VM yielded, so it did not move) */
947 }
948 if (!isIT(*(ci->u.l.savedpc - 1))) /* top not being used? */
949 L->top.p = ci->top.p; /* correct top */
950 if (counthook)
951 luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */
952 if (mask & LUA_MASKLINE) {
953 /* 'L->oldpc' may be invalid; use zero in this case */
954 int oldpc = (L->oldpc < p->sizecode) ? L->oldpc : 0;
955 int npci = pcRel(pc, p);
956 if (npci <= oldpc || /* call hook when jump back (loop), */
957 changedline(p, oldpc, npci)) { /* or when enter new line */
958 int newline = luaG_getfuncline(p, npci);
959 luaD_hook(L, LUA_HOOKLINE, newline, 0, 0); /* call line hook */
960 }
961 L->oldpc = npci; /* 'pc' of last call to line hook */
962 }
963 if (L->status == LUA_YIELD) { /* did hook yield? */
964 if (counthook)
965 L->hookcount = 1; /* undo decrement to zero */
966 ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
967 luaD_throw(L, LUA_YIELD);
968 }
969 return 1; /* keep 'trap' on */
970}
971

Callers 1

lvm.cFile · 0.70

Calls 4

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

Tested by

no test coverage detected