Fix cursor jumping for instructions which contain code
Description
Cursor jumps weirdly on complex instructions. Lets say we have
PUSH int 3;
DIP
{ DUP;
DROP;
};
When the cursor stands on PUSH int 3
and you click Next
, the cursor jumps on DUP
position.
This is the first weird behaviour: I think it should jump on DIP
position first.
Then you click Next
two more times, and cursor after DROP
jumps on DIP
.
This is the second weird behaviour: I think we should go over to the instruction after DROP.
Because of that, the unintuitive behaviour happens when you set a breakpoint on DIP
position: the execution will stop on this, but at the moment when the DIP body has already been executed. I don't think it's supposed to work so.
This whole weird jumping behaviour happens due to the way we handle complex instructions: we record children instruction first, and then we record the parent (DIP, IF, LOOP, and similar). We can't easily change its order because we need output stack after the execution to create the parent record, which can be only computed by going to the children first. And the option:
- to compute stack without recording
- yield parent
- then record children doesn't seem to work because we if a contract is infinite we will hang at this moment.
As a solution I suggest take into consideration complex instructions separately: if we meet one of them then record it with the previous stack, then record children nodes as usual. So, we will have two snapshots with the same stack (one after execution of precede instruction, the next one before execution of the body), but I think it's okay. It's like entrance in the function in regular languages.
Steps to reproduce
- Run the debugger on some contract with complex instruction like DIP, IF, LOOP, etc.
Prerequisites (if needed):
Expected behaviour
- Cursor jumps as expected
Actual behaviour
- It jumps in a weird way.
Environment
- Commit 06612bfd