svn commit: samba r8630 - in branches/SAMBA_4_0/source/lib/appweb/ejs: .

tridge at samba.org tridge at samba.org
Wed Jul 20 05:13:02 GMT 2005


Author: tridge
Date: 2005-07-20 05:13:01 +0000 (Wed, 20 Jul 2005)
New Revision: 8630

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8630

Log:
give a much nicer backtrace on assert() failures in ejs

I will submit this upstream

Modified:
   branches/SAMBA_4_0/source/lib/appweb/ejs/ejsInternal.h
   branches/SAMBA_4_0/source/lib/appweb/ejs/ejsLex.c
   branches/SAMBA_4_0/source/lib/appweb/ejs/ejsLib.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/appweb/ejs/ejsInternal.h
===================================================================
--- branches/SAMBA_4_0/source/lib/appweb/ejs/ejsInternal.h	2005-07-20 04:27:09 UTC (rev 8629)
+++ branches/SAMBA_4_0/source/lib/appweb/ejs/ejsInternal.h	2005-07-20 05:13:01 UTC (rev 8630)
@@ -192,6 +192,8 @@
 	char		*tokEndp;					/* Pointer past end of token */
 	char		*tokServp;					/* Pointer to next token char */
 	int			tokSize;					/* Size of token buffer */
+	struct ejEval *next;                    /* used for backtraces */
+	const char  *procName;                  /* gives name in backtrace */
 } EjsInput;
 
 /*

Modified: branches/SAMBA_4_0/source/lib/appweb/ejs/ejsLex.c
===================================================================
--- branches/SAMBA_4_0/source/lib/appweb/ejs/ejsLex.c	2005-07-20 04:27:09 UTC (rev 8629)
+++ branches/SAMBA_4_0/source/lib/appweb/ejs/ejsLex.c	2005-07-20 05:13:01 UTC (rev 8630)
@@ -60,11 +60,13 @@
 	mprAssert(ep);
 	mprAssert(script);
 
-	if ((ep->input = mprMalloc(sizeof(EjsInput))) == NULL) {
+	if ((ip = mprMalloc(sizeof(EjsInput))) == NULL) {
 		return -1;
 	}
-	ip = ep->input;
 	memset(ip, 0, sizeof(*ip));
+	ip->next = ep->input;
+	ep->input = ip;
+	ip->procName = ep->proc?ep->proc->procName:NULL;
 
 /*
  *	Create the parse token buffer and script buffer
@@ -102,6 +104,7 @@
 
 	ip = ep->input;
 	mprAssert(ip);
+	ep->input = ip->next;
 
 	for (i = 0; i < EJS_TOKEN_STACK; i++) {
 		mprFree(ip->putBack[i].token);

Modified: branches/SAMBA_4_0/source/lib/appweb/ejs/ejsLib.c
===================================================================
--- branches/SAMBA_4_0/source/lib/appweb/ejs/ejsLib.c	2005-07-20 04:27:09 UTC (rev 8629)
+++ branches/SAMBA_4_0/source/lib/appweb/ejs/ejsLib.c	2005-07-20 05:13:01 UTC (rev 8630)
@@ -385,7 +385,6 @@
 int ejsEvalScript(EjsId eid, char *script, MprVar *vp, char **emsg)
 {
 	Ejs			*ep;
-	EjsInput	*oldBlock;
 	int			state;
 	void		*endlessLoopTest;
 	int			loopCounter;
@@ -408,7 +407,6 @@
 	/*
 	 *	Allocate a new evaluation block, and save the old one
 	 */
-	oldBlock = ep->input;
 	ejsLexOpenScript(ep, script);
 
 	/*
@@ -447,11 +445,6 @@
 		*emsg = mprStrdup(ep->error);
 	}
 
-	/*
-	 *	Restore the old evaluation block
-	 */
-	ep->input = oldBlock;
-
 	if (state == EJS_STATE_ERR) {
 		return -1;
 	}
@@ -475,24 +468,31 @@
 {
 	EjsInput	*ip;
 	char		*errbuf, *msgbuf;
+	int frame = 0;
 
 	mprAssert(ep);
 
 	msgbuf = NULL;
 	mprAllocVsprintf(&msgbuf, MPR_MAX_STRING, fmt, args);
 
-	if (ep) {
-		ip = ep->input;
-		if (ip) {
-			mprAllocSprintf(&errbuf, MPR_MAX_STRING,
-				"%s\nError on line %d. Offending line: %s\n\n",
-				msgbuf, ip->lineNumber, ip->line);
-		} else {
-			mprAllocSprintf(&errbuf, MPR_MAX_STRING, "%s\n", msgbuf);
-		}
-		mprFree(ep->error);
-		ep->error = errbuf;
+	ip = ep->input;
+	mprAllocSprintf(&errbuf, MPR_MAX_STRING, "%s\nBacktrace:\n", msgbuf);
+
+	/* form a backtrace */
+	while (ip) {
+		char *msg2, *ebuf2;
+		mprAllocSprintf(&msg2, MPR_MAX_STRING,
+						"\t[%2d] %20s:%-4d -> %s\n",
+						frame++, ip->procName?ip->procName:"", ip->lineNumber, ip->line);
+		ebuf2 = mprRealloc(errbuf, strlen(errbuf) + strlen(msg2) + 1);
+		if (ebuf2 == NULL) break;
+		errbuf = ebuf2;
+		memcpy(errbuf+strlen(errbuf), msg2, strlen(msg2)+1);
+		mprFree(msg2);
+		ip = ip->next;
 	}
+	mprFree(ep->error);
+	ep->error = errbuf;
 	mprFree(msgbuf);
 }
 



More information about the samba-cvs mailing list