lj_debug.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /*
  2. ** Debugging and introspection.
  3. ** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #define lj_debug_c
  6. #define LUA_CORE
  7. #include "lj_obj.h"
  8. #include "lj_err.h"
  9. #include "lj_debug.h"
  10. #include "lj_str.h"
  11. #include "lj_tab.h"
  12. #include "lj_state.h"
  13. #include "lj_frame.h"
  14. #include "lj_bc.h"
  15. #if LJ_HASJIT
  16. #include "lj_jit.h"
  17. #endif
  18. /* -- Frames -------------------------------------------------------------- */
  19. /* Get frame corresponding to a level. */
  20. cTValue *lj_debug_frame(lua_State *L, int level, int *size)
  21. {
  22. cTValue *frame, *nextframe, *bot = tvref(L->stack);
  23. /* Traverse frames backwards. */
  24. for (nextframe = frame = L->base-1; frame > bot; ) {
  25. if (frame_gc(frame) == obj2gco(L))
  26. level++; /* Skip dummy frames. See lj_meta_call(). */
  27. if (level-- == 0) {
  28. *size = (int)(nextframe - frame);
  29. return frame; /* Level found. */
  30. }
  31. nextframe = frame;
  32. if (frame_islua(frame)) {
  33. frame = frame_prevl(frame);
  34. } else {
  35. if (frame_isvarg(frame))
  36. level++; /* Skip vararg pseudo-frame. */
  37. frame = frame_prevd(frame);
  38. }
  39. }
  40. *size = level;
  41. return NULL; /* Level not found. */
  42. }
  43. /* Invalid bytecode position. */
  44. #define NO_BCPOS (~(BCPos)0)
  45. /* Return bytecode position for function/frame or NO_BCPOS. */
  46. static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)
  47. {
  48. const BCIns *ins;
  49. GCproto *pt;
  50. BCPos pos;
  51. lua_assert(fn->c.gct == ~LJ_TFUNC || fn->c.gct == ~LJ_TTHREAD);
  52. if (!isluafunc(fn)) { /* Cannot derive a PC for non-Lua functions. */
  53. return NO_BCPOS;
  54. } else if (nextframe == NULL) { /* Lua function on top. */
  55. void *cf = cframe_raw(L->cframe);
  56. if (cf == NULL || (char *)cframe_pc(cf) == (char *)cframe_L(cf))
  57. return NO_BCPOS;
  58. ins = cframe_pc(cf); /* Only happens during error/hook handling. */
  59. } else {
  60. if (frame_islua(nextframe)) {
  61. ins = frame_pc(nextframe);
  62. } else if (frame_iscont(nextframe)) {
  63. ins = frame_contpc(nextframe);
  64. } else {
  65. /* Lua function below errfunc/gc/hook: find cframe to get the PC. */
  66. void *cf = cframe_raw(L->cframe);
  67. TValue *f = L->base-1;
  68. for (;;) {
  69. if (cf == NULL)
  70. return NO_BCPOS;
  71. while (cframe_nres(cf) < 0) {
  72. if (f >= restorestack(L, -cframe_nres(cf)))
  73. break;
  74. cf = cframe_raw(cframe_prev(cf));
  75. if (cf == NULL)
  76. return NO_BCPOS;
  77. }
  78. if (f < nextframe)
  79. break;
  80. if (frame_islua(f)) {
  81. f = frame_prevl(f);
  82. } else {
  83. if (frame_isc(f))
  84. cf = cframe_raw(cframe_prev(cf));
  85. f = frame_prevd(f);
  86. }
  87. }
  88. ins = cframe_pc(cf);
  89. }
  90. }
  91. pt = funcproto(fn);
  92. pos = proto_bcpos(pt, ins) - 1;
  93. #if LJ_HASJIT
  94. if (pos > pt->sizebc) { /* Undo the effects of lj_trace_exit for JLOOP. */
  95. GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins));
  96. lua_assert(bc_isret(bc_op(ins[-1])));
  97. pos = proto_bcpos(pt, mref(T->startpc, const BCIns));
  98. }
  99. #endif
  100. return pos;
  101. }
  102. /* -- Line numbers -------------------------------------------------------- */
  103. /* Get line number for a bytecode position. */
  104. BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc)
  105. {
  106. const void *lineinfo = proto_lineinfo(pt);
  107. if (pc <= pt->sizebc && lineinfo) {
  108. BCLine first = pt->firstline;
  109. if (pc == pt->sizebc) return first + pt->numline;
  110. if (pc-- == 0) return first;
  111. if (pt->numline < 256)
  112. return first + (BCLine)((const uint8_t *)lineinfo)[pc];
  113. else if (pt->numline < 65536)
  114. return first + (BCLine)((const uint16_t *)lineinfo)[pc];
  115. else
  116. return first + (BCLine)((const uint32_t *)lineinfo)[pc];
  117. }
  118. return 0;
  119. }
  120. /* Get line number for function/frame. */
  121. static BCLine debug_frameline(lua_State *L, GCfunc *fn, cTValue *nextframe)
  122. {
  123. BCPos pc = debug_framepc(L, fn, nextframe);
  124. if (pc != NO_BCPOS) {
  125. GCproto *pt = funcproto(fn);
  126. lua_assert(pc <= pt->sizebc);
  127. return lj_debug_line(pt, pc);
  128. }
  129. return -1;
  130. }
  131. /* -- Variable names ------------------------------------------------------ */
  132. /* Read ULEB128 value. */
  133. static uint32_t debug_read_uleb128(const uint8_t **pp)
  134. {
  135. const uint8_t *p = *pp;
  136. uint32_t v = *p++;
  137. if (LJ_UNLIKELY(v >= 0x80)) {
  138. int sh = 0;
  139. v &= 0x7f;
  140. do { v |= ((*p & 0x7f) << (sh += 7)); } while (*p++ >= 0x80);
  141. }
  142. *pp = p;
  143. return v;
  144. }
  145. /* Get name of a local variable from slot number and PC. */
  146. static const char *debug_varname(const GCproto *pt, BCPos pc, BCReg slot)
  147. {
  148. const uint8_t *p = proto_varinfo(pt);
  149. if (p) {
  150. BCPos lastpc = 0;
  151. for (;;) {
  152. const char *name = (const char *)p;
  153. uint32_t vn = *p++;
  154. BCPos startpc, endpc;
  155. if (vn < VARNAME__MAX) {
  156. if (vn == VARNAME_END) break; /* End of varinfo. */
  157. } else {
  158. while (*p++) ; /* Skip over variable name string. */
  159. }
  160. lastpc = startpc = lastpc + debug_read_uleb128(&p);
  161. if (startpc > pc) break;
  162. endpc = startpc + debug_read_uleb128(&p);
  163. if (pc < endpc && slot-- == 0) {
  164. if (vn < VARNAME__MAX) {
  165. #define VARNAMESTR(name, str) str "\0"
  166. name = VARNAMEDEF(VARNAMESTR);
  167. #undef VARNAMESTR
  168. if (--vn) while (*name++ || --vn) ;
  169. }
  170. return name;
  171. }
  172. }
  173. }
  174. return NULL;
  175. }
  176. /* Get name of local variable from 1-based slot number and function/frame. */
  177. static TValue *debug_localname(lua_State *L, const lua_Debug *ar,
  178. const char **name, BCReg slot1)
  179. {
  180. uint32_t offset = (uint32_t)ar->i_ci & 0xffff;
  181. uint32_t size = (uint32_t)ar->i_ci >> 16;
  182. TValue *frame = tvref(L->stack) + offset;
  183. TValue *nextframe = size ? frame + size : NULL;
  184. GCfunc *fn = frame_func(frame);
  185. BCPos pc = debug_framepc(L, fn, nextframe);
  186. if (!nextframe) nextframe = L->top;
  187. if ((int)slot1 < 0) { /* Negative slot number is for varargs. */
  188. if (pc != NO_BCPOS) {
  189. GCproto *pt = funcproto(fn);
  190. if ((pt->flags & PROTO_VARARG)) {
  191. slot1 = pt->numparams + (BCReg)(-(int)slot1);
  192. if (frame_isvarg(frame)) { /* Vararg frame has been set up? (pc!=0) */
  193. nextframe = frame;
  194. frame = frame_prevd(frame);
  195. }
  196. if (frame + slot1 < nextframe) {
  197. *name = "(*vararg)";
  198. return frame+slot1;
  199. }
  200. }
  201. }
  202. return NULL;
  203. }
  204. if (pc != NO_BCPOS &&
  205. (*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL)
  206. ;
  207. else if (slot1 > 0 && frame + slot1 < nextframe)
  208. *name = "(*temporary)";
  209. return frame+slot1;
  210. }
  211. /* Get name of upvalue. */
  212. const char *lj_debug_uvname(GCproto *pt, uint32_t idx)
  213. {
  214. const uint8_t *p = proto_uvinfo(pt);
  215. lua_assert(idx < pt->sizeuv);
  216. if (!p) return "";
  217. if (idx) while (*p++ || --idx) ;
  218. return (const char *)p;
  219. }
  220. /* Get name and value of upvalue. */
  221. const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp)
  222. {
  223. if (tvisfunc(o)) {
  224. GCfunc *fn = funcV(o);
  225. if (isluafunc(fn)) {
  226. GCproto *pt = funcproto(fn);
  227. if (idx < pt->sizeuv) {
  228. *tvp = uvval(&gcref(fn->l.uvptr[idx])->uv);
  229. return lj_debug_uvname(pt, idx);
  230. }
  231. } else {
  232. if (idx < fn->c.nupvalues) {
  233. *tvp = &fn->c.upvalue[idx];
  234. return "";
  235. }
  236. }
  237. }
  238. return NULL;
  239. }
  240. /* Deduce name of an object from slot number and PC. */
  241. const char *lj_debug_slotname(GCproto *pt, const BCIns *ip, BCReg slot,
  242. const char **name)
  243. {
  244. const char *lname;
  245. restart:
  246. lname = debug_varname(pt, proto_bcpos(pt, ip), slot);
  247. if (lname != NULL) { *name = lname; return "local"; }
  248. while (--ip > proto_bc(pt)) {
  249. BCIns ins = *ip;
  250. BCOp op = bc_op(ins);
  251. BCReg ra = bc_a(ins);
  252. if (bcmode_a(op) == BCMbase) {
  253. if (slot >= ra && (op != BC_KNIL || slot <= bc_d(ins)))
  254. return NULL;
  255. } else if (bcmode_a(op) == BCMdst && ra == slot) {
  256. switch (bc_op(ins)) {
  257. case BC_MOV:
  258. if (ra == slot) { slot = bc_d(ins); goto restart; }
  259. break;
  260. case BC_GGET:
  261. *name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_d(ins))));
  262. return "global";
  263. case BC_TGETS:
  264. *name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_c(ins))));
  265. if (ip > proto_bc(pt)) {
  266. BCIns insp = ip[-1];
  267. if (bc_op(insp) == BC_MOV && bc_a(insp) == ra+1 &&
  268. bc_d(insp) == bc_b(ins))
  269. return "method";
  270. }
  271. return "field";
  272. case BC_UGET:
  273. *name = lj_debug_uvname(pt, bc_d(ins));
  274. return "upvalue";
  275. default:
  276. return NULL;
  277. }
  278. }
  279. }
  280. return NULL;
  281. }
  282. /* Deduce function name from caller of a frame. */
  283. const char *lj_debug_funcname(lua_State *L, TValue *frame, const char **name)
  284. {
  285. TValue *pframe;
  286. GCfunc *fn;
  287. BCPos pc;
  288. if (frame <= tvref(L->stack))
  289. return NULL;
  290. if (frame_isvarg(frame))
  291. frame = frame_prevd(frame);
  292. pframe = frame_prev(frame);
  293. fn = frame_func(pframe);
  294. pc = debug_framepc(L, fn, frame);
  295. if (pc != NO_BCPOS) {
  296. GCproto *pt = funcproto(fn);
  297. const BCIns *ip = &proto_bc(pt)[check_exp(pc < pt->sizebc, pc)];
  298. MMS mm = bcmode_mm(bc_op(*ip));
  299. if (mm == MM_call) {
  300. BCReg slot = bc_a(*ip);
  301. if (bc_op(*ip) == BC_ITERC) slot -= 3;
  302. return lj_debug_slotname(pt, ip, slot, name);
  303. } else if (mm != MM__MAX) {
  304. *name = strdata(mmname_str(G(L), mm));
  305. return "metamethod";
  306. }
  307. }
  308. return NULL;
  309. }
  310. /* -- Source code locations ----------------------------------------------- */
  311. /* Generate shortened source name. */
  312. void lj_debug_shortname(char *out, GCstr *str)
  313. {
  314. const char *src = strdata(str);
  315. if (*src == '=') {
  316. strncpy(out, src+1, LUA_IDSIZE); /* Remove first char. */
  317. out[LUA_IDSIZE-1] = '\0'; /* Ensures null termination. */
  318. } else if (*src == '@') { /* Output "source", or "...source". */
  319. size_t len = str->len-1;
  320. src++; /* Skip the `@' */
  321. if (len >= LUA_IDSIZE) {
  322. src += len-(LUA_IDSIZE-4); /* Get last part of file name. */
  323. *out++ = '.'; *out++ = '.'; *out++ = '.';
  324. }
  325. strcpy(out, src);
  326. } else { /* Output [string "string"]. */
  327. size_t len; /* Length, up to first control char. */
  328. for (len = 0; len < LUA_IDSIZE-12; len++)
  329. if (((const unsigned char *)src)[len] < ' ') break;
  330. strcpy(out, "[string \""); out += 9;
  331. if (src[len] != '\0') { /* Must truncate? */
  332. if (len > LUA_IDSIZE-15) len = LUA_IDSIZE-15;
  333. strncpy(out, src, len); out += len;
  334. strcpy(out, "..."); out += 3;
  335. } else {
  336. strcpy(out, src); out += len;
  337. }
  338. strcpy(out, "\"]");
  339. }
  340. }
  341. /* Add current location of a frame to error message. */
  342. void lj_debug_addloc(lua_State *L, const char *msg,
  343. cTValue *frame, cTValue *nextframe)
  344. {
  345. if (frame) {
  346. GCfunc *fn = frame_func(frame);
  347. if (isluafunc(fn)) {
  348. BCLine line = debug_frameline(L, fn, nextframe);
  349. if (line >= 0) {
  350. char buf[LUA_IDSIZE];
  351. lj_debug_shortname(buf, proto_chunkname(funcproto(fn)));
  352. lj_str_pushf(L, "%s:%d: %s", buf, line, msg);
  353. return;
  354. }
  355. }
  356. }
  357. lj_str_pushf(L, "%s", msg);
  358. }
  359. /* Push location string for a bytecode position to Lua stack. */
  360. void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc)
  361. {
  362. GCstr *name = proto_chunkname(pt);
  363. const char *s = strdata(name);
  364. MSize i, len = name->len;
  365. BCLine line = lj_debug_line(pt, pc);
  366. if (*s == '@') {
  367. s++; len--;
  368. for (i = len; i > 0; i--)
  369. if (s[i] == '/' || s[i] == '\\') {
  370. s += i+1;
  371. break;
  372. }
  373. lj_str_pushf(L, "%s:%d", s, line);
  374. } else if (len > 40) {
  375. lj_str_pushf(L, "%p:%d", pt, line);
  376. } else if (*s == '=') {
  377. lj_str_pushf(L, "%s:%d", s+1, line);
  378. } else {
  379. lj_str_pushf(L, "\"%s\":%d", s, line);
  380. }
  381. }
  382. /* -- Public debug API ---------------------------------------------------- */
  383. /* lua_getupvalue() and lua_setupvalue() are in lj_api.c. */
  384. LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n)
  385. {
  386. const char *name = NULL;
  387. if (ar) {
  388. TValue *o = debug_localname(L, ar, &name, (BCReg)n);
  389. if (name) {
  390. copyTV(L, L->top, o);
  391. incr_top(L);
  392. }
  393. } else if (tvisfunc(L->top-1) && isluafunc(funcV(L->top-1))) {
  394. name = debug_varname(funcproto(funcV(L->top-1)), 0, (BCReg)n-1);
  395. }
  396. return name;
  397. }
  398. LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n)
  399. {
  400. const char *name = NULL;
  401. TValue *o = debug_localname(L, ar, &name, (BCReg)n);
  402. if (name)
  403. copyTV(L, o, L->top-1);
  404. L->top--;
  405. return name;
  406. }
  407. int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext)
  408. {
  409. int opt_f = 0, opt_L = 0;
  410. TValue *frame = NULL;
  411. TValue *nextframe = NULL;
  412. GCfunc *fn;
  413. if (*what == '>') {
  414. TValue *func = L->top - 1;
  415. api_check(L, tvisfunc(func));
  416. fn = funcV(func);
  417. L->top--;
  418. what++;
  419. } else {
  420. uint32_t offset = (uint32_t)ar->i_ci & 0xffff;
  421. uint32_t size = (uint32_t)ar->i_ci >> 16;
  422. lua_assert(offset != 0);
  423. frame = tvref(L->stack) + offset;
  424. if (size) nextframe = frame + size;
  425. lua_assert(frame <= tvref(L->maxstack) &&
  426. (!nextframe || nextframe <= tvref(L->maxstack)));
  427. fn = frame_func(frame);
  428. lua_assert(fn->c.gct == ~LJ_TFUNC);
  429. }
  430. for (; *what; what++) {
  431. if (*what == 'S') {
  432. if (isluafunc(fn)) {
  433. GCproto *pt = funcproto(fn);
  434. BCLine firstline = pt->firstline;
  435. GCstr *name = proto_chunkname(pt);
  436. ar->source = strdata(name);
  437. lj_debug_shortname(ar->short_src, name);
  438. ar->linedefined = (int)firstline;
  439. ar->lastlinedefined = (int)(firstline + pt->numline);
  440. ar->what = firstline ? "Lua" : "main";
  441. } else {
  442. ar->source = "=[C]";
  443. ar->short_src[0] = '[';
  444. ar->short_src[1] = 'C';
  445. ar->short_src[2] = ']';
  446. ar->short_src[3] = '\0';
  447. ar->linedefined = -1;
  448. ar->lastlinedefined = -1;
  449. ar->what = "C";
  450. }
  451. } else if (*what == 'l') {
  452. ar->currentline = frame ? debug_frameline(L, fn, nextframe) : -1;
  453. } else if (*what == 'u') {
  454. ar->nups = fn->c.nupvalues;
  455. if (ext) {
  456. if (isluafunc(fn)) {
  457. GCproto *pt = funcproto(fn);
  458. ar->nparams = pt->numparams;
  459. ar->isvararg = !!(pt->flags & PROTO_VARARG);
  460. } else {
  461. ar->nparams = 0;
  462. ar->isvararg = 1;
  463. }
  464. }
  465. } else if (*what == 'n') {
  466. ar->namewhat = frame ? lj_debug_funcname(L, frame, &ar->name) : NULL;
  467. if (ar->namewhat == NULL) {
  468. ar->namewhat = "";
  469. ar->name = NULL;
  470. }
  471. } else if (*what == 'f') {
  472. opt_f = 1;
  473. } else if (*what == 'L') {
  474. opt_L = 1;
  475. } else {
  476. return 0; /* Bad option. */
  477. }
  478. }
  479. if (opt_f) {
  480. setfuncV(L, L->top, fn);
  481. incr_top(L);
  482. }
  483. if (opt_L) {
  484. if (isluafunc(fn)) {
  485. GCtab *t = lj_tab_new(L, 0, 0);
  486. GCproto *pt = funcproto(fn);
  487. const void *lineinfo = proto_lineinfo(pt);
  488. if (lineinfo) {
  489. BCLine first = pt->firstline;
  490. int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4;
  491. MSize i, szl = pt->sizebc-1;
  492. for (i = 0; i < szl; i++) {
  493. BCLine line = first +
  494. (sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] :
  495. sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] :
  496. (BCLine)((const uint32_t *)lineinfo)[i]);
  497. setboolV(lj_tab_setint(L, t, line), 1);
  498. }
  499. }
  500. settabV(L, L->top, t);
  501. } else {
  502. setnilV(L->top);
  503. }
  504. incr_top(L);
  505. }
  506. return 1; /* Ok. */
  507. }
  508. LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
  509. {
  510. return lj_debug_getinfo(L, what, (lj_Debug *)ar, 0);
  511. }
  512. LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)
  513. {
  514. int size;
  515. cTValue *frame = lj_debug_frame(L, level, &size);
  516. if (frame) {
  517. ar->i_ci = (size << 16) + (int)(frame - tvref(L->stack));
  518. return 1;
  519. } else {
  520. ar->i_ci = level - size;
  521. return 0;
  522. }
  523. }
  524. /* Number of frames for the leading and trailing part of a traceback. */
  525. #define TRACEBACK_LEVELS1 12
  526. #define TRACEBACK_LEVELS2 10
  527. LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
  528. int level)
  529. {
  530. int top = (int)(L->top - L->base);
  531. int lim = TRACEBACK_LEVELS1;
  532. lua_Debug ar;
  533. if (msg) lua_pushfstring(L, "%s\n", msg);
  534. lua_pushliteral(L, "stack traceback:");
  535. while (lua_getstack(L1, level++, &ar)) {
  536. GCfunc *fn;
  537. if (level > lim) {
  538. if (!lua_getstack(L1, level + TRACEBACK_LEVELS2, &ar)) {
  539. level--;
  540. } else {
  541. lua_pushliteral(L, "\n\t...");
  542. lua_getstack(L1, -10, &ar);
  543. level = ar.i_ci - TRACEBACK_LEVELS2;
  544. }
  545. lim = 2147483647;
  546. continue;
  547. }
  548. lua_getinfo(L1, "Snlf", &ar);
  549. fn = funcV(L1->top-1); L1->top--;
  550. if (isffunc(fn) && !*ar.namewhat)
  551. lua_pushfstring(L, "\n\t[builtin#%d]:", fn->c.ffid);
  552. else
  553. lua_pushfstring(L, "\n\t%s:", ar.short_src);
  554. if (ar.currentline > 0)
  555. lua_pushfstring(L, "%d:", ar.currentline);
  556. if (*ar.namewhat) {
  557. lua_pushfstring(L, " in function " LUA_QS, ar.name);
  558. } else {
  559. if (*ar.what == 'm') {
  560. lua_pushliteral(L, " in main chunk");
  561. } else if (*ar.what == 'C') {
  562. lua_pushfstring(L, " at %p", fn->c.f);
  563. } else {
  564. lua_pushfstring(L, " in function <%s:%d>",
  565. ar.short_src, ar.linedefined);
  566. }
  567. }
  568. if ((int)(L->top - L->base) - top >= 15)
  569. lua_concat(L, (int)(L->top - L->base) - top);
  570. }
  571. lua_concat(L, (int)(L->top - L->base) - top);
  572. }