diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-18 14:10:43 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-18 14:10:43 -0300 |
commit | 6ee2dbdfe94e55cc098646df6aaee0483b5fff2c (patch) | |
tree | aa100b536448ff9104314b59f1ef3d7875706aa1 | |
parent | 1dbe708aa84f3a1e51daf8d7e2f714e2b02f554b (diff) | |
download | lua-6ee2dbdfe94e55cc098646df6aaee0483b5fff2c.tar.gz lua-6ee2dbdfe94e55cc098646df6aaee0483b5fff2c.tar.bz2 lua-6ee2dbdfe94e55cc098646df6aaee0483b5fff2c.zip |
traceback stops at first protected call
-rw-r--r-- | ldblib.c | 19 | ||||
-rw-r--r-- | ldebug.c | 7 | ||||
-rw-r--r-- | ldo.c | 10 | ||||
-rw-r--r-- | ldo.h | 3 | ||||
-rw-r--r-- | luadebug.h | 19 |
5 files changed, 39 insertions, 19 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.57 2002/06/13 13:44:50 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.58 2002/06/18 15:17:58 roberto Exp roberto $ |
3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -184,26 +184,30 @@ static int debug (lua_State *L) { | |||
184 | static int errorfb (lua_State *L) { | 184 | static int errorfb (lua_State *L) { |
185 | int level = 1; /* skip level 0 (it's this function) */ | 185 | int level = 1; /* skip level 0 (it's this function) */ |
186 | int firstpart = 1; /* still before eventual `...' */ | 186 | int firstpart = 1; /* still before eventual `...' */ |
187 | int alllevels = 1; | ||
188 | const char *msg = lua_tostring(L, 1); | ||
187 | lua_Debug ar; | 189 | lua_Debug ar; |
188 | lua_settop(L, 0); | 190 | lua_settop(L, 0); |
189 | lua_pushliteral(L, "stack traceback:\n"); | 191 | if (msg) { |
192 | alllevels = 0; | ||
193 | if (!strstr(msg, "stack traceback:\n")) | ||
194 | lua_pushliteral(L, "stack traceback:\n"); | ||
195 | } | ||
190 | while (lua_getstack(L, level++, &ar)) { | 196 | while (lua_getstack(L, level++, &ar)) { |
191 | char buff[10]; | ||
192 | if (level > LEVELS1 && firstpart) { | 197 | if (level > LEVELS1 && firstpart) { |
193 | /* no more than `LEVELS2' more levels? */ | 198 | /* no more than `LEVELS2' more levels? */ |
194 | if (!lua_getstack(L, level+LEVELS2, &ar)) | 199 | if (!lua_getstack(L, level+LEVELS2, &ar)) |
195 | level--; /* keep going */ | 200 | level--; /* keep going */ |
196 | else { | 201 | else { |
197 | lua_pushliteral(L, " ...\n"); /* too many levels */ | 202 | lua_pushliteral(L, "\t...\n"); /* too many levels */ |
198 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ | 203 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ |
199 | level++; | 204 | level++; |
200 | } | 205 | } |
201 | firstpart = 0; | 206 | firstpart = 0; |
202 | continue; | 207 | continue; |
203 | } | 208 | } |
204 | sprintf(buff, "%4d- ", level-1); | 209 | lua_pushliteral(L, "\t"); |
205 | lua_pushstring(L, buff); | 210 | lua_getinfo(L, "Snlc", &ar); |
206 | lua_getinfo(L, "Snl", &ar); | ||
207 | lua_pushfstring(L, "%s:", ar.short_src); | 211 | lua_pushfstring(L, "%s:", ar.short_src); |
208 | if (ar.currentline > 0) | 212 | if (ar.currentline > 0) |
209 | lua_pushfstring(L, "%d:", ar.currentline); | 213 | lua_pushfstring(L, "%d:", ar.currentline); |
@@ -226,6 +230,7 @@ static int errorfb (lua_State *L) { | |||
226 | } | 230 | } |
227 | lua_pushliteral(L, "\n"); | 231 | lua_pushliteral(L, "\n"); |
228 | lua_concat(L, lua_gettop(L)); | 232 | lua_concat(L, lua_gettop(L)); |
233 | if (!alllevels && ar.isprotected) break; | ||
229 | } | 234 | } |
230 | lua_concat(L, lua_gettop(L)); | 235 | lua_concat(L, lua_gettop(L)); |
231 | return 1; | 236 | return 1; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.119 2002/06/13 13:39:55 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.120 2002/06/18 15:19:27 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 | */ |
@@ -181,6 +181,7 @@ static void getname (lua_State *L, const TObject *f, lua_Debug *ar) { | |||
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | |||
184 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | 185 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { |
185 | StkId f; | 186 | StkId f; |
186 | CallInfo *ci; | 187 | CallInfo *ci; |
@@ -220,6 +221,10 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
220 | status = 2; | 221 | status = 2; |
221 | break; | 222 | break; |
222 | } | 223 | } |
224 | case 'c': { | ||
225 | ar->isprotected = (ci && luaD_isprotected(L, ci)); | ||
226 | break; | ||
227 | } | ||
223 | default: status = 0; /* invalid option */ | 228 | default: status = 0; /* invalid option */ |
224 | } | 229 | } |
225 | } | 230 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.179 2002/06/03 20:12:50 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.180 2002/06/18 15:19:27 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -501,5 +501,13 @@ int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud) { | |||
501 | return lj.status; | 501 | return lj.status; |
502 | } | 502 | } |
503 | 503 | ||
504 | |||
505 | int luaD_isprotected (lua_State *L, CallInfo *ci) { | ||
506 | struct lua_longjmp *l; | ||
507 | for (l = L->errorJmp; l; l = l->previous) | ||
508 | if (l->ci+1 == ci) return 1; | ||
509 | return 0; | ||
510 | } | ||
511 | |||
504 | /* }====================================================== */ | 512 | /* }====================================================== */ |
505 | 513 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.h,v 1.45 2002/05/15 18:57:44 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.46 2002/06/18 15:19:27 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -43,6 +43,7 @@ void luaD_growstack (lua_State *L, int n); | |||
43 | 43 | ||
44 | void luaD_throw (lua_State *L, int errcode); | 44 | void luaD_throw (lua_State *L, int errcode); |
45 | int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud); | 45 | int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud); |
46 | int luaD_isprotected (lua_State *L, CallInfo *ci); | ||
46 | 47 | ||
47 | 48 | ||
48 | #endif | 49 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luadebug.h,v 1.26 2002/03/14 16:50:06 roberto Exp roberto $ | 2 | ** $Id: luadebug.h,v 1.27 2002/04/04 17:21:31 roberto Exp roberto $ |
3 | ** Debugging API | 3 | ** Debugging API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -28,14 +28,15 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); | |||
28 | #define LUA_IDSIZE 60 | 28 | #define LUA_IDSIZE 60 |
29 | 29 | ||
30 | struct lua_Debug { | 30 | struct lua_Debug { |
31 | const char *event; /* `call', `return', `line' */ | 31 | const char *event; /* `call', `return', `line' */ |
32 | const char *name; /* (n) */ | 32 | const char *name; /* (n) */ |
33 | const char *namewhat; /* (n) `global', `local', `field', `method' */ | 33 | const char *namewhat; /* (n) `global', `local', `field', `method' */ |
34 | const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ | 34 | const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ |
35 | const char *source; /* (S) */ | 35 | const char *source; /* (S) */ |
36 | int currentline; /* (l) */ | 36 | int currentline; /* (l) */ |
37 | int nups; /* (u) number of upvalues */ | 37 | int isprotected; /* (c) function was called in protected mode */ |
38 | int linedefined; /* (S) */ | 38 | int nups; /* (u) number of upvalues */ |
39 | int linedefined; /* (S) */ | ||
39 | char short_src[LUA_IDSIZE]; /* (S) */ | 40 | char short_src[LUA_IDSIZE]; /* (S) */ |
40 | /* private part */ | 41 | /* private part */ |
41 | int i_ci; /* active function */ | 42 | int i_ci; /* active function */ |