From 52db68a600fbfbe1527250a114648da52a040247 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 21 Nov 1994 19:41:09 -0200 Subject: [PATCH] debug shows lines where functions were called --- inout.c | 70 ++++++++++++++++++++++++++++++++++----------------------- inout.h | 5 +++-- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/inout.c b/inout.c index a7dc7413..9cef2653 100644 --- a/inout.c +++ b/inout.c @@ -5,12 +5,13 @@ ** Also provides some predefined lua functions. */ -char *rcs_inout="$Id: inout.c,v 2.10 1994/11/09 18:09:22 roberto Exp roberto $"; +char *rcs_inout="$Id: inout.c,v 2.11 1994/11/14 21:40:14 roberto Exp roberto $"; #include #include #include +#include "mem.h" #include "opcode.h" #include "hash.h" #include "inout.h" @@ -23,15 +24,21 @@ int lua_linenumber; int lua_debug; int lua_debugline = 0; + /* Internal variables */ + #ifndef MAXFUNCSTACK -#define MAXFUNCSTACK 64 +#define MAXFUNCSTACK 100 #endif -static struct { + +typedef struct FuncStackNode { + struct FuncStackNode *next; char *file; int function; int line; -} funcstack[MAXFUNCSTACK]; +} FuncStackNode; + +static FuncStackNode *funcStack = NULL; static int nfuncstack=0; static FILE *fp; @@ -110,30 +117,35 @@ void lua_closestring (void) /* ** Called to execute SETFUNCTION opcode, this function pushs a function into -** function stack. Return 0 on success or 1 on error. +** function stack. */ -int lua_pushfunction (char *file, int function) +void lua_pushfunction (char *file, int function) { - if (nfuncstack >= MAXFUNCSTACK-1) + FuncStackNode *newNode; + if (nfuncstack++ >= MAXFUNCSTACK) { - lua_error ("function stack overflow"); - return 1; + lua_reportbug("function stack overflow"); } - funcstack[nfuncstack].function = function; - funcstack[nfuncstack].file = file; - funcstack[nfuncstack].line= lua_debugline; - nfuncstack++; - return 0; + newNode = new(FuncStackNode); + newNode->function = function; + newNode->file = file; + newNode->line= lua_debugline; + newNode->next = funcStack; + funcStack = newNode; } /* -** Called to execute RESET opcode, this function pops a function from +** Called to execute RESET opcode, this function pops a function from ** function stack. */ void lua_popfunction (void) { + FuncStackNode *temp = funcStack; + if (temp == NULL) return; --nfuncstack; - lua_debugline = funcstack[nfuncstack].line; + lua_debugline = temp->line; + funcStack = temp->next; + luaI_free(temp); } /* @@ -141,22 +153,24 @@ void lua_popfunction (void) */ void lua_reportbug (char *s) { - char msg[1024]; + char msg[MAXFUNCSTACK*80]; strcpy (msg, s); if (lua_debugline != 0) { - int i; - if (nfuncstack > 0) + if (funcStack) { - sprintf (strchr(msg,0), - "\n\tin statement begining at line %d in function \"%s\" of file \"%s\"", - lua_debugline, lua_constant[funcstack[nfuncstack-1].function], - funcstack[nfuncstack-1].file); - sprintf (strchr(msg,0), "\n\tactive stack\n"); - for (i=nfuncstack-1; i>=0; i--) - sprintf (strchr(msg,0), "\t-> function \"%s\" of file \"%s\"\n", - lua_constant[funcstack[i].function], - funcstack[i].file); + FuncStackNode *func = funcStack; + int line = lua_debugline; + sprintf (strchr(msg,0), "\n\tactive stack:\n"); + do + { + sprintf (strchr(msg,0), + "\t-> function \"%s\" at file \"%s\":%d\n", + lua_constant[func->function], func->file, line); + line = func->line; + func = func->next; + lua_popfunction(); + } while (func); } else { diff --git a/inout.h b/inout.h index 8155bbe4..57aa7b3e 100644 --- a/inout.h +++ b/inout.h @@ -1,11 +1,12 @@ /* -** $Id: inout.h,v 1.4 1994/11/03 22:34:29 roberto Exp roberto $ +** $Id: inout.h,v 1.5 1994/11/08 20:06:15 roberto Exp roberto $ */ #ifndef inout_h #define inout_h + extern int lua_linenumber; extern int lua_debug; extern int lua_debugline; @@ -14,7 +15,7 @@ char *lua_openfile (char *fn); void lua_closefile (void); char *lua_openstring (char *s); void lua_closestring (void); -int lua_pushfunction (char *file, int function); +void lua_pushfunction (char *file, int function); void lua_popfunction (void); void lua_reportbug (char *s);