diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 40 |
1 files changed, 16 insertions, 24 deletions
@@ -31,8 +31,7 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, | |||
31 | 31 | ||
32 | 32 | ||
33 | static int isLmark (CallInfo *ci) { | 33 | static int isLmark (CallInfo *ci) { |
34 | lua_assert(ci == NULL || ttype(ci->base - 1) == LUA_TFUNCTION); | 34 | return (ttype(ci->base - 1) == LUA_TFUNCTION && !ci_func(ci)->c.isC); |
35 | return (ci && ci->prev && !ci_func(ci)->c.isC); | ||
36 | } | 35 | } |
37 | 36 | ||
38 | 37 | ||
@@ -58,23 +57,17 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { | |||
58 | 57 | ||
59 | static CallInfo *ci_stack (lua_State *L, StkId obj) { | 58 | static CallInfo *ci_stack (lua_State *L, StkId obj) { |
60 | CallInfo *ci = L->ci; | 59 | CallInfo *ci = L->ci; |
61 | while (ci->base > obj) ci = ci->prev; | 60 | while (ci->base > obj) ci--; |
62 | return (ci != &L->basefunc) ? ci : NULL; | 61 | return ci; |
63 | } | 62 | } |
64 | 63 | ||
65 | 64 | ||
66 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | 65 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { |
67 | CallInfo *ci; | ||
68 | int status; | 66 | int status; |
69 | lua_lock(L); | 67 | lua_lock(L); |
70 | ci = L->ci; | 68 | if (L->ci - L->base_ci <= level) status = 0; /* there is no such level */ |
71 | while (level-- && ci != &L->basefunc) { | ||
72 | lua_assert(ci->base > ci->prev->base); | ||
73 | ci = ci->prev; | ||
74 | } | ||
75 | if (ci == &L->basefunc) status = 0; /* there is no such level */ | ||
76 | else { | 69 | else { |
77 | ar->_ci = ci; | 70 | ar->_ci = (L->ci - L->base_ci) - level; |
78 | status = 1; | 71 | status = 1; |
79 | } | 72 | } |
80 | lua_unlock(L); | 73 | lua_unlock(L); |
@@ -84,8 +77,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | |||
84 | 77 | ||
85 | int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | 78 | int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { |
86 | int refi; | 79 | int refi; |
87 | if (lineinfo == NULL || pc == -1) | 80 | if (lineinfo == NULL) return -1; /* no line info */ |
88 | return -1; /* no line info or function is not active */ | ||
89 | refi = prefi ? *prefi : 0; | 81 | refi = prefi ? *prefi : 0; |
90 | if (lineinfo[refi] < 0) | 82 | if (lineinfo[refi] < 0) |
91 | refline += -lineinfo[refi++]; | 83 | refline += -lineinfo[refi++]; |
@@ -115,10 +107,11 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | |||
115 | 107 | ||
116 | static int currentpc (CallInfo *ci) { | 108 | static int currentpc (CallInfo *ci) { |
117 | lua_assert(isLmark(ci)); | 109 | lua_assert(isLmark(ci)); |
118 | if (ci->pc) | 110 | if (ci->savedpc) |
111 | return (ci->savedpc - ci_func(ci)->l.p->code) - 1; | ||
112 | else if (ci->pc) | ||
119 | return (*ci->pc - ci_func(ci)->l.p->code) - 1; | 113 | return (*ci->pc - ci_func(ci)->l.p->code) - 1; |
120 | else | 114 | else return 0; |
121 | return -1; /* function is not active */ | ||
122 | } | 115 | } |
123 | 116 | ||
124 | 117 | ||
@@ -144,7 +137,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
144 | Proto *fp; | 137 | Proto *fp; |
145 | lua_lock(L); | 138 | lua_lock(L); |
146 | name = NULL; | 139 | name = NULL; |
147 | ci = ar->_ci; | 140 | ci = L->base_ci + ar->_ci; |
148 | fp = getluaproto(ci); | 141 | fp = getluaproto(ci); |
149 | if (fp) { /* is a Lua function? */ | 142 | if (fp) { /* is a Lua function? */ |
150 | name = luaF_getlocalname(fp, n, currentpc(ci)); | 143 | name = luaF_getlocalname(fp, n, currentpc(ci)); |
@@ -162,7 +155,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
162 | Proto *fp; | 155 | Proto *fp; |
163 | lua_lock(L); | 156 | lua_lock(L); |
164 | name = NULL; | 157 | name = NULL; |
165 | ci = ar->_ci; | 158 | ci = L->base_ci + ar->_ci; |
166 | fp = getluaproto(ci); | 159 | fp = getluaproto(ci); |
167 | L->top--; /* pop new value */ | 160 | L->top--; /* pop new value */ |
168 | if (fp) { /* is a Lua function? */ | 161 | if (fp) { /* is a Lua function? */ |
@@ -231,7 +224,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
231 | int status = 1; | 224 | int status = 1; |
232 | lua_lock(L); | 225 | lua_lock(L); |
233 | if (*what != '>') { /* function is active? */ | 226 | if (*what != '>') { /* function is active? */ |
234 | ci = ar->_ci; | 227 | ci = L->base_ci + ar->_ci; |
235 | f = ci->base - 1; | 228 | f = ci->base - 1; |
236 | } | 229 | } |
237 | else { | 230 | else { |
@@ -246,7 +239,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
246 | break; | 239 | break; |
247 | } | 240 | } |
248 | case 'l': { | 241 | case 'l': { |
249 | ar->currentline = currentline(ci); | 242 | ar->currentline = (ci) ? currentline(ci) : -1; |
250 | break; | 243 | break; |
251 | } | 244 | } |
252 | case 'u': { | 245 | case 'u': { |
@@ -495,14 +488,13 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
495 | 488 | ||
496 | static const char *getfuncname (lua_State *L, CallInfo *ci, | 489 | static const char *getfuncname (lua_State *L, CallInfo *ci, |
497 | const char **name) { | 490 | const char **name) { |
498 | ci = ci->prev; /* calling function */ | 491 | ci--; /* calling function */ |
499 | if (ci == &L->basefunc || !isLmark(ci)) | 492 | if (ci == L->base_ci || !isLmark(ci)) |
500 | return NULL; /* not an active Lua function */ | 493 | return NULL; /* not an active Lua function */ |
501 | else { | 494 | else { |
502 | Proto *p = ci_func(ci)->l.p; | 495 | Proto *p = ci_func(ci)->l.p; |
503 | int pc = currentpc(ci); | 496 | int pc = currentpc(ci); |
504 | Instruction i; | 497 | Instruction i; |
505 | if (pc == -1) return NULL; /* function is not activated */ | ||
506 | i = p->code[pc]; | 498 | i = p->code[pc]; |
507 | return (GET_OPCODE(i) == OP_CALL | 499 | return (GET_OPCODE(i) == OP_CALL |
508 | ? getobjname(L, ci->base+GETARG_A(i), name) | 500 | ? getobjname(L, ci->base+GETARG_A(i), name) |