Skip to content

Commit be76c1f

Browse files
committed
Fix function__return and function__entry dTrace probe missing after GH-103083
1 parent 16cd6cc commit be76c1f

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
@@ -971,6 +971,7 @@ dummy_func(
971971
#endif
972972
SYNC_SP();
973973
_PyFrame_SetStackPointer(frame, stack_pointer);
974+
DTRACE_FUNCTION_EXIT();
974975
assert(EMPTY());
975976
_Py_LeaveRecursiveCallPy(tstate);
976977
// GH-99729: We need to unlink the frame *before* clearing it:
@@ -1155,6 +1156,7 @@ dummy_func(
11551156
gen->gi_frame_state = FRAME_SUSPENDED + oparg;
11561157
SYNC_SP();
11571158
_PyFrame_SetStackPointer(frame, stack_pointer);
1159+
DTRACE_FUNCTION_EXIT();
11581160
tstate->exc_info = gen->gi_exc_state.previous_item;
11591161
gen->gi_exc_state.previous_item = NULL;
11601162
_Py_LeaveRecursiveCallPy(tstate);

Python/ceval.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ static void monitor_throw(PyThreadState *tstate,
276276

277277
static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg);
278278
static int get_exception_handler(PyCodeObject *, int, int*, int*, int*);
279+
static void dtrace_function_entry(_PyInterpreterFrame *);
280+
static void dtrace_function_return(_PyInterpreterFrame *);
279281
static _PyInterpreterFrame *
280282
_PyEvalFramePushAndInit_Ex(PyThreadState *tstate, _PyStackRef func,
281283
PyObject *locals, Py_ssize_t nargs, PyObject *callargs, PyObject *kwargs, _PyInterpreterFrame *previous);
@@ -814,9 +816,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
814816
_Py_Instrument(_PyFrame_GetCode(frame), tstate->interp);
815817
monitor_throw(tstate, frame, frame->instr_ptr);
816818
/* TO DO -- Monitor throw entry. */
819+
DTRACE_FUNCTION_ENTRY();
817820
goto resume_with_error;
818821
}
819-
820822
/* Local "register" variables.
821823
* These are cached values from the frame and code object. */
822824
_Py_CODEUNIT *next_instr;
@@ -834,6 +836,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
834836
}
835837

836838
next_instr = frame->instr_ptr;
839+
DTRACE_FUNCTION_ENTRY();
837840
resume_frame:
838841
stack_pointer = _PyFrame_GetStackPointer(frame);
839842

@@ -3062,6 +3065,37 @@ PyUnstable_Eval_RequestCodeExtraIndex(freefunc free)
30623065
return new_index;
30633066
}
30643067

3068+
3069+
static void
3070+
dtrace_function_entry(_PyInterpreterFrame *frame)
3071+
{
3072+
const char *filename;
3073+
const char *funcname;
3074+
int lineno;
3075+
3076+
PyCodeObject *code = _PyFrame_GetCode(frame);
3077+
filename = PyUnicode_AsUTF8(code->co_filename);
3078+
funcname = PyUnicode_AsUTF8(code->co_name);
3079+
lineno = PyUnstable_InterpreterFrame_GetLine(frame);
3080+
3081+
PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);
3082+
}
3083+
3084+
static void
3085+
dtrace_function_return(_PyInterpreterFrame *frame)
3086+
{
3087+
const char *filename;
3088+
const char *funcname;
3089+
int lineno;
3090+
3091+
PyCodeObject *code = _PyFrame_GetCode(frame);
3092+
filename = PyUnicode_AsUTF8(code->co_filename);
3093+
funcname = PyUnicode_AsUTF8(code->co_name);
3094+
lineno = PyUnstable_InterpreterFrame_GetLine(frame);
3095+
3096+
PyDTrace_FUNCTION_RETURN(filename, funcname, lineno);
3097+
}
3098+
30653099
/* Implement Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() as functions
30663100
for the limited API. */
30673101

Python/ceval_macros.h

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

292+
#define DTRACE_FUNCTION_EXIT() \
293+
if (PyDTrace_FUNCTION_RETURN_ENABLED()) { \
294+
dtrace_function_return(frame); \
295+
}
296+
297+
292298
#define DTRACE_FUNCTION_ENTRY() \
293299
if (PyDTrace_FUNCTION_ENTRY_ENABLED()) { \
294300
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)