示例#1
0
文件: nl-debug.c 项目: vxchao/newlisp
int debugPrintFunction(CELL * cell)
{
int preLen, pos = 0;
char * strPos;

STREAM strStream = {NULL, NULL, 0, 0, 0};

if(currentFunc == nilSymbol) return FALSE;

debugPrintCell = cell;
openStrStream(&strStream, MAX_STRING, 0);
printSymbol(currentFunc, (UINT)&strStream);
debugPrintCell = NULL;

strPos = strstr(strStream.buffer, debugPreStr);
if(strPos != NULL)
    {
    preLen = strlen(debugPreStr);
    while(*(strPos + preLen + pos) <= ' ' && *(strPos + preLen + pos) != 0) ++pos;
    if(pos) /* if there is white space */
        {
        /* swap whitespace and debugPreStr */
        strncpy(strPos, strPos + preLen, pos);
        strncpy(strPos + pos, debugPreStr, preLen);
        }
    varPrintf(OUT_CONSOLE, "%s", headerStr);
    varPrintf(OUT_CONSOLE, "%s", strStream.buffer);
    }

closeStrStream(&strStream);
return (strPos != NULL);
}
示例#2
0
文件: nl-debug.c 项目: vxchao/newlisp
void traceExit(CELL * result, CELL * cell, CELL * pCell, CELL * args)
{
if(traceFlag & (TRACE_IN_ENTRY | TRACE_IN_EXIT | TRACE_SIGNAL | TRACE_SIGINT | TRACE_TIMER)) return;

if(traceFlag == TRACE_PRINT_EVAL)
    {
    tracePrint("exit", result);
    return;
    }

traceFlag |= TRACE_IN_EXIT;

#ifdef DEBUGGER
if(traceFlag & TRACE_DEBUG_NEXT)
    {
    if(currentLevel >= recursionCount)
        traceFlag &= ~TRACE_DEBUG_NEXT;
    else 
        {
        traceFlag &= ~TRACE_IN_EXIT;
        return;
        }
    }

if( (pCell->type == CELL_LAMBDA || pCell->type == CELL_FEXPR)
        && args->type == CELL_SYMBOL)
    {
    if((UINT)recursionCount == *(debugStack + debugStackIdx - 2) )
        {
        debugStackIdx -= 2;
        if(debugStackIdx > 0)
            currentFunc = (SYMBOL *)*(debugStack + debugStackIdx - 1);
        if(debugStackIdx == 0)
            traceFlag &= ~TRACE_DEBUG_NEXT;
        }
    }

if(debugPrintFunction(cell))
    {
    varPrintf(OUT_CONSOLE, "\nRESULT: ");
    printCell(result, TRUE, OUT_CONSOLE);
    varPrintf(OUT_CONSOLE, "\n");

    if(debugStackIdx > 0)
        {
        getDebuggerInput(DEBUG_EXIT);
        if(!traceFlag) return;
        }
    }

if(traceFlag & TRACE_DEBUG_NEXT)
    currentLevel = recursionCount;
#endif /* DEBUGGER */

traceFlag &= ~TRACE_IN_EXIT;
}
示例#3
0
文件: nl-debug.c 项目: vxchao/newlisp
void tracePrint(char * label, CELL * expr)
{
UINT printDeviceSave = printDevice;

printDevice = tracePrintDevice;
varPrintf(OUT_DEVICE, "%d %s: ", recursionCount, label);
if(expr) printCell(expr, TRUE, OUT_DEVICE);
varPrintf(OUT_DEVICE, "%s", "\n");
printDevice = printDeviceSave;
}
示例#4
0
CELL * p_dumpSymbol(CELL * params)
{
char * name;
SYMBOL * sPtr;

getString(params, &name);

sPtr = findInsertSymbol(name, LOOKUP_ONLY);

if(sPtr == NULL)
	return(nilCell);

varPrintf(OUT_DEVICE, "name=%s color=%s parent=%s left=%s right=%s\n", 
	sPtr->name,
	(sPtr->color == RED) ? "red" : "black",
	(sPtr->parent) ? sPtr->parent->name : "ROOT",
	sPtr->left->name,
	sPtr->right->name);

return(trueCell);
}
示例#5
0
文件: nl-debug.c 项目: vxchao/newlisp
void getDebuggerInput(char * msg)
{
char command[MAX_LINE];
char * context;
jmp_buf errorJumpSave;
UINT * resultStackIdxSave;
SYMBOL * contextSave;

while(TRUE)
    {

    if(currentContext != mainContext)
        context = currentContext->name;
    else context = "";


    if(!evalSilent)
        varPrintf(OUT_CONSOLE, "\n[%s %d %s]%s", msg, recursionCount, context, footerStr);
    else evalSilent = FALSE;

    if(fgets(command, MAX_LINE - 1, IOchannel) == NULL)
        fatalError(ERR_IO_ERROR, 0, 0);

    /* client and server could have different line-termination */
    if(*(command + 1) == '\n' || *(command + 1) == '\r')
        {
        if(*command == 'n')
            {
            traceFlag |= TRACE_DEBUG_NEXT;
            currentLevel = recursionCount;
            break;
            }
        if(*command == 's')
            {
            traceFlag &= ~TRACE_DEBUG_NEXT;
            break;
            }
        if(*command == 'q')
            {
            closeTrace();
            longjmp(errorJump, ERR_USER_RESET);
            }
        if(*command == 'c')
            {
            closeTrace();
            break;
            }
        }

    resultStackIdxSave = resultStackIdx;
    memcpy(errorJumpSave, errorJump, sizeof(jmp_buf));
    contextSave = currentContext;
    currentContext = currentFunc->context;
    if(setjmp(errorJump))
        {
        cleanupResults(resultStackIdxSave);
        goto DEBUG_EVAL_END;
        }

    executeCommandLine(command, OUT_CONSOLE, NULL); 

    DEBUG_EVAL_END:
    currentContext = contextSave;
    memcpy(errorJump, errorJumpSave, sizeof(jmp_buf));
    }
}