ldebug.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. ** $Id: ldebug.c,v 2.107 2014/11/11 17:08:19 roberto Exp roberto $
  3. ** Debug Interface
  4. ** See Copyright Notice in lua.h
  5. */
  6. #define ldebug_c
  7. #define LUA_CORE
  8. #include "lprefix.h"
  9. #include <stdarg.h>
  10. #include <stddef.h>
  11. #include <string.h>
  12. #include "lua.h"
  13. #include "lapi.h"
  14. #include "lcode.h"
  15. #include "ldebug.h"
  16. #include "ldo.h"
  17. #include "lfunc.h"
  18. #include "lobject.h"
  19. #include "lopcodes.h"
  20. #include "lstate.h"
  21. #include "lstring.h"
  22. #include "ltable.h"
  23. #include "ltm.h"
  24. #include "lvm.h"
  25. #define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_TCCL)
  26. static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
  27. static int currentpc (CallInfo *ci) {
  28. lua_assert(isLua(ci));
  29. return pcRel(ci->u.l.savedpc, ci_func(ci)->p);
  30. }
  31. static int currentline (CallInfo *ci) {
  32. return getfuncline(ci_func(ci)->p, currentpc(ci));
  33. }
  34. /*
  35. ** this function can be called asynchronous (e.g. during a signal)
  36. */
  37. LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
  38. if (func == NULL || mask == 0) { /* turn off hooks? */
  39. mask = 0;
  40. func = NULL;
  41. }
  42. if (isLua(L->ci))
  43. L->oldpc = L->ci->u.l.savedpc;
  44. L->hook = func;
  45. L->basehookcount = count;
  46. resethookcount(L);
  47. L->hookmask = cast_byte(mask);
  48. }
  49. LUA_API lua_Hook lua_gethook (lua_State *L) {
  50. return L->hook;
  51. }
  52. LUA_API int lua_gethookmask (lua_State *L) {
  53. return L->hookmask;
  54. }
  55. LUA_API int lua_gethookcount (lua_State *L) {
  56. return L->basehookcount;
  57. }
  58. LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
  59. int status;
  60. CallInfo *ci;
  61. if (level < 0) return 0; /* invalid (negative) level */
  62. lua_lock(L);
  63. for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)
  64. level--;
  65. if (level == 0 && ci != &L->base_ci) { /* level found? */
  66. status = 1;
  67. ar->i_ci = ci;
  68. }
  69. else status = 0; /* no such level */
  70. lua_unlock(L);
  71. return status;
  72. }
  73. static const char *upvalname (Proto *p, int uv) {
  74. TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);
  75. if (s == NULL) return "?";
  76. else return getstr(s);
  77. }
  78. static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
  79. int nparams = clLvalue(ci->func)->p->numparams;
  80. if (n >= ci->u.l.base - ci->func - nparams)
  81. return NULL; /* no such vararg */
  82. else {
  83. *pos = ci->func + nparams + n;
  84. return "(*vararg)"; /* generic name for any vararg */
  85. }
  86. }
  87. static const char *findlocal (lua_State *L, CallInfo *ci, int n,
  88. StkId *pos) {
  89. const char *name = NULL;
  90. StkId base;
  91. if (isLua(ci)) {
  92. if (n < 0) /* access to vararg values? */
  93. return findvararg(ci, -n, pos);
  94. else {
  95. base = ci->u.l.base;
  96. name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
  97. }
  98. }
  99. else
  100. base = ci->func + 1;
  101. if (name == NULL) { /* no 'standard' name? */
  102. StkId limit = (ci == L->ci) ? L->top : ci->next->func;
  103. if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */
  104. name = "(*temporary)"; /* generic name for any valid slot */
  105. else
  106. return NULL; /* no name */
  107. }
  108. *pos = base + (n - 1);
  109. return name;
  110. }
  111. LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
  112. const char *name;
  113. lua_lock(L);
  114. if (ar == NULL) { /* information about non-active function? */
  115. if (!isLfunction(L->top - 1)) /* not a Lua function? */
  116. name = NULL;
  117. else /* consider live variables at function start (parameters) */
  118. name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
  119. }
  120. else { /* active function; get information through 'ar' */
  121. StkId pos = 0; /* to avoid warnings */
  122. name = findlocal(L, ar->i_ci, n, &pos);
  123. if (name) {
  124. setobj2s(L, L->top, pos);
  125. api_incr_top(L);
  126. }
  127. }
  128. lua_unlock(L);
  129. return name;
  130. }
  131. LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
  132. StkId pos = 0; /* to avoid warnings */
  133. const char *name = findlocal(L, ar->i_ci, n, &pos);
  134. lua_lock(L);
  135. if (name)
  136. setobjs2s(L, pos, L->top - 1);
  137. L->top--; /* pop value */
  138. lua_unlock(L);
  139. return name;
  140. }
  141. static void funcinfo (lua_Debug *ar, Closure *cl) {
  142. if (noLuaClosure(cl)) {
  143. ar->source = "=[C]";
  144. ar->linedefined = -1;
  145. ar->lastlinedefined = -1;
  146. ar->what = "C";
  147. }
  148. else {
  149. Proto *p = cl->l.p;
  150. ar->source = p->source ? getstr(p->source) : "=?";
  151. ar->linedefined = p->linedefined;
  152. ar->lastlinedefined = p->lastlinedefined;
  153. ar->what = (ar->linedefined == 0) ? "main" : "Lua";
  154. }
  155. luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
  156. }
  157. static void collectvalidlines (lua_State *L, Closure *f) {
  158. if (noLuaClosure(f)) {
  159. setnilvalue(L->top);
  160. api_incr_top(L);
  161. }
  162. else {
  163. int i;
  164. TValue v;
  165. int *lineinfo = f->l.p->lineinfo;
  166. Table *t = luaH_new(L); /* new table to store active lines */
  167. sethvalue(L, L->top, t); /* push it on stack */
  168. api_incr_top(L);
  169. setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */
  170. for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */
  171. luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */
  172. }
  173. }
  174. static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
  175. Closure *f, CallInfo *ci) {
  176. int status = 1;
  177. for (; *what; what++) {
  178. switch (*what) {
  179. case 'S': {
  180. funcinfo(ar, f);
  181. break;
  182. }
  183. case 'l': {
  184. ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;
  185. break;
  186. }
  187. case 'u': {
  188. ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
  189. if (noLuaClosure(f)) {
  190. ar->isvararg = 1;
  191. ar->nparams = 0;
  192. }
  193. else {
  194. ar->isvararg = f->l.p->is_vararg;
  195. ar->nparams = f->l.p->numparams;
  196. }
  197. break;
  198. }
  199. case 't': {
  200. ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;
  201. break;
  202. }
  203. case 'n': {
  204. /* calling function is a known Lua function? */
  205. if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
  206. ar->namewhat = getfuncname(L, ci->previous, &ar->name);
  207. else
  208. ar->namewhat = NULL;
  209. if (ar->namewhat == NULL) {
  210. ar->namewhat = ""; /* not found */
  211. ar->name = NULL;
  212. }
  213. break;
  214. }
  215. case 'L':
  216. case 'f': /* handled by lua_getinfo */
  217. break;
  218. default: status = 0; /* invalid option */
  219. }
  220. }
  221. return status;
  222. }
  223. LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
  224. int status;
  225. Closure *cl;
  226. CallInfo *ci;
  227. StkId func;
  228. lua_lock(L);
  229. if (*what == '>') {
  230. ci = NULL;
  231. func = L->top - 1;
  232. api_check(ttisfunction(func), "function expected");
  233. what++; /* skip the '>' */
  234. L->top--; /* pop function */
  235. }
  236. else {
  237. ci = ar->i_ci;
  238. func = ci->func;
  239. lua_assert(ttisfunction(ci->func));
  240. }
  241. cl = ttisclosure(func) ? clvalue(func) : NULL;
  242. status = auxgetinfo(L, what, ar, cl, ci);
  243. if (strchr(what, 'f')) {
  244. setobjs2s(L, L->top, func);
  245. api_incr_top(L);
  246. }
  247. if (strchr(what, 'L'))
  248. collectvalidlines(L, cl);
  249. lua_unlock(L);
  250. return status;
  251. }
  252. /*
  253. ** {======================================================
  254. ** Symbolic Execution
  255. ** =======================================================
  256. */
  257. static const char *getobjname (Proto *p, int lastpc, int reg,
  258. const char **name);
  259. /*
  260. ** find a "name" for the RK value 'c'
  261. */
  262. static void kname (Proto *p, int pc, int c, const char **name) {
  263. if (ISK(c)) { /* is 'c' a constant? */
  264. TValue *kvalue = &p->k[INDEXK(c)];
  265. if (ttisstring(kvalue)) { /* literal constant? */
  266. *name = svalue(kvalue); /* it is its own name */
  267. return;
  268. }
  269. /* else no reasonable name found */
  270. }
  271. else { /* 'c' is a register */
  272. const char *what = getobjname(p, pc, c, name); /* search for 'c' */
  273. if (what && *what == 'c') { /* found a constant name? */
  274. return; /* 'name' already filled */
  275. }
  276. /* else no reasonable name found */
  277. }
  278. *name = "?"; /* no reasonable name found */
  279. }
  280. static int filterpc (int pc, int jmptarget) {
  281. if (pc < jmptarget) /* is code conditional (inside a jump)? */
  282. return -1; /* cannot know who sets that register */
  283. else return pc; /* current position sets that register */
  284. }
  285. /*
  286. ** try to find last instruction before 'lastpc' that modified register 'reg'
  287. */
  288. static int findsetreg (Proto *p, int lastpc, int reg) {
  289. int pc;
  290. int setreg = -1; /* keep last instruction that changed 'reg' */
  291. int jmptarget = 0; /* any code before this address is conditional */
  292. for (pc = 0; pc < lastpc; pc++) {
  293. Instruction i = p->code[pc];
  294. OpCode op = GET_OPCODE(i);
  295. int a = GETARG_A(i);
  296. switch (op) {
  297. case OP_LOADNIL: {
  298. int b = GETARG_B(i);
  299. if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
  300. setreg = filterpc(pc, jmptarget);
  301. break;
  302. }
  303. case OP_TFORCALL: {
  304. if (reg >= a + 2) /* affect all regs above its base */
  305. setreg = filterpc(pc, jmptarget);
  306. break;
  307. }
  308. case OP_CALL:
  309. case OP_TAILCALL: {
  310. if (reg >= a) /* affect all registers above base */
  311. setreg = filterpc(pc, jmptarget);
  312. break;
  313. }
  314. case OP_JMP: {
  315. int b = GETARG_sBx(i);
  316. int dest = pc + 1 + b;
  317. /* jump is forward and do not skip 'lastpc'? */
  318. if (pc < dest && dest <= lastpc) {
  319. if (dest > jmptarget)
  320. jmptarget = dest; /* update 'jmptarget' */
  321. }
  322. break;
  323. }
  324. default:
  325. if (testAMode(op) && reg == a) /* any instruction that set A */
  326. setreg = filterpc(pc, jmptarget);
  327. break;
  328. }
  329. }
  330. return setreg;
  331. }
  332. static const char *getobjname (Proto *p, int lastpc, int reg,
  333. const char **name) {
  334. int pc;
  335. *name = luaF_getlocalname(p, reg + 1, lastpc);
  336. if (*name) /* is a local? */
  337. return "local";
  338. /* else try symbolic execution */
  339. pc = findsetreg(p, lastpc, reg);
  340. if (pc != -1) { /* could find instruction? */
  341. Instruction i = p->code[pc];
  342. OpCode op = GET_OPCODE(i);
  343. switch (op) {
  344. case OP_MOVE: {
  345. int b = GETARG_B(i); /* move from 'b' to 'a' */
  346. if (b < GETARG_A(i))
  347. return getobjname(p, pc, b, name); /* get name for 'b' */
  348. break;
  349. }
  350. case OP_GETTABUP:
  351. case OP_GETTABLE: {
  352. int k = GETARG_C(i); /* key index */
  353. int t = GETARG_B(i); /* table index */
  354. const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
  355. ? luaF_getlocalname(p, t + 1, pc)
  356. : upvalname(p, t);
  357. kname(p, pc, k, name);
  358. return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
  359. }
  360. case OP_GETUPVAL: {
  361. *name = upvalname(p, GETARG_B(i));
  362. return "upvalue";
  363. }
  364. case OP_LOADK:
  365. case OP_LOADKX: {
  366. int b = (op == OP_LOADK) ? GETARG_Bx(i)
  367. : GETARG_Ax(p->code[pc + 1]);
  368. if (ttisstring(&p->k[b])) {
  369. *name = svalue(&p->k[b]);
  370. return "constant";
  371. }
  372. break;
  373. }
  374. case OP_SELF: {
  375. int k = GETARG_C(i); /* key index */
  376. kname(p, pc, k, name);
  377. return "method";
  378. }
  379. default: break; /* go through to return NULL */
  380. }
  381. }
  382. return NULL; /* could not find reasonable name */
  383. }
  384. static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
  385. TMS tm = (TMS)0; /* to avoid warnings */
  386. Proto *p = ci_func(ci)->p; /* calling function */
  387. int pc = currentpc(ci); /* calling instruction index */
  388. Instruction i = p->code[pc]; /* calling instruction */
  389. if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
  390. *name = "?";
  391. return "hook";
  392. }
  393. switch (GET_OPCODE(i)) {
  394. case OP_CALL:
  395. case OP_TAILCALL: /* get function name */
  396. return getobjname(p, pc, GETARG_A(i), name);
  397. case OP_TFORCALL: { /* for iterator */
  398. *name = "for iterator";
  399. return "for iterator";
  400. }
  401. /* all other instructions can call only through metamethods */
  402. case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
  403. tm = TM_INDEX;
  404. break;
  405. case OP_SETTABUP: case OP_SETTABLE:
  406. tm = TM_NEWINDEX;
  407. break;
  408. case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:
  409. case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:
  410. case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {
  411. int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD); /* ORDER OP */
  412. tm = cast(TMS, offset + cast_int(TM_ADD)); /* ORDER TM */
  413. break;
  414. }
  415. case OP_UNM: tm = TM_UNM; break;
  416. case OP_BNOT: tm = TM_BNOT; break;
  417. case OP_LEN: tm = TM_LEN; break;
  418. case OP_CONCAT: tm = TM_CONCAT; break;
  419. case OP_EQ: tm = TM_EQ; break;
  420. case OP_LT: tm = TM_LT; break;
  421. case OP_LE: tm = TM_LE; break;
  422. default: lua_assert(0); /* other instructions cannot call a function */
  423. }
  424. *name = getstr(G(L)->tmname[tm]);
  425. return "metamethod";
  426. }
  427. /* }====================================================== */
  428. /*
  429. ** The subtraction of two potentially unrelated pointers is
  430. ** not ISO C, but it should not crash a program; the subsequent
  431. ** checks are ISO C and ensure a correct result.
  432. */
  433. static int isinstack (CallInfo *ci, const TValue *o) {
  434. ptrdiff_t i = o - ci->u.l.base;
  435. return (0 <= i && i < (ci->top - ci->u.l.base) && ci->u.l.base + i == o);
  436. }
  437. /*
  438. ** Checks whether value 'o' came from an upvalue. (That can only happen
  439. ** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on
  440. ** upvalues.)
  441. */
  442. static const char *getupvalname (CallInfo *ci, const TValue *o,
  443. const char **name) {
  444. LClosure *c = ci_func(ci);
  445. int i;
  446. for (i = 0; i < c->nupvalues; i++) {
  447. if (c->upvals[i]->v == o) {
  448. *name = upvalname(c->p, i);
  449. return "upvalue";
  450. }
  451. }
  452. return NULL;
  453. }
  454. static const char *varinfo (lua_State *L, const TValue *o) {
  455. const char *name = NULL; /* to avoid warnings */
  456. CallInfo *ci = L->ci;
  457. const char *kind = NULL;
  458. if (isLua(ci)) {
  459. kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
  460. if (!kind && isinstack(ci, o)) /* no? try a register */
  461. kind = getobjname(ci_func(ci)->p, currentpc(ci),
  462. cast_int(o - ci->u.l.base), &name);
  463. }
  464. return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : "";
  465. }
  466. l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
  467. const char *t = objtypename(o);
  468. luaG_runerror(L, "attempt to %s a %s value%s", op, t, varinfo(L, o));
  469. }
  470. l_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) {
  471. if (ttisstring(p1) || cvt2str(p1)) p1 = p2;
  472. luaG_typeerror(L, p1, "concatenate");
  473. }
  474. l_noret luaG_opinterror (lua_State *L, const TValue *p1,
  475. const TValue *p2, const char *msg) {
  476. lua_Number temp;
  477. if (!tonumber(p1, &temp)) /* first operand is wrong? */
  478. p2 = p1; /* now second is wrong */
  479. luaG_typeerror(L, p2, msg);
  480. }
  481. /*
  482. ** Error when both values are convertible to numbers, but not to integers
  483. */
  484. l_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) {
  485. lua_Integer temp;
  486. if (!tointeger(p1, &temp))
  487. p2 = p1;
  488. luaG_runerror(L, "number%s has no integer representation", varinfo(L, p2));
  489. }
  490. l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
  491. const char *t1 = objtypename(p1);
  492. const char *t2 = objtypename(p2);
  493. if (t1 == t2)
  494. luaG_runerror(L, "attempt to compare two %s values", t1);
  495. else
  496. luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
  497. }
  498. static void addinfo (lua_State *L, const char *msg) {
  499. CallInfo *ci = L->ci;
  500. if (isLua(ci)) { /* is Lua code? */
  501. char buff[LUA_IDSIZE]; /* add file:line information */
  502. int line = currentline(ci);
  503. TString *src = ci_func(ci)->p->source;
  504. if (src)
  505. luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
  506. else { /* no source available; use "?" instead */
  507. buff[0] = '?'; buff[1] = '\0';
  508. }
  509. luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
  510. }
  511. }
  512. l_noret luaG_errormsg (lua_State *L) {
  513. if (L->errfunc != 0) { /* is there an error handling function? */
  514. StkId errfunc = restorestack(L, L->errfunc);
  515. if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
  516. setobjs2s(L, L->top, L->top - 1); /* move argument */
  517. setobjs2s(L, L->top - 1, errfunc); /* push function */
  518. L->top++; /* assume EXTRA_STACK */
  519. luaD_call(L, L->top - 2, 1, 0); /* call it */
  520. }
  521. luaD_throw(L, LUA_ERRRUN);
  522. }
  523. l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
  524. va_list argp;
  525. va_start(argp, fmt);
  526. addinfo(L, luaO_pushvfstring(L, fmt, argp));
  527. va_end(argp);
  528. luaG_errormsg(L);
  529. }
  530. void luaG_traceexec (lua_State *L) {
  531. CallInfo *ci = L->ci;
  532. lu_byte mask = L->hookmask;
  533. int counthook = ((mask & LUA_MASKCOUNT) && L->hookcount == 0);
  534. if (counthook)
  535. resethookcount(L); /* reset count */
  536. if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
  537. ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
  538. return; /* do not call hook again (VM yielded, so it did not move) */
  539. }
  540. if (counthook)
  541. luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */
  542. if (mask & LUA_MASKLINE) {
  543. Proto *p = ci_func(ci)->p;
  544. int npc = pcRel(ci->u.l.savedpc, p);
  545. int newline = getfuncline(p, npc);
  546. if (npc == 0 || /* call linehook when enter a new function, */
  547. ci->u.l.savedpc <= L->oldpc || /* when jump back (loop), or when */
  548. newline != getfuncline(p, pcRel(L->oldpc, p))) /* enter a new line */
  549. luaD_hook(L, LUA_HOOKLINE, newline); /* call line hook */
  550. }
  551. L->oldpc = ci->u.l.savedpc;
  552. if (L->status == LUA_YIELD) { /* did hook yield? */
  553. if (counthook)
  554. L->hookcount = 1; /* undo decrement to zero */
  555. ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
  556. ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
  557. ci->func = L->top - 1; /* protect stack below results */
  558. luaD_throw(L, LUA_YIELD);
  559. }
  560. }