Skip to content

Commit f666de4

Browse files
committed
Fix backtraces with observed frameful frameless calls
1 parent 8fc959e commit f666de4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Zend/zend_builtin_functions.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ ZEND_FUNCTION(debug_print_backtrace)
17761776

17771777
ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit) /* {{{ */
17781778
{
1779-
zend_execute_data *call;
1779+
zend_execute_data *call, *last_call = NULL;
17801780
zend_object *object;
17811781
bool fake_frame = 0;
17821782
int lineno, frameno = 0;
@@ -1821,6 +1821,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
18211821

18221822
if (skip_last) {
18231823
/* skip debug_backtrace() */
1824+
last_call = call;
18241825
call = call->prev_execute_data;
18251826
}
18261827

@@ -1857,9 +1858,14 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
18571858
zval *arg = zend_get_zval_ptr(op_data, op_data->op1_type, &op_data->op1, call);
18581859
if (Z_TYPE_P(arg) == IS_UNDEF) goto not_frameless_call;
18591860
}
1861+
zend_function *func = ZEND_FLF_FUNC(opline);
1862+
/* Assume frameless functions are not recursive with themselves.
1863+
* This condition may be true when observers are enabled. */
1864+
if (last_call && last_call->func == func) {
1865+
goto not_frameless_call;
1866+
}
18601867
stack_frame = zend_new_array(8);
18611868
zend_hash_real_init_mixed(stack_frame);
1862-
zend_function *func = ZEND_FLF_FUNC(opline);
18631869
zend_string *name = func->common.function_name;
18641870
ZVAL_STRINGL(&tmp, ZSTR_VAL(name), ZSTR_LEN(name));
18651871
_zend_hash_append_ex(stack_frame, ZSTR_KNOWN(ZEND_STR_FUNCTION), &tmp, 1);
@@ -2068,6 +2074,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
20682074
} else {
20692075
fake_frame = 0;
20702076
include_filename = filename;
2077+
last_call = call;
20712078
call = prev;
20722079
}
20732080
}

0 commit comments

Comments
 (0)