Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Jan 1999 12:56:17 +0900 (JST)
From:      dcs@newsguy.com
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/9652: ficl is difficult to debug
Message-ID:  <199901240356.MAA03100@daniel.sobral>

next in thread | raw e-mail | index | archive | help

>Number:         9652
>Category:       bin
>Synopsis:       FICL has "see" but not "trace" or "step" (tsk, tsk!)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 23 20:00:00 PST 1999
>Closed-Date:
>Last-Modified:
>Originator:     Daniel C. Sobral
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
>Environment:

	Current as of Jan 23.

>Description:

	FICL has a "see" facility, but surprisingly lacks any kind of
trace facility.

>How-To-Repeat:

	UTSL.

>Fix:

	I added a FICL_TRACE-conditioned trace facility based on "see".
It is ugly because words' functions are almost all static, and ficlExec,
where the trace has to be located, can't get their pointers. So, #ifdef
this staticization, and add most of see's body into ficlExec. Duplication
of code, uglyness, etc. But it is cleanly #ifdef'ed, and works like a
charm.

	It does not provide "step" facility, though, just trace. It is
tunable at run-time through "trace!". If anyone (most likely me :) ever
wants a step facility, I'll add it. Should be easy.


--- ficl.h	1999/01/23 07:17:28	1.6
+++ ficl.h	1999/01/24 03:40:41
@@ -797,6 +797,13 @@
 void       constantParen(FICL_VM *pVM);
 void       twoConstParen(FICL_VM *pVM);
 
+/*
+** So we can more easily debug...
+*/
+#ifdef FICL_TRACE
+extern int ficl_trace;
+#endif
+
 #if defined(__i386__) && !defined(TESTMAIN)
 extern void ficlOutb(FICL_VM *pVM);
 extern void ficlInb(FICL_VM *pVM);
--- ficl.c	1999/01/23 07:17:28	1.4
+++ ficl.c	1999/01/24 03:42:06
@@ -29,6 +29,10 @@
 #include <string.h>
 #include "ficl.h"
 
+#ifdef FICL_TRACE
+int ficl_trace = 0;
+#endif
+
 
 /*
 ** Local prototypes
@@ -204,7 +209,90 @@
         */
         for (;;)
         {
+#ifdef FICL_TRACE
+        char buffer[40];
+	CELL *pc;
+#endif
             tempFW = *pVM->ip++;
+#ifdef FICL_TRACE
+        if (ficl_trace && isAFiclWord(tempFW))
+        {
+	extern void literalParen(FICL_VM*);
+	extern void stringLit(FICL_VM*);
+	extern void ifParen(FICL_VM*);
+	extern void branchParen(FICL_VM*);
+	extern void qDoParen(FICL_VM*);
+	extern void doParen(FICL_VM*);
+	extern void loopParen(FICL_VM*);
+	extern void plusLoopParen(FICL_VM*);
+
+            if      (tempFW->code == literalParen)
+            {
+                CELL v = *++pc;
+                if (isAFiclWord(v.p))
+                {
+                    FICL_WORD *pLit = (FICL_WORD *)v.p;
+                    sprintf(buffer, "    literal %.*s (%#lx)",
+                        pLit->nName, pLit->name, v.u);
+                }
+                else
+                    sprintf(buffer, "    literal %ld (%#lx)", v.i, v.u);
+            }
+            else if (tempFW->code == stringLit)
+            {
+                FICL_STRING *sp = (FICL_STRING *)(void *)++pc;
+                pc = (CELL *)alignPtr(sp->text + sp->count + 1) - 1;
+                sprintf(buffer, "    s\" %.*s\"", sp->count, sp->text);
+            }
+            else if (tempFW->code == ifParen)
+            {
+                CELL c = *++pc;
+                if (c.i > 0)
+                    sprintf(buffer, "    if / while (branch rel %ld)", c.i);
+                else
+                    sprintf(buffer, "    until (branch rel %ld)", c.i);
+            }
+            else if (tempFW->code == branchParen)
+            {
+                CELL c = *++pc;
+                if (c.i > 0)
+                    sprintf(buffer, "    else (branch rel %ld)", c.i);
+                else
+                    sprintf(buffer, "    repeat (branch rel %ld)", c.i);
+            }
+            else if (tempFW->code == qDoParen)
+            {
+                CELL c = *++pc;
+                sprintf(buffer, "    ?do (leave abs %#lx)", c.u);
+            }
+            else if (tempFW->code == doParen)
+            {
+                CELL c = *++pc;
+                sprintf(buffer, "    do (leave abs %#lx)", c.u);
+            }
+            else if (tempFW->code == loopParen)
+            {
+                CELL c = *++pc;
+                sprintf(buffer, "    loop (branch rel %#ld)", c.i);
+            }
+            else if (tempFW->code == plusLoopParen)
+            {
+                CELL c = *++pc;
+                sprintf(buffer, "    +loop (branch rel %#ld)", c.i);
+            }
+            else /* default: print word's name */
+            {
+                sprintf(buffer, "    %.*s", tempFW->nName, tempFW->name);
+            }
+
+            vmTextOut(pVM, buffer, 1);
+        }
+        else if (ficl_trace) /* probably not a word - punt and print value */
+        {
+            sprintf(buffer, "    %ld (%#lx)", pc->i, pc->u);
+            vmTextOut(pVM, buffer, 1);
+        }
+#endif FICL_TRACE
             /*
             ** inline code for
             ** vmExecute(pVM, tempFW);
--- words.c	1999/01/23 07:17:28	1.8
+++ words.c	1999/01/23 07:27:34	1.9
@@ -1068,7 +1068,11 @@
 ** called (not?branch) since it does "branch if false".
 **************************************************************************/
 
+#ifdef FICL_TRACE
+void ifParen(FICL_VM *pVM)
+#else
 static void ifParen(FICL_VM *pVM)
+#endif
 {
     UNS32 flag;
     
@@ -1130,7 +1134,11 @@
 ** compilation address, and branches to that location.
 **************************************************************************/
 
+#ifdef FICL_TRACE
+void branchParen(FICL_VM *pVM)
+#else
 static void branchParen(FICL_VM *pVM)
+#endif
 {
     vmBranchRelative(pVM, *(int *)(pVM->ip));
     return;
@@ -1277,8 +1285,11 @@
 ** parameter stack at runtime. This code is compiled by "literal".
 **
 **************************************************************************/
-
+#ifdef FICL_TRACE
+void literalParen(FICL_VM *pVM)
+#else
 static void literalParen(FICL_VM *pVM)
+#endif
 {
 #if FICL_ROBUST > 1
     vmCheckStack(pVM, 0, 1);
@@ -1591,8 +1602,11 @@
     return;
 }
 
-
+#ifdef FICL_TRACE
+void doParen(FICL_VM *pVM)
+#else
 static void doParen(FICL_VM *pVM)
+#endif
 {
     CELL index, limit;
 #if FICL_ROBUST > 1
@@ -1631,8 +1645,11 @@
     return;
 }
 
-
+#ifdef FICL_TRACE
+void qDoParen(FICL_VM *pVM)
+#else
 static void qDoParen(FICL_VM *pVM)
+#endif
 {
     CELL index, limit;
 #if FICL_ROBUST > 1
@@ -1705,8 +1722,11 @@
     return;
 }
 
-
+#ifdef FICL_TRACE
+void loopParen(FICL_VM *pVM)
+#else
 static void loopParen(FICL_VM *pVM)
+#endif
 {
     INT32 index = stackGetTop(pVM->rStack).i;
     INT32 limit = stackFetch(pVM->rStack, 1).i;
@@ -1727,8 +1747,11 @@
     return;
 }
 
-
+#ifdef FICL_TRACE
+void plusLoopParen(FICL_VM *pVM)
+#else
 static void plusLoopParen(FICL_VM *pVM)
+#endif
 {
     INT32 index = stackGetTop(pVM->rStack).i;
     INT32 limit = stackFetch(pVM->rStack, 1).i;
@@ -2034,8 +2057,11 @@
 ** and count on the stack. Finally, update ip to point to the first
 ** aligned address after the string text.
 **************************************************************************/
-
+#ifdef FICL_TRACE
+void stringLit(FICL_VM *pVM)
+#else
 static void stringLit(FICL_VM *pVM)
+#endif
 {
     FICL_STRING *sp = (FICL_STRING *)(pVM->ip);
     FICL_COUNT count = sp->count;
@@ -3787,7 +3813,11 @@
 ** like it's in the dictionary address range.
 ** NOTE: this excludes :noname words!
 */
+#ifdef FICL_TRACE
+int isAFiclWord(FICL_WORD *pFW)
+#else
 static int isAFiclWord(FICL_WORD *pFW)
+#endif
 {
     void *pv = (void *)pFW;
     FICL_DICT *pd  = ficlGetDict();
@@ -4405,6 +4435,18 @@
     return;
 }
 
+/************************* freebsd added trace ***************************/
+
+#ifdef FICL_TRACE
+static void ficlTrace(FICL_VM *pVM)
+{
+#if FICL_ROBUST > 1
+    vmCheckStack(pVM, 1, 1);
+#endif
+
+    ficl_trace = stackPopINT32(pVM->pStack);
+}
+#endif
 
 /**************************************************************************
                         f i c l C o m p i l e C o r e
@@ -4578,6 +4620,9 @@
     dictAppendWord(dp, "key?",	    keyQuestion,    FW_DEFAULT);
     dictAppendWord(dp, "ms",        ms,             FW_DEFAULT);
     dictAppendWord(dp, "seconds",   pseconds,       FW_DEFAULT);
+#ifdef FICL_TRACE
+    dictAppendWord(dp, "trace!",    ficlTrace,      FW_DEFAULT);
+#endif
     /*
     ** EXCEPTION word set
     */

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901240356.MAA03100>