diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.44 2009/03/10 17:14:37 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.45 2009/03/26 12:56:38 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 | */ |
@@ -86,18 +86,18 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | |||
86 | int status; | 86 | int status; |
87 | CallInfo *ci; | 87 | CallInfo *ci; |
88 | lua_lock(L); | 88 | lua_lock(L); |
89 | for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { | 89 | for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous) { |
90 | level--; | 90 | level--; |
91 | if (isLua(ci)) /* Lua function? */ | 91 | if (isLua(ci)) /* Lua function? */ |
92 | level -= ci->u.l.tailcalls; /* skip lost tail calls */ | 92 | level -= ci->u.l.tailcalls; /* skip lost tail calls */ |
93 | } | 93 | } |
94 | if (level == 0 && ci > L->base_ci) { /* level found? */ | 94 | if (level == 0 && ci != &L->base_ci) { /* level found? */ |
95 | status = 1; | 95 | status = 1; |
96 | ar->i_ci = cast_int(ci - L->base_ci); | 96 | ar->i_ci = ci; |
97 | } | 97 | } |
98 | else if (level < 0) { /* level is of a lost tail call? */ | 98 | else if (level < 0) { /* level is of a lost tail call? */ |
99 | status = 1; | 99 | status = 1; |
100 | ar->i_ci = 0; | 100 | ar->i_ci = NULL; |
101 | } | 101 | } |
102 | else status = 0; /* no such level */ | 102 | else status = 0; /* no such level */ |
103 | lua_unlock(L); | 103 | lua_unlock(L); |
@@ -116,7 +116,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n) { | |||
116 | if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) | 116 | if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) |
117 | return name; /* is a local variable in a Lua function */ | 117 | return name; /* is a local variable in a Lua function */ |
118 | else { | 118 | else { |
119 | StkId limit = (ci == L->ci) ? L->top : (ci+1)->func; | 119 | StkId limit = (ci == L->ci) ? L->top : ci->next->func; |
120 | if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ | 120 | if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ |
121 | return "(*temporary)"; | 121 | return "(*temporary)"; |
122 | else | 122 | else |
@@ -126,7 +126,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n) { | |||
126 | 126 | ||
127 | 127 | ||
128 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | 128 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { |
129 | CallInfo *ci = L->base_ci + ar->i_ci; | 129 | CallInfo *ci = ar->i_ci; |
130 | const char *name = findlocal(L, ci, n); | 130 | const char *name = findlocal(L, ci, n); |
131 | lua_lock(L); | 131 | lua_lock(L); |
132 | if (name) { | 132 | if (name) { |
@@ -139,7 +139,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
139 | 139 | ||
140 | 140 | ||
141 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | 141 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { |
142 | CallInfo *ci = L->base_ci + ar->i_ci; | 142 | CallInfo *ci = ar->i_ci; |
143 | const char *name = findlocal(L, ci, n); | 143 | const char *name = findlocal(L, ci, n); |
144 | lua_lock(L); | 144 | lua_lock(L); |
145 | if (name) | 145 | if (name) |
@@ -246,8 +246,8 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
246 | f = clvalue(func); | 246 | f = clvalue(func); |
247 | L->top--; /* pop function */ | 247 | L->top--; /* pop function */ |
248 | } | 248 | } |
249 | else if (ar->i_ci != 0) { /* no tail call? */ | 249 | else if (ar->i_ci != NULL) { /* no tail call? */ |
250 | ci = L->base_ci + ar->i_ci; | 250 | ci = ar->i_ci; |
251 | lua_assert(ttisfunction(ci->func)); | 251 | lua_assert(ttisfunction(ci->func)); |
252 | f = clvalue(ci->func); | 252 | f = clvalue(ci->func); |
253 | } | 253 | } |
@@ -525,9 +525,9 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, | |||
525 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | 525 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { |
526 | TMS tm = 0; | 526 | TMS tm = 0; |
527 | Instruction i; | 527 | Instruction i; |
528 | if ((isLua(ci) && ci->u.l.tailcalls > 0) || !isLua(ci - 1)) | 528 | if ((isLua(ci) && ci->u.l.tailcalls > 0) || !isLua(ci->previous)) |
529 | return NULL; /* calling function is not Lua (or is unknown) */ | 529 | return NULL; /* calling function is not Lua (or is unknown) */ |
530 | ci--; /* calling function */ | 530 | ci = ci->previous; /* calling function */ |
531 | i = ci_func(ci)->l.p->code[currentpc(L, ci)]; | 531 | i = ci_func(ci)->l.p->code[currentpc(L, ci)]; |
532 | switch (GET_OPCODE(i)) { | 532 | switch (GET_OPCODE(i)) { |
533 | case OP_CALL: | 533 | case OP_CALL: |