diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-01-19 10:00:45 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-01-19 10:00:45 -0200 |
commit | 2877bad4c260d11c22c3b12e633d6b1ca3415789 (patch) | |
tree | 2109684c4521c34b584bfd24e0eae05688c7fc32 /ldo.c | |
parent | 27163f032eed6b851b98a0ab67b1387d701e61c0 (diff) | |
download | lua-2877bad4c260d11c22c3b12e633d6b1ca3415789.tar.gz lua-2877bad4c260d11c22c3b12e633d6b1ca3415789.tar.bz2 lua-2877bad4c260d11c22c3b12e633d6b1ca3415789.zip |
new debug API (first version)
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 43 |
1 files changed, 18 insertions, 25 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.64 1999/12/30 18:40:57 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.65 2000/01/13 15:56:03 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 | */ |
@@ -55,8 +55,9 @@ void luaD_checkstack (lua_State *L, int n) { | |||
55 | lua_error(L, "BAD STACK OVERFLOW! DATA CORRUPTED!!"); | 55 | lua_error(L, "BAD STACK OVERFLOW! DATA CORRUPTED!!"); |
56 | } | 56 | } |
57 | else { | 57 | else { |
58 | lua_Dbgactreg dummy; | ||
58 | L->stack_last += EXTRA_STACK; /* to be used by error message */ | 59 | L->stack_last += EXTRA_STACK; /* to be used by error message */ |
59 | if (lua_stackedfunction(L, L->stacksize/SLOTS_PER_F) == LUA_NOOBJECT) { | 60 | if (lua_getstack(L, L->stacksize/SLOTS_PER_F, &dummy) == 0) { |
60 | /* too few funcs on stack: doesn't look like a recursion loop */ | 61 | /* too few funcs on stack: doesn't look like a recursion loop */ |
61 | lua_error(L, "Lua2C - C2Lua overflow"); | 62 | lua_error(L, "Lua2C - C2Lua overflow"); |
62 | } | 63 | } |
@@ -100,13 +101,17 @@ void luaD_openstack (lua_State *L, StkId pos) { | |||
100 | } | 101 | } |
101 | 102 | ||
102 | 103 | ||
103 | void luaD_lineHook (lua_State *L, int line) { | 104 | void luaD_lineHook (lua_State *L, StkId func, int line) { |
104 | if (L->allowhooks) { | 105 | if (L->allowhooks) { |
106 | lua_Dbgactreg ar; | ||
105 | struct C_Lua_Stack oldCLS = L->Cstack; | 107 | struct C_Lua_Stack oldCLS = L->Cstack; |
106 | StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; | 108 | StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; |
107 | L->Cstack.num = 0; | 109 | L->Cstack.num = 0; |
110 | ar._func = func; | ||
111 | ar.event = "line"; | ||
112 | ar.currentline = line; | ||
108 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 113 | L->allowhooks = 0; /* cannot call hooks inside a hook */ |
109 | (*L->linehook)(L, line); | 114 | (*L->linehook)(L, &ar); |
110 | L->allowhooks = 1; | 115 | L->allowhooks = 1; |
111 | L->top = old_top; | 116 | L->top = old_top; |
112 | L->Cstack = oldCLS; | 117 | L->Cstack = oldCLS; |
@@ -114,29 +119,17 @@ void luaD_lineHook (lua_State *L, int line) { | |||
114 | } | 119 | } |
115 | 120 | ||
116 | 121 | ||
117 | void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook, | 122 | void luaD_callHook (lua_State *L, StkId func, lua_Dbghook callhook, |
118 | int isreturn) { | 123 | const char *event) { |
119 | if (L->allowhooks) { | 124 | if (L->allowhooks) { |
125 | lua_Dbgactreg ar; | ||
120 | struct C_Lua_Stack oldCLS = L->Cstack; | 126 | struct C_Lua_Stack oldCLS = L->Cstack; |
121 | StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; | 127 | StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; |
122 | L->Cstack.num = 0; | 128 | L->Cstack.num = 0; |
129 | ar._func = func; | ||
130 | ar.event = event; | ||
123 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 131 | L->allowhooks = 0; /* cannot call hooks inside a hook */ |
124 | if (isreturn) | 132 | callhook(L, &ar); |
125 | callhook(L, LUA_NOOBJECT, "(return)", 0); | ||
126 | else { | ||
127 | switch (ttype(func)) { | ||
128 | case LUA_T_LPROTO: | ||
129 | callhook(L, func, tfvalue(func)->source->str, | ||
130 | tfvalue(func)->lineDefined); | ||
131 | break; | ||
132 | case LUA_T_LCLOSURE: | ||
133 | callhook(L, func, tfvalue(protovalue(func))->source->str, | ||
134 | tfvalue(protovalue(func))->lineDefined); | ||
135 | break; | ||
136 | default: | ||
137 | callhook(L, func, "(C)", -1); | ||
138 | } | ||
139 | } | ||
140 | L->allowhooks = 1; | 133 | L->allowhooks = 1; |
141 | L->top = old_top; | 134 | L->top = old_top; |
142 | L->Cstack = oldCLS; | 135 | L->Cstack = oldCLS; |
@@ -157,7 +150,7 @@ static StkId callC (lua_State *L, lua_CFunction f, StkId base) { | |||
157 | L->Cstack.lua2C = base; | 150 | L->Cstack.lua2C = base; |
158 | L->Cstack.base = L->top; | 151 | L->Cstack.base = L->top; |
159 | if (L->callhook) | 152 | if (L->callhook) |
160 | luaD_callHook(L, base-1, L->callhook, 0); | 153 | luaD_callHook(L, base-1, L->callhook, "call"); |
161 | (*f)(L); /* do the actual call */ | 154 | (*f)(L); /* do the actual call */ |
162 | firstResult = L->Cstack.base; | 155 | firstResult = L->Cstack.base; |
163 | L->Cstack = oldCLS; | 156 | L->Cstack = oldCLS; |
@@ -195,7 +188,7 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) { | |||
195 | */ | 188 | */ |
196 | void luaD_call (lua_State *L, StkId func, int nResults) { | 189 | void luaD_call (lua_State *L, StkId func, int nResults) { |
197 | StkId firstResult; | 190 | StkId firstResult; |
198 | lua_CHFunction callhook = L->callhook; | 191 | lua_Dbghook callhook = L->callhook; |
199 | retry: /* for `function' tag method */ | 192 | retry: /* for `function' tag method */ |
200 | switch (ttype(func)) { | 193 | switch (ttype(func)) { |
201 | case LUA_T_CPROTO: | 194 | case LUA_T_CPROTO: |
@@ -228,7 +221,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
228 | } | 221 | } |
229 | } | 222 | } |
230 | if (callhook) /* same hook that was active at entry */ | 223 | if (callhook) /* same hook that was active at entry */ |
231 | luaD_callHook(L, NULL, callhook, 1); /* `return' hook */ | 224 | luaD_callHook(L, func, callhook, "return"); |
232 | /* adjust the number of results */ | 225 | /* adjust the number of results */ |
233 | if (nResults == MULT_RET) | 226 | if (nResults == MULT_RET) |
234 | nResults = L->top - firstResult; | 227 | nResults = L->top - firstResult; |