upvalue names always can be NULL (if debug info was removed), so

always check for that case
This commit is contained in:
Roberto Ierusalimschy
2011-09-13 14:40:20 -03:00
parent d281d23f8d
commit 05de314701

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.c,v 2.83 2011/08/09 20:58:29 roberto Exp roberto $ ** $Id: ldebug.c,v 2.84 2011/08/12 20:01:44 roberto Exp roberto $
** Debug Interface ** Debug Interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -94,6 +94,13 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
} }
static const char *upvalname (Proto *p, int uv) {
TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);
if (s == NULL) return "?";
else return getstr(s);
}
static const char *findvararg (CallInfo *ci, int n, StkId *pos) { static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
int nparams = clLvalue(ci->func)->p->numparams; int nparams = clLvalue(ci->func)->p->numparams;
if (n >= ci->u.l.base - ci->func - nparams) if (n >= ci->u.l.base - ci->func - nparams)
@@ -376,9 +383,9 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
if (pc != -1) { /* could find instruction? */ if (pc != -1) { /* could find instruction? */
Instruction i = p->code[pc]; Instruction i = p->code[pc];
OpCode op = GET_OPCODE(i); OpCode op = GET_OPCODE(i);
int a = GETARG_A(i);
switch (op) { switch (op) {
case OP_MOVE: { case OP_MOVE: {
int a = GETARG_A(i);
int b = GETARG_B(i); /* move from 'b' to 'a' */ int b = GETARG_B(i); /* move from 'b' to 'a' */
lua_assert(reg == a); lua_assert(reg == a);
if (b < a) if (b < a)
@@ -390,14 +397,13 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
int t = GETARG_B(i); int t = GETARG_B(i);
const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
? luaF_getlocalname(p, t + 1, pc) ? luaF_getlocalname(p, t + 1, pc)
: getstr(p->upvalues[t].name); : upvalname(p, t);
kname(p, pc, k, name); kname(p, pc, k, name);
return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
} }
case OP_GETUPVAL: { case OP_GETUPVAL: {
int u = GETARG_B(i); /* upvalue index */ int u = GETARG_B(i); /* upvalue index */
TString *tn = p->upvalues[u].name; *name = upvalname(p, u);
*name = tn ? getstr(tn) : "?";
return "upvalue"; return "upvalue";
} }
case OP_LOADK: case OP_LOADK:
@@ -481,7 +487,7 @@ static const char *getupvalname (CallInfo *ci, const TValue *o,
int i; int i;
for (i = 0; i < c->nupvalues; i++) { for (i = 0; i < c->nupvalues; i++) {
if (c->upvals[i]->v == o) { if (c->upvals[i]->v == o) {
*name = getstr(c->p->upvalues[i].name); *name = upvalname(c->p, i);
return "upvalue"; return "upvalue";
} }
} }