diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-06-26 16:28:31 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-06-26 16:28:31 -0300 |
commit | afef009fcea199bd4eff28ea6e5206b59cda9939 (patch) | |
tree | 3954490fd4149900be8e795f630104637cd02f4b /ldebug.c | |
parent | b69e712713785394ceefa11ab3e5f9636abea733 (diff) | |
download | lua-afef009fcea199bd4eff28ea6e5206b59cda9939.tar.gz lua-afef009fcea199bd4eff28ea6e5206b59cda9939.tar.bz2 lua-afef009fcea199bd4eff28ea6e5206b59cda9939.zip |
new version of debug system
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 74 |
1 files changed, 44 insertions, 30 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.22 2000/06/08 17:48:31 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.23 2000/06/12 13:52:05 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 | */ |
@@ -23,22 +23,21 @@ | |||
23 | #include "luadebug.h" | 23 | #include "luadebug.h" |
24 | 24 | ||
25 | 25 | ||
26 | static const lua_Type normtype[] = { /* ORDER LUA_T */ | ||
27 | TAG_USERDATA, TAG_NUMBER, TAG_STRING, TAG_TABLE, | ||
28 | TAG_LCLOSURE, TAG_CCLOSURE, TAG_NIL, | ||
29 | TAG_LCLOSURE, TAG_CCLOSURE /* TAG_LMARK, TAG_CMARK */ | ||
30 | }; | ||
31 | |||
32 | 26 | ||
33 | static void setnormalized (TObject *d, const TObject *s) { | 27 | static void setnormalized (TObject *d, const TObject *s) { |
34 | d->value = s->value; | 28 | switch (s->ttype) { |
35 | d->ttype = normtype[ttype(s)]; | 29 | case TAG_CMARK: { |
36 | } | 30 | clvalue(d) = clvalue(s); |
37 | 31 | ttype(d) = TAG_CCLOSURE; | |
38 | 32 | break; | |
39 | 33 | } | |
40 | static int hasdebuginfo (lua_State *L, StkId f) { | 34 | case TAG_LMARK: { |
41 | return (f+1 < L->top && (f+1)->ttype == TAG_LINE); | 35 | clvalue(d) = infovalue(s)->func; |
36 | ttype(d) = TAG_LCLOSURE; | ||
37 | break; | ||
38 | } | ||
39 | default: *d = *s; | ||
40 | } | ||
42 | } | 41 | } |
43 | 42 | ||
44 | 43 | ||
@@ -88,22 +87,35 @@ int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | |||
88 | 87 | ||
89 | static int lua_nups (StkId f) { | 88 | static int lua_nups (StkId f) { |
90 | switch (ttype(f)) { | 89 | switch (ttype(f)) { |
91 | case TAG_LCLOSURE: case TAG_CCLOSURE: | 90 | case TAG_LCLOSURE: case TAG_CCLOSURE: case TAG_CMARK: |
92 | case TAG_LMARK: case TAG_CMARK: | ||
93 | return clvalue(f)->nupvalues; | 91 | return clvalue(f)->nupvalues; |
92 | case TAG_LMARK: | ||
93 | return infovalue(f)->func->nupvalues; | ||
94 | default: | 94 | default: |
95 | return 0; | 95 | return 0; |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | static int lua_currentline (lua_State *L, StkId f) { | 100 | static int lua_currentline (StkId f) { |
101 | return hasdebuginfo(L, f) ? (f+1)->value.i : -1; | 101 | if (ttype(f) != TAG_LMARK) |
102 | return -1; /* only active lua functions have current-line information */ | ||
103 | else { | ||
104 | CallInfo *ci = infovalue(f); | ||
105 | int *lines = ci->func->f.l->lines; | ||
106 | if (!lines) return -1; /* no static debug information */ | ||
107 | else return lines[ci->pc]; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | |||
112 | static int lua_currentpc (StkId f) { | ||
113 | return infovalue(f)->pc; | ||
102 | } | 114 | } |
103 | 115 | ||
104 | 116 | ||
105 | static Proto *getluaproto (StkId f) { | 117 | static Proto *getluaproto (StkId f) { |
106 | return (ttype(f) == TAG_LMARK) ? clvalue(f)->f.l : NULL; | 118 | return (ttype(f) == TAG_LMARK) ? infovalue(f)->func->f.l : NULL; |
107 | } | 119 | } |
108 | 120 | ||
109 | 121 | ||
@@ -111,12 +123,9 @@ int lua_getlocal (lua_State *L, const lua_Debug *ar, lua_Localvar *v) { | |||
111 | StkId f = ar->_func; | 123 | StkId f = ar->_func; |
112 | Proto *fp = getluaproto(f); | 124 | Proto *fp = getluaproto(f); |
113 | if (!fp) return 0; /* `f' is not a Lua function? */ | 125 | if (!fp) return 0; /* `f' is not a Lua function? */ |
114 | v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); | 126 | v->name = luaF_getlocalname(fp, v->index, lua_currentpc(f)); |
115 | if (!v->name) return 0; | 127 | if (!v->name) return 0; |
116 | /* if `name', there must be a TAG_LINE */ | 128 | v->value = luaA_putluaObject(L, (f+1)+(v->index-1)); |
117 | /* therefore, f+2 points to function base */ | ||
118 | LUA_ASSERT(L, ttype(f+1) == TAG_LINE, ""); | ||
119 | v->value = luaA_putluaObject(L, (f+2)+(v->index-1)); | ||
120 | return 1; | 129 | return 1; |
121 | } | 130 | } |
122 | 131 | ||
@@ -124,22 +133,27 @@ int lua_getlocal (lua_State *L, const lua_Debug *ar, lua_Localvar *v) { | |||
124 | int lua_setlocal (lua_State *L, const lua_Debug *ar, lua_Localvar *v) { | 133 | int lua_setlocal (lua_State *L, const lua_Debug *ar, lua_Localvar *v) { |
125 | StkId f = ar->_func; | 134 | StkId f = ar->_func; |
126 | Proto *fp = getluaproto(f); | 135 | Proto *fp = getluaproto(f); |
136 | UNUSED(L); | ||
127 | if (!fp) return 0; /* `f' is not a Lua function? */ | 137 | if (!fp) return 0; /* `f' is not a Lua function? */ |
128 | v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); | 138 | v->name = luaF_getlocalname(fp, v->index, lua_currentpc(f)); |
129 | if (!v->name || v->name[0] == '*') return 0; /* `*' starts private locals */ | 139 | if (!v->name || v->name[0] == '*') return 0; /* `*' starts private locals */ |
130 | LUA_ASSERT(L, ttype(f+1) == TAG_LINE, ""); | 140 | *((f+1)+(v->index-1)) = *v->value; |
131 | *((f+2)+(v->index-1)) = *v->value; | ||
132 | return 1; | 141 | return 1; |
133 | } | 142 | } |
134 | 143 | ||
135 | 144 | ||
136 | static void lua_funcinfo (lua_Debug *ar, StkId func) { | 145 | static void lua_funcinfo (lua_Debug *ar, StkId func) { |
137 | switch (ttype(func)) { | 146 | switch (ttype(func)) { |
138 | case TAG_LCLOSURE: case TAG_LMARK: | 147 | case TAG_LCLOSURE: |
139 | ar->source = clvalue(func)->f.l->source->str; | 148 | ar->source = clvalue(func)->f.l->source->str; |
140 | ar->linedefined = clvalue(func)->f.l->lineDefined; | 149 | ar->linedefined = clvalue(func)->f.l->lineDefined; |
141 | ar->what = "Lua"; | 150 | ar->what = "Lua"; |
142 | break; | 151 | break; |
152 | case TAG_LMARK: | ||
153 | ar->source = infovalue(func)->func->f.l->source->str; | ||
154 | ar->linedefined = infovalue(func)->func->f.l->lineDefined; | ||
155 | ar->what = "Lua"; | ||
156 | break; | ||
143 | case TAG_CCLOSURE: case TAG_CMARK: | 157 | case TAG_CCLOSURE: case TAG_CMARK: |
144 | ar->source = "(C)"; | 158 | ar->source = "(C)"; |
145 | ar->linedefined = -1; | 159 | ar->linedefined = -1; |
@@ -191,7 +205,7 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
191 | lua_funcinfo(ar, func); | 205 | lua_funcinfo(ar, func); |
192 | break; | 206 | break; |
193 | case 'l': | 207 | case 'l': |
194 | ar->currentline = lua_currentline(L, func); | 208 | ar->currentline = lua_currentline(func); |
195 | break; | 209 | break; |
196 | case 'u': | 210 | case 'u': |
197 | ar->nups = lua_nups(func); | 211 | ar->nups = lua_nups(func); |