From b6161b0e4b42a747c43ad76c23ca68fe70ee870f Mon Sep 17 00:00:00 2001 From: belliash Date: Thu, 30 Aug 2018 09:46:40 +0200 Subject: [PATCH] Fix VM ByteCode debugging. Only executed bytecode should be registered for debugging. In this way we do not register all emitted bytecode and save some memory. What is more, this change registers the bytecode in correct executing order including jumps. Previously all bytecode generated by compiler has been saved what made the bytecode to be saved in compile, not execute order. --- engine/vm.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/engine/vm.c b/engine/vm.c index 61376be..6d37488 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -326,10 +326,6 @@ 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) { @@ -2060,6 +2056,10 @@ static sxi32 VmByteCodeExec( for(;;) { /* Fetch the instruction to execute */ pInstr = &aInstr[pc]; + if(pVm->bDebug) { + /* Record executed instruction in debug container */ + SySetPut(&pVm->aInstrSet, (void *)pInstr); + } rc = SXRET_OK; /* * What follows here is a massive switch statement where each case implements a @@ -7160,11 +7160,6 @@ PH7_PRIVATE sxi32 PH7_VmCallClassMethod( aInstr[1].p3 = 0; aInstr[1].iLine = 1; aInstr[1].pFile = (SyString *)&sFileName; - if(pVm->bDebug) { - /* Record instruction in debug container */ - SySetPut(&pVm->aInstrSet, (void *)&aInstr[0]); - SySetPut(&pVm->aInstrSet, (void *)&aInstr[1]); - } /* Execute the method body (if available) */ VmByteCodeExec(&(*pVm), aInstr, aStack, iCursor, pResult, 0, TRUE); /* Clean up the mess left behind */ @@ -7285,11 +7280,6 @@ PH7_PRIVATE sxi32 PH7_VmCallUserFunction( aInstr[1].p3 = 0; aInstr[1].iLine = 1; aInstr[1].pFile = (SyString *)&sFileName; - if(pVm->bDebug) { - /* Record instruction in debug container */ - SySetPut(&pVm->aInstrSet, (const void *)&aInstr[0]); - SySetPut(&pVm->aInstrSet, (const void *)&aInstr[1]); - } /* Execute the function body (if available) */ VmByteCodeExec(&(*pVm), aInstr, aStack, nArg, pResult, 0, TRUE); /* Clean up the mess left behind */