debug shows lines where functions were called

This commit is contained in:
Roberto Ierusalimschy
1994-11-21 19:41:09 -02:00
parent bba1ae427f
commit 52db68a600
2 changed files with 45 additions and 30 deletions

70
inout.c
View File

@@ -5,12 +5,13 @@
** Also provides some predefined lua functions. ** 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 <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "mem.h"
#include "opcode.h" #include "opcode.h"
#include "hash.h" #include "hash.h"
#include "inout.h" #include "inout.h"
@@ -23,15 +24,21 @@ int lua_linenumber;
int lua_debug; int lua_debug;
int lua_debugline = 0; int lua_debugline = 0;
/* Internal variables */ /* Internal variables */
#ifndef MAXFUNCSTACK #ifndef MAXFUNCSTACK
#define MAXFUNCSTACK 64 #define MAXFUNCSTACK 100
#endif #endif
static struct {
typedef struct FuncStackNode {
struct FuncStackNode *next;
char *file; char *file;
int function; int function;
int line; int line;
} funcstack[MAXFUNCSTACK]; } FuncStackNode;
static FuncStackNode *funcStack = NULL;
static int nfuncstack=0; static int nfuncstack=0;
static FILE *fp; static FILE *fp;
@@ -110,30 +117,35 @@ void lua_closestring (void)
/* /*
** Called to execute SETFUNCTION opcode, this function pushs a function into ** 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"); lua_reportbug("function stack overflow");
return 1;
} }
funcstack[nfuncstack].function = function; newNode = new(FuncStackNode);
funcstack[nfuncstack].file = file; newNode->function = function;
funcstack[nfuncstack].line= lua_debugline; newNode->file = file;
nfuncstack++; newNode->line= lua_debugline;
return 0; 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. ** function stack.
*/ */
void lua_popfunction (void) void lua_popfunction (void)
{ {
FuncStackNode *temp = funcStack;
if (temp == NULL) return;
--nfuncstack; --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) void lua_reportbug (char *s)
{ {
char msg[1024]; char msg[MAXFUNCSTACK*80];
strcpy (msg, s); strcpy (msg, s);
if (lua_debugline != 0) if (lua_debugline != 0)
{ {
int i; if (funcStack)
if (nfuncstack > 0)
{ {
sprintf (strchr(msg,0), FuncStackNode *func = funcStack;
"\n\tin statement begining at line %d in function \"%s\" of file \"%s\"", int line = lua_debugline;
lua_debugline, lua_constant[funcstack[nfuncstack-1].function], sprintf (strchr(msg,0), "\n\tactive stack:\n");
funcstack[nfuncstack-1].file); do
sprintf (strchr(msg,0), "\n\tactive stack\n"); {
for (i=nfuncstack-1; i>=0; i--) sprintf (strchr(msg,0),
sprintf (strchr(msg,0), "\t-> function \"%s\" of file \"%s\"\n", "\t-> function \"%s\" at file \"%s\":%d\n",
lua_constant[funcstack[i].function], lua_constant[func->function], func->file, line);
funcstack[i].file); line = func->line;
func = func->next;
lua_popfunction();
} while (func);
} }
else else
{ {

View File

@@ -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 #ifndef inout_h
#define inout_h #define inout_h
extern int lua_linenumber; extern int lua_linenumber;
extern int lua_debug; extern int lua_debug;
extern int lua_debugline; extern int lua_debugline;
@@ -14,7 +15,7 @@ char *lua_openfile (char *fn);
void lua_closefile (void); void lua_closefile (void);
char *lua_openstring (char *s); char *lua_openstring (char *s);
void lua_closestring (void); void lua_closestring (void);
int lua_pushfunction (char *file, int function); void lua_pushfunction (char *file, int function);
void lua_popfunction (void); void lua_popfunction (void);
void lua_reportbug (char *s); void lua_reportbug (char *s);