aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ldebug.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/ldebug.c b/ldebug.c
index 18bdc595..9110f437 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -33,6 +33,8 @@
33 33
34#define LuaClosure(f) ((f) != NULL && (f)->c.tt == LUA_VLCL) 34#define LuaClosure(f) ((f) != NULL && (f)->c.tt == LUA_VLCL)
35 35
36static const char strlocal[] = "local";
37static const char strupval[] = "upvalue";
36 38
37static const char *funcnamefromcall (lua_State *L, CallInfo *ci, 39static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
38 const char **name); 40 const char **name);
@@ -505,7 +507,7 @@ static const char *basicgetobjname (const Proto *p, int *ppc, int reg,
505 int pc = *ppc; 507 int pc = *ppc;
506 *name = luaF_getlocalname(p, reg + 1, pc); 508 *name = luaF_getlocalname(p, reg + 1, pc);
507 if (*name) /* is a local? */ 509 if (*name) /* is a local? */
508 return "local"; 510 return strlocal;
509 /* else try symbolic execution */ 511 /* else try symbolic execution */
510 *ppc = pc = findsetreg(p, pc, reg); 512 *ppc = pc = findsetreg(p, pc, reg);
511 if (pc != -1) { /* could find instruction? */ 513 if (pc != -1) { /* could find instruction? */
@@ -520,7 +522,7 @@ static const char *basicgetobjname (const Proto *p, int *ppc, int reg,
520 } 522 }
521 case OP_GETUPVAL: { 523 case OP_GETUPVAL: {
522 *name = upvalname(p, GETARG_B(i)); 524 *name = upvalname(p, GETARG_B(i));
523 return "upvalue"; 525 return strupval;
524 } 526 }
525 case OP_LOADK: return kname(p, GETARG_Bx(i), name); 527 case OP_LOADK: return kname(p, GETARG_Bx(i), name);
526 case OP_LOADKX: return kname(p, GETARG_Ax(p->code[pc + 1]), name); 528 case OP_LOADKX: return kname(p, GETARG_Ax(p->code[pc + 1]), name);
@@ -550,8 +552,13 @@ static const char *isEnv (const Proto *p, int pc, Instruction i, int isup) {
550 const char *name; /* name of indexed variable */ 552 const char *name; /* name of indexed variable */
551 if (isup) /* is 't' an upvalue? */ 553 if (isup) /* is 't' an upvalue? */
552 name = upvalname(p, t); 554 name = upvalname(p, t);
553 else /* 't' is a register */ 555 else { /* 't' is a register */
554 basicgetobjname(p, &pc, t, &name); 556 const char *what = basicgetobjname(p, &pc, t, &name);
557 /* 'name' must be the name of a local variable (at the current
558 level or an upvalue) */
559 if (what != strlocal && what != strupval)
560 name = NULL; /* cannot be the variable _ENV */
561 }
555 return (name && strcmp(name, LUA_ENV) == 0) ? "global" : "field"; 562 return (name && strcmp(name, LUA_ENV) == 0) ? "global" : "field";
556} 563}
557 564
@@ -698,7 +705,7 @@ static const char *getupvalname (CallInfo *ci, const TValue *o,
698 for (i = 0; i < c->nupvalues; i++) { 705 for (i = 0; i < c->nupvalues; i++) {
699 if (c->upvals[i]->v.p == o) { 706 if (c->upvals[i]->v.p == o) {
700 *name = upvalname(c->p, i); 707 *name = upvalname(c->p, i);
701 return "upvalue"; 708 return strupval;
702 } 709 }
703 } 710 }
704 return NULL; 711 return NULL;
@@ -810,16 +817,15 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
810/* add src:line information to 'msg' */ 817/* add src:line information to 'msg' */
811const char *luaG_addinfo (lua_State *L, const char *msg, TString *src, 818const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
812 int line) { 819 int line) {
813 char buff[LUA_IDSIZE]; 820 if (src == NULL) /* no debug information? */
814 if (src) { 821 return luaO_pushfstring(L, "?:?: %s", msg);
822 else {
823 char buff[LUA_IDSIZE];
815 size_t idlen; 824 size_t idlen;
816 const char *id = getlstr(src, idlen); 825 const char *id = getlstr(src, idlen);
817 luaO_chunkid(buff, id, idlen); 826 luaO_chunkid(buff, id, idlen);
827 return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
818 } 828 }
819 else { /* no source available; use "?" instead */
820 buff[0] = '?'; buff[1] = '\0';
821 }
822 return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
823} 829}
824 830
825 831
@@ -832,6 +838,10 @@ l_noret luaG_errormsg (lua_State *L) {
832 L->top.p++; /* assume EXTRA_STACK */ 838 L->top.p++; /* assume EXTRA_STACK */
833 luaD_callnoyield(L, L->top.p - 2, 1); /* call it */ 839 luaD_callnoyield(L, L->top.p - 2, 1); /* call it */
834 } 840 }
841 if (ttisnil(s2v(L->top.p - 1))) { /* error object is nil? */
842 /* change it to a proper message */
843 setsvalue2s(L, L->top.p - 1, luaS_newliteral(L, "<no error object>"));
844 }
835 luaD_throw(L, LUA_ERRRUN); 845 luaD_throw(L, LUA_ERRRUN);
836} 846}
837 847
@@ -841,12 +851,8 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
841 const char *msg; 851 const char *msg;
842 va_list argp; 852 va_list argp;
843 luaC_checkGC(L); /* error message uses memory */ 853 luaC_checkGC(L); /* error message uses memory */
844 va_start(argp, fmt); 854 pushvfstring(L, argp, fmt, msg);
845 msg = luaO_pushvfstring(L, fmt, argp); /* format message */ 855 if (isLua(ci)) { /* Lua function? */
846 va_end(argp);
847 if (msg == NULL) /* no memory to format message? */
848 luaD_throw(L, LUA_ERRMEM);
849 else if (isLua(ci)) { /* Lua function? */
850 /* add source:line information */ 856 /* add source:line information */
851 luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci)); 857 luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci));
852 setobjs2s(L, L->top.p - 2, L->top.p - 1); /* remove 'msg' */ 858 setobjs2s(L, L->top.p - 2, L->top.p - 1); /* remove 'msg' */