diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-30 16:28:40 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-30 16:28:40 -0200 |
commit | bcdbdaccc37aacdb8305f5012c2963e4cb343005 (patch) | |
tree | c6e0ad8afa371840f49d92b3f1455f3e57cbccc6 /ldebug.c | |
parent | 5cafe5af02bfe2188ba0b69f5a7a8fe44c38ed24 (diff) | |
download | lua-bcdbdaccc37aacdb8305f5012c2963e4cb343005.tar.gz lua-bcdbdaccc37aacdb8305f5012c2963e4cb343005.tar.bz2 lua-bcdbdaccc37aacdb8305f5012c2963e4cb343005.zip |
more debug information (still with bug for tag methods...)
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 38 |
1 files changed, 21 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.2 1999/12/23 18:19:57 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.3 1999/12/29 16:31:15 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 | */ |
@@ -45,9 +45,9 @@ int lua_setdebug (lua_State *L, int debug) { | |||
45 | } | 45 | } |
46 | 46 | ||
47 | 47 | ||
48 | lua_Function lua_stackedfunction (lua_State *L, int level) { | 48 | static lua_Function aux_stackedfunction (lua_State *L, int level, StkId top) { |
49 | int i; | 49 | int i; |
50 | for (i = (L->top-1)-L->stack; i>=0; i--) { | 50 | for (i = (top-1)-L->stack; i>=0; i--) { |
51 | if (is_T_MARK(L->stack[i].ttype)) { | 51 | if (is_T_MARK(L->stack[i].ttype)) { |
52 | if (level == 0) | 52 | if (level == 0) |
53 | return L->stack+i; | 53 | return L->stack+i; |
@@ -58,10 +58,15 @@ lua_Function lua_stackedfunction (lua_State *L, int level) { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | const char *luaG_getname (lua_State *L, const char **name) { | 61 | lua_Function lua_stackedfunction (lua_State *L, int level) { |
62 | lua_Function f = lua_stackedfunction(L, 0); | 62 | return aux_stackedfunction(L, level, L->top); |
63 | } | ||
64 | |||
65 | |||
66 | static const char *luaG_getname (lua_State *L, const char **name, StkId top) { | ||
67 | lua_Function f = aux_stackedfunction(L, 0, top); | ||
63 | if (f == LUA_NOOBJECT || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL) | 68 | if (f == LUA_NOOBJECT || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL) |
64 | return NULL; /* no name available */ | 69 | return ""; /* no name available */ |
65 | else { | 70 | else { |
66 | int i = (f+2)->value.i; | 71 | int i = (f+2)->value.i; |
67 | if (ttype(f) == LUA_T_LCLMARK) | 72 | if (ttype(f) == LUA_T_LCLMARK) |
@@ -69,14 +74,7 @@ const char *luaG_getname (lua_State *L, const char **name) { | |||
69 | LUA_ASSERT(L, ttype(f) == LUA_T_LMARK, "must be a Lua function"); | 74 | LUA_ASSERT(L, ttype(f) == LUA_T_LMARK, "must be a Lua function"); |
70 | LUA_ASSERT(L, ttype(&tfvalue(f)->consts[i]) == LUA_T_STRING, ""); | 75 | LUA_ASSERT(L, ttype(&tfvalue(f)->consts[i]) == LUA_T_STRING, ""); |
71 | *name = tsvalue(&tfvalue(f)->consts[i])->str; | 76 | *name = tsvalue(&tfvalue(f)->consts[i])->str; |
72 | switch (ttype(f+2)) { | 77 | return luaO_typename(f+2); |
73 | case LUA_T_NGLOBAL: return "global"; | ||
74 | case LUA_T_NLOCAL: return "local"; | ||
75 | case LUA_T_NDOT: return "field"; | ||
76 | default: | ||
77 | LUA_INTERNALERROR(L, "invalid tag for NAME"); | ||
78 | return NULL; /* unreacheable; to avoid warnings */ | ||
79 | } | ||
80 | } | 78 | } |
81 | } | 79 | } |
82 | 80 | ||
@@ -162,8 +160,14 @@ static int checkfunc (lua_State *L, TObject *o) { | |||
162 | 160 | ||
163 | 161 | ||
164 | const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { | 162 | const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { |
165 | /* try to find a name for given function */ | ||
166 | GlobalVar *g; | 163 | GlobalVar *g; |
164 | if (is_T_MARK(ttype(o))) { /* `o' is an active function? */ | ||
165 | /* look for caller debug information */ | ||
166 | const char *kind = luaG_getname(L, name, o); | ||
167 | if (*kind) return kind; | ||
168 | /* else go through */ | ||
169 | } | ||
170 | /* try to find a name for given function */ | ||
167 | luaA_setnormalized(L->top, o); /* to be used by `checkfunc' */ | 171 | luaA_setnormalized(L->top, o); /* to be used by `checkfunc' */ |
168 | for (g=L->rootglobal; g; g=g->next) { | 172 | for (g=L->rootglobal; g; g=g->next) { |
169 | if (checkfunc(L, &g->value)) { | 173 | if (checkfunc(L, &g->value)) { |
@@ -180,8 +184,8 @@ const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { | |||
180 | static void call_index_error (lua_State *L, TObject *o, const char *tp, | 184 | static void call_index_error (lua_State *L, TObject *o, const char *tp, |
181 | const char *v) { | 185 | const char *v) { |
182 | const char *name; | 186 | const char *name; |
183 | const char *kind = luaG_getname(L, &name); | 187 | const char *kind = luaG_getname(L, &name, L->top); |
184 | if (kind) { /* is there a name? */ | 188 | if (*kind) { /* is there a name? */ |
185 | luaL_verror(L, "%.10s `%.30s' is not a %.10s", kind, name, tp); | 189 | luaL_verror(L, "%.10s `%.30s' is not a %.10s", kind, name, tp); |
186 | } | 190 | } |
187 | else { | 191 | else { |