Repository navigation
Conversation
With HXCPP_STACK_SCRIPTABLE, the debugger reads a cppia function's `this` and
variables relative to its hx::StackFrame, taking the frame base to be
`inStack - stackSize`. That isn't where the frame starts. At a call, ctx->frame is
set to the stack pointer before `this` and the arguments are pushed (pushArgs /
AutoStack), and the function's StackLayout already counts the `this` slot and the
arguments, so runFunction's `pointer += stackSize` allocates the whole layout again on
top of them. The StackFrame is then pushed at
frame + sizeof(hx::Object *) + argBytes + stackSize
so `inStack - stackSize` lands on the first argument (or the first local, with no
arguments), not on `this`. Inspecting variables in a cppia function with arguments
read an Int argument as `this` and crashed; locals read from the wrong slots.
scriptableBase() computes the base from the StackFrame by subtracting the layout
size, the `this` slot and the arguments' bytes, and getScriptableVariables,
getScriptableValue and setScriptableValue use it. The closure path (CppiaClosure::doRun)
writes `this` to ctx->frame and lays out the same, so it's covered too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
HXCPP_STACK_SCRIPTABLE, the debugger reads a cppia function'sthisand local variables relative to the function'shx::StackFrame, taking the frame base to beinStack - stackSize. That isn't where the frame starts.At a call,
ctx->frameis set to the stack pointer beforethisand the arguments are pushed (pushArgsplusAutoStack), and the function'sStackLayoutalready counts thethisslot and the arguments (the layout starts atsizeof(void *)andCppiaStackVar::linkadds each argument).runFunctionthen doespointer += stackSize, which allocates the whole layout again on top of what was pushed, andCPPIA_STACK_FRAMEpushes theStackFramethere. So the frame sits atand
inStack - stackSizelands on the first argument (or on the first local, when there are none), not onthis.Symptom: with hxcpp-debugger, inspecting variables inside a cppia function that has arguments reads an
Intargument asthisand crashes the debuggee; locals read from the wrong slots.Fix:
scriptableBase()computes the base from theStackFrameby subtracting the layout size, thethisslot and the arguments' bytes (fromsTypeSize[argType]), andgetScriptableVariables,getScriptableValueandsetScriptableValueuse it. The closure path (CppiaClosure::doRun) writesthistoctx->frameand lays the stack out the same way, so it's covered as well.This is the variable-reading half of what I've been running for a few months in a fork, together with hxcpp-debugger, to debug hot-reloaded cppia code (whirlinggizmo/hotreload-hx). It's independent of the
HXCPP_API_LEVEL >= 500gate on the cppia debug hook: with the gate, the fix matters on Haxe 5; without it (in my fork), on 4.x too. This PR leaves the gate alone.