Permalink
Browse files

Fixed issue #1003: Add option to xdebug_print_function_stack() to sup…

…press filename and line number.

You can now as second parameter to xdebug_print_function_stack() pass
XDEBUG_STACK_NO_DESC to avoid the first line.
  • Loading branch information...
derickr committed Dec 9, 2013
1 parent 4354f68 commit f13060eba1cf95aa7f9064c473e13cdc67d207a3
@@ -0,0 +1,26 @@
+--TEST--
+Test for xdebug_print_function_stack() without description
+--INI--
+xdebug.cli_color=0
+xdebug.collect_params=3
+html_errors=0
+--FILE--
+<?php
+function foo()
+{
+ xdebug_print_function_stack("test message", XDEBUG_STACK_NO_DESC);
+}
+
+function bar()
+{
+ foo(1, 3, 'foo', 'bar' );
+}
+
+bar();
+?>
+--EXPECTF--
+Call Stack:
+%w%f %w%d 1. {main}() %sprint_function_stack-no-description-001.php:0
+%w%f %w%d 2. bar() %sprint_function_stack-no-description-001.php:12
+%w%f %w%d 3. foo(1, 3, 'foo', 'bar') %sprint_function_stack-no-description-001.php:9
+%w%f %w%d 4. xdebug_print_function_stack('test message', 1) %sprint_function_stack-no-description-001.php:4
@@ -0,0 +1,26 @@
+--TEST--
+Test for xdebug_print_function_stack() without description (CLI colour)
+--INI--
+xdebug.cli_color=2
+xdebug.collect_params=3
+html_errors=0
+--FILE--
+<?php
+function foo()
+{
+ xdebug_print_function_stack("test message", XDEBUG_STACK_NO_DESC);
+}
+
+function bar()
+{
+ foo(1, 3, 'foo', 'bar' );
+}
+
+bar();
+?>
+--EXPECTF--
+Call Stack:
+%w%f %w%d 1. {main}() %sprint_function_stack-no-description-002.php:0
+%w%f %w%d 2. bar() %sprint_function_stack-no-description-002.php:12
+%w%f %w%d 3. foo(1, 3, 'foo', 'bar') %sprint_function_stack-no-description-002.php:9
+%w%f %w%d 4. xdebug_print_function_stack('test message', 1) %sprint_function_stack-no-description-002.php:4
@@ -0,0 +1,32 @@
+--TEST--
+Test for xdebug_print_function_stack() without description (HTML)
+--INI--
+xdebug.cli_color=0
+xdebug.collect_params=3
+xdebug.file_link_format=
+html_errors=1
+--FILE--
+<?php
+function foo()
+{
+ xdebug_print_function_stack("test message", XDEBUG_STACK_NO_DESC);
+}
+
+function bar()
+{
+ foo(1, 3, 'foo', 'bar' );
+}
+
+bar();
+?>
+--EXPECTF--
+<br />
+<font size='1'><table class='xdebug-error xe-xdebug' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
+<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
+<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
+<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>{main}( )</td><td title='/home/derick/dev/php/derickr-xdebug/tests/print_function_stack-no-description-003.php' bgcolor='#eeeeec'>../print_function_stack-no-description-003.php<b>:</b>0</td></tr>
+<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>bar( )</td><td title='/home/derick/dev/php/derickr-xdebug/tests/print_function_stack-no-description-003.php' bgcolor='#eeeeec'>../print_function_stack-no-description-003.php<b>:</b>12</td></tr>
+<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>foo( <span>1</span>, <span>3</span>, <span>&#39;foo&#39;</span>, <span>&#39;bar&#39;</span> )</td><td title='/home/derick/dev/php/derickr-xdebug/tests/print_function_stack-no-description-003.php' bgcolor='#eeeeec'>../print_function_stack-no-description-003.php<b>:</b>9</td></tr>
+<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.xdebug-print-function-stack.html' target='_new'>xdebug_print_function_stack</a>
+( <span>&#39;test message&#39;</span>, <span>1</span> )</td><td title='/home/derick/dev/php/derickr-xdebug/tests/print_function_stack-no-description-003.php' bgcolor='#eeeeec'>../print_function_stack-no-description-003.php<b>:</b>4</td></tr>
+</table></font>
View
@@ -705,6 +705,8 @@ PHP_MINIT_FUNCTION(xdebug)
REGISTER_LONG_CONSTANT("XDEBUG_CC_UNUSED", XDEBUG_CC_OPTION_UNUSED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_CC_DEAD_CODE", XDEBUG_CC_OPTION_DEAD_CODE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("XDEBUG_STACK_NO_DESC", XDEBUG_STACK_NO_DESC, CONST_CS | CONST_PERSISTENT);
+
XG(breakpoint_count) = 0;
XG(output_is_tty) = OUTPUT_NOT_CHECKED;
View
@@ -456,7 +456,7 @@ void xdebug_append_error_footer(xdebug_str *str, int html TSRMLS_DC)
xdebug_str_add(str, formats[7], 0);
}
-static char *get_printable_stack(int html, int error_type, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC)
+static char *get_printable_stack(int html, int error_type, char *buffer, const char *error_filename, const int error_lineno, int include_decription TSRMLS_DC)
{
char *prepend_string;
char *append_string;
@@ -469,7 +469,9 @@ static char *get_printable_stack(int html, int error_type, char *buffer, const c
xdebug_str_add(&str, prepend_string ? prepend_string : "", 0);
xdebug_append_error_head(&str, html, error_type_str_simple TSRMLS_CC);
- xdebug_append_error_description(&str, html, error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
+ if (include_decription) {
+ xdebug_append_error_description(&str, html, error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
+ }
xdebug_append_printable_stack(&str, html TSRMLS_CC);
xdebug_append_error_footer(&str, html TSRMLS_CC);
xdebug_str_add(&str, append_string ? append_string : "", 0);
@@ -660,7 +662,7 @@ void xdebug_error_cb(int type, const char *error_filename, const uint error_line
xdfree(str.d);
free(tmp_buf);
} else {
- printable_stack = get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno TSRMLS_CC);
+ printable_stack = get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno, 1 TSRMLS_CC);
if (XG(do_collect_errors) && (type != E_ERROR) && (type != E_COMPILE_ERROR) && (type != E_USER_ERROR)) {
xdebug_llist_insert_next(XG(collected_errors), XDEBUG_LLIST_TAIL(XG(collected_errors)), printable_stack);
} else {
@@ -670,7 +672,7 @@ void xdebug_error_cb(int type, const char *error_filename, const uint error_line
}
} else if (XG(do_collect_errors)) {
char *printable_stack;
- printable_stack = get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno TSRMLS_CC);
+ printable_stack = get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno, 1 TSRMLS_CC);
xdebug_llist_insert_next(XG(collected_errors), XDEBUG_LLIST_TAIL(XG(collected_errors)), printable_stack);
}
}
@@ -775,24 +777,25 @@ void xdebug_error_cb(int type, const char *error_filename, const uint error_line
}
}
-/* {{{ proto array xdebug_print_function_stack([string message])
+/* {{{ proto array xdebug_print_function_stack([string message [, int options])
Displays a stack trace */
PHP_FUNCTION(xdebug_print_function_stack)
{
char *message = NULL;
int message_len;
function_stack_entry *i;
char *tmp;
+ long options = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &message, &message_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &message, &message_len, &options) == FAILURE) {
return;
}
i = xdebug_get_stack_frame(0 TSRMLS_CC);
if (message) {
- tmp = get_printable_stack(PG(html_errors), 0, message, i->filename, i->lineno TSRMLS_CC);
+ tmp = get_printable_stack(PG(html_errors), 0, message, i->filename, i->lineno, !(options & XDEBUG_STACK_NO_DESC) TSRMLS_CC);
} else {
- tmp = get_printable_stack(PG(html_errors), 0, "user triggered", i->filename, i->lineno TSRMLS_CC);
+ tmp = get_printable_stack(PG(html_errors), 0, "user triggered", i->filename, i->lineno, !(options & XDEBUG_STACK_NO_DESC) TSRMLS_CC);
}
php_printf("%s", tmp);
xdfree(tmp);
@@ -807,7 +810,7 @@ PHP_FUNCTION(xdebug_get_formatted_function_stack)
char *tmp;
i = xdebug_get_stack_frame(0 TSRMLS_CC);
- tmp = get_printable_stack(PG(html_errors), 0, "user triggered", i->filename, i->lineno TSRMLS_CC);
+ tmp = get_printable_stack(PG(html_errors), 0, "user triggered", i->filename, i->lineno, 1 TSRMLS_CC);
RETVAL_STRING(tmp, 1);
xdfree(tmp);
}
View
@@ -21,6 +21,8 @@
#include "xdebug_str.h"
+#define XDEBUG_STACK_NO_DESC 0x01
+
function_stack_entry *xdebug_add_stack_frame(zend_execute_data *zdata, zend_op_array *op_array, int type TSRMLS_DC);
void xdebug_append_error_head(xdebug_str *str, int html, char *error_type_str TSRMLS_DC);
void xdebug_append_error_description(xdebug_str *str, int html, const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC);

0 comments on commit f13060e

Please sign in to comment.