diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-21 19:41:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-21 19:41:09 -0200 |
commit | 52db68a600fbfbe1527250a114648da52a040247 (patch) | |
tree | 15b8ced5177b80f95d9a3e921f2a4820c2c146f1 | |
parent | bba1ae427fa914d5b7e8fea7b3aa2ad91fb3a4f6 (diff) | |
download | lua-52db68a600fbfbe1527250a114648da52a040247.tar.gz lua-52db68a600fbfbe1527250a114648da52a040247.tar.bz2 lua-52db68a600fbfbe1527250a114648da52a040247.zip |
debug shows lines where functions were called
-rw-r--r-- | inout.c | 70 | ||||
-rw-r--r-- | inout.h | 5 |
2 files changed, 45 insertions, 30 deletions
@@ -5,12 +5,13 @@ | |||
5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | char *rcs_inout="$Id: inout.c,v 2.10 1994/11/09 18:09:22 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.11 1994/11/14 21:40:14 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
12 | #include <string.h> | 12 | #include <string.h> |
13 | 13 | ||
14 | #include "mem.h" | ||
14 | #include "opcode.h" | 15 | #include "opcode.h" |
15 | #include "hash.h" | 16 | #include "hash.h" |
16 | #include "inout.h" | 17 | #include "inout.h" |
@@ -23,15 +24,21 @@ int lua_linenumber; | |||
23 | int lua_debug; | 24 | int lua_debug; |
24 | int lua_debugline = 0; | 25 | int lua_debugline = 0; |
25 | 26 | ||
27 | |||
26 | /* Internal variables */ | 28 | /* Internal variables */ |
29 | |||
27 | #ifndef MAXFUNCSTACK | 30 | #ifndef MAXFUNCSTACK |
28 | #define MAXFUNCSTACK 64 | 31 | #define MAXFUNCSTACK 100 |
29 | #endif | 32 | #endif |
30 | static struct { | 33 | |
34 | typedef struct FuncStackNode { | ||
35 | struct FuncStackNode *next; | ||
31 | char *file; | 36 | char *file; |
32 | int function; | 37 | int function; |
33 | int line; | 38 | int line; |
34 | } funcstack[MAXFUNCSTACK]; | 39 | } FuncStackNode; |
40 | |||
41 | static FuncStackNode *funcStack = NULL; | ||
35 | static int nfuncstack=0; | 42 | static int nfuncstack=0; |
36 | 43 | ||
37 | static FILE *fp; | 44 | static FILE *fp; |
@@ -110,30 +117,35 @@ void lua_closestring (void) | |||
110 | 117 | ||
111 | /* | 118 | /* |
112 | ** Called to execute SETFUNCTION opcode, this function pushs a function into | 119 | ** Called to execute SETFUNCTION opcode, this function pushs a function into |
113 | ** function stack. Return 0 on success or 1 on error. | 120 | ** function stack. |
114 | */ | 121 | */ |
115 | int lua_pushfunction (char *file, int function) | 122 | void lua_pushfunction (char *file, int function) |
116 | { | 123 | { |
117 | if (nfuncstack >= MAXFUNCSTACK-1) | 124 | FuncStackNode *newNode; |
125 | if (nfuncstack++ >= MAXFUNCSTACK) | ||
118 | { | 126 | { |
119 | lua_error ("function stack overflow"); | 127 | lua_reportbug("function stack overflow"); |
120 | return 1; | ||
121 | } | 128 | } |
122 | funcstack[nfuncstack].function = function; | 129 | newNode = new(FuncStackNode); |
123 | funcstack[nfuncstack].file = file; | 130 | newNode->function = function; |
124 | funcstack[nfuncstack].line= lua_debugline; | 131 | newNode->file = file; |
125 | nfuncstack++; | 132 | newNode->line= lua_debugline; |
126 | return 0; | 133 | newNode->next = funcStack; |
134 | funcStack = newNode; | ||
127 | } | 135 | } |
128 | 136 | ||
129 | /* | 137 | /* |
130 | ** Called to execute RESET opcode, this function pops a function from | 138 | ** Called to execute RESET opcode, this function pops a function from |
131 | ** function stack. | 139 | ** function stack. |
132 | */ | 140 | */ |
133 | void lua_popfunction (void) | 141 | void lua_popfunction (void) |
134 | { | 142 | { |
143 | FuncStackNode *temp = funcStack; | ||
144 | if (temp == NULL) return; | ||
135 | --nfuncstack; | 145 | --nfuncstack; |
136 | lua_debugline = funcstack[nfuncstack].line; | 146 | lua_debugline = temp->line; |
147 | funcStack = temp->next; | ||
148 | luaI_free(temp); | ||
137 | } | 149 | } |
138 | 150 | ||
139 | /* | 151 | /* |
@@ -141,22 +153,24 @@ void lua_popfunction (void) | |||
141 | */ | 153 | */ |
142 | void lua_reportbug (char *s) | 154 | void lua_reportbug (char *s) |
143 | { | 155 | { |
144 | char msg[1024]; | 156 | char msg[MAXFUNCSTACK*80]; |
145 | strcpy (msg, s); | 157 | strcpy (msg, s); |
146 | if (lua_debugline != 0) | 158 | if (lua_debugline != 0) |
147 | { | 159 | { |
148 | int i; | 160 | if (funcStack) |
149 | if (nfuncstack > 0) | ||
150 | { | 161 | { |
151 | sprintf (strchr(msg,0), | 162 | FuncStackNode *func = funcStack; |
152 | "\n\tin statement begining at line %d in function \"%s\" of file \"%s\"", | 163 | int line = lua_debugline; |
153 | lua_debugline, lua_constant[funcstack[nfuncstack-1].function], | 164 | sprintf (strchr(msg,0), "\n\tactive stack:\n"); |
154 | funcstack[nfuncstack-1].file); | 165 | do |
155 | sprintf (strchr(msg,0), "\n\tactive stack\n"); | 166 | { |
156 | for (i=nfuncstack-1; i>=0; i--) | 167 | sprintf (strchr(msg,0), |
157 | sprintf (strchr(msg,0), "\t-> function \"%s\" of file \"%s\"\n", | 168 | "\t-> function \"%s\" at file \"%s\":%d\n", |
158 | lua_constant[funcstack[i].function], | 169 | lua_constant[func->function], func->file, line); |
159 | funcstack[i].file); | 170 | line = func->line; |
171 | func = func->next; | ||
172 | lua_popfunction(); | ||
173 | } while (func); | ||
160 | } | 174 | } |
161 | else | 175 | else |
162 | { | 176 | { |
@@ -1,11 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: inout.h,v 1.4 1994/11/03 22:34:29 roberto Exp roberto $ | 2 | ** $Id: inout.h,v 1.5 1994/11/08 20:06:15 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | 5 | ||
6 | #ifndef inout_h | 6 | #ifndef inout_h |
7 | #define inout_h | 7 | #define inout_h |
8 | 8 | ||
9 | |||
9 | extern int lua_linenumber; | 10 | extern int lua_linenumber; |
10 | extern int lua_debug; | 11 | extern int lua_debug; |
11 | extern int lua_debugline; | 12 | extern int lua_debugline; |
@@ -14,7 +15,7 @@ char *lua_openfile (char *fn); | |||
14 | void lua_closefile (void); | 15 | void lua_closefile (void); |
15 | char *lua_openstring (char *s); | 16 | char *lua_openstring (char *s); |
16 | void lua_closestring (void); | 17 | void lua_closestring (void); |
17 | int lua_pushfunction (char *file, int function); | 18 | void lua_pushfunction (char *file, int function); |
18 | void lua_popfunction (void); | 19 | void lua_popfunction (void); |
19 | void lua_reportbug (char *s); | 20 | void lua_reportbug (char *s); |
20 | 21 | ||