diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 36 |
1 files changed, 19 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.11 2004/12/03 20:35:33 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.12 2004/12/20 15:50:00 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 | */ |
@@ -30,17 +30,18 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | 32 | ||
33 | static const char *getfuncname (CallInfo *ci, const char **name); | 33 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); |
34 | 34 | ||
35 | 35 | ||
36 | static int currentpc (CallInfo *ci) { | 36 | static int currentpc (lua_State *L, CallInfo *ci) { |
37 | UNUSED(L); | ||
37 | if (!isLua(ci)) return -1; /* function is not a Lua function? */ | 38 | if (!isLua(ci)) return -1; /* function is not a Lua function? */ |
38 | return pcRel(ci->savedpc, ci_func(ci)->l.p); | 39 | return pcRel(ci->savedpc, ci_func(ci)->l.p); |
39 | } | 40 | } |
40 | 41 | ||
41 | 42 | ||
42 | static int currentline (CallInfo *ci) { | 43 | static int currentline (lua_State *L, CallInfo *ci) { |
43 | int pc = currentpc(ci); | 44 | int pc = currentpc(L, ci); |
44 | if (pc < 0) | 45 | if (pc < 0) |
45 | return -1; /* only active lua functions have current-line information */ | 46 | return -1; /* only active lua functions have current-line information */ |
46 | else | 47 | else |
@@ -116,7 +117,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
116 | ci = L->base_ci + ar->i_ci; | 117 | ci = L->base_ci + ar->i_ci; |
117 | fp = getluaproto(ci); | 118 | fp = getluaproto(ci); |
118 | if (fp) { /* is a Lua function? */ | 119 | if (fp) { /* is a Lua function? */ |
119 | name = luaF_getlocalname(fp, n, currentpc(ci)); | 120 | name = luaF_getlocalname(fp, n, currentpc(L, ci)); |
120 | if (name) | 121 | if (name) |
121 | luaA_pushobject(L, ci->base+(n-1)); /* push value */ | 122 | luaA_pushobject(L, ci->base+(n-1)); /* push value */ |
122 | } | 123 | } |
@@ -135,7 +136,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
135 | fp = getluaproto(ci); | 136 | fp = getluaproto(ci); |
136 | L->top--; /* pop new value */ | 137 | L->top--; /* pop new value */ |
137 | if (fp) { /* is a Lua function? */ | 138 | if (fp) { /* is a Lua function? */ |
138 | name = luaF_getlocalname(fp, n, currentpc(ci)); | 139 | name = luaF_getlocalname(fp, n, currentpc(L, ci)); |
139 | if (!name || name[0] == '(') /* `(' starts private locals */ | 140 | if (!name || name[0] == '(') /* `(' starts private locals */ |
140 | name = NULL; | 141 | name = NULL; |
141 | else | 142 | else |
@@ -183,7 +184,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, | |||
183 | break; | 184 | break; |
184 | } | 185 | } |
185 | case 'l': { | 186 | case 'l': { |
186 | ar->currentline = (ci) ? currentline(ci) : -1; | 187 | ar->currentline = (ci) ? currentline(L, ci) : -1; |
187 | break; | 188 | break; |
188 | } | 189 | } |
189 | case 'u': { | 190 | case 'u': { |
@@ -191,7 +192,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, | |||
191 | break; | 192 | break; |
192 | } | 193 | } |
193 | case 'n': { | 194 | case 'n': { |
194 | ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL; | 195 | ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; |
195 | if (ar->namewhat == NULL) { | 196 | if (ar->namewhat == NULL) { |
196 | ar->namewhat = ""; /* not found */ | 197 | ar->namewhat = ""; /* not found */ |
197 | ar->name = NULL; | 198 | ar->name = NULL; |
@@ -446,10 +447,11 @@ static const char *kname (Proto *p, int c) { | |||
446 | } | 447 | } |
447 | 448 | ||
448 | 449 | ||
449 | static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { | 450 | static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, |
451 | const char **name) { | ||
450 | if (isLua(ci)) { /* a Lua function? */ | 452 | if (isLua(ci)) { /* a Lua function? */ |
451 | Proto *p = ci_func(ci)->l.p; | 453 | Proto *p = ci_func(ci)->l.p; |
452 | int pc = currentpc(ci); | 454 | int pc = currentpc(L, ci); |
453 | Instruction i; | 455 | Instruction i; |
454 | *name = luaF_getlocalname(p, stackpos+1, pc); | 456 | *name = luaF_getlocalname(p, stackpos+1, pc); |
455 | if (*name) /* is a local? */ | 457 | if (*name) /* is a local? */ |
@@ -467,7 +469,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { | |||
467 | int a = GETARG_A(i); | 469 | int a = GETARG_A(i); |
468 | int b = GETARG_B(i); /* move from `b' to `a' */ | 470 | int b = GETARG_B(i); /* move from `b' to `a' */ |
469 | if (b < a) | 471 | if (b < a) |
470 | return getobjname(ci, b, name); /* get name for `b' */ | 472 | return getobjname(L, ci, b, name); /* get name for `b' */ |
471 | break; | 473 | break; |
472 | } | 474 | } |
473 | case OP_GETTABLE: { | 475 | case OP_GETTABLE: { |
@@ -492,15 +494,15 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { | |||
492 | } | 494 | } |
493 | 495 | ||
494 | 496 | ||
495 | static const char *getfuncname (CallInfo *ci, const char **name) { | 497 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { |
496 | Instruction i; | 498 | Instruction i; |
497 | if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) | 499 | if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) |
498 | return NULL; /* calling function is not Lua (or is unknown) */ | 500 | return NULL; /* calling function is not Lua (or is unknown) */ |
499 | ci--; /* calling function */ | 501 | ci--; /* calling function */ |
500 | i = ci_func(ci)->l.p->code[currentpc(ci)]; | 502 | i = ci_func(ci)->l.p->code[currentpc(L, ci)]; |
501 | if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || | 503 | if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || |
502 | GET_OPCODE(i) == OP_TFORLOOP) | 504 | GET_OPCODE(i) == OP_TFORLOOP) |
503 | return getobjname(ci, GETARG_A(i), name); | 505 | return getobjname(L, ci, GETARG_A(i), name); |
504 | else | 506 | else |
505 | return NULL; /* no useful name can be found */ | 507 | return NULL; /* no useful name can be found */ |
506 | } | 508 | } |
@@ -519,7 +521,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { | |||
519 | const char *name = NULL; | 521 | const char *name = NULL; |
520 | const char *t = luaT_typenames[ttype(o)]; | 522 | const char *t = luaT_typenames[ttype(o)]; |
521 | const char *kind = (isinstack(L->ci, o)) ? | 523 | const char *kind = (isinstack(L->ci, o)) ? |
522 | getobjname(L->ci, o - L->base, &name) : NULL; | 524 | getobjname(L, L->ci, o - L->base, &name) : NULL; |
523 | if (kind) | 525 | if (kind) |
524 | luaG_runerror(L, "attempt to %s %s `%s' (a %s value)", | 526 | luaG_runerror(L, "attempt to %s %s `%s' (a %s value)", |
525 | op, kind, name, t); | 527 | op, kind, name, t); |
@@ -558,7 +560,7 @@ static void addinfo (lua_State *L, const char *msg) { | |||
558 | CallInfo *ci = L->ci; | 560 | CallInfo *ci = L->ci; |
559 | if (isLua(ci)) { /* is Lua code? */ | 561 | if (isLua(ci)) { /* is Lua code? */ |
560 | char buff[LUA_IDSIZE]; /* add file:line information */ | 562 | char buff[LUA_IDSIZE]; /* add file:line information */ |
561 | int line = currentline(ci); | 563 | int line = currentline(L, ci); |
562 | luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); | 564 | luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); |
563 | luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); | 565 | luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); |
564 | } | 566 | } |