Skip to content

Keep the frame stack balanced when tracing is switched - #2119

Merged
slozier merged 1 commit into
IronLanguages:mainfrom
BCSharp:frame-stack
Oct 27, 2026
Merged

slozier merged 1 commit into
IronLanguages:mainfrom
BCSharp:frame-stack

Conversation

@BCSharp

@BCSharp BCSharp commented Oct 25, 2026

Copy link
Copy Markdown
Member

Bug: code compiled for tracing has its frames pushed and popped on the frame stack by the thread's trace listener, on the FrameEnter and FrameExit events. A thread without a trace function got a (dummy) listener only while some thread had tracing on, so when tracing was switched on or off between the two events of a frame, only one of them was handled:

  • A traced function that called sys.settrace(None) left its frame on the stack for good, as did its traced callers.
  • A frame entered while no thread was tracing and exited after another thread switched tracing on popped a frame it had not pushed: for exec'd code, the frame that exec pushes for the same code object, so exec then popped its caller's frame. At exit this could fail with "Index was out of range" in RunnableScriptCode.PopFrame.

The dispatcher now registers a dummy listener for any thread that runs code compiled for tracing, whether or not tracing is on at the moment. A dummy listener only maintains the frame stack and no longer calls trace functions: as in CPython, a thread without a trace function gets no trace events, not even for frames that have a local trace function.

@slozier slozier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good to me!

@slozier
slozier merged commit 2cac934 into IronLanguages:main Oct 27, 2026
35 checks passed
@BCSharp
BCSharp deleted the frame-stack branch October 27, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants