diff options
author | msmith <msmith@FreeBSD.org> | 1999-01-24 06:06:21 +0000 |
---|---|---|
committer | msmith <msmith@FreeBSD.org> | 1999-01-24 06:06:21 +0000 |
commit | e106763b9268a14d32642e0c09e366243a5eda71 (patch) | |
tree | dbd64e629665661cf4bc66cbaee79c008ee02bc1 /sys/boot | |
parent | a4c067a4598ea12fc0079892fe4b6695efdd39c0 (diff) | |
download | FreeBSD-src-e106763b9268a14d32642e0c09e366243a5eda71.zip FreeBSD-src-e106763b9268a14d32642e0c09e366243a5eda71.tar.gz |
From the PR:
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.
PR: bin/9652
Submitted by: "Daniel C. Sobral" <dcs@newsguy.com>
Diffstat (limited to 'sys/boot')
-rw-r--r-- | sys/boot/ficl/ficl.c | 87 | ||||
-rw-r--r-- | sys/boot/ficl/ficl.h | 7 | ||||
-rw-r--r-- | sys/boot/ficl/words.c | 57 |
3 files changed, 145 insertions, 6 deletions
diff --git a/sys/boot/ficl/ficl.c b/sys/boot/ficl/ficl.c index f8b13ac..6ca806f 100644 --- a/sys/boot/ficl/ficl.c +++ b/sys/boot/ficl/ficl.c @@ -29,6 +29,10 @@ #include <string.h> #include "ficl.h" +#ifdef FICL_TRACE +int ficl_trace = 0; +#endif + /* ** Local prototypes @@ -204,7 +208,90 @@ int ficlExec(FICL_VM *pVM, char *pText, INT32 size) */ 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); diff --git a/sys/boot/ficl/ficl.h b/sys/boot/ficl/ficl.h index 7a54df9..644a700 100644 --- a/sys/boot/ficl/ficl.h +++ b/sys/boot/ficl/ficl.h @@ -797,6 +797,13 @@ void ficlCompileSoftCore(FICL_VM *pVM); 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); diff --git a/sys/boot/ficl/words.c b/sys/boot/ficl/words.c index cc0db3d..04cbc0a 100644 --- a/sys/boot/ficl/words.c +++ b/sys/boot/ficl/words.c @@ -1068,7 +1068,11 @@ static void ifCoIm(FICL_VM *pVM) ** 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 @@ static void elseCoIm(FICL_VM *pVM) ** 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 @@ static void interpWord(FICL_VM *pVM, STRINGINFO si) ** 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 @@ static void doCoIm(FICL_VM *pVM) 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 @@ static void qDoCoIm(FICL_VM *pVM) 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 @@ static void plusLoopCoIm(FICL_VM *pVM) 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 @@ static void loopParen(FICL_VM *pVM) 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 @@ static void compileOnly(FICL_VM *pVM) ** 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; @@ -3783,7 +3809,11 @@ static void setParentWid(FICL_VM *pVM) ** 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(); @@ -4401,6 +4431,18 @@ static void fkey(FICL_VM *pVM) 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 @@ -4574,6 +4616,9 @@ void ficlCompileCore(FICL_DICT *dp) 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 */ |