Skip to content

Commit

Permalink
Add a error-specific class to stack traces.
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Mar 2, 2012
1 parent b59d6ea commit aa1b5c4
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 26 deletions.
2 changes: 1 addition & 1 deletion tests/bug00305.phpt
Expand Up @@ -10,7 +10,7 @@ throw new Exception("<MARK>");
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-uncaught-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught exception 'Exception' with message '&lt;MARK&gt;' in <a style='color: black' href='xdebug://%sbug00305.php@2'>%sbug00305.php</a> on line <i>2</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Exception: &lt;MARK&gt; in <a style='color: black' href='xdebug://%sbug00305.php@2'>%sbug00305.php</a> on line <i>2</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
Expand Down
4 changes: 2 additions & 2 deletions tests/bug00340.phpt
Expand Up @@ -21,14 +21,14 @@ throw new MyException();
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Array to string conversion in %sbug00340.php on line <i>11</i></th></tr>
<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='%sbug00340.php' bgcolor='#eeeeec'>../bug00340.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-uncaught-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught exception 'MyException' with message 'Array' in %sbug00340.php on line <i>11</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> MyException: Array in %sbug00340.php on line <i>11</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
Expand Down
6 changes: 3 additions & 3 deletions tests/bug00635.phpt
Expand Up @@ -19,21 +19,21 @@ throw new Exception('Uncaught exception');
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Exception: Caught exception in %sbug00635.php on line <i>4</i></th></tr>
<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='%sbug00635.php' bgcolor='#eeeeec'>../bug00635.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Exception: Uncaught exception in %sbug00635.php on line <i>9</i></th></tr>
<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='%sbug00635.php' bgcolor='#eeeeec'>../bug00635.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-uncaught-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught exception 'Exception' with message 'Uncaught exception' in %sbug00635.php on line <i>9</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Exception: Uncaught exception in %sbug00635.php on line <i>9</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
Expand Down
2 changes: 1 addition & 1 deletion tests/stacktrace_html_0.phpt
Expand Up @@ -30,7 +30,7 @@ foo( $a );
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Call to undefined function poo() in /%s/stacktrace_html_0.php on line <i>4</i></th></tr>
<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>
Expand Down
2 changes: 1 addition & 1 deletion tests/stacktrace_html_1.phpt
Expand Up @@ -30,7 +30,7 @@ foo( $a );
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Call to undefined function poo() in /%s/stacktrace_html_1.php on line <i>4</i></th></tr>
<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>
Expand Down
2 changes: 1 addition & 1 deletion tests/stacktrace_html_2.phpt
Expand Up @@ -33,7 +33,7 @@ foo( $a );
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Call to undefined function poo() in /%s/stacktrace_html_2.php on line <i>4</i></th></tr>
<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>
Expand Down
2 changes: 1 addition & 1 deletion tests/stacktrace_html_3.phpt
Expand Up @@ -33,7 +33,7 @@ foo( $a );
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Call to undefined function poo() in /%s/stacktrace_html_3.php on line <i>4</i></th></tr>
<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>
Expand Down
2 changes: 1 addition & 1 deletion tests/stacktrace_html_4.phpt
Expand Up @@ -33,7 +33,7 @@ foo( $a );
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Call to undefined function poo() in /%s/stacktrace_html_4.php on line <i>4</i></th></tr>
<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>
Expand Down
2 changes: 1 addition & 1 deletion tests/stacktrace_html_4_novar.phpt
Expand Up @@ -33,7 +33,7 @@ foo( $a );
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Call to undefined function poo() in /%s/stacktrace_html_4_novar.php on line <i>4</i></th></tr>
<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>
Expand Down
2 changes: 1 addition & 1 deletion xdebug.c
Expand Up @@ -1083,7 +1083,7 @@ static void xdebug_throw_exception_hook(zval *exception TSRMLS_DC)
}
if (PG(display_errors)) {
xdebug_str tmp_str = { 0, 0, NULL };
xdebug_append_error_head(&tmp_str, PG(html_errors) TSRMLS_CC);
xdebug_append_error_head(&tmp_str, PG(html_errors), "exception" TSRMLS_CC);
xdebug_str_add(&tmp_str, exception_trace, 0);
xdebug_append_error_footer(&tmp_str, PG(html_errors) TSRMLS_CC);

Expand Down
33 changes: 21 additions & 12 deletions xdebug_stack.c
Expand Up @@ -67,7 +67,7 @@ static char* ansi_formats[10] = {
#endif

static char* html_formats[12] = {
"<br />\n<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>\n",
"<br />\n<font size='1'><table class='xdebug-error xe-%s' dir='ltr' border='1' cellspacing='0' cellpadding='1'>\n",
"<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> %s: %s in %s on line <i>%d</i></th></tr>\n",
#if HAVE_PHP_MEMORY_USAGE
"<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>\n<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>\n",
Expand Down Expand Up @@ -246,11 +246,15 @@ static int create_file_link(char **filename, const char *error_filename, int err
return fname.l;
}

void xdebug_append_error_head(xdebug_str *str, int html TSRMLS_DC)
void xdebug_append_error_head(xdebug_str *str, int html, char *error_type_str TSRMLS_DC)
{
char **formats = select_formats(html TSRMLS_CC);

xdebug_str_add(str, formats[0], 0);

if (html) {
xdebug_str_add(str, xdebug_sprintf(formats[0], error_type_str), 1);
} else {
xdebug_str_add(str, formats[0], 0);
}
}

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 Expand Up @@ -437,22 +441,27 @@ 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, const char *error_type_str, 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 TSRMLS_DC)
{
char *prepend_string;
char *append_string;
char *error_type_str = xdebug_error_type(error_type);
char *error_type_str_simple = xdebug_error_type_simple(error_type);
xdebug_str str = {0, 0, NULL};

prepend_string = INI_STR("error_prepend_string");
append_string = INI_STR("error_append_string");

xdebug_str_add(&str, prepend_string ? prepend_string : "", 0);
xdebug_append_error_head(&str, html TSRMLS_CC);
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);
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);

xdfree(error_type_str);
xdfree(error_type_str_simple);

return str.d;
}

Expand Down Expand Up @@ -614,7 +623,7 @@ void xdebug_error_cb(int type, const char *error_filename, const uint error_line
strncpy(tmp_buf, buffer, p - buffer );

/* Append error */
xdebug_append_error_head(&str, PG(html_errors) TSRMLS_CC);
xdebug_append_error_head(&str, PG(html_errors), "uncaught-exception" TSRMLS_CC);
xdebug_append_error_description(&str, PG(html_errors), error_type_str, tmp_buf, error_filename, error_lineno TSRMLS_CC);
xdebug_append_printable_stack(&str, PG(html_errors) TSRMLS_CC);
xdebug_str_add(&str, XG(last_exception_trace), 0);
Expand All @@ -624,14 +633,14 @@ 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), error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
printable_stack = get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno TSRMLS_CC);
php_output_error(printable_stack TSRMLS_CC);
xdfree(printable_stack);
}
}
if (XG(do_collect_errors)) {
char *printable_stack;
printable_stack = get_printable_stack(PG(html_errors), error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
printable_stack = get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno TSRMLS_CC);
xdebug_llist_insert_next(XG(collected_errors), XDEBUG_LLIST_TAIL(XG(collected_errors)), printable_stack);
}
}
Expand Down Expand Up @@ -747,9 +756,9 @@ PHP_FUNCTION(xdebug_print_function_stack)

i = xdebug_get_stack_frame(0 TSRMLS_CC);
if (message) {
tmp = get_printable_stack(PG(html_errors), "Xdebug", message, i->filename, i->lineno TSRMLS_CC);
tmp = get_printable_stack(PG(html_errors), 0, message, i->filename, i->lineno TSRMLS_CC);
} else {
tmp = get_printable_stack(PG(html_errors), "Xdebug", "user triggered", i->filename, i->lineno TSRMLS_CC);
tmp = get_printable_stack(PG(html_errors), 0, "user triggered", i->filename, i->lineno TSRMLS_CC);
}
php_printf("%s", tmp);
xdfree(tmp);
Expand All @@ -764,7 +773,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), "Xdebug", "user triggered", i->filename, i->lineno TSRMLS_CC);
tmp = get_printable_stack(PG(html_errors), 0, "user triggered", i->filename, i->lineno TSRMLS_CC);
RETVAL_STRING(tmp, 1);
xdfree(tmp);
}
Expand Down
2 changes: 1 addition & 1 deletion xdebug_stack.h
Expand Up @@ -22,7 +22,7 @@
#include "xdebug_str.h"

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 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);
void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC);
void xdebug_append_error_footer(xdebug_str *str, int html TSRMLS_DC);
Expand Down
48 changes: 48 additions & 0 deletions xdebug_var.c
Expand Up @@ -31,6 +31,51 @@

ZEND_EXTERN_MODULE_GLOBALS(xdebug)

char* xdebug_error_type_simple(int type)
{
switch (type) {
case E_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
return xdstrdup("fatal-error");
break;
#if PHP_VERSION_ID >= 50200
case E_RECOVERABLE_ERROR:
return xdstrdup("catchable-fatal-error");
break;
#endif
case E_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_WARNING:
return xdstrdup("warning");
break;
case E_PARSE:
return xdstrdup("parse-error");
break;
case E_NOTICE:
case E_USER_NOTICE:
return xdstrdup("notice");
break;
case E_STRICT:
return xdstrdup("strict-standards");
break;
#if PHP_VERSION_ID >= 50300
case E_DEPRECATED:
case E_USER_DEPRECATED:
return xdstrdup("deprecated");
break;
#endif
case 0:
return xdstrdup("xdebug");
break;
default:
return xdstrdup("unknown-error");
break;
}
}

char* xdebug_error_type(int type)
{
switch (type) {
Expand Down Expand Up @@ -67,6 +112,9 @@ char* xdebug_error_type(int type)
return xdstrdup("Deprecated");
break;
#endif
case 0:
return xdstrdup("Xdebug");
break;
default:
return xdstrdup("Unknown error");
break;
Expand Down
1 change: 1 addition & 0 deletions xdebug_var.h
Expand Up @@ -64,6 +64,7 @@ void xdebug_var_export_fancy(zval **struc, xdebug_str *str, int level, int debug
void xdebug_var_export_xml_node(zval **struc, char *name, xdebug_xml_node *node, xdebug_var_export_options *options, int level TSRMLS_DC);

char* xdebug_xmlize(char *string, int len, int *newlen);
char* xdebug_error_type_simple(int type);
char* xdebug_error_type(int type);
zval *xdebug_get_zval(zend_execute_data *zdata, int node_type, XDEBUG_ZNODE *node, temp_variable *Ts, int *is_var);
char* xdebug_get_zval_value(zval *val, int debug_zval, xdebug_var_export_options *options);
Expand Down

0 comments on commit aa1b5c4

Please sign in to comment.