@@ -1781,13 +1781,12 @@ ZEND_FUNCTION(debug_print_backtrace)
1781
1781
} else {
1782
1782
/* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
1783
1783
zend_bool build_filename_arg = 1 ;
1784
+ uint32_t include_kind = 0 ;
1785
+ if (ptr -> func && ZEND_USER_CODE (ptr -> func -> common .type ) && ptr -> opline -> opcode == ZEND_INCLUDE_OR_EVAL ) {
1786
+ include_kind = ptr -> opline -> extended_value ;
1787
+ }
1784
1788
1785
- if (!ptr -> func || !ZEND_USER_CODE (ptr -> func -> common .type ) || ptr -> opline -> opcode != ZEND_INCLUDE_OR_EVAL ) {
1786
- /* can happen when calling eval from a custom sapi */
1787
- function_name = "unknown" ;
1788
- build_filename_arg = 0 ;
1789
- } else
1790
- switch (ptr -> opline -> extended_value ) {
1789
+ switch (include_kind ) {
1791
1790
case ZEND_EVAL :
1792
1791
function_name = "eval" ;
1793
1792
build_filename_arg = 0 ;
@@ -1805,8 +1804,11 @@ ZEND_FUNCTION(debug_print_backtrace)
1805
1804
function_name = "require_once" ;
1806
1805
break ;
1807
1806
default :
1808
- /* this can actually happen if you use debug_backtrace() in your error_handler and
1809
- * you're in the top-scope */
1807
+ /* Skip dummy frame unless it is needed to preserve filename/lineno info. */
1808
+ if (!filename ) {
1809
+ goto skip_frame ;
1810
+ }
1811
+
1810
1812
function_name = "unknown" ;
1811
1813
build_filename_arg = 0 ;
1812
1814
break ;
@@ -1857,10 +1859,12 @@ ZEND_FUNCTION(debug_print_backtrace)
1857
1859
ZEND_PUTS (")\n" );
1858
1860
}
1859
1861
}
1862
+ ++ indent ;
1863
+
1864
+ skip_frame :
1860
1865
include_filename = filename ;
1861
1866
call = skip ;
1862
1867
ptr = skip -> prev_execute_data ;
1863
- ++ indent ;
1864
1868
}
1865
1869
}
1866
1870
@@ -2009,13 +2013,12 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
2009
2013
/* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
2010
2014
zend_bool build_filename_arg = 1 ;
2011
2015
zend_string * pseudo_function_name ;
2016
+ uint32_t include_kind = 0 ;
2017
+ if (ptr -> func && ZEND_USER_CODE (ptr -> func -> common .type ) && ptr -> opline -> opcode == ZEND_INCLUDE_OR_EVAL ) {
2018
+ include_kind = ptr -> opline -> extended_value ;
2019
+ }
2012
2020
2013
- if (!ptr -> func || !ZEND_USER_CODE (ptr -> func -> common .type ) || ptr -> opline -> opcode != ZEND_INCLUDE_OR_EVAL ) {
2014
- /* can happen when calling eval from a custom sapi */
2015
- pseudo_function_name = ZSTR_KNOWN (ZEND_STR_UNKNOWN );
2016
- build_filename_arg = 0 ;
2017
- } else
2018
- switch (ptr -> opline -> extended_value ) {
2021
+ switch (include_kind ) {
2019
2022
case ZEND_EVAL :
2020
2023
pseudo_function_name = ZSTR_KNOWN (ZEND_STR_EVAL );
2021
2024
build_filename_arg = 0 ;
@@ -2033,8 +2036,12 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
2033
2036
pseudo_function_name = ZSTR_KNOWN (ZEND_STR_REQUIRE_ONCE );
2034
2037
break ;
2035
2038
default :
2036
- /* this can actually happen if you use debug_backtrace() in your error_handler and
2037
- * you're in the top-scope */
2039
+ /* Skip dummy frame unless it is needed to preserve filename/lineno info. */
2040
+ if (!filename ) {
2041
+ zval_ptr_dtor (& stack_frame );
2042
+ goto skip_frame ;
2043
+ }
2044
+
2038
2045
pseudo_function_name = ZSTR_KNOWN (ZEND_STR_UNKNOWN );
2039
2046
build_filename_arg = 0 ;
2040
2047
break ;
@@ -2060,8 +2067,8 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
2060
2067
2061
2068
zend_hash_next_index_insert_new (Z_ARRVAL_P (return_value ), & stack_frame );
2062
2069
2070
+ skip_frame :
2063
2071
include_filename = filename ;
2064
-
2065
2072
call = skip ;
2066
2073
ptr = skip -> prev_execute_data ;
2067
2074
}
0 commit comments