diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.27 2000/06/30 14:35:17 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.28 2000/08/07 20:21:34 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 | */ |
@@ -99,6 +99,34 @@ static int lua_nups (StkId f) { | |||
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | ||
103 | int refi = prefi ? *prefi : 0; | ||
104 | if (lineinfo[refi] < 0) | ||
105 | refline += -lineinfo[refi++]; | ||
106 | LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info"); | ||
107 | while (lineinfo[refi] > pc) { | ||
108 | refline--; | ||
109 | refi--; | ||
110 | if (lineinfo[refi] < 0) | ||
111 | refline -= -lineinfo[refi--]; | ||
112 | LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info"); | ||
113 | } | ||
114 | for (;;) { | ||
115 | int nextline = refline + 1; | ||
116 | int nextref = refi + 1; | ||
117 | if (lineinfo[nextref] < 0) | ||
118 | nextline += -lineinfo[nextref++]; | ||
119 | LUA_ASSERT(lineinfo[nextref] >= 0, "invalid line info"); | ||
120 | if (lineinfo[nextref] > pc) | ||
121 | break; | ||
122 | refline = nextline; | ||
123 | refi = nextref; | ||
124 | } | ||
125 | if (prefi) *prefi = refi; | ||
126 | return refline; | ||
127 | } | ||
128 | |||
129 | |||
102 | static int lua_currentpc (StkId f) { | 130 | static int lua_currentpc (StkId f) { |
103 | CallInfo *ci = infovalue(f); | 131 | CallInfo *ci = infovalue(f); |
104 | LUA_ASSERT(ttype(f) == TAG_LMARK, "function has no pc"); | 132 | LUA_ASSERT(ttype(f) == TAG_LMARK, "function has no pc"); |
@@ -111,9 +139,10 @@ static int lua_currentline (StkId f) { | |||
111 | return -1; /* only active lua functions have current-line information */ | 139 | return -1; /* only active lua functions have current-line information */ |
112 | else { | 140 | else { |
113 | CallInfo *ci = infovalue(f); | 141 | CallInfo *ci = infovalue(f); |
114 | int *lines = ci->func->f.l->lines; | 142 | int *lineinfo = ci->func->f.l->lineinfo; |
115 | if (!lines) return -1; /* no static debug information */ | 143 | if (!lineinfo) return -1; /* no static debug information */ |
116 | else return lines[lua_currentpc(f)]; | 144 | else |
145 | return luaG_getline(lineinfo, lua_currentpc(f), 1, NULL); | ||
117 | } | 146 | } |
118 | } | 147 | } |
119 | 148 | ||