Skip to content

Commit f11b7c4

Browse files
committed
Fix function__return and function__entry dTrace probe missing after GH-103083
1 parent da071fa commit f11b7c4

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix `function__return` and `function__entry` dTrace probe missing after
2+
`GH-103083`

Python/bytecodes.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ dummy_func(
986986
_PyStackRef temp = retval;
987987
DEAD(retval);
988988
SAVE_STACK();
989+
DTRACE_FUNCTION_EXIT();
989990
assert(EMPTY());
990991
_Py_LeaveRecursiveCallPy(tstate);
991992
// GH-99729: We need to unlink the frame *before* clearing it:
@@ -1173,6 +1174,7 @@ dummy_func(
11731174
_PyStackRef temp = retval;
11741175
DEAD(retval);
11751176
SAVE_STACK();
1177+
DTRACE_FUNCTION_EXIT();
11761178
tstate->exc_info = gen->gi_exc_state.previous_item;
11771179
gen->gi_exc_state.previous_item = NULL;
11781180
_Py_LeaveRecursiveCallPy(tstate);

Python/ceval.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ static void monitor_throw(PyThreadState *tstate,
275275
_Py_CODEUNIT *instr);
276276

277277
static int get_exception_handler(PyCodeObject *, int, int*, int*, int*);
278+
static void dtrace_function_entry(_PyInterpreterFrame *);
279+
static void dtrace_function_return(_PyInterpreterFrame *);
278280
static _PyInterpreterFrame *
279281
_PyEvalFramePushAndInit_Ex(PyThreadState *tstate, _PyStackRef func,
280282
PyObject *locals, Py_ssize_t nargs, PyObject *callargs, PyObject *kwargs, _PyInterpreterFrame *previous);
@@ -820,9 +822,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
820822
_Py_Instrument(_PyFrame_GetCode(frame), tstate->interp);
821823
monitor_throw(tstate, frame, frame->instr_ptr);
822824
/* TO DO -- Monitor throw entry. */
825+
DTRACE_FUNCTION_ENTRY();
823826
goto resume_with_error;
824827
}
825-
826828
/* Local "register" variables.
827829
* These are cached values from the frame and code object. */
828830
_Py_CODEUNIT *next_instr;
@@ -840,6 +842,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
840842
}
841843

842844
next_instr = frame->instr_ptr;
845+
DTRACE_FUNCTION_ENTRY();
843846
resume_frame:
844847
stack_pointer = _PyFrame_GetStackPointer(frame);
845848

@@ -3068,6 +3071,37 @@ PyUnstable_Eval_RequestCodeExtraIndex(freefunc free)
30683071
return new_index;
30693072
}
30703073

3074+
3075+
static void
3076+
dtrace_function_entry(_PyInterpreterFrame *frame)
3077+
{
3078+
const char *filename;
3079+
const char *funcname;
3080+
int lineno;
3081+
3082+
PyCodeObject *code = _PyFrame_GetCode(frame);
3083+
filename = PyUnicode_AsUTF8(code->co_filename);
3084+
funcname = PyUnicode_AsUTF8(code->co_name);
3085+
lineno = PyUnstable_InterpreterFrame_GetLine(frame);
3086+
3087+
PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);
3088+
}
3089+
3090+
static void
3091+
dtrace_function_return(_PyInterpreterFrame *frame)
3092+
{
3093+
const char *filename;
3094+
const char *funcname;
3095+
int lineno;
3096+
3097+
PyCodeObject *code = _PyFrame_GetCode(frame);
3098+
filename = PyUnicode_AsUTF8(code->co_filename);
3099+
funcname = PyUnicode_AsUTF8(code->co_name);
3100+
lineno = PyUnstable_InterpreterFrame_GetLine(frame);
3101+
3102+
PyDTrace_FUNCTION_RETURN(filename, funcname, lineno);
3103+
}
3104+
30713105
/* Implement Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() as functions
30723106
for the limited API. */
30733107

Python/ceval_macros.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ GETITEM(PyObject *v, Py_ssize_t i) {
290290
#define CONSTS() _PyFrame_GetCode(frame)->co_consts
291291
#define NAMES() _PyFrame_GetCode(frame)->co_names
292292

293+
#define DTRACE_FUNCTION_EXIT() \
294+
if (PyDTrace_FUNCTION_RETURN_ENABLED()) { \
295+
dtrace_function_return(frame); \
296+
}
297+
298+
293299
#define DTRACE_FUNCTION_ENTRY() \
294300
if (PyDTrace_FUNCTION_ENTRY_ENABLED()) { \
295301
dtrace_function_entry(frame); \

Python/generated_cases.c.h

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)