Skip to content

Skip unnecessary unknown() frames in backtraces #6195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1781,13 +1781,12 @@ ZEND_FUNCTION(debug_print_backtrace)
} else {
/* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
zend_bool build_filename_arg = 1;
uint32_t include_kind = 0;
if (ptr->func && ZEND_USER_CODE(ptr->func->common.type) && ptr->opline->opcode == ZEND_INCLUDE_OR_EVAL) {
include_kind = ptr->opline->extended_value;
}

if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type) || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
/* can happen when calling eval from a custom sapi */
function_name = "unknown";
build_filename_arg = 0;
} else
switch (ptr->opline->extended_value) {
switch (include_kind) {
case ZEND_EVAL:
function_name = "eval";
build_filename_arg = 0;
Expand All @@ -1805,8 +1804,11 @@ ZEND_FUNCTION(debug_print_backtrace)
function_name = "require_once";
break;
default:
/* this can actually happen if you use debug_backtrace() in your error_handler and
* you're in the top-scope */
/* Skip dummy frame unless it is needed to preserve filename/lineno info. */
if (!filename) {
goto skip_frame;
}

function_name = "unknown";
build_filename_arg = 0;
break;
Expand Down Expand Up @@ -1857,10 +1859,12 @@ ZEND_FUNCTION(debug_print_backtrace)
ZEND_PUTS(")\n");
}
}
++indent;

skip_frame:
include_filename = filename;
call = skip;
ptr = skip->prev_execute_data;
++indent;
}
}

Expand Down Expand Up @@ -2009,13 +2013,12 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
/* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
zend_bool build_filename_arg = 1;
zend_string *pseudo_function_name;
uint32_t include_kind = 0;
if (ptr->func && ZEND_USER_CODE(ptr->func->common.type) && ptr->opline->opcode == ZEND_INCLUDE_OR_EVAL) {
include_kind = ptr->opline->extended_value;
}

if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type) || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
/* can happen when calling eval from a custom sapi */
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_UNKNOWN);
build_filename_arg = 0;
} else
switch (ptr->opline->extended_value) {
switch (include_kind) {
case ZEND_EVAL:
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_EVAL);
build_filename_arg = 0;
Expand All @@ -2033,8 +2036,12 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
pseudo_function_name = ZSTR_KNOWN(ZEND_STR_REQUIRE_ONCE);
break;
default:
/* this can actually happen if you use debug_backtrace() in your error_handler and
* you're in the top-scope */
/* Skip dummy frame unless it is needed to preserve filename/lineno info. */
if (!filename) {
zval_ptr_dtor(&stack_frame);
goto skip_frame;
}

pseudo_function_name = ZSTR_KNOWN(ZEND_STR_UNKNOWN);
build_filename_arg = 0;
break;
Expand All @@ -2060,8 +2067,8 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int

zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &stack_frame);

skip_frame:
include_filename = filename;

call = skip;
ptr = skip->prev_execute_data;
}
Expand Down
5 changes: 2 additions & 3 deletions ext/phar/tests/cache_list/frontcontroller29.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught Error: Call to undefined function oopsie_daisy() in phar://%sfatalerror.phps:1
Stack trace:
#0 [internal function]: unknown()
#1 %s(%d): Phar::webPhar('whatever', 'index.php', '404.php', Array)
#2 {main}
#0 %s(%d): Phar::webPhar('whatever', 'index.php', '404.php', Array)
#1 {main}
thrown in phar://%sfatalerror.phps on line 1
5 changes: 2 additions & 3 deletions ext/phar/tests/frontcontroller29.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Content-type: text/html; charset=UTF-8
--EXPECTF--
Fatal error: Uncaught Error: Call to undefined function oopsie_daisy() in phar://%sfatalerror.phps:1
Stack trace:
#0 [internal function]: unknown()
#1 %s(%d): Phar::webPhar('whatever', 'index.php', '404.php', Array)
#2 {main}
#0 %s(%d): Phar::webPhar('whatever', 'index.php', '404.php', Array)
#1 {main}
thrown in phar://%sfatalerror.phps on line 1