◐ Shell
clean mode source ↗

gh-122029: Do not unpack method for legacy tracing anymore by gaogaotiantian · Pull Request #130898 · python/cpython

INSTRUMENTED_CALL and INSTRUMENTED_CALL_KW now unpack the method before monitoring, so they are not affected by this change. The bytecode that this affects is INSTRUMENTED_CALL_FUNCTION_EX.

For INSTRUMENTED_CALL_FUNCTION_EX, we do not unpack the callable, instead, we use PyObject_Call directly on the callable. Because of this, sys.monitoring does not know this eventually calls into a C function, because the callable is a Python method, so c_return event will not be generated.

With the current code, because we unpack the method in sys.setprofile, we will generate an unmatched c_call, which is horrible.

The ideal result is probably have a consistent result for all three bytecodes, but that requires some refactoring for CALL_FUNCTION_EX which @markshannon was kind of against. If we can't achieve that, we should at least generated paired events - so we don't have a c_call without its c_return. That's why I removed the unpack code for legacy tracing.