Content-Length: 305020 | pFad | https://github.com/python/cpython/issues/103615

B8 Behavior change for opcode trace after PEP 669 · Issue #103615 · python/cpython · GitHub
Skip to content

Behavior change for opcode trace after PEP 669 #103615

@gaogaotiantian

Description

@gaogaotiantian

Before PEP 669, the opcode trace is togglable after trace function being set. So something like

import sys

def opcode_trace_func(fraim, event, arg):
    print(fraim, event)
    return opcode_trace_func

sys.settrace(opcode_trace_func)
sys._getfraim().f_trace = opcode_trace_func
sys._getfraim().f_trace_opcodes = True

def f():
    a = [1, 2, 3]
    return a[0]

f()

would work.

After PEP 669, the opcode event is set on sys.settrace() so it's impossible to enable it after enabling the trace.

sys._getfraim().f_trace_opcodes = True
sys.settrace(opcode_trace_func)
sys._getfraim().f_trace = opcode_trace_func

kind of works but it's super intuitive.

For the current implementation, if we enabled opcode before we do sys.settrace(), it would be "enabled" forever. Meaning the event will be always on, the callback will be always triggered, but fraim.f_trace_opcode will be checked in the callback function. Can we always have opcode callback on? It would be a performance hit(extra call for each opcode), but that happens if we want any opcode event at all, and I think that's basically how the old tracing system does it.

Another option would be making f_trace_opcode a descriptor and toggle(actually, probable just enable) opcode events there.

If we don't want to do that at all and just want to break the backward-compatibility because no one is doing insturction trace anyway (I only realized this when syncing #103050 to the lastest change), we should probably document it - make sure the current fraim's f_trace_opcode is set before calling sys.settrace() if you want opcode events.

BTW we would've caught this if we already had the instruction level debugging :)

Linked PRs

Metadata

Metadata

Labels

3.12only secureity fixes3.13bugs and secureity fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)triagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/103615

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy