Created
April 8, 2011 19:49
-
-
Save patrickallaert/910580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: Zend/zend_builtin_functions.c | |
=================================================================== | |
--- Zend/zend_builtin_functions.c (revision 309942) | |
+++ Zend/zend_builtin_functions.c (working copy) | |
@@ -2047,11 +2048,11 @@ | |
} | |
} | |
-/* {{{ proto void debug_print_backtrace([int options]) */ | |
+/* {{{ proto void debug_print_backtrace([int options[, int limit]]) */ | |
ZEND_FUNCTION(debug_print_backtrace) | |
{ | |
zend_execute_data *ptr, *skip; | |
- int lineno; | |
+ int lineno, frameno = 0; | |
char *function_name; | |
char *filename; | |
const char *class_name = NULL; | |
@@ -2060,8 +2061,9 @@ | |
zval *arg_array = NULL; | |
int indent = 0; | |
long options = 0; | |
+ long limit = 0; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &options) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &options, &limit) == FAILURE) { | |
return; | |
} | |
@@ -2070,9 +2072,10 @@ | |
/* skip debug_backtrace() */ | |
ptr = ptr->prev_execute_data; | |
- while (ptr) { | |
+ while (ptr && (limit == 0 || frameno < limit)) { | |
const char *free_class_name = NULL; | |
+ frameno++; | |
class_name = call_type = NULL; | |
arg_array = NULL; | |
Index: Zend/tests/debug_print_backtrace_limit.phpt | |
=================================================================== | |
--- Zend/tests/debug_print_backtrace_limit.phpt (revision 0) | |
+++ Zend/tests/debug_print_backtrace_limit.phpt (revision 0) | |
@@ -0,0 +1,31 @@ | |
+--TEST-- | |
+debug_print_backtrace limit | |
+--FILE-- | |
+<?php | |
+function a() { | |
+ b(); | |
+} | |
+ | |
+function b() { | |
+ c(); | |
+} | |
+ | |
+function c() { | |
+ debug_print_backtrace(0, 1); | |
+ debug_print_backtrace(0, 2); | |
+ debug_print_backtrace(0, 0); | |
+ debug_print_backtrace(0, 4); | |
+} | |
+ | |
+a(); | |
+?> | |
+--EXPECTF-- | |
+#0 c() called at [%s/debug_print_backtrace_limit.php:7] | |
+#0 c() called at [%s/debug_print_backtrace_limit.php:7] | |
+#1 b() called at [%s/debug_print_backtrace_limit.php:3] | |
+#0 c() called at [%s/debug_print_backtrace_limit.php:7] | |
+#1 b() called at [%s/debug_print_backtrace_limit.php:3] | |
+#2 a() called at [%s/debug_print_backtrace_limit.php:17] | |
+#0 c() called at [%s/debug_print_backtrace_limit.php:7] | |
+#1 b() called at [%s/debug_print_backtrace_limit.php:3] | |
+#2 a() called at [%s/debug_print_backtrace_limit.php:17] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment