Add PC field to VMFrame, ensure that it is updated whenever vm increments/decrements the pc

Does not change alignment, the offsets used in VMFrame still work
We need this for the debugger because we otherwise have no way to get the pc; it was a local in `ExecScriptFunc()`
This commit is contained in:
nikitalita 2025-03-02 15:45:35 -08:00
parent 82264e07fd
commit ebf78661af
2 changed files with 6 additions and 2 deletions

View file

@ -54,7 +54,8 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
const double *konstf = sfunc->KonstF;
const FString *konsts = sfunc->KonstS;
const FVoidObj *konsta = sfunc->KonstA;
const VMOP *pc = sfunc->Code;
f->PC = sfunc->Code;
const VMOP *&pc = f->PC;
assert(!(f->Func->VarFlags & VARF_Native) && "Only script functions should ever reach VMExec");
@ -1958,7 +1959,8 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
while(--try_depth >= 0)
{
pc = exception_frames[try_depth];
f->PC = exception_frames[try_depth];
pc = f->PC;
assert(pc->op == OP_CATCH);
while (pc->a > 1)
{

View file

@ -239,6 +239,7 @@ extern const VMOpInfo OpInfo[NUM_OPS];
// VM frame layout:
// VMFrame header
// parameter stack - 16 byte boundary, 16 bytes each
// program counter
// double registers - 8 bytes each
// string registers - 4 or 8 bytes each
// address registers - 4 or 8 bytes each
@ -249,6 +250,7 @@ struct VMFrame
{
VMFrame *ParentFrame;
VMFunction *Func;
const VMOP *PC = nullptr;
VM_UBYTE NumRegD;
VM_UBYTE NumRegF;
VM_UBYTE NumRegS;