diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 40 |
1 files changed, 10 insertions, 30 deletions
@@ -54,13 +54,6 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { | |||
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | static CallInfo *ci_stack (lua_State *L, StkId obj) { | ||
58 | CallInfo *ci = L->ci; | ||
59 | while (ci->base > obj && ci > L->base_ci) ci--; | ||
60 | return ci; | ||
61 | } | ||
62 | |||
63 | |||
64 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | 57 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { |
65 | int status; | 58 | int status; |
66 | lua_lock(L); | 59 | lua_lock(L); |
@@ -283,6 +276,7 @@ static int checklineinfo (const Proto *pt) { | |||
283 | int *lineinfo = pt->lineinfo; | 276 | int *lineinfo = pt->lineinfo; |
284 | if (lineinfo == NULL) return 1; | 277 | if (lineinfo == NULL) return 1; |
285 | check(pt->sizelineinfo >= 2 && lineinfo[pt->sizelineinfo-1] == MAX_INT); | 278 | check(pt->sizelineinfo >= 2 && lineinfo[pt->sizelineinfo-1] == MAX_INT); |
279 | lua_assert(luaG_getline(lineinfo, pt->sizecode-1, 1, NULL) < MAX_INT); | ||
286 | if (*lineinfo < 0) lineinfo++; | 280 | if (*lineinfo < 0) lineinfo++; |
287 | check(*lineinfo == 0); | 281 | check(*lineinfo == 0); |
288 | return 1; | 282 | return 1; |
@@ -292,7 +286,7 @@ static int checklineinfo (const Proto *pt) { | |||
292 | static int precheck (const Proto *pt) { | 286 | static int precheck (const Proto *pt) { |
293 | check(checklineinfo(pt)); | 287 | check(checklineinfo(pt)); |
294 | check(pt->maxstacksize <= MAXSTACK); | 288 | check(pt->maxstacksize <= MAXSTACK); |
295 | check(pt->numparams+pt->is_vararg <= pt->maxstacksize); | 289 | lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize); |
296 | check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); | 290 | check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); |
297 | return 1; | 291 | return 1; |
298 | } | 292 | } |
@@ -381,7 +375,9 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { | |||
381 | check(c < MAXSTACK && b < c); | 375 | check(c < MAXSTACK && b < c); |
382 | break; | 376 | break; |
383 | } | 377 | } |
384 | case OP_JMP: { | 378 | case OP_JMP: |
379 | case OP_FORLOOP: | ||
380 | case OP_TFORLOOP: { | ||
385 | int dest = pc+1+b; | 381 | int dest = pc+1+b; |
386 | check(0 <= dest && dest < pt->sizecode); | 382 | check(0 <= dest && dest < pt->sizecode); |
387 | /* not full check and jump is forward and do not skip `lastpc'? */ | 383 | /* not full check and jump is forward and do not skip `lastpc'? */ |
@@ -407,21 +403,6 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { | |||
407 | if (b > 0) checkreg(pt, a+b-1); | 403 | if (b > 0) checkreg(pt, a+b-1); |
408 | break; | 404 | break; |
409 | } | 405 | } |
410 | case OP_FORPREP: | ||
411 | case OP_TFORPREP: { | ||
412 | int dest = pc-b; /* jump is negated here */ | ||
413 | check(0 <= dest && dest < pt->sizecode && | ||
414 | GET_OPCODE(pt->code[dest]) == op+1); | ||
415 | break; | ||
416 | } | ||
417 | case OP_FORLOOP: | ||
418 | case OP_TFORLOOP: { | ||
419 | int dest = pc+b; | ||
420 | check(0 <= dest && dest < pt->sizecode && | ||
421 | pt->code[dest] == SET_OPCODE(i, op-1)); | ||
422 | checkreg(pt, a + ((op == OP_FORLOOP) ? 2 : 3)); | ||
423 | break; | ||
424 | } | ||
425 | case OP_SETLIST: { | 406 | case OP_SETLIST: { |
426 | checkreg(pt, a + (b&(LFIELDS_PER_FLUSH-1)) + 1); | 407 | checkreg(pt, a + (b&(LFIELDS_PER_FLUSH-1)) + 1); |
427 | break; | 408 | break; |
@@ -445,12 +426,11 @@ int luaG_checkcode (const Proto *pt) { | |||
445 | } | 426 | } |
446 | 427 | ||
447 | 428 | ||
448 | static const char *getobjname (lua_State *L, StkId obj, const char **name) { | 429 | static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, |
449 | CallInfo *ci = ci_stack(L, obj); | 430 | const char **name) { |
450 | if (isLmark(ci)) { /* an active Lua function? */ | 431 | if (isLmark(ci)) { /* an active Lua function? */ |
451 | Proto *p = ci_func(ci)->l.p; | 432 | Proto *p = ci_func(ci)->l.p; |
452 | int pc = currentpc(L, ci); | 433 | int pc = currentpc(L, ci); |
453 | int stackpos = obj - ci->base; | ||
454 | Instruction i; | 434 | Instruction i; |
455 | *name = luaF_getlocalname(p, stackpos+1, pc); | 435 | *name = luaF_getlocalname(p, stackpos+1, pc); |
456 | if (*name) /* is a local? */ | 436 | if (*name) /* is a local? */ |
@@ -467,7 +447,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
467 | int a = GETARG_A(i); | 447 | int a = GETARG_A(i); |
468 | int b = GETARG_B(i); /* move from `b' to `a' */ | 448 | int b = GETARG_B(i); /* move from `b' to `a' */ |
469 | if (b < a) | 449 | if (b < a) |
470 | return getobjname(L, ci->base+b, name); /* get name for `b' */ | 450 | return getobjname(L, ci, b, name); /* get name for `b' */ |
471 | break; | 451 | break; |
472 | } | 452 | } |
473 | case OP_GETTABLE: | 453 | case OP_GETTABLE: |
@@ -496,7 +476,7 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | |||
496 | Instruction i; | 476 | Instruction i; |
497 | i = p->code[pc]; | 477 | i = p->code[pc]; |
498 | return (GET_OPCODE(i) == OP_CALL | 478 | return (GET_OPCODE(i) == OP_CALL |
499 | ? getobjname(L, ci->base+GETARG_A(i), name) | 479 | ? getobjname(L, ci, GETARG_A(i), name) |
500 | : NULL); /* no useful name found */ | 480 | : NULL); /* no useful name found */ |
501 | } | 481 | } |
502 | } | 482 | } |
@@ -504,7 +484,7 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | |||
504 | 484 | ||
505 | void luaG_typeerror (lua_State *L, StkId o, const char *op) { | 485 | void luaG_typeerror (lua_State *L, StkId o, const char *op) { |
506 | const char *name; | 486 | const char *name; |
507 | const char *kind = getobjname(L, o, &name); | 487 | const char *kind = getobjname(L, L->ci, o - L->ci->base, &name); /* ?? */ |
508 | const char *t = luaT_typenames[ttype(o)]; | 488 | const char *t = luaT_typenames[ttype(o)]; |
509 | if (kind) | 489 | if (kind) |
510 | luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", | 490 | luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", |