diff options
Diffstat (limited to 'ldebug.c')
| -rw-r--r-- | ldebug.c | 44 |
1 files changed, 32 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.79 2011/04/18 19:49:13 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.80 2011/04/19 16:22:13 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 | */ |
| @@ -284,15 +284,32 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
| 284 | ** ======================================================= | 284 | ** ======================================================= |
| 285 | */ | 285 | */ |
| 286 | 286 | ||
| 287 | static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | ||
| 288 | const char **name); | ||
| 287 | 289 | ||
| 288 | static void kname (Proto *p, int c, int reg, const char *what, | 290 | |
| 289 | const char **name) { | 291 | /* |
| 290 | if (c == reg && what && *what == 'c') | 292 | ** find a "name" for the RK value 'c' |
| 291 | return; /* index is a constant; name already correct */ | 293 | */ |
| 292 | else if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) | 294 | static void kname (lua_State *L, CallInfo *ci, int c, int oreg, |
| 293 | *name = svalue(&p->k[INDEXK(c)]); | 295 | const char *what, const char **name) { |
| 294 | else | 296 | if (ISK(c)) { /* is 'c' a constant? */ |
| 295 | *name = "?"; | 297 | TValue *kvalue = &ci_func(ci)->l.p->k[INDEXK(c)]; |
| 298 | if (ttisstring(kvalue)) { /* literal constant? */ | ||
| 299 | *name = svalue(kvalue); /* it is its own name */ | ||
| 300 | return; | ||
| 301 | } | ||
| 302 | /* else no reasonable name found */ | ||
| 303 | } | ||
| 304 | else { /* 'c' is a register */ | ||
| 305 | if (c != oreg) /* not the original register? */ | ||
| 306 | what = getobjname(L, ci, c, name); /* search for 'c' */ | ||
| 307 | if (what && *what == 'c') { /* found a constant name? */ | ||
| 308 | return; /* 'name' already filled */ | ||
| 309 | } | ||
| 310 | /* else no reasonable name found */ | ||
| 311 | } | ||
| 312 | *name = "?"; /* no reasonable name found */ | ||
| 296 | } | 313 | } |
| 297 | 314 | ||
| 298 | 315 | ||
| @@ -328,7 +345,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
| 328 | const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ | 345 | const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ |
| 329 | ? luaF_getlocalname(p, t + 1, pc) | 346 | ? luaF_getlocalname(p, t + 1, pc) |
| 330 | : getstr(p->upvalues[t].name); | 347 | : getstr(p->upvalues[t].name); |
| 331 | kname(p, k, a, what, name); | 348 | kname(L, ci, k, a, what, name); |
| 332 | what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; | 349 | what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; |
| 333 | } | 350 | } |
| 334 | break; | 351 | break; |
| @@ -363,7 +380,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
| 363 | case OP_SELF: { | 380 | case OP_SELF: { |
| 364 | if (reg == a) { | 381 | if (reg == a) { |
| 365 | int k = GETARG_C(i); /* key index */ | 382 | int k = GETARG_C(i); /* key index */ |
| 366 | kname(p, k, a, what, name); | 383 | kname(L, ci, k, a, what, name); |
| 367 | what = "method"; | 384 | what = "method"; |
| 368 | } | 385 | } |
| 369 | break; | 386 | break; |
| @@ -443,7 +460,10 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | |||
| 443 | 460 | ||
| 444 | 461 | ||
| 445 | 462 | ||
| 446 | /* only ANSI way to check whether a pointer points to an array */ | 463 | /* |
| 464 | ** only ANSI way to check whether a pointer points to an array | ||
| 465 | ** (used only for error messages, so efficiency is not a big concern) | ||
| 466 | */ | ||
| 447 | static int isinstack (CallInfo *ci, const TValue *o) { | 467 | static int isinstack (CallInfo *ci, const TValue *o) { |
| 448 | StkId p; | 468 | StkId p; |
| 449 | for (p = ci->u.l.base; p < ci->top; p++) | 469 | for (p = ci->u.l.base; p < ci->top; p++) |
