summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-28 15:30:22 (GMT)
committerGitHub <noreply@github.com>2022-06-28 15:30:22 (GMT)
commit3b4f5ed1689e37ddeb2de4d817ed26a7477b442e (patch)
tree444778b2efe50d95e29a8f257d0b9a7a71698ee9 /Python/ceval.c
parent50a2e36ce9097b0f376780e2f996c30936095eec (diff)
downloadcpython-3b4f5ed1689e37ddeb2de4d817ed26a7477b442e.zip
cpython-3b4f5ed1689e37ddeb2de4d817ed26a7477b442e.tar.gz
cpython-3b4f5ed1689e37ddeb2de4d817ed26a7477b442e.tar.bz2
[3.11] GH-93516: Backport GH-93769 (GH-94231)
* Store offset of first traceable instruction to avoid having to recompute it all the time when tracing.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c93
1 files changed, 41 insertions, 52 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 763187a..2d79483 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5608,57 +5608,51 @@ handle_eval_breaker:
case DO_TRACING:
#endif
{
- if (tstate->tracing == 0) {
+ if (tstate->tracing == 0 &&
+ INSTR_OFFSET() >= frame->f_code->_co_firsttraceable
+ ) {
+ assert(
+ _PyOpcode_Deopt[first_instr[frame->f_code->_co_firsttraceable]]
+ == RESUME
+ );
int instr_prev = _PyInterpreterFrame_LASTI(frame);
frame->prev_instr = next_instr;
TRACING_NEXTOPARG();
- switch(opcode) {
- case COPY_FREE_VARS:
- case MAKE_CELL:
- case RETURN_GENERATOR:
- /* Frame not fully initialized */
- break;
- case RESUME:
- if (oparg < 2) {
- CHECK_EVAL_BREAKER();
- }
- /* Call tracing */
- TRACE_FUNCTION_ENTRY();
- DTRACE_FUNCTION_ENTRY();
- break;
- case POP_TOP:
- if (_Py_OPCODE(next_instr[-1]) == RETURN_GENERATOR) {
- /* Frame not fully initialized */
- break;
- }
- /* fall through */
- default:
- /* line-by-line tracing support */
- if (PyDTrace_LINE_ENABLED()) {
- maybe_dtrace_line(frame, &tstate->trace_info, instr_prev);
- }
-
- if (cframe.use_tracing &&
- tstate->c_tracefunc != NULL && !tstate->tracing) {
- int err;
- /* see maybe_call_line_trace()
- for expository comments */
- _PyFrame_SetStackPointer(frame, stack_pointer);
-
- err = maybe_call_line_trace(tstate->c_tracefunc,
- tstate->c_traceobj,
- tstate, frame, instr_prev);
- if (err) {
- /* trace function raised an exception */
- next_instr++;
- goto error;
- }
- /* Reload possibly changed frame fields */
- next_instr = frame->prev_instr;
+ if (opcode == RESUME) {
+ if (oparg < 2) {
+ CHECK_EVAL_BREAKER();
+ }
+ /* Call tracing */
+ TRACE_FUNCTION_ENTRY();
+ DTRACE_FUNCTION_ENTRY();
+ }
+ else {
+ /* line-by-line tracing support */
+ if (PyDTrace_LINE_ENABLED()) {
+ maybe_dtrace_line(frame, &tstate->trace_info, instr_prev);
+ }
- stack_pointer = _PyFrame_GetStackPointer(frame);
- frame->stacktop = -1;
+ if (cframe.use_tracing &&
+ tstate->c_tracefunc != NULL && !tstate->tracing) {
+ int err;
+ /* see maybe_call_line_trace()
+ for expository comments */
+ _PyFrame_SetStackPointer(frame, stack_pointer);
+
+ err = maybe_call_line_trace(tstate->c_tracefunc,
+ tstate->c_traceobj,
+ tstate, frame, instr_prev);
+ if (err) {
+ /* trace function raised an exception */
+ next_instr++;
+ goto error;
}
+ /* Reload possibly changed frame fields */
+ next_instr = frame->prev_instr;
+
+ stack_pointer = _PyFrame_GetStackPointer(frame);
+ frame->stacktop = -1;
+ }
}
}
TRACING_NEXTOPARG();
@@ -6896,13 +6890,8 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
if (_PyCode_InitLineArray(frame->f_code)) {
return -1;
}
- int entry_point = 0;
- _Py_CODEUNIT *code = _PyCode_CODE(frame->f_code);
- while (_PyOpcode_Deopt[_Py_OPCODE(code[entry_point])] != RESUME) {
- entry_point++;
- }
int lastline;
- if (instr_prev <= entry_point) {
+ if (instr_prev <= frame->f_code->_co_firsttraceable) {
lastline = -1;
}
else {