Repository navigation
Lua stack traces: a raising callback, package init or payload leaves no frames behind - #1554
Merged
Merged
Conversation
… behind With -stacktraces, xpcall unwinds past the pops of a callback or package init that raises, so wurst_stack_depth stayed raised for the rest of the game and every later trace showed the failed frames. The callback adapter now saves the depth before xpcall and puts it back after; a package init puts it back when its xpcall fails. The error handlers still see the failing frames, as they run before the unwind. Builds without -stacktraces emit the adapters as before.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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
-stacktraces, a Lua callback, package init or hot reload payload which raises no longer leaves its frames on the stack-trace stack, so traces taken later show only their own frames.The problem
StackTraceInjector2makes every instrumented function push its call position on entry and pop it on a normal return. A Lua callback runs through anxpcalladapter (LuaTranslator.callbackAdapterFor), a package init through anxpcallwith__wurst_init_error, and a hot reload payload throughpcall(install). When the code raises, the unwind skips the pops:wurst_stack_depthstayed raised for the rest of the game, every later trace showed the failed frames below its own, and each further error added more. Reload hooks already put the depth back (#1551); nothing else did. Found by the review of #1551.The change
xpcalland writes it back after: one local read and one global write per call, only with-stacktraces. The error handler still sees the failing frames, as it runs before the unwind. A callback run synchronously inside another instrumented function (ForGroup, an externpcall) returns to that function's depth, the depth on entering the adapter.xpcallfails, from one global (__wurst_initStackDepth): inits run one after another, and the init call has no local of its own (the 200-locals accounting).__wurst_hotreload_applysaves and restores the depth aroundpcall(install), as the hook runner does around each hook (LuaTranslator.stackTraceDepth, shared by all three).-stacktracesthe emitted adapters, inits and runtime are byte-identical (callbackAdapterWithoutStacktracesKeepsNoDepth).Both an ordinary error and the deliberate thread abort (
I2S(1 div 0)) are covered: their handlers differ in what they print, butxpcallreturns false for both and the depth is put back for both.Evidence
Tests which fail before the change:
raisingCallbackLeavesNoStackFramesBehind(an ordinary error and the abort inside a callback run throughpcallin an instrumented function; the traces showed "when calling boom" and "via function reference" frames),raisingPackageInitLeavesNoStackFramesBehind(a raising and an aborting init, with its own driver, since the harness fails a run with a failed init), andfailedInstallLeavesNoFramesBehind(a payload adds a package whose init raises; the trace after showed "when calling explode").Unit tests, Windows:
LuaBackendAuditTests(300),LuaTranslationTests(152),LuaHotReloadTests(121),DeterministicChecks(38),HotReloadPipelineTests(6). Linux is covered by PR CI; macOS is unverified. Not measured in the game: the change is to emitted Lua which the test runtime runs as the game would, and a trace's content is a diagnostic, not game state.