From 178f3820f60cfb6c975fe857268672f0624016af Mon Sep 17 00:00:00 2001 From: belliash Date: Sun, 26 Aug 2018 19:59:17 +0200 Subject: [PATCH] Enable debugging. This commit introduces ne debug feature. The PH7 Engine limits the VM dump to the global scope. Since Aer Script is fully object-oriented language the dump option contains only information about last call of OP_DONE. This change, forces the VM to store all instructions set in a global container when debugging is enabled, thus providing information the dump of whole script parse. --- engine/vm.c | 13 ++++++++++++- include/ph7int.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/engine/vm.c b/engine/vm.c index 8cccfd9..7354ea1 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -319,6 +319,10 @@ PH7_PRIVATE sxi32 PH7_VmEmitInstr( /* Instruction index in the bytecode array */ *pIndex = SySetUsed(pVm->pByteContainer); } + if(pVm->bDebug) { + /* Record instruction in debug container */ + SySetPut(&pVm->aInstrSet, (void *)&sInstr); + } /* Finally,record the instruction */ rc = SySetPut(pVm->pByteContainer, (const void *)&sInstr); if(rc != SXRET_OK) { @@ -981,6 +985,10 @@ PH7_PRIVATE sxi32 PH7_VmInit( SyStringInitFromBuf(&sBuiltin, PH7_BUILTIN_LIB, sizeof(PH7_BUILTIN_LIB) - 1); /* Precompile the built-in library */ VmEvalChunk(&(*pVm), 0, &sBuiltin, PH7_AERSCRIPT_CODE); + /* Initialize instructions debug container */ + if(pVm->bDebug) { + SySetInit(&pVm->aInstrSet, &pVm->sAllocator, sizeof(VmInstr)); + } /* Reset the code generator */ PH7_ResetCodeGenerator(&(*pVm), pEngine->xConf.xErr, pEngine->xConf.pErrData); return SXRET_OK; @@ -5756,7 +5764,10 @@ PH7_PRIVATE sxi32 PH7_VmDump( void *pUserData /* Last argument to xConsumer() */ ) { sxi32 rc; - rc = VmByteCodeDump(pVm->pByteContainer, xConsumer, pUserData); + if(!pVm->bDebug) { + return SXRET_OK; + } + rc = VmByteCodeDump(&pVm->aInstrSet, xConsumer, pUserData); return rc; } /* diff --git a/include/ph7int.h b/include/ph7int.h index 898f0ad..6786c6e 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -1199,6 +1199,7 @@ struct ph7_vm { SyMutex *pMutex; /* Recursive mutex associated with VM. */ #endif ph7 *pEngine; /* Interpreter that own this VM */ + SySet aInstrSet; /* Instructions debug container */ SySet aByteCode; /* Default bytecode container */ SySet *pByteContainer; /* Current bytecode container */ VmFrame *pFrame; /* Stack of active frames */ @@ -1232,7 +1233,8 @@ struct ph7_vm { void *pStdin; /* STDIN IO stream */ void *pStdout; /* STDOUT IO stream */ void *pStderr; /* STDERR IO stream */ - int bErrReport; /* TRUE to report all runtime Error/Warning/Notice */ + sxbool bDebug; /* TRUE to enable debugging */ + sxbool bErrReport; /* TRUE to report all runtime Error/Warning/Notice */ int nRecursionDepth; /* Current recursion depth */ int nMaxDepth; /* Maximum allowed recursion depth */ int nObDepth; /* OB depth */