cpython/Lib/test/dtracedata/call_stack.py
Pablo Galindo Salgado b1e8453dda gh-98894: Restore function entry/exit DTrace probes
The function__entry and function__return probes stopped working in Python 3.11
when the interpreter was restructured around the new bytecode system. This change
restores these probes by adding DTRACE_FUNCTION_ENTRY() at the start_frame label
in bytecodes.c and DTRACE_FUNCTION_RETURN() in the RETURN_VALUE and YIELD_VALUE
instructions. The helper functions are defined in ceval.c and extract the
filename, function name, and line number from the frame before firing the probe.

This builds on the approach from https://github.com/python/cpython/pull/125019
but avoids modifying the JIT template since the JIT does not currently support
DTrace. The macros are conditionally compiled with WITH_DTRACE and are no-ops
otherwise. The tests have been updated to use modern opcode names (CALL, CALL_KW,
CALL_FUNCTION_EX) and a new bpftrace backend was added for Linux CI alongside
the existing SystemTap tests. Line probe tests were removed since that probe
was never restored after 3.11.
2025-12-08 00:57:42 +00:00

30 lines
519 B
Python

def function_1():
function_3(1, 2)
# Check stacktrace
def function_2():
function_1()
# CALL with positional args
def function_3(dummy, dummy2):
pass
# CALL_KW (keyword arguments)
def function_4(**dummy):
return 1
return 2 # unreachable
# CALL_FUNCTION_EX (unpacking)
def function_5(dummy, dummy2, **dummy3):
if False:
return 7
return 8
def start():
function_1()
function_2()
function_3(1, 2)
function_4(test=42)
function_5(*(1, 2), **{"test": 42})
start()