diff options
Diffstat (limited to 'ldebug.c')
| -rw-r--r-- | ldebug.c | 92 |
1 files changed, 62 insertions, 30 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.121 2016/10/19 12:32:10 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.122 2017/04/26 17:46:52 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 | */ |
| @@ -350,28 +350,36 @@ static const char *getobjname (Proto *p, int lastpc, int reg, | |||
| 350 | 350 | ||
| 351 | 351 | ||
| 352 | /* | 352 | /* |
| 353 | ** find a "name" for the RK value 'c' | 353 | ** Find a "name" for the constant 'c'. |
| 354 | */ | 354 | */ |
| 355 | static void kname (Proto *p, int pc, int c, const char **name) { | 355 | static void kname (Proto *p, int c, const char **name) { |
| 356 | if (ISK(c)) { /* is 'c' a constant? */ | 356 | TValue *kvalue = &p->k[INDEXK(c)]; |
| 357 | TValue *kvalue = &p->k[INDEXK(c)]; | 357 | *name = (ttisstring(kvalue)) ? svalue(kvalue) : "?"; |
| 358 | if (ttisstring(kvalue)) { /* literal constant? */ | 358 | } |
| 359 | *name = svalue(kvalue); /* it is its own name */ | 359 | |
| 360 | return; | 360 | |
| 361 | } | 361 | /* |
| 362 | /* else no reasonable name found */ | 362 | ** Find a "name" for the register 'c'. |
| 363 | } | 363 | */ |
| 364 | else { /* 'c' is a register */ | 364 | static void rname (Proto *p, int pc, int c, const char **name) { |
| 365 | const char *what = getobjname(p, pc, c, name); /* search for 'c' */ | 365 | const char *what = getobjname(p, pc, c, name); /* search for 'c' */ |
| 366 | if (what && *what == 'c') { /* found a constant name? */ | 366 | if (!(what && *what == 'c')) /* did not find a constant name? */ |
| 367 | return; /* 'name' already filled */ | 367 | *name = "?"; |
| 368 | } | 368 | } |
| 369 | /* else no reasonable name found */ | 369 | |
| 370 | } | 370 | |
| 371 | *name = "?"; /* no reasonable name found */ | 371 | /* |
| 372 | ** Find a "name" for the R/K index 'c'. | ||
| 373 | */ | ||
| 374 | static void rkname (Proto *p, int pc, int c, const char **name) { | ||
| 375 | if (ISK(c)) /* is 'c' a constant? */ | ||
| 376 | kname(p, INDEXK(c), name); | ||
| 377 | else /* 'c' is a register */ | ||
| 378 | rname(p, pc, c, name); | ||
| 372 | } | 379 | } |
| 373 | 380 | ||
| 374 | 381 | ||
| 382 | |||
| 375 | static int filterpc (int pc, int jmptarget) { | 383 | static int filterpc (int pc, int jmptarget) { |
| 376 | if (pc < jmptarget) /* is code conditional (inside a jump)? */ | 384 | if (pc < jmptarget) /* is code conditional (inside a jump)? */ |
| 377 | return -1; /* cannot know who sets that register */ | 385 | return -1; /* cannot know who sets that register */ |
| @@ -428,8 +436,22 @@ static int findsetreg (Proto *p, int lastpc, int reg) { | |||
| 428 | } | 436 | } |
| 429 | 437 | ||
| 430 | 438 | ||
| 431 | static const char *getobjname (Proto *p, int lastpc, int reg, | 439 | /* |
| 432 | const char **name) { | 440 | ** Check whether table being indexed by instruction 'i' is the |
| 441 | ** environment '_ENV' | ||
| 442 | */ | ||
| 443 | static const char *gxf (Proto *p, int pc, Instruction i, int isup) { | ||
| 444 | int t = GETARG_B(i); /* table index */ | ||
| 445 | const char *name; /* name of indexed variable */ | ||
| 446 | if (isup) /* is an upvalue? */ | ||
| 447 | name = upvalname(p, t); | ||
| 448 | else | ||
| 449 | getobjname(p, pc, t, &name); | ||
| 450 | return (name && strcmp(name, LUA_ENV) == 0) ? "global" : "field"; | ||
| 451 | } | ||
| 452 | |||
| 453 | |||
| 454 | const char *getobjname (Proto *p, int lastpc, int reg, const char **name) { | ||
| 433 | int pc; | 455 | int pc; |
| 434 | *name = luaF_getlocalname(p, reg + 1, lastpc); | 456 | *name = luaF_getlocalname(p, reg + 1, lastpc); |
| 435 | if (*name) /* is a local? */ | 457 | if (*name) /* is a local? */ |
| @@ -446,15 +468,24 @@ static const char *getobjname (Proto *p, int lastpc, int reg, | |||
| 446 | return getobjname(p, pc, b, name); /* get name for 'b' */ | 468 | return getobjname(p, pc, b, name); /* get name for 'b' */ |
| 447 | break; | 469 | break; |
| 448 | } | 470 | } |
| 449 | case OP_GETTABUP: | 471 | case OP_GETTABUP: { |
| 472 | int k = GETARG_C(i); /* key index */ | ||
| 473 | kname(p, k, name); | ||
| 474 | return gxf(p, pc, i, 1); | ||
| 475 | } | ||
| 450 | case OP_GETTABLE: { | 476 | case OP_GETTABLE: { |
| 451 | int k = GETARG_C(i); /* key index */ | 477 | int k = GETARG_C(i); /* key index */ |
| 452 | int t = GETARG_B(i); /* table index */ | 478 | rname(p, pc, k, name); |
| 453 | const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ | 479 | return gxf(p, pc, i, 0); |
| 454 | ? luaF_getlocalname(p, t + 1, pc) | 480 | } |
| 455 | : upvalname(p, t); | 481 | case OP_GETI: { |
| 456 | kname(p, pc, k, name); | 482 | *name = "integer index"; |
| 457 | return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; | 483 | return "field"; |
| 484 | } | ||
| 485 | case OP_GETFIELD: { | ||
| 486 | int k = GETARG_C(i); /* key index */ | ||
| 487 | kname(p, k, name); | ||
| 488 | return gxf(p, pc, i, 0); | ||
| 458 | } | 489 | } |
| 459 | case OP_GETUPVAL: { | 490 | case OP_GETUPVAL: { |
| 460 | *name = upvalname(p, GETARG_B(i)); | 491 | *name = upvalname(p, GETARG_B(i)); |
| @@ -472,7 +503,7 @@ static const char *getobjname (Proto *p, int lastpc, int reg, | |||
| 472 | } | 503 | } |
| 473 | case OP_SELF: { | 504 | case OP_SELF: { |
| 474 | int k = GETARG_C(i); /* key index */ | 505 | int k = GETARG_C(i); /* key index */ |
| 475 | kname(p, pc, k, name); | 506 | rkname(p, pc, k, name); |
| 476 | return "method"; | 507 | return "method"; |
| 477 | } | 508 | } |
| 478 | default: break; /* go through to return NULL */ | 509 | default: break; /* go through to return NULL */ |
| @@ -508,9 +539,10 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci, | |||
| 508 | } | 539 | } |
| 509 | /* other instructions can do calls through metamethods */ | 540 | /* other instructions can do calls through metamethods */ |
| 510 | case OP_SELF: case OP_GETTABUP: case OP_GETTABLE: | 541 | case OP_SELF: case OP_GETTABUP: case OP_GETTABLE: |
| 542 | case OP_GETI: case OP_GETFIELD: | ||
| 511 | tm = TM_INDEX; | 543 | tm = TM_INDEX; |
| 512 | break; | 544 | break; |
| 513 | case OP_SETTABUP: case OP_SETTABLE: | 545 | case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD: |
| 514 | tm = TM_NEWINDEX; | 546 | tm = TM_NEWINDEX; |
| 515 | break; | 547 | break; |
| 516 | case OP_ADDI: | 548 | case OP_ADDI: |
