Skip to content

Commit

Permalink
Implemented issue xdebug#304: File name and line number info for over…
Browse files Browse the repository at this point in the history
…loaded var_dump().
  • Loading branch information
derickr committed Jan 6, 2014
1 parent 7a925bd commit cb77989
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 37 deletions.
94 changes: 94 additions & 0 deletions tests/vardump-overload-cli-2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
--TEST--
Test for overloaded var_dump() on the CLI with file
--INI--
xdebug.overload_var_dump=2
html_errors=0
xdebug.cli_color=0
xdebug.default_enable=1
xdebug.var_display_max_data=32
xdebug.var_display_max_depth=2
xdebug.var_display_max_children=8
--FILE--
<?php
$array = array(
"Hello, this is a very long string with some other useful info",
array(
"depth2" => array(
"depth3" => array(
"depth4" => false,
)
)
),
range(0, 16)
);
var_dump($array);

ini_set('xdebug.cli_color', 2);
var_dump($array);
--EXPECTF--
%svardump-overload-cli-2.php:%d:
array(3) {
[0] =>
string(61) "Hello, this is a very long strin"...
[1] =>
array(1) {
'depth2' =>
array(1) {
...
}
}
[2] =>
array(17) {
[0] =>
int(0)
[1] =>
int(1)
[2] =>
int(2)
[3] =>
int(3)
[4] =>
int(4)
[5] =>
int(5)
[6] =>
int(6)
[7] =>
int(7)

(more elements)...
}
}
%svardump-overload-cli-2.php:%d:
array(3) {
[0] =>
string(61) "Hello, this is a very long strin"...
[1] =>
array(1) {
'depth2' =>
array(1) {
...
}
}
[2] =>
array(17) {
[0] =>
int(0)
[1] =>
int(1)
[2] =>
int(2)
[3] =>
int(3)
[4] =>
int(4)
[5] =>
int(5)
[6] =>
int(6)
[7] =>
int(7)

(more elements)...
}
}
1 change: 1 addition & 0 deletions tests/xdebug_var_dump.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ html_errors=1
date.timezone=Europe/Oslo
xdebug.var_display_max_children=11
xdebug.overload_var_dump=1
xdebug.file_link_format=
--FILE--
<?php
class TimeStuff {
Expand Down
57 changes: 57 additions & 0 deletions tests/xdebug_var_dump_file.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--TEST--
Test for file display with xdebug_var_dump()
--INI--
xdebug.default_enable=1
xdebug.auto_trace=0
xdebug.profiler_enable=0
html_errors=1
date.timezone=Europe/Oslo
xdebug.var_display_max_children=11
xdebug.overload_var_dump=2
xdebug.file_link_format=
--FILE--
<?php
class TimeStuff {
private $timestamp;
private $user_defined;
private $self;
protected $tm;
public $date;

function TimeStuff($ts = null)
{
$this->self = &$this;
$this->timestamp = $ts === null ? time() : $ts;
$this->user_defined = ($ts !== null);
$this->date = date("Y-m-d H:i:s T", $this->timestamp);
$this->tm = getdate($this->timestamp);
}
}

$ts1 = new TimeStuff(1092515106);

var_dump($ts1);
?>
--EXPECTF--
<pre class='xdebug-var-dump' dir='ltr'>
<small>%sxdebug_var_dump_file.php:%d:</small>
<b>object</b>(<i>TimeStuff</i>)[<i>1</i>]
<i>private</i> 'timestamp' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>1092515106</font>
<i>private</i> 'user_defined' <font color='#888a85'>=&gt;</font> <small>boolean</small> <font color='#75507b'>true</font>
<i>private</i> 'self' <font color='#888a85'>=&gt;</font>
<i>&</i><b>object</b>(<i>TimeStuff</i>)[<i>1</i>]
<i>protected</i> 'tm' <font color='#888a85'>=&gt;</font>
<b>array</b> <i>(size=11)</i>
'seconds' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>6</font>
'minutes' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>25</font>
'hours' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>22</font>
'mday' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>14</font>
'wday' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>6</font>
'mon' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>8</font>
'year' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>2004</font>
'yday' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>226</font>
'weekday' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'Saturday'</font> <i>(length=8)</i>
'month' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'August'</font> <i>(length=6)</i>
0 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>1092515106</font>
<i>public</i> 'date' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'2004-08-14 22:25:06 CEST'</font> <i>(length=24)</i>
</pre>
57 changes: 57 additions & 0 deletions tests/xdebug_var_dump_file_link.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--TEST--
Test for file and link display with xdebug_var_dump()
--INI--
xdebug.default_enable=1
xdebug.auto_trace=0
xdebug.profiler_enable=0
html_errors=1
date.timezone=Europe/Oslo
xdebug.var_display_max_children=11
xdebug.overload_var_dump=2
xdebug.file_link_format=xdebug://%f@%l
--FILE--
<?php
class TimeStuff {
private $timestamp;
private $user_defined;
private $self;
protected $tm;
public $date;

function TimeStuff($ts = null)
{
$this->self = &$this;
$this->timestamp = $ts === null ? time() : $ts;
$this->user_defined = ($ts !== null);
$this->date = date("Y-m-d H:i:s T", $this->timestamp);
$this->tm = getdate($this->timestamp);
}
}

$ts1 = new TimeStuff(1092515106);

var_dump($ts1);
?>
--EXPECTF--
<pre class='xdebug-var-dump' dir='ltr'>
<small><a href='xdebug://%sxdebug_var_dump_file_link.php@%d'>%sxdebug_var_dump_file_link.php:%d</a>:</small>
<b>object</b>(<i>TimeStuff</i>)[<i>1</i>]
<i>private</i> 'timestamp' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>1092515106</font>
<i>private</i> 'user_defined' <font color='#888a85'>=&gt;</font> <small>boolean</small> <font color='#75507b'>true</font>
<i>private</i> 'self' <font color='#888a85'>=&gt;</font>
<i>&</i><b>object</b>(<i>TimeStuff</i>)[<i>1</i>]
<i>protected</i> 'tm' <font color='#888a85'>=&gt;</font>
<b>array</b> <i>(size=11)</i>
'seconds' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>6</font>
'minutes' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>25</font>
'hours' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>22</font>
'mday' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>14</font>
'wday' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>6</font>
'mon' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>8</font>
'year' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>2004</font>
'yday' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>226</font>
'weekday' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'Saturday'</font> <i>(length=8)</i>
'month' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'August'</font> <i>(length=6)</i>
0 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>1092515106</font>
<i>public</i> 'date' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'2004-08-14 22:25:06 CEST'</font> <i>(length=24)</i>
</pre>
34 changes: 34 additions & 0 deletions usefulstuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,40 @@ int xdebug_format_output_filename(char **filename, char *format, char *script_na
return fname.l;
}

int xdebug_format_file_link(char **filename, const char *error_filename, int error_lineno TSRMLS_DC)
{
xdebug_str fname = {0, 0, NULL};
char *format = XG(file_link_format);

while (*format)
{
if (*format != '%') {
xdebug_str_addl(&fname, (char *) format, 1, 0);
} else {
format++;
switch (*format)
{
case 'f': /* filename */
xdebug_str_add(&fname, xdebug_sprintf("%s", error_filename), 1);
break;

case 'l': /* line number */
xdebug_str_add(&fname, xdebug_sprintf("%d", error_lineno), 1);
break;

case '%': /* literal % */
xdebug_str_addl(&fname, "%", 1, 0);
break;
}
}
format++;
}

*filename = fname.d;

return fname.l;
}

void xdebug_open_log(TSRMLS_D)
{
/* initialize remote log file */
Expand Down
1 change: 1 addition & 0 deletions usefulstuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ char *xdebug_path_to_url(const char *fileurl TSRMLS_DC);
char *xdebug_path_from_url(const char *fileurl TSRMLS_DC);
FILE *xdebug_fopen(char *fname, char *mode, char *extension, char **new_fname);
int xdebug_format_output_filename(char **filename, char *format, char *script_name);
int xdebug_format_file_link(char **filename, const char *error_filename, int error_lineno TSRMLS_DC);
void xdebug_open_log(TSRMLS_D);
void xdebug_close_log(TSRMLS_D);

Expand Down
38 changes: 2 additions & 36 deletions xdebug_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,40 +211,6 @@ void xdebug_log_stack(const char *error_type_str, char *buffer, const char *erro
}
}

static int create_file_link(char **filename, const char *error_filename, int error_lineno TSRMLS_DC)
{
xdebug_str fname = {0, 0, NULL};
char *format = XG(file_link_format);

while (*format)
{
if (*format != '%') {
xdebug_str_addl(&fname, (char *) format, 1, 0);
} else {
format++;
switch (*format)
{
case 'f': /* filename */
xdebug_str_add(&fname, xdebug_sprintf("%s", error_filename), 1);
break;

case 'l': /* line number */
xdebug_str_add(&fname, xdebug_sprintf("%d", error_lineno), 1);
break;

case '%': /* literal % */
xdebug_str_addl(&fname, "%", 1, 0);
break;
}
}
format++;
}

*filename = fname.d;

return fname.l;
}

void xdebug_append_error_head(xdebug_str *str, int html, char *error_type_str TSRMLS_DC)
{
char **formats = select_formats(html TSRMLS_CC);
Expand Down Expand Up @@ -281,7 +247,7 @@ void xdebug_append_error_description(xdebug_str *str, int html, const char *erro
if (strlen(XG(file_link_format)) > 0 && html) {
char *file_link;

create_file_link(&file_link, error_filename, error_lineno TSRMLS_CC);
xdebug_format_file_link(&file_link, error_filename, error_lineno TSRMLS_CC);
xdebug_str_add(str, xdebug_sprintf(formats[11], error_type_str, escaped, file_link, error_filename, error_lineno), 1);
xdfree(file_link);
} else {
Expand Down Expand Up @@ -407,7 +373,7 @@ void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC)
char *just_filename = strrchr(i->filename, DEFAULT_SLASH);
char *file_link;

create_file_link(&file_link, i->filename, i->lineno TSRMLS_CC);
xdebug_format_file_link(&file_link, i->filename, i->lineno TSRMLS_CC);
xdebug_str_add(str, xdebug_sprintf(formats[10], i->filename, file_link, just_filename, i->lineno), 1);
xdfree(file_link);
} else {
Expand Down
22 changes: 21 additions & 1 deletion xdebug_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ xdebug_var_export_options* xdebug_var_export_options_from_ini(TSRMLS_D)
options->max_data = XG(display_max_data);
options->max_depth = XG(display_max_depth);
options->show_hidden = 0;
options->show_location = XG(overload_var_dump) > 1;

if (options->max_children == -1 || options->max_children > XDEBUG_MAX_INT) {
options->max_children = XDEBUG_MAX_INT;
Expand All @@ -274,7 +275,7 @@ xdebug_var_export_options* xdebug_var_export_options_from_ini(TSRMLS_D)
return options;
}

xdebug_var_export_options xdebug_var_nolimit_options = { XDEBUG_MAX_INT, XDEBUG_MAX_INT, 1023, 1, NULL, 0 };
xdebug_var_export_options xdebug_var_nolimit_options = { XDEBUG_MAX_INT, XDEBUG_MAX_INT, 1023, 1, 0, NULL, 0 };

xdebug_var_export_options* xdebug_var_get_nolimit_options(TSRMLS_D)
{
Expand Down Expand Up @@ -821,6 +822,10 @@ char* xdebug_get_zval_value_text_ansi(zval *val, int mode, int debug_zval, xdebu
default_options = 1;
}

if (options->show_location) {
xdebug_str_add(&str, xdebug_sprintf("%s%s%s:%s%d%s:\n", ANSI_COLOR_BOLD, zend_get_executed_filename(TSRMLS_C), ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOLD, zend_get_executed_lineno(TSRMLS_C), ANSI_COLOR_BOLD_OFF), 1);
}

xdebug_var_export_text_ansi(&val, (xdebug_str*) &str, mode, 1, debug_zval, options TSRMLS_CC);

if (default_options) {
Expand Down Expand Up @@ -896,6 +901,10 @@ char* xdebug_get_zval_synopsis_text_ansi(zval *val, int mode, int debug_zval, xd
default_options = 1;
}

if (options->show_location) {
xdebug_str_add(&str, xdebug_sprintf("%s%s: %d%s\n", ANSI_COLOR_BOLD, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), ANSI_COLOR_BOLD_OFF), 1);
}

xdebug_var_synopsis_text_ansi(&val, (xdebug_str*) &str, mode, 1, debug_zval, options TSRMLS_CC);

if (default_options) {
Expand Down Expand Up @@ -1606,6 +1615,17 @@ char* xdebug_get_zval_value_fancy(char *name, zval *val, int *len, int debug_zva
}

xdebug_str_addl(&str, "<pre class='xdebug-var-dump' dir='ltr'>", 39, 0);
if (options->show_location) {
if (strlen(XG(file_link_format)) > 0) {
char *file_link;

xdebug_format_file_link(&file_link, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
xdebug_str_add(&str, xdebug_sprintf("\n<small><a href='%s'>%s:%d</a>:</small>", file_link, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)), 1);
xdfree(file_link);
} else {
xdebug_str_add(&str, xdebug_sprintf("\n<small>%s:%d:</small>", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)), 1);
}
}
xdebug_var_export_fancy(&val, (xdebug_str*) &str, 1, debug_zval, options TSRMLS_CC);
xdebug_str_addl(&str, "</pre>", 6, 0);

Expand Down
1 change: 1 addition & 0 deletions xdebug_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct xdebug_var_export_options {
int max_data;
int max_depth;
int show_hidden;
int show_location;
xdebug_var_runtime_page *runtime;
int no_decoration;
} xdebug_var_export_options;
Expand Down

0 comments on commit cb77989

Please sign in to comment.