diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 35 |
1 files changed, 17 insertions, 18 deletions
@@ -25,8 +25,7 @@ | |||
25 | 25 | ||
26 | 26 | ||
27 | 27 | ||
28 | static const char *getfuncname (lua_State *L, CallInfo *ci, | 28 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); |
29 | const char **name); | ||
30 | 29 | ||
31 | 30 | ||
32 | 31 | ||
@@ -57,7 +56,7 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { | |||
57 | 56 | ||
58 | static CallInfo *ci_stack (lua_State *L, StkId obj) { | 57 | static CallInfo *ci_stack (lua_State *L, StkId obj) { |
59 | CallInfo *ci = L->ci; | 58 | CallInfo *ci = L->ci; |
60 | while (ci->base > obj) ci--; | 59 | while (ci->base > obj && ci > L->base_ci) ci--; |
61 | return ci; | 60 | return ci; |
62 | } | 61 | } |
63 | 62 | ||
@@ -105,22 +104,22 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | |||
105 | } | 104 | } |
106 | 105 | ||
107 | 106 | ||
108 | static int currentpc (CallInfo *ci) { | 107 | static int currentpc (lua_State *L, CallInfo *ci) { |
109 | lua_assert(isLmark(ci)); | 108 | lua_assert(isLmark(ci)); |
110 | if (ci->savedpc) | 109 | if (ci->pc == NULL) return 0; /* function is not active */ |
111 | return (ci->savedpc - ci_func(ci)->l.p->code) - 1; | 110 | if (ci == L->ci || ci->pc != (ci+1)->pc) /* no other function using `pc'? */ |
112 | else if (ci->pc) | ||
113 | return (*ci->pc - ci_func(ci)->l.p->code) - 1; | 111 | return (*ci->pc - ci_func(ci)->l.p->code) - 1; |
114 | else return 0; | 112 | else /* function's pc is saved */ |
113 | return (ci->savedpc - ci_func(ci)->l.p->code) - 1; | ||
115 | } | 114 | } |
116 | 115 | ||
117 | 116 | ||
118 | static int currentline (CallInfo *ci) { | 117 | static int currentline (lua_State *L, CallInfo *ci) { |
119 | if (!isLmark(ci)) | 118 | if (!isLmark(ci)) |
120 | return -1; /* only active lua functions have current-line information */ | 119 | return -1; /* only active lua functions have current-line information */ |
121 | else { | 120 | else { |
122 | int *lineinfo = ci_func(ci)->l.p->lineinfo; | 121 | int *lineinfo = ci_func(ci)->l.p->lineinfo; |
123 | return luaG_getline(lineinfo, currentpc(ci), 1, NULL); | 122 | return luaG_getline(lineinfo, currentpc(L, ci), 1, NULL); |
124 | } | 123 | } |
125 | } | 124 | } |
126 | 125 | ||
@@ -140,7 +139,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
140 | ci = L->base_ci + ar->_ci; | 139 | ci = L->base_ci + ar->_ci; |
141 | fp = getluaproto(ci); | 140 | fp = getluaproto(ci); |
142 | if (fp) { /* is a Lua function? */ | 141 | if (fp) { /* is a Lua function? */ |
143 | name = luaF_getlocalname(fp, n, currentpc(ci)); | 142 | name = luaF_getlocalname(fp, n, currentpc(L, ci)); |
144 | if (name) | 143 | if (name) |
145 | luaA_pushobject(L, ci->base+(n-1)); /* push value */ | 144 | luaA_pushobject(L, ci->base+(n-1)); /* push value */ |
146 | } | 145 | } |
@@ -159,7 +158,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
159 | fp = getluaproto(ci); | 158 | fp = getluaproto(ci); |
160 | L->top--; /* pop new value */ | 159 | L->top--; /* pop new value */ |
161 | if (fp) { /* is a Lua function? */ | 160 | if (fp) { /* is a Lua function? */ |
162 | name = luaF_getlocalname(fp, n, currentpc(ci)); | 161 | name = luaF_getlocalname(fp, n, currentpc(L, ci)); |
163 | if (!name || name[0] == '(') /* `(' starts private locals */ | 162 | if (!name || name[0] == '(') /* `(' starts private locals */ |
164 | name = NULL; | 163 | name = NULL; |
165 | else | 164 | else |
@@ -239,7 +238,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
239 | break; | 238 | break; |
240 | } | 239 | } |
241 | case 'l': { | 240 | case 'l': { |
242 | ar->currentline = (ci) ? currentline(ci) : -1; | 241 | ar->currentline = (ci) ? currentline(L, ci) : -1; |
243 | break; | 242 | break; |
244 | } | 243 | } |
245 | case 'u': { | 244 | case 'u': { |
@@ -254,13 +253,14 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
254 | } | 253 | } |
255 | case 'f': { | 254 | case 'f': { |
256 | setobj(L->top, f); | 255 | setobj(L->top, f); |
257 | incr_top; /* push function */ | 256 | status = 2; |
258 | break; | 257 | break; |
259 | } | 258 | } |
260 | default: status = 0; /* invalid option */ | 259 | default: status = 0; /* invalid option */ |
261 | } | 260 | } |
262 | } | 261 | } |
263 | if (!ci) L->top--; /* pop function */ | 262 | if (!ci) L->top--; /* pop function */ |
263 | if (status == 2) incr_top(L); | ||
264 | lua_unlock(L); | 264 | lua_unlock(L); |
265 | return status; | 265 | return status; |
266 | } | 266 | } |
@@ -449,7 +449,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
449 | CallInfo *ci = ci_stack(L, obj); | 449 | CallInfo *ci = ci_stack(L, obj); |
450 | if (isLmark(ci)) { /* an active Lua function? */ | 450 | if (isLmark(ci)) { /* an active Lua function? */ |
451 | Proto *p = ci_func(ci)->l.p; | 451 | Proto *p = ci_func(ci)->l.p; |
452 | int pc = currentpc(ci); | 452 | int pc = currentpc(L, ci); |
453 | int stackpos = obj - ci->base; | 453 | int stackpos = obj - ci->base; |
454 | Instruction i; | 454 | Instruction i; |
455 | *name = luaF_getlocalname(p, stackpos+1, pc); | 455 | *name = luaF_getlocalname(p, stackpos+1, pc); |
@@ -486,14 +486,13 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
486 | } | 486 | } |
487 | 487 | ||
488 | 488 | ||
489 | static const char *getfuncname (lua_State *L, CallInfo *ci, | 489 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { |
490 | const char **name) { | ||
491 | ci--; /* calling function */ | 490 | ci--; /* calling function */ |
492 | if (ci == L->base_ci || !isLmark(ci)) | 491 | if (ci == L->base_ci || !isLmark(ci)) |
493 | return NULL; /* not an active Lua function */ | 492 | return NULL; /* not an active Lua function */ |
494 | else { | 493 | else { |
495 | Proto *p = ci_func(ci)->l.p; | 494 | Proto *p = ci_func(ci)->l.p; |
496 | int pc = currentpc(ci); | 495 | int pc = currentpc(L, ci); |
497 | Instruction i; | 496 | Instruction i; |
498 | i = p->code[pc]; | 497 | i = p->code[pc]; |
499 | return (GET_OPCODE(i) == OP_CALL | 498 | return (GET_OPCODE(i) == OP_CALL |