debug shows lines where functions were called
This commit is contained in:
66
inout.c
66
inout.c
@@ -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,20 +117,21 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -132,8 +140,12 @@ int lua_pushfunction (char *file, int function)
|
|||||||
*/
|
*/
|
||||||
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)
|
{
|
||||||
|
FuncStackNode *func = funcStack;
|
||||||
|
int line = lua_debugline;
|
||||||
|
sprintf (strchr(msg,0), "\n\tactive stack:\n");
|
||||||
|
do
|
||||||
{
|
{
|
||||||
sprintf (strchr(msg,0),
|
sprintf (strchr(msg,0),
|
||||||
"\n\tin statement begining at line %d in function \"%s\" of file \"%s\"",
|
"\t-> function \"%s\" at file \"%s\":%d\n",
|
||||||
lua_debugline, lua_constant[funcstack[nfuncstack-1].function],
|
lua_constant[func->function], func->file, line);
|
||||||
funcstack[nfuncstack-1].file);
|
line = func->line;
|
||||||
sprintf (strchr(msg,0), "\n\tactive stack\n");
|
func = func->next;
|
||||||
for (i=nfuncstack-1; i>=0; i--)
|
lua_popfunction();
|
||||||
sprintf (strchr(msg,0), "\t-> function \"%s\" of file \"%s\"\n",
|
} while (func);
|
||||||
lua_constant[funcstack[i].function],
|
|
||||||
funcstack[i].file);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
5
inout.h
5
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
|
#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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user