sys.settrace does not produce events for C functions
The docs for sys.settrace mention that:
event is a string: 'call', 'line', 'return', 'exception', >> 'c_call', 'c_return', or 'c_exception'
But in the code for ceval.c the only point where call_trace is invoked with PyTrace_C_CALL or PyTrace_C_RETURN is under the C_TRACE macro. In this macro this line prevents any function set up using sys.settrace to call call_trace with the mentioned arguments: if (tstate->use_tracing && tstate->c_profilefunc) Notice that from the code of PyEval_SetTrace and PyEval_SetProfile, only the later sets tstate->c_profilefunc and therefore only functions installed using sys.setprofile will recieve a c_call for the event. Xiang Zhan has suggested me to ask here what is the best course of action: 1) Document this behavior. 2) Fix the code. This question is related to this issue: https://bugs.python.org/issue17799 Thanks everyone for your time! Pablo
As I posted to the issue: The reason not to pass C calls to the tracing function is that tracing exists to support pdb and other debuggers, and pdb only cares about tracing through Python code. So the docs should be updated. On Sun, Jan 21, 2018 at 11:40 AM, Pablo Galindo Salgado <pablogsal@gmail.com
wrote:
The docs for sys.settrace mention that:
event is a string: 'call', 'line', 'return', 'exception', >> 'c_call', 'c_return', or 'c_exception'
But in the code for ceval.c the only point where call_trace is invoked with PyTrace_C_CALL or PyTrace_C_RETURN is under the C_TRACE macro. In this macro this line prevents any function set up using sys.settrace to call call_trace with the mentioned arguments:
if (tstate->use_tracing && tstate->c_profilefunc)
Notice that from the code of PyEval_SetTrace and PyEval_SetProfile, only the later sets tstate->c_profilefunc and therefore only functions installed using sys.setprofile will recieve a c_call for the event.
Xiang Zhan has suggested me to ask here what is the best course of action:
1) Document this behavior.
2) Fix the code.
This question is related to this issue: https://bugs.python.org/issue17799
Thanks everyone for your time!
Pablo
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ guido%40python.org
-- --Guido van Rossum (python.org/~guido)
participants (2)
-
Guido van Rossum -
Pablo Galindo Salgado