summaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-09-13 14:40:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-09-13 14:40:20 -0300
commit05de3147012dd955649eaba96904394404ef3753 (patch)
treeaa46748e75b681ea65d363597344b6ef5cd7bd3b /ldebug.c
parentd281d23f8dbd3e29e805176d51161c943bc6196e (diff)
downloadlua-05de3147012dd955649eaba96904394404ef3753.tar.gz
lua-05de3147012dd955649eaba96904394404ef3753.tar.bz2
lua-05de3147012dd955649eaba96904394404ef3753.zip
upvalue names always can be NULL (if debug info was removed), so
always check for that case
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/ldebug.c b/ldebug.c
index 1dfac128..062fd304 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.83 2011/08/09 20:58:29 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.84 2011/08/12 20:01:44 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -94,6 +94,13 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
94} 94}
95 95
96 96
97static const char *upvalname (Proto *p, int uv) {
98 TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);
99 if (s == NULL) return "?";
100 else return getstr(s);
101}
102
103
97static const char *findvararg (CallInfo *ci, int n, StkId *pos) { 104static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
98 int nparams = clLvalue(ci->func)->p->numparams; 105 int nparams = clLvalue(ci->func)->p->numparams;
99 if (n >= ci->u.l.base - ci->func - nparams) 106 if (n >= ci->u.l.base - ci->func - nparams)
@@ -376,9 +383,9 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
376 if (pc != -1) { /* could find instruction? */ 383 if (pc != -1) { /* could find instruction? */
377 Instruction i = p->code[pc]; 384 Instruction i = p->code[pc];
378 OpCode op = GET_OPCODE(i); 385 OpCode op = GET_OPCODE(i);
379 int a = GETARG_A(i);
380 switch (op) { 386 switch (op) {
381 case OP_MOVE: { 387 case OP_MOVE: {
388 int a = GETARG_A(i);
382 int b = GETARG_B(i); /* move from 'b' to 'a' */ 389 int b = GETARG_B(i); /* move from 'b' to 'a' */
383 lua_assert(reg == a); 390 lua_assert(reg == a);
384 if (b < a) 391 if (b < a)
@@ -390,14 +397,13 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
390 int t = GETARG_B(i); 397 int t = GETARG_B(i);
391 const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ 398 const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
392 ? luaF_getlocalname(p, t + 1, pc) 399 ? luaF_getlocalname(p, t + 1, pc)
393 : getstr(p->upvalues[t].name); 400 : upvalname(p, t);
394 kname(p, pc, k, name); 401 kname(p, pc, k, name);
395 return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; 402 return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
396 } 403 }
397 case OP_GETUPVAL: { 404 case OP_GETUPVAL: {
398 int u = GETARG_B(i); /* upvalue index */ 405 int u = GETARG_B(i); /* upvalue index */
399 TString *tn = p->upvalues[u].name; 406 *name = upvalname(p, u);
400 *name = tn ? getstr(tn) : "?";
401 return "upvalue"; 407 return "upvalue";
402 } 408 }
403 case OP_LOADK: 409 case OP_LOADK:
@@ -476,12 +482,12 @@ static int isinstack (CallInfo *ci, const TValue *o) {
476 482
477 483
478static const char *getupvalname (CallInfo *ci, const TValue *o, 484static const char *getupvalname (CallInfo *ci, const TValue *o,
479 const char **name) { 485 const char **name) {
480 LClosure *c = ci_func(ci); 486 LClosure *c = ci_func(ci);
481 int i; 487 int i;
482 for (i = 0; i < c->nupvalues; i++) { 488 for (i = 0; i < c->nupvalues; i++) {
483 if (c->upvals[i]->v == o) { 489 if (c->upvals[i]->v == o) {
484 *name = getstr(c->p->upvalues[i].name); 490 *name = upvalname(c->p, i);
485 return "upvalue"; 491 return "upvalue";
486 } 492 }
487 } 493 }