summaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c85
1 files changed, 22 insertions, 63 deletions
diff --git a/ldebug.c b/ldebug.c
index 34b3eec5..323a5f7c 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.103 2002/03/19 12:45:25 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.104 2002/03/22 16:54:31 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*/
@@ -34,6 +34,24 @@ static int isLmark (CallInfo *ci) {
34} 34}
35 35
36 36
37static int currentpc (lua_State *L, CallInfo *ci) {
38 if (ci->pc == NULL) return -1; /* function is not an active Lua function */
39 if (ci == L->ci || ci->pc != (ci+1)->pc) /* no other function using `pc'? */
40 return (*ci->pc - ci_func(ci)->l.p->code) - 1;
41 else /* function's pc is saved */
42 return (ci->savedpc - ci_func(ci)->l.p->code) - 1;
43}
44
45
46static int currentline (lua_State *L, CallInfo *ci) {
47 int pc = currentpc(L, ci);
48 if (pc < 0)
49 return -1; /* only active lua functions have current-line information */
50 else
51 return ci_func(ci)->l.p->lineinfo[pc];
52}
53
54
37LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { 55LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) {
38 lua_Hook oldhook; 56 lua_Hook oldhook;
39 lua_lock(L); 57 lua_lock(L);
@@ -45,10 +63,13 @@ LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) {
45 63
46 64
47LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { 65LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) {
66 CallInfo *ci;
48 lua_Hook oldhook; 67 lua_Hook oldhook;
49 lua_lock(L); 68 lua_lock(L);
50 oldhook = L->linehook; 69 oldhook = L->linehook;
51 L->linehook = func; 70 L->linehook = func;
71 for (ci = L->base_ci; ci <= L->ci; ci++)
72 ci->lastpc = currentpc(L, ci);
52 lua_unlock(L); 73 lua_unlock(L);
53 return oldhook; 74 return oldhook;
54} 75}
@@ -67,57 +88,6 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
67} 88}
68 89
69 90
70int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) {
71 int refi;
72 if (lineinfo == NULL) return -1; /* no line info */
73 refi = prefi ? *prefi : 0;
74 if (lineinfo[refi] < 0)
75 refline += -lineinfo[refi++];
76 lua_assert(lineinfo[refi] >= 0);
77 while (lineinfo[refi] > pc) {
78 refline--;
79 refi--;
80 if (lineinfo[refi] < 0)
81 refline -= -lineinfo[refi--];
82 lua_assert(lineinfo[refi] >= 0);
83 }
84 for (;;) {
85 int nextline = refline + 1;
86 int nextref = refi + 1;
87 if (lineinfo[nextref] < 0)
88 nextline += -lineinfo[nextref++];
89 lua_assert(lineinfo[nextref] >= 0);
90 if (lineinfo[nextref] > pc)
91 break;
92 refline = nextline;
93 refi = nextref;
94 }
95 if (prefi) *prefi = refi;
96 return refline;
97}
98
99
100static int currentpc (lua_State *L, CallInfo *ci) {
101 lua_assert(isLmark(ci));
102 if (ci->pc == NULL) return 0; /* function is not active */
103 if (ci == L->ci || ci->pc != (ci+1)->pc) /* no other function using `pc'? */
104 return (*ci->pc - ci_func(ci)->l.p->code) - 1;
105 else /* function's pc is saved */
106 return (ci->savedpc - ci_func(ci)->l.p->code) - 1;
107}
108
109
110static int currentline (lua_State *L, CallInfo *ci) {
111 if (!isLmark(ci))
112 return -1; /* only active lua functions have current-line information */
113 else {
114 int *lineinfo = ci_func(ci)->l.p->lineinfo;
115 return luaG_getline(lineinfo, currentpc(L, ci), 1, NULL);
116 }
117}
118
119
120
121static Proto *getluaproto (CallInfo *ci) { 91static Proto *getluaproto (CallInfo *ci) {
122 return (isLmark(ci) ? ci_func(ci)->l.p : NULL); 92 return (isLmark(ci) ? ci_func(ci)->l.p : NULL);
123} 93}
@@ -272,19 +242,8 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
272#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) 242#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize)
273 243
274 244
275static int checklineinfo (const Proto *pt) {
276 int *lineinfo = pt->lineinfo;
277 if (lineinfo == NULL) return 1;
278 check(pt->sizelineinfo >= 2 && lineinfo[pt->sizelineinfo-1] == MAX_INT);
279 lua_assert(luaG_getline(lineinfo, pt->sizecode-1, 1, NULL) < MAX_INT);
280 if (*lineinfo < 0) lineinfo++;
281 check(*lineinfo == 0);
282 return 1;
283}
284
285 245
286static int precheck (const Proto *pt) { 246static int precheck (const Proto *pt) {
287 check(checklineinfo(pt));
288 check(pt->maxstacksize <= MAXSTACK); 247 check(pt->maxstacksize <= MAXSTACK);
289 lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize); 248 lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize);
290 check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); 249 check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);