Skip to content

Commit 0d4ff66

Browse files
committed
Expose the source of exit points in zend_jit_dump_exit_info()
This adds a new flag: ZEND_JIT_DEBUG_TRACE_EXIT_INFO_SRC. When the flag is set, zend_jit_dump_exit_info() exposes the source of exit points, in debug builds. Closes phpGH-19700
1 parent 5b8a532 commit 0d4ff66

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ PHP 8.6 UPGRADE NOTES
5959
11. Changes to INI File Handling
6060
========================================
6161

62+
- Opcache:
63+
. opcache.jit_debug accepts a new flag: ZEND_JIT_DEBUG_TRACE_EXIT_INFO_SRC.
64+
When used along with ZEND_JIT_DEBUG_TRACE_EXIT_INFO, the source of exit
65+
points is printed in exit info output, in debug builds.
66+
6267
========================================
6368
12. Windows Support
6469
========================================

ext/opcache/jit/zend_jit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV zend_runtime_jit(Z
106106

107107
static int zend_jit_trace_op_len(const zend_op *opline);
108108
static int zend_jit_trace_may_exit(const zend_op_array *op_array, const zend_op *opline);
109-
static uint32_t zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t flags);
109+
static uint32_t _zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t flags ZEND_FILE_LINE_DC);
110+
#define zend_jit_trace_get_exit_point(to_opline, flags) _zend_jit_trace_get_exit_point(to_opline, flags ZEND_FILE_LINE_CC)
110111
static const void *zend_jit_trace_get_exit_addr(uint32_t n);
111112
static void zend_jit_trace_add_code(const void *start, uint32_t size);
112113
static zend_string *zend_jit_func_name(const zend_op_array *op_array);

ext/opcache/jit/zend_jit.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@
6464
#define ZEND_JIT_DEBUG_SIZE (1<<9)
6565
#define ZEND_JIT_DEBUG_ASM_ADDR (1<<10)
6666

67-
#define ZEND_JIT_DEBUG_TRACE_START (1<<12)
68-
#define ZEND_JIT_DEBUG_TRACE_STOP (1<<13)
69-
#define ZEND_JIT_DEBUG_TRACE_COMPILED (1<<14)
70-
#define ZEND_JIT_DEBUG_TRACE_EXIT (1<<15)
71-
#define ZEND_JIT_DEBUG_TRACE_ABORT (1<<16)
72-
#define ZEND_JIT_DEBUG_TRACE_BLACKLIST (1<<17)
73-
#define ZEND_JIT_DEBUG_TRACE_BYTECODE (1<<18)
74-
#define ZEND_JIT_DEBUG_TRACE_TSSA (1<<19)
75-
#define ZEND_JIT_DEBUG_TRACE_EXIT_INFO (1<<20)
67+
#define ZEND_JIT_DEBUG_TRACE_START (1<<12)
68+
#define ZEND_JIT_DEBUG_TRACE_STOP (1<<13)
69+
#define ZEND_JIT_DEBUG_TRACE_COMPILED (1<<14)
70+
#define ZEND_JIT_DEBUG_TRACE_EXIT (1<<15)
71+
#define ZEND_JIT_DEBUG_TRACE_ABORT (1<<16)
72+
#define ZEND_JIT_DEBUG_TRACE_BLACKLIST (1<<17)
73+
#define ZEND_JIT_DEBUG_TRACE_BYTECODE (1<<18)
74+
#define ZEND_JIT_DEBUG_TRACE_TSSA (1<<19)
75+
#define ZEND_JIT_DEBUG_TRACE_EXIT_INFO (1<<20)
76+
#define ZEND_JIT_DEBUG_TRACE_EXIT_INFO_SRC (1<<21)
7677

7778
#define ZEND_JIT_DEBUG_IR_SRC (1<<24)
7879
#define ZEND_JIT_DEBUG_IR_FINAL (1<<25)

ext/opcache/jit/zend_jit_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ typedef struct _zend_jit_trace_exit_info {
456456
uint32_t stack_offset;
457457
zend_jit_ref_snapshot poly_func;
458458
zend_jit_ref_snapshot poly_this;
459+
#if ZEND_DEBUG
460+
const char *filename;
461+
int lineno;
462+
#endif
459463
} zend_jit_trace_exit_info;
460464

461465
typedef struct _zend_jit_trace_stack {

ext/opcache/jit/zend_jit_trace.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static uint32_t zend_jit_exit_point_by_addr(const void *addr)
132132
return (uint32_t)-1;
133133
}
134134

135-
static uint32_t zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t flags)
135+
static uint32_t _zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t flags ZEND_FILE_LINE_DC)
136136
{
137137
zend_jit_trace_info *t = &zend_jit_traces[ZEND_JIT_TRACE_NUM];
138138
uint32_t exit_point;
@@ -178,7 +178,13 @@ static uint32_t zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t
178178
&& memcmp(t->stack_map + t->exit_info[i].stack_offset, stack, stack_size * sizeof(zend_jit_trace_stack)) == 0)) {
179179
if (t->exit_info[i].opline == to_opline
180180
&& t->exit_info[i].flags == flags
181-
&& t->exit_info[i].stack_size == stack_size) {
181+
&& t->exit_info[i].stack_size == stack_size
182+
#if ZEND_DEBUG
183+
&& (((JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_EXIT_INFO_SRC) == 0)
184+
|| (strcmp(t->exit_info[i].filename, __zend_filename) == 0
185+
&& t->exit_info[i].lineno == __zend_lineno))
186+
#endif
187+
) {
182188
return i;
183189
}
184190
}
@@ -202,6 +208,15 @@ static uint32_t zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t
202208
t->exit_info[exit_point].stack_offset = stack_offset;
203209
t->exit_info[exit_point].poly_func = (zend_jit_ref_snapshot){.reg = ZREG_NONE};
204210
t->exit_info[exit_point].poly_this = (zend_jit_ref_snapshot){.reg = ZREG_NONE};
211+
#if ZEND_DEBUG
212+
if ((JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_EXIT_INFO_SRC) != 0) {
213+
t->exit_info[exit_point].filename = __zend_filename;
214+
t->exit_info[exit_point].lineno = __zend_lineno;
215+
} else {
216+
t->exit_info[exit_point].filename = NULL;
217+
t->exit_info[exit_point].lineno = 0;
218+
}
219+
#endif
205220
}
206221

207222
return exit_point;
@@ -8096,6 +8111,11 @@ static void zend_jit_dump_exit_info(zend_jit_trace_info *t)
80968111
fprintf(stderr, ":unknown(zval_copy(%s))", zend_reg_name(STACK_REG(stack, j)));
80978112
}
80988113
}
8114+
#if ZEND_DEBUG
8115+
if ((JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_EXIT_INFO_SRC) != 0) {
8116+
fprintf(stderr, " %s:%d", t->exit_info[i].filename, t->exit_info[i].lineno);
8117+
}
8118+
#endif
80998119
fprintf(stderr, "\n");
81008120
}
81018121
}

0 commit comments

Comments
 (0)