diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 41 |
1 files changed, 20 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.127 2002/08/06 15:32:22 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.128 2002/08/06 18:01:50 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 | */ |
@@ -25,14 +25,14 @@ | |||
25 | 25 | ||
26 | 26 | ||
27 | 27 | ||
28 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); | 28 | static const char *getfuncname (CallInfo *ci, const char **name); |
29 | 29 | ||
30 | 30 | ||
31 | static int isLua (CallInfo *ci) { | 31 | static int isLua (CallInfo *ci) { |
32 | return isLfunction (ci->base - 1); | 32 | return isLfunction (ci->base - 1); |
33 | } | 33 | } |
34 | 34 | ||
35 | static int currentpc (lua_State *L, CallInfo *ci) { | 35 | static int currentpc (CallInfo *ci) { |
36 | if (!isLua(ci)) return -1; /* function is not a Lua function? */ | 36 | if (!isLua(ci)) return -1; /* function is not a Lua function? */ |
37 | if (ci->pc != &luaV_callingmark) /* is not calling another Lua function? */ | 37 | if (ci->pc != &luaV_callingmark) /* is not calling another Lua function? */ |
38 | ci->u.l.savedpc = *ci->pc; /* `pc' may not be saved; save it */ | 38 | ci->u.l.savedpc = *ci->pc; /* `pc' may not be saved; save it */ |
@@ -41,8 +41,8 @@ static int currentpc (lua_State *L, CallInfo *ci) { | |||
41 | } | 41 | } |
42 | 42 | ||
43 | 43 | ||
44 | static int currentline (lua_State *L, CallInfo *ci) { | 44 | static int currentline (CallInfo *ci) { |
45 | int pc = currentpc(L, ci); | 45 | int pc = currentpc(ci); |
46 | if (pc < 0) | 46 | if (pc < 0) |
47 | return -1; /* only active lua functions have current-line information */ | 47 | return -1; /* only active lua functions have current-line information */ |
48 | else | 48 | else |
@@ -62,7 +62,7 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask) { | |||
62 | setallowhook(L, allow); | 62 | setallowhook(L, allow); |
63 | resethookcount(L); | 63 | resethookcount(L); |
64 | for (ci = L->ci; ci != L->base_ci; ci--) /* update all `savedpc's */ | 64 | for (ci = L->ci; ci != L->base_ci; ci--) /* update all `savedpc's */ |
65 | currentpc(L, ci); | 65 | currentpc(ci); |
66 | lua_unlock(L); | 66 | lua_unlock(L); |
67 | return 1; | 67 | return 1; |
68 | } | 68 | } |
@@ -105,7 +105,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
105 | ci = L->base_ci + ar->i_ci; | 105 | ci = L->base_ci + ar->i_ci; |
106 | fp = getluaproto(ci); | 106 | fp = getluaproto(ci); |
107 | if (fp) { /* is a Lua function? */ | 107 | if (fp) { /* is a Lua function? */ |
108 | name = luaF_getlocalname(fp, n, currentpc(L, ci)); | 108 | name = luaF_getlocalname(fp, n, currentpc(ci)); |
109 | if (name) | 109 | if (name) |
110 | luaA_pushobject(L, ci->base+(n-1)); /* push value */ | 110 | luaA_pushobject(L, ci->base+(n-1)); /* push value */ |
111 | } | 111 | } |
@@ -124,7 +124,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
124 | fp = getluaproto(ci); | 124 | fp = getluaproto(ci); |
125 | L->top--; /* pop new value */ | 125 | L->top--; /* pop new value */ |
126 | if (fp) { /* is a Lua function? */ | 126 | if (fp) { /* is a Lua function? */ |
127 | name = luaF_getlocalname(fp, n, currentpc(L, ci)); | 127 | name = luaF_getlocalname(fp, n, currentpc(ci)); |
128 | if (!name || name[0] == '(') /* `(' starts private locals */ | 128 | if (!name || name[0] == '(') /* `(' starts private locals */ |
129 | name = NULL; | 129 | name = NULL; |
130 | else | 130 | else |
@@ -205,7 +205,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
205 | break; | 205 | break; |
206 | } | 206 | } |
207 | case 'l': { | 207 | case 'l': { |
208 | ar->currentline = (ci) ? currentline(L, ci) : -1; | 208 | ar->currentline = (ci) ? currentline(ci) : -1; |
209 | break; | 209 | break; |
210 | } | 210 | } |
211 | case 'u': { | 211 | case 'u': { |
@@ -213,7 +213,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
213 | break; | 213 | break; |
214 | } | 214 | } |
215 | case 'n': { | 215 | case 'n': { |
216 | ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; | 216 | ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL; |
217 | if (ar->namewhat == NULL) | 217 | if (ar->namewhat == NULL) |
218 | getname(L, f, ar); | 218 | getname(L, f, ar); |
219 | break; | 219 | break; |
@@ -415,11 +415,10 @@ static const char *kname (Proto *p, int c) { | |||
415 | } | 415 | } |
416 | 416 | ||
417 | 417 | ||
418 | static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, | 418 | static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { |
419 | const char **name) { | ||
420 | if (isLua(ci)) { /* a Lua function? */ | 419 | if (isLua(ci)) { /* a Lua function? */ |
421 | Proto *p = ci_func(ci)->l.p; | 420 | Proto *p = ci_func(ci)->l.p; |
422 | int pc = currentpc(L, ci); | 421 | int pc = currentpc(ci); |
423 | Instruction i; | 422 | Instruction i; |
424 | *name = luaF_getlocalname(p, stackpos+1, pc); | 423 | *name = luaF_getlocalname(p, stackpos+1, pc); |
425 | if (*name) /* is a local? */ | 424 | if (*name) /* is a local? */ |
@@ -436,7 +435,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, | |||
436 | int a = GETARG_A(i); | 435 | int a = GETARG_A(i); |
437 | int b = GETARG_B(i); /* move from `b' to `a' */ | 436 | int b = GETARG_B(i); /* move from `b' to `a' */ |
438 | if (b < a) | 437 | if (b < a) |
439 | return getobjname(L, ci, b, name); /* get name for `b' */ | 438 | return getobjname(ci, b, name); /* get name for `b' */ |
440 | break; | 439 | break; |
441 | } | 440 | } |
442 | case OP_GETTABLE: { | 441 | case OP_GETTABLE: { |
@@ -454,17 +453,17 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, | |||
454 | } | 453 | } |
455 | 454 | ||
456 | 455 | ||
457 | static Instruction getcurrentinstr (lua_State *L, CallInfo *ci) { | 456 | static Instruction getcurrentinstr (CallInfo *ci) { |
458 | return (!isLua(ci)) ? (Instruction)(-1) : | 457 | return (!isLua(ci)) ? (Instruction)(-1) : |
459 | ci_func(ci)->l.p->code[currentpc(L, ci)]; | 458 | ci_func(ci)->l.p->code[currentpc(ci)]; |
460 | } | 459 | } |
461 | 460 | ||
462 | 461 | ||
463 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | 462 | static const char *getfuncname (CallInfo *ci, const char **name) { |
464 | Instruction i; | 463 | Instruction i; |
465 | ci--; /* calling function */ | 464 | ci--; /* calling function */ |
466 | i = getcurrentinstr(L, ci); | 465 | i = getcurrentinstr(ci); |
467 | return (GET_OPCODE(i) == OP_CALL ? getobjname(L, ci, GETARG_A(i), name) | 466 | return (GET_OPCODE(i) == OP_CALL ? getobjname(ci, GETARG_A(i), name) |
468 | : NULL); /* no useful name found */ | 467 | : NULL); /* no useful name found */ |
469 | } | 468 | } |
470 | 469 | ||
@@ -482,7 +481,7 @@ void luaG_typeerror (lua_State *L, const TObject *o, const char *op) { | |||
482 | const char *name = NULL; | 481 | const char *name = NULL; |
483 | const char *t = luaT_typenames[ttype(o)]; | 482 | const char *t = luaT_typenames[ttype(o)]; |
484 | const char *kind = (isinstack(L->ci, o)) ? | 483 | const char *kind = (isinstack(L->ci, o)) ? |
485 | getobjname(L, L->ci, o - L->ci->base, &name) : NULL; | 484 | getobjname(L->ci, o - L->ci->base, &name) : NULL; |
486 | if (kind) | 485 | if (kind) |
487 | luaG_runerror(L, "attempt to %s %s `%s' (a %s value)", | 486 | luaG_runerror(L, "attempt to %s %s `%s' (a %s value)", |
488 | op, kind, name, t); | 487 | op, kind, name, t); |
@@ -527,7 +526,7 @@ static void addinfo (lua_State *L, int internal) { | |||
527 | } | 526 | } |
528 | else { /* add file:line information */ | 527 | else { /* add file:line information */ |
529 | char buff[LUA_IDSIZE]; | 528 | char buff[LUA_IDSIZE]; |
530 | int line = currentline(L, ci); | 529 | int line = currentline(ci); |
531 | luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); | 530 | luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); |
532 | luaO_pushfstring(L, "%s:%d: %s\n", buff, line, msg); | 531 | luaO_pushfstring(L, "%s:%d: %s\n", buff, line, msg); |
533 | } | 532 | } |