Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ldebug.c File Reference
#include "lprefix.h"
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include "lua.h"
#include "lapi.h"
#include "lcode.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lvm.h"

Go to the source code of this file.

Macros

#define ldebug_c
 
#define LUA_CORE
 
#define noLuaClosure(f)   ((f) == NULL || (f)->c.tt == LUA_TCCL)
 
#define ci_func(ci)   (clLvalue((ci)->func))
 

Functions

static const char * funcnamefromcode (lua_State *L, CallInfo *ci, const char **name)
 
static int currentpc (CallInfo *ci)
 
static int currentline (CallInfo *ci)
 
static void swapextra (lua_State *L)
 
LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count)
 
LUA_API lua_Hook lua_gethook (lua_State *L)
 
LUA_API int lua_gethookmask (lua_State *L)
 
LUA_API int lua_gethookcount (lua_State *L)
 
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar)
 
static const char * upvalname (Proto *p, int uv)
 
static const char * findvararg (CallInfo *ci, int n, StkId *pos)
 
static const char * findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos)
 
LUA_API const char * lua_getlocal (lua_State *L, const lua_Debug *ar, int n)
 
LUA_API const char * lua_setlocal (lua_State *L, const lua_Debug *ar, int n)
 
static void funcinfo (lua_Debug *ar, Closure *cl)
 
static void collectvalidlines (lua_State *L, Closure *f)
 
static const char * getfuncname (lua_State *L, CallInfo *ci, const char **name)
 
static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, Closure *f, CallInfo *ci)
 
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar)
 
static const char * getobjname (Proto *p, int lastpc, int reg, const char **name)
 
static void kname (Proto *p, int pc, int c, const char **name)
 
static int filterpc (int pc, int jmptarget)
 
static int findsetreg (Proto *p, int lastpc, int reg)
 
static int isinstack (CallInfo *ci, const TValue *o)
 
static const char * getupvalname (CallInfo *ci, const TValue *o, const char **name)
 
static const char * varinfo (lua_State *L, const TValue *o)
 
l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op)
 
l_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2)
 
l_noret luaG_opinterror (lua_State *L, const TValue *p1, const TValue *p2, const char *msg)
 
l_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2)
 
l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2)
 
const char * luaG_addinfo (lua_State *L, const char *msg, TString *src, int line)
 
l_noret luaG_errormsg (lua_State *L)
 
l_noret luaG_runerror (lua_State *L, const char *fmt,...)
 
void luaG_traceexec (lua_State *L)
 

Macro Definition Documentation

◆ ci_func

#define ci_func ( ci)    (clLvalue((ci)->func))

◆ ldebug_c

#define ldebug_c

Definition at line 7 of file lua-5.3.6/src/ldebug.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.3.6/src/ldebug.c.

◆ noLuaClosure

#define noLuaClosure ( f)    ((f) == NULL || (f)->c.tt == LUA_TCCL)

Definition at line 34 of file lua-5.3.6/src/ldebug.c.

Referenced by auxgetinfo(), collectvalidlines(), and funcinfo().

Function Documentation

◆ auxgetinfo()

static int auxgetinfo ( lua_State * L,
const char * what,
lua_Debug * ar,
Closure * f,
CallInfo * ci )
static

Definition at line 263 of file lua-5.3.6/src/ldebug.c.

264 {
265 int status = 1;
266 for (; *what; what++) {
267 switch (*what) {
268 case 'S': {
269 funcinfo(ar, f);
270 break;
271 }
272 case 'l': {
273 ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;
274 break;
275 }
276 case 'u': {
277 ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
278 if (noLuaClosure(f)) {
279 ar->isvararg = 1;
280 ar->nparams = 0;
281 }
282 else {
283 ar->isvararg = f->l.p->is_vararg;
284 ar->nparams = f->l.p->numparams;
285 }
286 break;
287 }
288 case 't': {
289 ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;
290 break;
291 }
292 case 'n': {
293 ar->namewhat = getfuncname(L, ci, &ar->name);
294 if (ar->namewhat == NULL) {
295 ar->namewhat = ""; /* not found */
296 ar->name = NULL;
297 }
298 break;
299 }
300 case 'L':
301 case 'f': /* handled by lua_getinfo */
302 break;
303 default: status = 0; /* invalid option */
304 }
305 }
306 return status;
307}
#define NULL
Definition gmacros.h:924
#define isLua(ci)
#define CIST_TAIL
#define noLuaClosure(f)
static void funcinfo(lua_Debug *ar, Closure *cl)
static int currentline(CallInfo *ci)
static const char * getfuncname(lua_State *L, CallInfo *ci, const char **name)
struct Proto * p
const char * name
unsigned char nparams
const char * namewhat

References Closure::c, CallInfo::callstatus, CIST_TAIL, lua_Debug::currentline, currentline(), funcinfo(), getfuncname(), Proto::is_vararg, isLua, lua_Debug::istailcall, lua_Debug::isvararg, Closure::l, lua_Debug::name, lua_Debug::namewhat, noLuaClosure, lua_Debug::nparams, NULL, Proto::numparams, lua_Debug::nups, and LClosure::p.

Referenced by lua_getinfo().

◆ collectvalidlines()

static void collectvalidlines ( lua_State * L,
Closure * f )
static

Definition at line 230 of file lua-5.3.6/src/ldebug.c.

230 {
231 if (noLuaClosure(f)) {
232 setnilvalue(L->top);
233 api_incr_top(L);
234 }
235 else {
236 int i;
237 TValue v;
238 int *lineinfo = f->l.p->lineinfo;
239 Table *t = luaH_new(L); /* new table to store active lines */
240 sethvalue(L, L->top, t); /* push it on stack */
241 api_incr_top(L);
242 setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */
243 for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */
244 luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */
245 }
246}
#define api_incr_top(L)
#define setbvalue(obj, x)
#define sethvalue(L, obj, x)
#define setnilvalue(obj)
Table * luaH_new(lua_State *L, int narray, int nhash)
void luaH_setint(lua_State *L, Table *t, int key, TValue *value)

References api_incr_top, Closure::l, Proto::lineinfo, luaH_new(), luaH_setint(), noLuaClosure, LClosure::p, setbvalue, sethvalue, setnilvalue, Proto::sizelineinfo, and lua_State::top.

Referenced by lua_getinfo().

◆ currentline()

static int currentline ( CallInfo * ci)
static

Definition at line 51 of file lua-5.3.6/src/ldebug.c.

51 {
52 return getfuncline(ci_func(ci)->p, currentpc(ci));
53}
#define getfuncline(f, pc)
#define ci_func(ci)
static int currentpc(CallInfo *ci)

References ci_func, currentpc(), and getfuncline.

Referenced by auxgetinfo(), and luaG_runerror().

◆ currentpc()

static int currentpc ( CallInfo * ci)
static

Definition at line 45 of file lua-5.3.6/src/ldebug.c.

45 {
46 lua_assert(isLua(ci));
47 return pcRel(ci->u.l.savedpc, ci_func(ci)->p);
48}
#define pcRel(pc, p)
#define lua_assert(c)
struct CallInfo::@64::@65 l
const Instruction * savedpc
union CallInfo::@64 u

References ci_func, isLua, CallInfo::l, lua_assert, pcRel, CallInfo::savedpc, and CallInfo::u.

Referenced by currentline(), findlocal(), funcnamefromcode(), and varinfo().

◆ filterpc()

static int filterpc ( int pc,
int jmptarget )
static

Definition at line 376 of file lua-5.3.6/src/ldebug.c.

376 {
377 if (pc < jmptarget) /* is code conditional (inside a jump)? */
378 return -1; /* cannot know who sets that register */
379 else return pc; /* current position sets that register */
380}

Referenced by findsetreg().

◆ findlocal()

static const char * findlocal ( lua_State * L,
CallInfo * ci,
int n,
StkId * pos )
static

Definition at line 146 of file lua-5.3.6/src/ldebug.c.

147 {
148 const char *name = NULL;
149 StkId base;
150 if (isLua(ci)) {
151 if (n < 0) /* access to vararg values? */
152 return findvararg(ci, n, pos);
153 else {
154 base = ci->u.l.base;
155 name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
156 }
157 }
158 else
159 base = ci->func + 1;
160 if (name == NULL) { /* no 'standard' name? */
161 StkId limit = (ci == L->ci) ? L->top : ci->next->func;
162 if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */
163 name = "(*temporary)"; /* generic name for any valid slot */
164 else
165 return NULL; /* no name */
166 }
167 *pos = base + (n - 1);
168 return name;
169}
const char * name
Definition lsqlite3.c:2154
const char * luaF_getlocalname(const Proto *f, int local_number, int pc)
#define next(ls)
static const char * findvararg(CallInfo *ci, int n, StkId *pos)

References CallInfo::base, lua_State::ci, ci_func, currentpc(), findvararg(), CallInfo::func, isLua, CallInfo::l, luaF_getlocalname(), name, CallInfo::next, NULL, lua_State::top, and CallInfo::u.

Referenced by lua_getlocal(), and lua_setlocal().

◆ findsetreg()

static int findsetreg ( Proto * p,
int lastpc,
int reg )
static

Definition at line 386 of file lua-5.3.6/src/ldebug.c.

386 {
387 int pc;
388 int setreg = -1; /* keep last instruction that changed 'reg' */
389 int jmptarget = 0; /* any code before this address is conditional */
390 for (pc = 0; pc < lastpc; pc++) {
391 Instruction i = p->code[pc];
392 OpCode op = GET_OPCODE(i);
393 int a = GETARG_A(i);
394 switch (op) {
395 case OP_LOADNIL: {
396 int b = GETARG_B(i);
397 if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
398 setreg = filterpc(pc, jmptarget);
399 break;
400 }
401 case OP_TFORCALL: {
402 if (reg >= a + 2) /* affect all regs above its base */
403 setreg = filterpc(pc, jmptarget);
404 break;
405 }
406 case OP_CALL:
407 case OP_TAILCALL: {
408 if (reg >= a) /* affect all registers above base */
409 setreg = filterpc(pc, jmptarget);
410 break;
411 }
412 case OP_JMP: {
413 int b = GETARG_sBx(i);
414 int dest = pc + 1 + b;
415 /* jump is forward and do not skip 'lastpc'? */
416 if (pc < dest && dest <= lastpc) {
417 if (dest > jmptarget)
418 jmptarget = dest; /* update 'jmptarget' */
419 }
420 break;
421 }
422 default:
423 if (testAMode(op) && reg == a) /* any instruction that set A */
424 setreg = filterpc(pc, jmptarget);
425 break;
426 }
427 }
428 return setreg;
429}
lu_int32 Instruction
#define GETARG_A(i)
#define GETARG_sBx(i)
#define GETARG_B(i)
#define GET_OPCODE(i)
#define testAMode(m)
static int filterpc(int pc, int jmptarget)
Instruction * code

References Proto::code, filterpc(), GET_OPCODE, GETARG_A, GETARG_B, GETARG_sBx, OP_CALL, OP_JMP, OP_LOADNIL, OP_TAILCALL, OP_TFORCALL, and testAMode.

Referenced by getobjname().

◆ findvararg()

static const char * findvararg ( CallInfo * ci,
int n,
StkId * pos )
static

Definition at line 134 of file lua-5.3.6/src/ldebug.c.

134 {
135 int nparams = clLvalue(ci->func)->p->numparams;
136 int nvararg = cast_int(ci->u.l.base - ci->func) - nparams;
137 if (n <= -nvararg)
138 return NULL; /* no such vararg */
139 else {
140 *pos = ci->func + nparams - n;
141 return "(*vararg)"; /* generic name for any vararg */
142 }
143}
#define cast_int(i)
#define clLvalue(o)

References CallInfo::base, cast_int, clLvalue, CallInfo::func, CallInfo::l, NULL, and CallInfo::u.

Referenced by findlocal().

◆ funcinfo()

static void funcinfo ( lua_Debug * ar,
Closure * cl )
static

Definition at line 212 of file lua-5.3.6/src/ldebug.c.

212 {
213 if (noLuaClosure(cl)) {
214 ar->source = "=[C]";
215 ar->linedefined = -1;
216 ar->lastlinedefined = -1;
217 ar->what = "C";
218 }
219 else {
220 Proto *p = cl->l.p;
221 ar->source = p->source ? getstr(p->source) : "=?";
222 ar->linedefined = p->linedefined;
224 ar->what = (ar->linedefined == 0) ? "main" : "Lua";
225 }
227}
void luaO_chunkid(char *out, const char *source, size_t bufflen)
#define getstr(ts)
#define LUA_IDSIZE
TString * source
const char * what
const char * source
char short_src[LUA_IDSIZE]

References getstr, Closure::l, Proto::lastlinedefined, lua_Debug::lastlinedefined, Proto::linedefined, lua_Debug::linedefined, LUA_IDSIZE, luaO_chunkid(), noLuaClosure, LClosure::p, lua_Debug::short_src, Proto::source, lua_Debug::source, and lua_Debug::what.

Referenced by auxgetinfo().

◆ funcnamefromcode()

static const char * funcnamefromcode ( lua_State * L,
CallInfo * ci,
const char ** name )
static

Definition at line 492 of file lua-5.3.6/src/ldebug.c.

493 {
494 TMS tm = (TMS)0; /* (initial value avoids warnings) */
495 Proto *p = ci_func(ci)->p; /* calling function */
496 int pc = currentpc(ci); /* calling instruction index */
497 Instruction i = p->code[pc]; /* calling instruction */
498 if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
499 *name = "?";
500 return "hook";
501 }
502 switch (GET_OPCODE(i)) {
503 case OP_CALL:
504 case OP_TAILCALL:
505 return getobjname(p, pc, GETARG_A(i), name); /* get function name */
506 case OP_TFORCALL: { /* for iterator */
507 *name = "for iterator";
508 return "for iterator";
509 }
510 /* other instructions can do calls through metamethods */
511 case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
512 tm = TM_INDEX;
513 break;
514 case OP_SETTABUP: case OP_SETTABLE:
515 tm = TM_NEWINDEX;
516 break;
517 case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:
518 case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:
519 case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {
520 int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD); /* ORDER OP */
521 tm = cast(TMS, offset + cast_int(TM_ADD)); /* ORDER TM */
522 break;
523 }
524 case OP_UNM: tm = TM_UNM; break;
525 case OP_BNOT: tm = TM_BNOT; break;
526 case OP_LEN: tm = TM_LEN; break;
527 case OP_CONCAT: tm = TM_CONCAT; break;
528 case OP_EQ: tm = TM_EQ; break;
529 case OP_LT: tm = TM_LT; break;
530 case OP_LE: tm = TM_LE; break;
531 default:
532 return NULL; /* cannot find a reasonable name */
533 }
534 *name = getstr(G(L)->tmname[tm]);
535 return "metamethod";
536}
#define cast(t, exp)
#define G(L)
@ TM_NEWINDEX
@ TM_INDEX
@ TM_UNM
@ TM_EQ
@ TM_LEN
@ TM_ADD
@ TM_LE
@ TM_CONCAT
@ TM_LT
#define CIST_HOOKED
static const char * getobjname(Proto *p, int lastpc, int reg, const char **name)
@ TM_BNOT
static TString ** tmname
struct Proto ** p

References CallInfo::callstatus, cast, cast_int, ci_func, CIST_HOOKED, Proto::code, currentpc(), G, GET_OPCODE, GETARG_A, getobjname(), getstr, name, NULL, OP_ADD, OP_BAND, OP_BNOT, OP_BOR, OP_BXOR, OP_CALL, OP_CONCAT, OP_DIV, OP_EQ, OP_GETTABLE, OP_GETTABUP, OP_IDIV, OP_LE, OP_LEN, OP_LT, OP_MOD, OP_MUL, OP_POW, OP_SELF, OP_SETTABLE, OP_SETTABUP, OP_SHL, OP_SHR, OP_SUB, OP_TAILCALL, OP_TFORCALL, OP_UNM, Proto::p, TM_ADD, TM_BNOT, TM_CONCAT, TM_EQ, TM_INDEX, TM_LE, TM_LEN, TM_LT, TM_NEWINDEX, TM_UNM, and tmname.

Referenced by getfuncname().

◆ getfuncname()

static const char * getfuncname ( lua_State * L,
CallInfo * ci,
const char ** name )
static

Definition at line 249 of file lua-5.3.6/src/ldebug.c.

249 {
250 if (ci == NULL) /* no 'ci'? */
251 return NULL; /* no info */
252 else if (ci->callstatus & CIST_FIN) { /* is this a finalizer? */
253 *name = "__gc";
254 return "metamethod"; /* report it as such */
255 }
256 /* calling function is a known Lua function? */
257 else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
258 return funcnamefromcode(L, ci->previous, name);
259 else return NULL; /* no way to find a name */
260}
static const char * funcnamefromcode(lua_State *L, CallInfo *ci, const char **name)
#define CIST_FIN
struct CallInfo * previous

References CallInfo::callstatus, CIST_FIN, CIST_TAIL, funcnamefromcode(), isLua, name, NULL, and CallInfo::previous.

Referenced by auxgetinfo().

◆ getobjname()

static const char * getobjname ( Proto * p,
int lastpc,
int reg,
const char ** name )
static

Definition at line 432 of file lua-5.3.6/src/ldebug.c.

433 {
434 int pc;
435 *name = luaF_getlocalname(p, reg + 1, lastpc);
436 if (*name) /* is a local? */
437 return "local";
438 /* else try symbolic execution */
439 pc = findsetreg(p, lastpc, reg);
440 if (pc != -1) { /* could find instruction? */
441 Instruction i = p->code[pc];
442 OpCode op = GET_OPCODE(i);
443 switch (op) {
444 case OP_MOVE: {
445 int b = GETARG_B(i); /* move from 'b' to 'a' */
446 if (b < GETARG_A(i))
447 return getobjname(p, pc, b, name); /* get name for 'b' */
448 break;
449 }
450 case OP_GETTABUP:
451 case OP_GETTABLE: {
452 int k = GETARG_C(i); /* key index */
453 int t = GETARG_B(i); /* table index */
454 const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
455 ? luaF_getlocalname(p, t + 1, pc)
456 : upvalname(p, t);
457 kname(p, pc, k, name);
458 return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
459 }
460 case OP_GETUPVAL: {
461 *name = upvalname(p, GETARG_B(i));
462 return "upvalue";
463 }
464 case OP_LOADK:
465 case OP_LOADKX: {
466 int b = (op == OP_LOADK) ? GETARG_Bx(i)
467 : GETARG_Ax(p->code[pc + 1]);
468 if (ttisstring(&p->k[b])) {
469 *name = svalue(&p->k[b]);
470 return "constant";
471 }
472 break;
473 }
474 case OP_SELF: {
475 int k = GETARG_C(i); /* key index */
476 kname(p, pc, k, name);
477 return "method";
478 }
479 default: break; /* go through to return NULL */
480 }
481 }
482 return NULL; /* could not find reasonable name */
483}
#define ttisstring(o)
#define svalue(o)
#define GETARG_Bx(i)
#define GETARG_C(i)
#define GETARG_Ax(i)
#define LUA_ENV
static int findsetreg(Proto *p, int lastpc, int reg)
static void kname(Proto *p, int pc, int c, const char **name)
static const char * upvalname(Proto *p, int uv)

References Proto::code, findsetreg(), GET_OPCODE, GETARG_A, GETARG_Ax, GETARG_B, GETARG_Bx, GETARG_C, getobjname(), Proto::k, kname(), LUA_ENV, luaF_getlocalname(), name, NULL, OP_GETTABLE, OP_GETTABUP, OP_GETUPVAL, OP_LOADK, OP_LOADKX, OP_MOVE, OP_SELF, svalue, ttisstring, and upvalname().

Referenced by funcnamefromcode(), getobjname(), kname(), and varinfo().

◆ getupvalname()

static const char * getupvalname ( CallInfo * ci,
const TValue * o,
const char ** name )
static

Definition at line 558 of file lua-5.3.6/src/ldebug.c.

559 {
560 LClosure *c = ci_func(ci);
561 int i;
562 for (i = 0; i < c->nupvalues; i++) {
563 if (c->upvals[i]->v == o) {
564 *name = upvalname(c->p, i);
565 return "upvalue";
566 }
567 }
568 return NULL;
569}

References ci_func, name, NULL, LClosure::p, upvalname(), LClosure::upvals, and UpVal::v.

Referenced by varinfo().

◆ isinstack()

static int isinstack ( CallInfo * ci,
const TValue * o )
static

Definition at line 547 of file lua-5.3.6/src/ldebug.c.

547 {
548 ptrdiff_t i = o - ci->u.l.base;
549 return (0 <= i && i < (ci->top - ci->u.l.base) && ci->u.l.base + i == o);
550}

References CallInfo::base, CallInfo::l, CallInfo::top, and CallInfo::u.

Referenced by varinfo().

◆ kname()

static void kname ( Proto * p,
int pc,
int c,
const char ** name )
static

Definition at line 356 of file lua-5.3.6/src/ldebug.c.

356 {
357 if (ISK(c)) { /* is 'c' a constant? */
358 TValue *kvalue = &p->k[INDEXK(c)];
359 if (ttisstring(kvalue)) { /* literal constant? */
360 *name = svalue(kvalue); /* it is its own name */
361 return;
362 }
363 /* else no reasonable name found */
364 }
365 else { /* 'c' is a register */
366 const char *what = getobjname(p, pc, c, name); /* search for 'c' */
367 if (what && *what == 'c') { /* found a constant name? */
368 return; /* 'name' already filled */
369 }
370 /* else no reasonable name found */
371 }
372 *name = "?"; /* no reasonable name found */
373}
#define ISK(x)
#define INDEXK(r)

References getobjname(), INDEXK, ISK, Proto::k, name, svalue, and ttisstring.

Referenced by getobjname().

◆ lua_gethook()

LUA_API lua_Hook lua_gethook ( lua_State * L)

Definition at line 95 of file lua-5.3.6/src/ldebug.c.

95 {
96 return L->hook;
97}

References lua_State::hook.

◆ lua_gethookcount()

LUA_API int lua_gethookcount ( lua_State * L)

Definition at line 105 of file lua-5.3.6/src/ldebug.c.

105 {
106 return L->basehookcount;
107}

References lua_State::basehookcount.

◆ lua_gethookmask()

LUA_API int lua_gethookmask ( lua_State * L)

Definition at line 100 of file lua-5.3.6/src/ldebug.c.

100 {
101 return L->hookmask;
102}

References lua_State::hookmask.

◆ lua_getinfo()

LUA_API int lua_getinfo ( lua_State * L,
const char * what,
lua_Debug * ar )

Definition at line 310 of file lua-5.3.6/src/ldebug.c.

310 {
311 int status;
312 Closure *cl;
313 CallInfo *ci;
314 StkId func;
315 lua_lock(L);
316 swapextra(L);
317 if (*what == '>') {
318 ci = NULL;
319 func = L->top - 1;
320 api_check(L, ttisfunction(func), "function expected");
321 what++; /* skip the '>' */
322 L->top--; /* pop function */
323 }
324 else {
325 ci = ar->i_ci;
326 func = ci->func;
328 }
329 cl = ttisclosure(func) ? clvalue(func) : NULL;
330 status = auxgetinfo(L, what, ar, cl, ci);
331 if (strchr(what, 'f')) {
332 setobjs2s(L, L->top, func);
333 api_incr_top(L);
334 }
335 swapextra(L); /* correct before option 'L', which can raise a mem. error */
336 if (strchr(what, 'L'))
337 collectvalidlines(L, cl);
338 lua_unlock(L);
339 return status;
340}
#define lua_unlock(L)
#define api_check
#define lua_lock(L)
#define ttisfunction(o)
#define clvalue(o)
#define setobjs2s
#define ttisclosure(o)
static void swapextra(lua_State *L)
static void collectvalidlines(lua_State *L, Closure *f)
static int auxgetinfo(lua_State *L, const char *what, lua_Debug *ar, Closure *f, CallInfo *ci)

References api_check, api_incr_top, auxgetinfo(), clvalue, collectvalidlines(), CallInfo::func, lua_Debug::i_ci, lua_assert, lua_lock, lua_unlock, NULL, setobjs2s, swapextra(), lua_State::top, ttisclosure, and ttisfunction.

◆ lua_getlocal()

LUA_API const char * lua_getlocal ( lua_State * L,
const lua_Debug * ar,
int n )

Definition at line 172 of file lua-5.3.6/src/ldebug.c.

172 {
173 const char *name;
174 lua_lock(L);
175 swapextra(L);
176 if (ar == NULL) { /* information about non-active function? */
177 if (!isLfunction(L->top - 1)) /* not a Lua function? */
178 name = NULL;
179 else /* consider live variables at function start (parameters) */
180 name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
181 }
182 else { /* active function; get information through 'ar' */
183 StkId pos = NULL; /* to avoid warnings */
184 name = findlocal(L, ar->i_ci, n, &pos);
185 if (name) {
186 setobj2s(L, L->top, pos);
187 api_incr_top(L);
188 }
189 }
190 swapextra(L);
191 lua_unlock(L);
192 return name;
193}
#define setobj2s
#define isLfunction(o)
static const char * findlocal(lua_State *L, CallInfo *ci, int n, StkId *pos)

References api_incr_top, clLvalue, findlocal(), lua_Debug::i_ci, isLfunction, lua_lock, lua_unlock, luaF_getlocalname(), name, NULL, setobj2s, swapextra(), and lua_State::top.

◆ lua_getstack()

LUA_API int lua_getstack ( lua_State * L,
int level,
lua_Debug * ar )

Definition at line 110 of file lua-5.3.6/src/ldebug.c.

110 {
111 int status;
112 CallInfo *ci;
113 if (level < 0) return 0; /* invalid (negative) level */
114 lua_lock(L);
115 for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)
116 level--;
117 if (level == 0 && ci != &L->base_ci) { /* level found? */
118 status = 1;
119 ar->i_ci = ci;
120 }
121 else status = 0; /* no such level */
122 lua_unlock(L);
123 return status;
124}

References lua_State::base_ci, lua_State::ci, lua_Debug::i_ci, lua_lock, lua_unlock, and CallInfo::previous.

◆ lua_sethook()

LUA_API void lua_sethook ( lua_State * L,
lua_Hook func,
int mask,
int count )

Definition at line 81 of file lua-5.3.6/src/ldebug.c.

81 {
82 if (func == NULL || mask == 0) { /* turn off hooks? */
83 mask = 0;
84 func = NULL;
85 }
86 if (isLua(L->ci))
87 L->oldpc = L->ci->u.l.savedpc;
88 L->hook = func;
89 L->basehookcount = count;
92}
#define resethookcount(L)
#define cast_byte(i)
#define mask(n)
const Instruction * oldpc

References lua_State::basehookcount, cast_byte, lua_State::ci, lua_State::hook, lua_State::hookmask, isLua, CallInfo::l, mask, NULL, lua_State::oldpc, resethookcount, CallInfo::savedpc, and CallInfo::u.

◆ lua_setlocal()

LUA_API const char * lua_setlocal ( lua_State * L,
const lua_Debug * ar,
int n )

Definition at line 196 of file lua-5.3.6/src/ldebug.c.

196 {
197 StkId pos = NULL; /* to avoid warnings */
198 const char *name;
199 lua_lock(L);
200 swapextra(L);
201 name = findlocal(L, ar->i_ci, n, &pos);
202 if (name) {
203 setobjs2s(L, pos, L->top - 1);
204 L->top--; /* pop value */
205 }
206 swapextra(L);
207 lua_unlock(L);
208 return name;
209}

References findlocal(), lua_Debug::i_ci, lua_lock, lua_unlock, name, NULL, setobjs2s, swapextra(), and lua_State::top.

◆ luaG_addinfo()

const char * luaG_addinfo ( lua_State * L,
const char * msg,
TString * src,
int line )

Definition at line 629 of file lua-5.3.6/src/ldebug.c.

630 {
631 char buff[LUA_IDSIZE];
632 if (src)
633 luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
634 else { /* no source available; use "?" instead */
635 buff[0] = '?'; buff[1] = '\0';
636 }
637 return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
638}
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)

References getstr, LUA_IDSIZE, luaO_chunkid(), and luaO_pushfstring().

Referenced by lexerror(), lexerror(), and luaG_runerror().

◆ luaG_concaterror()

l_noret luaG_concaterror ( lua_State * L,
const TValue * p1,
const TValue * p2 )

Definition at line 592 of file lua-5.3.6/src/ldebug.c.

592 {
593 if (ttisstring(p1) || cvt2str(p1)) p1 = p2;
594 luaG_typeerror(L, p1, "concatenate");
595}
l_noret luaG_typeerror(lua_State *L, const TValue *o, const char *op)
#define cvt2str(o)

References cvt2str, luaG_typeerror(), and ttisstring.

◆ luaG_errormsg()

l_noret luaG_errormsg ( lua_State * L)

Definition at line 641 of file lua-5.3.6/src/ldebug.c.

641 {
642 if (L->errfunc != 0) { /* is there an error handling function? */
643 StkId errfunc = restorestack(L, L->errfunc);
644 setobjs2s(L, L->top, L->top - 1); /* move argument */
645 setobjs2s(L, L->top - 1, errfunc); /* push function */
646 L->top++; /* assume EXTRA_STACK */
647 luaD_callnoyield(L, L->top - 2, 1); /* call it */
648 }
650}
void luaD_throw(lua_State *L, int errcode)
#define restorestack(L, n)
#define LUA_ERRRUN
void luaD_callnoyield(lua_State *L, StkId func, int nResults)

References lua_State::errfunc, LUA_ERRRUN, luaD_callnoyield(), luaD_throw(), restorestack, setobjs2s, and lua_State::top.

Referenced by luaG_runerror().

◆ luaG_opinterror()

l_noret luaG_opinterror ( lua_State * L,
const TValue * p1,
const TValue * p2,
const char * msg )

Definition at line 598 of file lua-5.3.6/src/ldebug.c.

599 {
600 lua_Number temp;
601 if (!tonumber(p1, &temp)) /* first operand is wrong? */
602 p2 = p1; /* now second is wrong */
603 luaG_typeerror(L, p2, msg);
604}
LUA_NUMBER lua_Number
#define tonumber(o, n)

References luaG_typeerror(), and tonumber.

Referenced by luaT_trybinTM().

◆ luaG_ordererror()

l_noret luaG_ordererror ( lua_State * L,
const TValue * p1,
const TValue * p2 )

Definition at line 618 of file lua-5.3.6/src/ldebug.c.

618 {
619 const char *t1 = luaT_objtypename(L, p1);
620 const char *t2 = luaT_objtypename(L, p2);
621 if (strcmp(t1, t2) == 0)
622 luaG_runerror(L, "attempt to compare two %s values", t1);
623 else
624 luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
625}
l_noret luaG_runerror(lua_State *L, const char *fmt,...)
const char * luaT_objtypename(lua_State *L, const TValue *o)

References luaG_runerror(), and luaT_objtypename().

◆ luaG_runerror()

l_noret luaG_runerror ( lua_State * L,
const char * fmt,
... )

Definition at line 653 of file lua-5.3.6/src/ldebug.c.

653 {
654 CallInfo *ci = L->ci;
655 const char *msg;
656 va_list argp;
657 luaC_checkGC(L); /* error message uses memory */
658 va_start(argp, fmt);
659 msg = luaO_pushvfstring(L, fmt, argp); /* format message */
660 va_end(argp);
661 if (isLua(ci)) /* if Lua function, add source:line information */
662 luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci));
663 luaG_errormsg(L);
664}
#define luaC_checkGC(L)
const char * luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp)
const char * luaG_addinfo(lua_State *L, const char *msg, TString *src, int line)
l_noret luaG_errormsg(lua_State *L)

References lua_State::ci, ci_func, currentline(), isLua, luaC_checkGC, luaG_addinfo(), luaG_errormsg(), and luaO_pushvfstring().

Referenced by luaG_ordererror(), luaG_tointerror(), and luaG_typeerror().

◆ luaG_tointerror()

l_noret luaG_tointerror ( lua_State * L,
const TValue * p1,
const TValue * p2 )

Definition at line 610 of file lua-5.3.6/src/ldebug.c.

610 {
611 lua_Integer temp;
612 if (!tointeger(p1, &temp))
613 p2 = p1;
614 luaG_runerror(L, "number%s has no integer representation", varinfo(L, p2));
615}
LUA_INTEGER lua_Integer
static const char * varinfo(lua_State *L, const TValue *o)
#define tointeger(o, i)

References luaG_runerror(), tointeger, and varinfo().

Referenced by luaT_trybinTM().

◆ luaG_traceexec()

void luaG_traceexec ( lua_State * L)

Definition at line 667 of file lua-5.3.6/src/ldebug.c.

667 {
668 CallInfo *ci = L->ci;
669 lu_byte mask = L->hookmask;
670 int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
671 if (counthook)
672 resethookcount(L); /* reset count */
673 else if (!(mask & LUA_MASKLINE))
674 return; /* no line hook and count != 0; nothing to be done */
675 if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
676 ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
677 return; /* do not call hook again (VM yielded, so it did not move) */
678 }
679 if (counthook)
680 luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */
681 if (mask & LUA_MASKLINE) {
682 Proto *p = ci_func(ci)->p;
683 int npc = pcRel(ci->u.l.savedpc, p);
684 int newline = getfuncline(p, npc);
685 if (npc == 0 || /* call linehook when enter a new function, */
686 ci->u.l.savedpc <= L->oldpc || /* when jump back (loop), or when */
687 newline != getfuncline(p, pcRel(L->oldpc, p))) /* enter a new line */
688 luaD_hook(L, LUA_HOOKLINE, newline); /* call line hook */
689 }
690 L->oldpc = ci->u.l.savedpc;
691 if (L->status == LUA_YIELD) { /* did hook yield? */
692 if (counthook)
693 L->hookcount = 1; /* undo decrement to zero */
694 ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
695 ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
696 ci->func = L->top - 1; /* protect stack below results */
698 }
699}
unsigned char lu_byte
#define LUA_MASKCOUNT
#define LUA_MASKLINE
#define LUA_HOOKCOUNT
#define LUA_YIELD
#define LUA_HOOKLINE
void luaD_hook(lua_State *L, int event, int line)
#define CIST_HOOKYIELD

References CallInfo::callstatus, lua_State::ci, ci_func, CIST_HOOKYIELD, CallInfo::func, getfuncline, lua_State::hookcount, lua_State::hookmask, CallInfo::l, LUA_HOOKCOUNT, LUA_HOOKLINE, LUA_MASKCOUNT, LUA_MASKLINE, LUA_YIELD, luaD_hook(), luaD_throw(), mask, lua_State::oldpc, Proto::p, pcRel, resethookcount, CallInfo::savedpc, lua_State::status, lua_State::top, and CallInfo::u.

◆ luaG_typeerror()

l_noret luaG_typeerror ( lua_State * L,
const TValue * o,
const char * op )

Definition at line 586 of file lua-5.3.6/src/ldebug.c.

586 {
587 const char *t = luaT_objtypename(L, o);
588 luaG_runerror(L, "attempt to %s a %s value%s", op, t, varinfo(L, o));
589}

References luaG_runerror(), luaT_objtypename(), and varinfo().

Referenced by luaG_concaterror(), and luaG_opinterror().

◆ swapextra()

static void swapextra ( lua_State * L)
static

Definition at line 62 of file lua-5.3.6/src/ldebug.c.

62 {
63 if (L->status == LUA_YIELD) {
64 CallInfo *ci = L->ci; /* get function that yielded */
65 StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
66 ci->func = restorestack(L, ci->extra);
67 ci->extra = savestack(L, temp);
68 }
69}
#define savestack(L, p)

References lua_State::ci, CallInfo::extra, CallInfo::func, LUA_YIELD, restorestack, savestack, and lua_State::status.

Referenced by lua_getinfo(), lua_getlocal(), and lua_setlocal().

◆ upvalname()

static const char * upvalname ( Proto * p,
int uv )
static

Definition at line 127 of file lua-5.3.6/src/ldebug.c.

127 {
128 TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);
129 if (s == NULL) return "?";
130 else return getstr(s);
131}
#define check_exp(c, e)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318
TString ** upvalues

References check_exp, getstr, NULL, s, and Proto::upvalues.

Referenced by getobjname(), and getupvalname().

◆ varinfo()

static const char * varinfo ( lua_State * L,
const TValue * o )
static

Definition at line 572 of file lua-5.3.6/src/ldebug.c.

572 {
573 const char *name = NULL; /* to avoid warnings */
574 CallInfo *ci = L->ci;
575 const char *kind = NULL;
576 if (isLua(ci)) {
577 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
578 if (!kind && isinstack(ci, o)) /* no? try a register */
579 kind = getobjname(ci_func(ci)->p, currentpc(ci),
580 cast_int(o - ci->u.l.base), &name);
581 }
582 return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : "";
583}
static int isinstack(CallInfo *ci, const TValue *o)
static const char * getupvalname(CallInfo *ci, const TValue *o, const char **name)

References CallInfo::base, cast_int, lua_State::ci, ci_func, currentpc(), getobjname(), getupvalname(), isinstack(), isLua, CallInfo::l, luaO_pushfstring(), name, NULL, and CallInfo::u.

Referenced by luaG_tointerror(), and luaG_typeerror().