Skip to content

Commit 5809b25

Browse files
gh-128563: Move lltrace into the frame struct (GH-129113)
1 parent 31f149d commit 5809b25

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

Include/internal/pycore_frame.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ typedef struct _PyInterpreterFrame {
7676
_PyStackRef *stackpointer;
7777
uint16_t return_offset; /* Only relevant during a function call */
7878
char owner;
79-
char visited;
79+
#ifdef Py_DEBUG
80+
uint8_t visited:1;
81+
uint8_t lltrace:7;
82+
#else
83+
uint8_t visited;
84+
#endif
8085
/* Locals and stack */
8186
_PyStackRef localsplus[1];
8287
} _PyInterpreterFrame;

Python/bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4990,7 +4990,7 @@ dummy_func(
49904990
_Py_CODEUNIT *target = _PyFrame_GetBytecode(frame) + exit->target;
49914991
#if defined(Py_DEBUG) && !defined(_Py_JIT)
49924992
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
4993-
if (lltrace >= 2) {
4993+
if (frame->lltrace >= 2) {
49944994
printf("SIDE EXIT: [UOp ");
49954995
_PyUOpPrint(&next_uop[-1]);
49964996
printf(", exit %u, temp %d, target %d -> %s]\n",
@@ -5108,7 +5108,7 @@ dummy_func(
51085108
_Py_CODEUNIT *target = frame->instr_ptr;
51095109
#if defined(Py_DEBUG) && !defined(_Py_JIT)
51105110
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
5111-
if (lltrace >= 2) {
5111+
if (frame->lltrace >= 2) {
51125112
printf("DYNAMIC EXIT: [UOp ");
51135113
_PyUOpPrint(&next_uop[-1]);
51145114
printf(", exit %u, temp %d, target %d -> %s]\n",

Python/ceval.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
799799
#endif
800800
uint8_t opcode; /* Current opcode */
801801
int oparg; /* Current opcode argument, if any */
802-
#ifdef LLTRACE
803-
int lltrace = 0;
804-
#endif
805802

806803
_PyInterpreterFrame entry_frame;
807804

@@ -821,6 +818,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
821818
entry_frame.owner = FRAME_OWNED_BY_INTERPRETER;
822819
entry_frame.visited = 0;
823820
entry_frame.return_offset = 0;
821+
#ifdef LLTRACE
822+
entry_frame.lltrace = 0;
823+
#endif
824824
/* Push frame */
825825
entry_frame.previous = tstate->current_frame;
826826
frame->previous = &entry_frame;
@@ -880,9 +880,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
880880
stack_pointer = _PyFrame_GetStackPointer(frame);
881881

882882
#ifdef LLTRACE
883-
lltrace = maybe_lltrace_resume_frame(frame, GLOBALS());
884-
if (lltrace < 0) {
885-
goto exit_unwind;
883+
{
884+
int lltrace = maybe_lltrace_resume_frame(frame, GLOBALS());
885+
frame->lltrace = lltrace;
886+
if (lltrace < 0) {
887+
goto exit_unwind;
888+
}
886889
}
887890
#endif
888891

@@ -1002,7 +1005,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10021005
}
10031006
/* Resume normal execution */
10041007
#ifdef LLTRACE
1005-
if (lltrace >= 5) {
1008+
if (frame->lltrace >= 5) {
10061009
lltrace_resume_frame(frame);
10071010
}
10081011
#endif
@@ -1079,7 +1082,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10791082
for (;;) {
10801083
uopcode = next_uop->opcode;
10811084
#ifdef Py_DEBUG
1082-
if (lltrace >= 3) {
1085+
if (frame->lltrace >= 3) {
10831086
dump_stack(frame, stack_pointer);
10841087
if (next_uop->opcode == _START_EXECUTOR) {
10851088
printf("%4d uop: ", 0);
@@ -1121,7 +1124,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
11211124

11221125
jump_to_error_target:
11231126
#ifdef Py_DEBUG
1124-
if (lltrace >= 2) {
1127+
if (frame->lltrace >= 2) {
11251128
printf("Error: [UOp ");
11261129
_PyUOpPrint(&next_uop[-1]);
11271130
printf(" @ %d -> %s]\n",
@@ -1157,7 +1160,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
11571160
next_instr = next_uop[-1].target + _PyFrame_GetBytecode(frame);
11581161
goto_to_tier1:
11591162
#ifdef Py_DEBUG
1160-
if (lltrace >= 2) {
1163+
if (frame->lltrace >= 2) {
11611164
printf("DEOPT: [UOp ");
11621165
_PyUOpPrint(&next_uop[-1]);
11631166
printf(" -> %s]\n",

Python/ceval_macros.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
8282
#ifdef LLTRACE
83-
#define PRE_DISPATCH_GOTO() if (lltrace >= 5) { \
83+
#define PRE_DISPATCH_GOTO() if (frame->lltrace >= 5) { \
8484
lltrace_instruction(frame, stack_pointer, next_instr, opcode, oparg); }
8585
#else
8686
#define PRE_DISPATCH_GOTO() ((void)0)
@@ -89,7 +89,8 @@
8989
#if LLTRACE
9090
#define LLTRACE_RESUME_FRAME() \
9191
do { \
92-
lltrace = maybe_lltrace_resume_frame(frame, GLOBALS()); \
92+
int lltrace = maybe_lltrace_resume_frame(frame, GLOBALS()); \
93+
frame->lltrace = lltrace; \
9394
if (lltrace < 0) { \
9495
goto exit_unwind; \
9596
} \

Python/executor_cases.c.h

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

0 commit comments

Comments
 (0)