Skip to content

Commit 3a28c62

Browse files
committed
Work on Debug callback.
1 parent 4a4b4b3 commit 3a28c62

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

Zend/zend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ int zend_startup_error_notify_callbacks();
362362
int zend_shutdown_error_notify_callbacks();
363363
void zend_error_notify_all_callbacks(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args);
364364
void zend_error_notify_callbacks_apply(llist_apply_func_t callback);
365+
#if ZEND_DEBUG
366+
void report_zend_debug_error_notify_cb(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args);
367+
#endif
365368
END_EXTERN_C()
366369

367370
#define DEBUG_BACKTRACE_PROVIDE_OBJECT (1<<0)

main/main.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,36 @@ PHPAPI void php_html_puts(const char *str, size_t size)
11881188
}
11891189
/* }}} */
11901190

1191+
#if ZEND_DEBUG
1192+
/* {{{ report_zend_debug_error_notify_cb */
1193+
void report_zend_debug_error_notify_cb(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args)
1194+
{
1195+
if (PG(report_zend_debug)) {
1196+
zend_bool trigger_break;
1197+
char *buffer;
1198+
1199+
vspprintf(&buffer, PG(log_errors_max_len), format, args);
1200+
1201+
switch (type) {
1202+
case E_ERROR:
1203+
case E_CORE_ERROR:
1204+
case E_COMPILE_ERROR:
1205+
case E_USER_ERROR:
1206+
trigger_break=1;
1207+
break;
1208+
default:
1209+
trigger_break=0;
1210+
break;
1211+
}
1212+
1213+
zend_output_debug_string(trigger_break, "%s(%" PRIu32 ") : %s", error_filename, error_lineno, buffer);
1214+
1215+
efree(buffer);
1216+
}
1217+
}
1218+
/* }}} */
1219+
#endif
1220+
11911221
/* {{{ php_error_cb
11921222
extended error handling function */
11931223
static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args)
@@ -1356,24 +1386,6 @@ static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, co
13561386
}
13571387
}
13581388
}
1359-
#if ZEND_DEBUG
1360-
if (PG(report_zend_debug)) {
1361-
zend_bool trigger_break;
1362-
1363-
switch (type) {
1364-
case E_ERROR:
1365-
case E_CORE_ERROR:
1366-
case E_COMPILE_ERROR:
1367-
case E_USER_ERROR:
1368-
trigger_break=1;
1369-
break;
1370-
default:
1371-
trigger_break=0;
1372-
break;
1373-
}
1374-
zend_output_debug_string(trigger_break, "%s(%" PRIu32 ") : %s - %s", error_filename, error_lineno, error_type_str, buffer);
1375-
}
1376-
#endif
13771389
}
13781390

13791391
/* Bail out if we can't recover */
@@ -2136,6 +2148,10 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
21362148
setlocale(LC_CTYPE, "");
21372149
zend_update_current_locale();
21382150

2151+
#if ZEND_DEBUG
2152+
zend_register_error_notify_callback("report_zend_debug", report_zend_debug_error_notify_cb);
2153+
#endif
2154+
21392155
#if HAVE_TZSET
21402156
tzset();
21412157
#endif

0 commit comments

Comments
 (0)