traceback stops at first protected call

This commit is contained in:
Roberto Ierusalimschy 2002-06-18 14:10:43 -03:00
parent 1dbe708aa8
commit 6ee2dbdfe9
5 changed files with 39 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.57 2002/06/13 13:44:50 roberto Exp roberto $
** $Id: ldblib.c,v 1.58 2002/06/18 15:17:58 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -184,26 +184,30 @@ static int debug (lua_State *L) {
static int errorfb (lua_State *L) {
int level = 1; /* skip level 0 (it's this function) */
int firstpart = 1; /* still before eventual `...' */
int alllevels = 1;
const char *msg = lua_tostring(L, 1);
lua_Debug ar;
lua_settop(L, 0);
lua_pushliteral(L, "stack traceback:\n");
if (msg) {
alllevels = 0;
if (!strstr(msg, "stack traceback:\n"))
lua_pushliteral(L, "stack traceback:\n");
}
while (lua_getstack(L, level++, &ar)) {
char buff[10];
if (level > LEVELS1 && firstpart) {
/* no more than `LEVELS2' more levels? */
if (!lua_getstack(L, level+LEVELS2, &ar))
level--; /* keep going */
else {
lua_pushliteral(L, " ...\n"); /* too many levels */
lua_pushliteral(L, "\t...\n"); /* too many levels */
while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */
level++;
}
firstpart = 0;
continue;
}
sprintf(buff, "%4d- ", level-1);
lua_pushstring(L, buff);
lua_getinfo(L, "Snl", &ar);
lua_pushliteral(L, "\t");
lua_getinfo(L, "Snlc", &ar);
lua_pushfstring(L, "%s:", ar.short_src);
if (ar.currentline > 0)
lua_pushfstring(L, "%d:", ar.currentline);
@ -226,6 +230,7 @@ static int errorfb (lua_State *L) {
}
lua_pushliteral(L, "\n");
lua_concat(L, lua_gettop(L));
if (!alllevels && ar.isprotected) break;
}
lua_concat(L, lua_gettop(L));
return 1;

View File

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 1.119 2002/06/13 13:39:55 roberto Exp roberto $
** $Id: ldebug.c,v 1.120 2002/06/18 15:19:27 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -181,6 +181,7 @@ static void getname (lua_State *L, const TObject *f, lua_Debug *ar) {
}
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
StkId f;
CallInfo *ci;
@ -220,6 +221,10 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
status = 2;
break;
}
case 'c': {
ar->isprotected = (ci && luaD_isprotected(L, ci));
break;
}
default: status = 0; /* invalid option */
}
}

10
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.179 2002/06/03 20:12:50 roberto Exp roberto $
** $Id: ldo.c,v 1.180 2002/06/18 15:19:27 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -501,5 +501,13 @@ int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud) {
return lj.status;
}
int luaD_isprotected (lua_State *L, CallInfo *ci) {
struct lua_longjmp *l;
for (l = L->errorJmp; l; l = l->previous)
if (l->ci+1 == ci) return 1;
return 0;
}
/* }====================================================== */

3
ldo.h
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.h,v 1.45 2002/05/15 18:57:44 roberto Exp roberto $
** $Id: ldo.h,v 1.46 2002/06/18 15:19:27 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -43,6 +43,7 @@ void luaD_growstack (lua_State *L, int n);
void luaD_throw (lua_State *L, int errcode);
int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud);
int luaD_isprotected (lua_State *L, CallInfo *ci);
#endif

View File

@ -1,5 +1,5 @@
/*
** $Id: luadebug.h,v 1.26 2002/03/14 16:50:06 roberto Exp roberto $
** $Id: luadebug.h,v 1.27 2002/04/04 17:21:31 roberto Exp roberto $
** Debugging API
** See Copyright Notice in lua.h
*/
@ -28,14 +28,15 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func);
#define LUA_IDSIZE 60
struct lua_Debug {
const char *event; /* `call', `return', `line' */
const char *name; /* (n) */
const char *namewhat; /* (n) `global', `local', `field', `method' */
const char *what; /* (S) `Lua' function, `C' function, Lua `main' */
const char *source; /* (S) */
int currentline; /* (l) */
int nups; /* (u) number of upvalues */
int linedefined; /* (S) */
const char *event; /* `call', `return', `line' */
const char *name; /* (n) */
const char *namewhat; /* (n) `global', `local', `field', `method' */
const char *what; /* (S) `Lua' function, `C' function, Lua `main' */
const char *source; /* (S) */
int currentline; /* (l) */
int isprotected; /* (c) function was called in protected mode */
int nups; /* (u) number of upvalues */
int linedefined; /* (S) */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
int i_ci; /* active function */