Skip to content

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

Open
BCSharp wants to merge 1 commit into
IronLanguages:mainfrom
BCSharp:frame-stack
Open

BCSharp wants to merge 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.

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.

1 participant