Skip to content

Commit

Permalink
Merge branch 'master' of github.com:xdebug/xdebug
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Dec 10, 2013
2 parents deecd49 + d73d80b commit 7fc3359
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 9 deletions.
26 changes: 26 additions & 0 deletions tests/print_function_stack-no-description-001.phpt
@@ -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
26 changes: 26 additions & 0 deletions tests/print_function_stack-no-description-002.phpt
@@ -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
32 changes: 32 additions & 0 deletions tests/print_function_stack-no-description-003.phpt
@@ -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>
2 changes: 2 additions & 0 deletions xdebug.c
Expand Up @@ -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;

Expand Down
21 changes: 12 additions & 9 deletions xdebug_stack.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions xdebug_stack.h
Expand Up @@ -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);
Expand Down

0 comments on commit 7fc3359

Please sign in to comment.