In order to test issue 29988 reliably, we want the ability to run trace hooks for every opcode in a frame, rather than for every line. The simplest API we've been able to come up with for that is a "f_trace_opcodes" attribute on the frame which we set from the trace hook the first time that it runs.
The f_trace attribute is writable from a tracing function. There are different restrictions, for example you can't jump inside a 'for' loop from outside. The code of the setter is complex and hard for modifications (see the discussion on PR 2827). Allowing to trace opcodes can make it more complex.
Steve's also requested the ability to *turn off* line debugging, and I'm thinking it may make sense to allow all four configurations: * both line and opcode events disabled * only getting one or the other * getting both kinds of event Opcode events would definitely be off by default, and if you do turn them on, then you'd be in a situation similar to importing ctypes: the interpreter is no longer guaranteed to work correctly. (Although unlike ctypes, you shouldn't get segfaults because of it)
My posted PR implements the "independent flags" option, where f_trace_lines and f_trace_opcodes allow per-line and per-opcode events to be requested independently. The default is to emit per-line events (as has historically been the case).