ldebug.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. ** $Id: ldebug.c,v 2.109 2014/12/10 11:30:09 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. }
  139. lua_unlock(L);
  140. return name;
  141. }
  142. static void funcinfo (lua_Debug *ar, Closure *cl) {
  143. if (noLuaClosure(cl)) {
  144. ar->source = "=[C]";
  145. ar->linedefined = -1;
  146. ar->lastlinedefined = -1;
  147. ar->what = "C";
  148. }
  149. else {
  150. Proto *p = cl->l.p;
  151. ar->source = p->source ? getstr(p->source) : "=?";
  152. ar->linedefined = p->linedefined;
  153. ar->lastlinedefined = p->lastlinedefined;
  154. ar->what = (ar->linedefined == 0) ? "main" : "Lua";
  155. }
  156. luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
  157. }
  158. static void collectvalidlines (lua_State *L, Closure *f) {
  159. if (noLuaClosure(f)) {
  160. setnilvalue(L->top);
  161. api_incr_top(L);
  162. }
  163. else {
  164. int i;
  165. TValue v;
  166. int *lineinfo = f->l.p->lineinfo;
  167. Table *t = luaH_new(L); /* new table to store active lines */
  168. sethvalue(L, L->top, t); /* push it on stack */
  169. api_incr_top(L);
  170. setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */
  171. for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */
  172. luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */
  173. }
  174. }
  175. static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
  176. Closure *f, CallInfo *ci) {
  177. int status = 1;
  178. for (; *what; what++) {
  179. switch (*what) {
  180. case 'S': {
  181. funcinfo(ar, f);
  182. break;
  183. }
  184. case 'l': {
  185. ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;
  186. break;
  187. }
  188. case 'u': {
  189. ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
  190. if (noLuaClosure(f)) {
  191. ar->isvararg = 1;
  192. ar->nparams = 0;
  193. }
  194. else {
  195. ar->isvararg = f->l.p->is_vararg;
  196. ar->nparams = f->l.p->numparams;
  197. }
  198. break;
  199. }
  200. case 't': {
  201. ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;
  202. break;
  203. }
  204. case 'n': {
  205. /* calling function is a known Lua function? */
  206. if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
  207. ar->namewhat = getfuncname(L, ci->previous, &ar->name);
  208. else
  209. ar->namewhat = NULL;
  210. if (ar->namewhat == NULL) {
  211. ar->namewhat = ""; /* not found */
  212. ar->name = NULL;
  213. }
  214. break;
  215. }
  216. case 'L':
  217. case 'f': /* handled by lua_getinfo */
  218. break;
  219. default: status = 0; /* invalid option */
  220. }
  221. }
  222. return status;
  223. }
  224. LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
  225. int status;
  226. Closure *cl;
  227. CallInfo *ci;
  228. StkId func;
  229. lua_lock(L);
  230. if (*what == '>') {
  231. ci = NULL;
  232. func = L->top - 1;
  233. api_check(ttisfunction(func), "function expected");
  234. what++; /* skip the '>' */
  235. L->top--; /* pop function */
  236. }
  237. else {
  238. ci = ar->i_ci;
  239. func = ci->func;
  240. lua_assert(ttisfunction(ci->func));
  241. }
  242. cl = ttisclosure(func) ? clvalue(func) : NULL;
  243. status = auxgetinfo(L, what, ar, cl, ci);
  244. if (strchr(what, 'f')) {
  245. setobjs2s(L, L->top, func);
  246. api_incr_top(L);
  247. }
  248. if (strchr(what, 'L'))
  249. collectvalidlines(L, cl);
  250. lua_unlock(L);
  251. return status;
  252. }
  253. /*
  254. ** {======================================================
  255. ** Symbolic Execution
  256. ** =======================================================
  257. */
  258. static const char *getobjname (Proto *p, int lastpc, int reg,
  259. const char **name);
  260. /*
  261. ** find a "name" for the RK value 'c'
  262. */
  263. static void kname (Proto *p, int pc, int c, const char **name) {
  264. if (ISK(c)) { /* is 'c' a constant? */
  265. TValue *kvalue = &p->k[INDEXK(c)];
  266. if (ttisstring(kvalue)) { /* literal constant? */
  267. *name = svalue(kvalue); /* it is its own name */
  268. return;
  269. }
  270. /* else no reasonable name found */
  271. }
  272. else { /* 'c' is a register */
  273. const char *what = getobjname(p, pc, c, name); /* search for 'c' */
  274. if (what && *what == 'c') { /* found a constant name? */
  275. return; /* 'name' already filled */
  276. }
  277. /* else no reasonable name found */
  278. }
  279. *name = "?"; /* no reasonable name found */
  280. }
  281. static int filterpc (int pc, int jmptarget) {
  282. if (pc < jmptarget) /* is code conditional (inside a jump)? */
  283. return -1; /* cannot know who sets that register */
  284. else return pc; /* current position sets that register */
  285. }
  286. /*
  287. ** try to find last instruction before 'lastpc' that modified register 'reg'
  288. */
  289. static int findsetreg (Proto *p, int lastpc, int reg) {
  290. int pc;
  291. int setreg = -1; /* keep last instruction that changed 'reg' */
  292. int jmptarget = 0; /* any code before this address is conditional */
  293. for (pc = 0; pc < lastpc; pc++) {
  294. Instruction i = p->code[pc];
  295. OpCode op = GET_OPCODE(i);
  296. int a = GETARG_A(i);
  297. switch (op) {
  298. case OP_LOADNIL: {
  299. int b = GETARG_B(i);
  300. if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
  301. setreg = filterpc(pc, jmptarget);
  302. break;
  303. }
  304. case OP_TFORCALL: {
  305. if (reg >= a + 2) /* affect all regs above its base */
  306. setreg = filterpc(pc, jmptarget);
  307. break;
  308. }
  309. case OP_CALL:
  310. case OP_TAILCALL: {
  311. if (reg >= a) /* affect all registers above base */
  312. setreg = filterpc(pc, jmptarget);
  313. break;
  314. }
  315. case OP_JMP: {
  316. int b = GETARG_sBx(i);
  317. int dest = pc + 1 + b;
  318. /* jump is forward and do not skip 'lastpc'? */
  319. if (pc < dest && dest <= lastpc) {
  320. if (dest > jmptarget)
  321. jmptarget = dest; /* update 'jmptarget' */
  322. }
  323. break;
  324. }
  325. default:
  326. if (testAMode(op) && reg == a) /* any instruction that set A */
  327. setreg = filterpc(pc, jmptarget);
  328. break;
  329. }
  330. }
  331. return setreg;
  332. }
  333. static const char *getobjname (Proto *p, int lastpc, int reg,
  334. const char **name) {
  335. int pc;
  336. *name = luaF_getlocalname(p, reg + 1, lastpc);
  337. if (*name) /* is a local? */
  338. return "local";
  339. /* else try symbolic execution */
  340. pc = findsetreg(p, lastpc, reg);
  341. if (pc != -1) { /* could find instruction? */
  342. Instruction i = p->code[pc];
  343. OpCode op = GET_OPCODE(i);
  344. switch (op) {
  345. case OP_MOVE: {
  346. int b = GETARG_B(i); /* move from 'b' to 'a' */
  347. if (b < GETARG_A(i))
  348. return getobjname(p, pc, b, name); /* get name for 'b' */
  349. break;
  350. }
  351. case OP_GETTABUP:
  352. case OP_GETTABLE: {
  353. int k = GETARG_C(i); /* key index */
  354. int t = GETARG_B(i); /* table index */
  355. const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
  356. ? luaF_getlocalname(p, t + 1, pc)
  357. : upvalname(p, t);
  358. kname(p, pc, k, name);
  359. return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
  360. }
  361. case OP_GETUPVAL: {
  362. *name = upvalname(p, GETARG_B(i));
  363. return "upvalue";
  364. }
  365. case OP_LOADK:
  366. case OP_LOADKX: {
  367. int b = (op == OP_LOADK) ? GETARG_Bx(i)
  368. : GETARG_Ax(p->code[pc + 1]);
  369. if (ttisstring(&p->k[b])) {
  370. *name = svalue(&p->k[b]);
  371. return "constant";
  372. }
  373. break;
  374. }
  375. case OP_SELF: {
  376. int k = GETARG_C(i); /* key index */
  377. kname(p, pc, k, name);
  378. return "method";
  379. }
  380. default: break; /* go through to return NULL */
  381. }
  382. }
  383. return NULL; /* could not find reasonable name */
  384. }
  385. static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
  386. TMS tm = (TMS)0; /* to avoid warnings */
  387. Proto *p = ci_func(ci)->p; /* calling function */
  388. int pc = currentpc(ci); /* calling instruction index */
  389. Instruction i = p->code[pc]; /* calling instruction */
  390. if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
  391. *name = "?";
  392. return "hook";
  393. }
  394. switch (GET_OPCODE(i)) {
  395. case OP_CALL:
  396. case OP_TAILCALL: /* get function name */
  397. return getobjname(p, pc, GETARG_A(i), name);
  398. case OP_TFORCALL: { /* for iterator */
  399. *name = "for iterator";
  400. return "for iterator";
  401. }
  402. /* all other instructions can call only through metamethods */
  403. case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
  404. tm = TM_INDEX;
  405. break;
  406. case OP_SETTABUP: case OP_SETTABLE:
  407. tm = TM_NEWINDEX;
  408. break;
  409. case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:
  410. case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:
  411. case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {
  412. int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD); /* ORDER OP */
  413. tm = cast(TMS, offset + cast_int(TM_ADD)); /* ORDER TM */
  414. break;
  415. }
  416. case OP_UNM: tm = TM_UNM; break;
  417. case OP_BNOT: tm = TM_BNOT; break;
  418. case OP_LEN: tm = TM_LEN; break;
  419. case OP_CONCAT: tm = TM_CONCAT; break;
  420. case OP_EQ: tm = TM_EQ; break;
  421. case OP_LT: tm = TM_LT; break;
  422. case OP_LE: tm = TM_LE; break;
  423. default: lua_assert(0); /* other instructions cannot call a function */
  424. }
  425. *name = getstr(G(L)->tmname[tm]);
  426. return "metamethod";
  427. }
  428. /* }====================================================== */
  429. /*
  430. ** The subtraction of two potentially unrelated pointers is
  431. ** not ISO C, but it should not crash a program; the subsequent
  432. ** checks are ISO C and ensure a correct result.
  433. */
  434. static int isinstack (CallInfo *ci, const TValue *o) {
  435. ptrdiff_t i = o - ci->u.l.base;
  436. return (0 <= i && i < (ci->top - ci->u.l.base) && ci->u.l.base + i == o);
  437. }
  438. /*
  439. ** Checks whether value 'o' came from an upvalue. (That can only happen
  440. ** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on
  441. ** upvalues.)
  442. */
  443. static const char *getupvalname (CallInfo *ci, const TValue *o,
  444. const char **name) {
  445. LClosure *c = ci_func(ci);
  446. int i;
  447. for (i = 0; i < c->nupvalues; i++) {
  448. if (c->upvals[i]->v == o) {
  449. *name = upvalname(c->p, i);
  450. return "upvalue";
  451. }
  452. }
  453. return NULL;
  454. }
  455. static const char *varinfo (lua_State *L, const TValue *o) {
  456. const char *name = NULL; /* to avoid warnings */
  457. CallInfo *ci = L->ci;
  458. const char *kind = NULL;
  459. if (isLua(ci)) {
  460. kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
  461. if (!kind && isinstack(ci, o)) /* no? try a register */
  462. kind = getobjname(ci_func(ci)->p, currentpc(ci),
  463. cast_int(o - ci->u.l.base), &name);
  464. }
  465. return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : "";
  466. }
  467. l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
  468. const char *t = objtypename(o);
  469. luaG_runerror(L, "attempt to %s a %s value%s", op, t, varinfo(L, o));
  470. }
  471. l_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) {
  472. if (ttisstring(p1) || cvt2str(p1)) p1 = p2;
  473. luaG_typeerror(L, p1, "concatenate");
  474. }
  475. l_noret luaG_opinterror (lua_State *L, const TValue *p1,
  476. const TValue *p2, const char *msg) {
  477. lua_Number temp;
  478. if (!tonumber(p1, &temp)) /* first operand is wrong? */
  479. p2 = p1; /* now second is wrong */
  480. luaG_typeerror(L, p2, msg);
  481. }
  482. /*
  483. ** Error when both values are convertible to numbers, but not to integers
  484. */
  485. l_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) {
  486. lua_Integer temp;
  487. if (!tointeger(p1, &temp))
  488. p2 = p1;
  489. luaG_runerror(L, "number%s has no integer representation", varinfo(L, p2));
  490. }
  491. l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
  492. const char *t1 = objtypename(p1);
  493. const char *t2 = objtypename(p2);
  494. if (t1 == t2)
  495. luaG_runerror(L, "attempt to compare two %s values", t1);
  496. else
  497. luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
  498. }
  499. static void addinfo (lua_State *L, const char *msg) {
  500. CallInfo *ci = L->ci;
  501. if (isLua(ci)) { /* is Lua code? */
  502. char buff[LUA_IDSIZE]; /* add file:line information */
  503. int line = currentline(ci);
  504. TString *src = ci_func(ci)->p->source;
  505. if (src)
  506. luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
  507. else { /* no source available; use "?" instead */
  508. buff[0] = '?'; buff[1] = '\0';
  509. }
  510. luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
  511. }
  512. }
  513. l_noret luaG_errormsg (lua_State *L) {
  514. if (L->errfunc != 0) { /* is there an error handling function? */
  515. StkId errfunc = restorestack(L, L->errfunc);
  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. }