Skip to content

Commit 99c4d8e

Browse files
committed
JIT/FFI print FFI types in JIT debug traces
1 parent ffeff8a commit 99c4d8e

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

Zend/zend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ ZEND_API zend_ffi_dcl* (*zend_ffi_cache_type_get)(zend_string *str, void *cont
105105
ZEND_API zend_ffi_dcl* (*zend_ffi_cache_type_add)(zend_string *str, zend_ffi_dcl *dcl, void *context) = NULL;
106106
ZEND_API zend_ffi_scope* (*zend_ffi_cache_scope_get)(zend_string *str) = NULL;
107107
ZEND_API zend_ffi_scope* (*zend_ffi_cache_scope_add)(zend_string *str, zend_ffi_scope *scope) = NULL;
108+
ZEND_API void (*zend_ffi_type_print)(FILE *f, const zend_ffi_type *type) = NULL;
108109

109110
/* This callback must be signal handler safe! */
110111
void (*zend_on_timeout)(int seconds);

Zend/zend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ ZEND_API extern zend_ffi_dcl* (*zend_ffi_cache_type_get)(zend_string *str, voi
421421
ZEND_API extern zend_ffi_dcl* (*zend_ffi_cache_type_add)(zend_string *str, zend_ffi_dcl *dcl, void *context);
422422
ZEND_API extern zend_ffi_scope* (*zend_ffi_cache_scope_get)(zend_string *str);
423423
ZEND_API extern zend_ffi_scope* (*zend_ffi_cache_scope_add)(zend_string *str, zend_ffi_scope *scope);
424-
424+
ZEND_API extern void (*zend_ffi_type_print)(FILE *f, const zend_ffi_type *type);
425425

426426
/* If DTrace is available and enabled */
427427
extern ZEND_API bool zend_dtrace_enabled;

ext/ffi/ffi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5314,6 +5314,17 @@ static ZEND_INI_DISP(zend_ffi_enable_displayer_cb) /* {{{ */
53145314
}
53155315
/* }}} */
53165316

5317+
static void _zend_ffi_type_print(FILE *f, const zend_ffi_type *type) /* {{{ */
5318+
{
5319+
zend_ffi_ctype_name_buf buf;
5320+
5321+
buf.start = buf.end = buf.buf + ((MAX_TYPE_NAME_LEN * 3) / 4);
5322+
if (!zend_ffi_ctype_name(&buf, ZEND_FFI_TYPE(type))) {
5323+
} else {
5324+
fwrite(buf.start, buf.end - buf.start, 1, f);
5325+
}
5326+
}
5327+
53175328
ZEND_INI_BEGIN()
53185329
ZEND_INI_ENTRY_EX("ffi.enable", "preload", ZEND_INI_SYSTEM, OnUpdateFFIEnable, zend_ffi_enable_displayer_cb)
53195330
STD_ZEND_INI_ENTRY("ffi.preload", NULL, ZEND_INI_SYSTEM, OnUpdateString, preload, zend_ffi_globals, ffi_globals)
@@ -5597,6 +5608,7 @@ ZEND_MINIT_FUNCTION(ffi)
55975608
zend_ffi_ctype_handlers.get_gc = zend_fake_get_gc;
55985609

55995610
zend_ffi_cdata_create = _zend_ffi_cdata_create;
5611+
zend_ffi_type_print = _zend_ffi_type_print;
56005612

56015613
if (FFI_G(preload)) {
56025614
return zend_ffi_preload(FFI_G(preload));

ext/opcache/jit/zend_jit_trace.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8335,9 +8335,11 @@ static void zend_jit_dump_trace(zend_jit_trace_rec *trace_buffer, zend_ssa *tssa
83358335
p++;
83368336
#ifdef HAVE_FFI
83378337
if ((p+1)->op == ZEND_JIT_TRACE_OP1_FFI_TYPE) {
8338-
fprintf(stderr, " op1(%sobject of class %s: ffi_type)", ref,
8338+
fprintf(stderr, " op1(%sobject of class %s: ", ref,
83398339
ZSTR_VAL(p->ce->name));
83408340
p++;
8341+
zend_ffi_type_print(stderr, p->ptr);
8342+
fprintf(stderr, ")");
83418343
} else if ((p+1)->op == ZEND_JIT_TRACE_OP1_FFI_SYMBOLS) {
83428344
fprintf(stderr, " op1(%sobject of class %s: ffi_symbols)", ref,
83438345
ZSTR_VAL(p->ce->name));
@@ -8359,9 +8361,11 @@ static void zend_jit_dump_trace(zend_jit_trace_rec *trace_buffer, zend_ssa *tssa
83598361
p++;
83608362
#ifdef HAVE_FFI
83618363
if ((p+1)->op == ZEND_JIT_TRACE_OP2_FFI_TYPE) {
8362-
fprintf(stderr, " op2(%sobject of class %s: ffi_type)", ref,
8364+
fprintf(stderr, " op2(%sobject of class %s: ", ref,
83638365
ZSTR_VAL(p->ce->name));
83648366
p++;
8367+
zend_ffi_type_print(stderr, p->ptr);
8368+
fprintf(stderr, ")");
83658369
} else
83668370
#endif
83678371
fprintf(stderr, " op2(%sobject of class %s)", ref,
@@ -8379,9 +8383,11 @@ static void zend_jit_dump_trace(zend_jit_trace_rec *trace_buffer, zend_ssa *tssa
83798383
p++;
83808384
#ifdef HAVE_FFI
83818385
if ((p+1)->op == ZEND_JIT_TRACE_OP3_FFI_TYPE) {
8382-
fprintf(stderr, " op3(%sobject of class %s: ffi_type)", ref,
8386+
fprintf(stderr, " op3(%sobject of class %s: ", ref,
83838387
ZSTR_VAL(p->ce->name));
83848388
p++;
8389+
zend_ffi_type_print(stderr, p->ptr);
8390+
fprintf(stderr, ")");
83858391
} else
83868392
#endif
83878393
fprintf(stderr, " op3(%sobject of class %s)", ref,

0 commit comments

Comments
 (0)