Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- Added ANSI colour output for the shell. (Patch by Michael Maclean).

SVN Rev: 3337
  • Loading branch information...
commit 23c5739ee923938aba0c029d3971db563cb43606 1 parent b6844bf
Derick Rethans authored August 07, 2010
15  php_xdebug.h
@@ -38,6 +38,12 @@ extern zend_module_entry xdebug_module_entry;
38 38
 
39 39
 #define MICRO_IN_SEC 1000000.00
40 40
 
  41
+#ifndef PHP_WIN32
  42
+#define OUTPUT_NOT_CHECKED -1
  43
+#define OUTPUT_IS_TTY       1
  44
+#define OUTPUT_NOT_TTY      0
  45
+#endif
  46
+
41 47
 #ifdef PHP_WIN32
42 48
 #define PHP_XDEBUG_API __declspec(dllexport)
43 49
 #else
@@ -81,6 +87,10 @@ PHP_RSHUTDOWN_FUNCTION(xdebug);
81 87
 PHP_MINFO_FUNCTION(xdebug);
82 88
 ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug);
83 89
 
  90
+#ifndef PHP_WIN32
  91
+int xdebug_is_output_tty();
  92
+#endif
  93
+
84 94
 /* call stack functions */
85 95
 PHP_FUNCTION(xdebug_get_stack_depth);
86 96
 PHP_FUNCTION(xdebug_get_function_stack);
@@ -177,6 +187,11 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
177 187
 	long          display_max_data;
178 188
 	long          display_max_depth;
179 189
 
  190
+#ifndef PHP_WIN32
  191
+	zend_bool     cli_color;
  192
+	int           output_is_tty;
  193
+#endif
  194
+
180 195
 	/* used for code coverage */
181 196
 	zend_bool     do_code_coverage;
182 197
 	xdebug_hash  *code_coverage;
52  xdebug.c
@@ -292,6 +292,9 @@ PHP_INI_BEGIN()
292 292
 	STD_PHP_INI_ENTRY("xdebug.var_display_max_children", "128",         PHP_INI_ALL,    OnUpdateLong,   display_max_children, zend_xdebug_globals, xdebug_globals)
293 293
 	STD_PHP_INI_ENTRY("xdebug.var_display_max_data",     "512",         PHP_INI_ALL,    OnUpdateLong,   display_max_data,     zend_xdebug_globals, xdebug_globals)
294 294
 	STD_PHP_INI_ENTRY("xdebug.var_display_max_depth",    "3",           PHP_INI_ALL,    OnUpdateLong,   display_max_depth,    zend_xdebug_globals, xdebug_globals)
  295
+#ifndef PHP_WIN32
  296
+	STD_PHP_INI_ENTRY("xdebug.cli_color",                "0",           PHP_INI_ALL,    OnUpdateBool,   cli_color,            zend_xdebug_globals, xdebug_globals)
  297
+#endif
295 298
 
296 299
 	/* Scream support */
297 300
 	STD_PHP_INI_BOOLEAN("xdebug.scream",                 "0",           PHP_INI_ALL,    OnUpdateBool,   do_scream,            zend_xdebug_globals, xdebug_globals)
@@ -308,6 +311,7 @@ static void php_xdebug_init_globals (zend_xdebug_globals *xg TSRMLS_DC)
308 311
 	xg->do_code_coverage     = 0;
309 312
 	xg->breakpoint_count     = 0;
310 313
 	xg->ide_key              = NULL;
  314
+	xg->output_is_tty        = OUTPUT_NOT_CHECKED;
311 315
 
312 316
 	xdebug_llist_init(&xg->server, xdebug_superglobals_dump_dtor);
313 317
 	xdebug_llist_init(&xg->get, xdebug_superglobals_dump_dtor);
@@ -423,6 +427,11 @@ void xdebug_env_config()
423 427
 		if (strcasecmp(envvar, "remote_cookie_expire_time") == 0) {
424 428
 			name = "xdebug.remote_cookie_expire_time";
425 429
 		}
  430
+#ifndef PHP_WIN32
  431
+		else if (strcasecmp(envvar, "cli_color") == 0) {
  432
+			name = "xdebug.cli_color";
  433
+		}
  434
+#endif
426 435
 
427 436
 		if (name) {
428 437
 			zend_alter_ini_entry(name, strlen(name) + 1, envval, strlen(envval), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
@@ -478,6 +487,26 @@ static int xdebug_include_or_eval_handler(ZEND_OPCODE_HANDLER_ARGS)
478 487
 	return ZEND_USER_OPCODE_DISPATCH;
479 488
 }
480 489
 
  490
+#ifndef PHP_WIN32
  491
+int xdebug_is_output_tty()
  492
+{
  493
+	if (XG(output_is_tty) == OUTPUT_NOT_CHECKED) {
  494
+		php_stream *output = php_stream_open_wrapper("php://stdout", "w", REPORT_ERRORS, NULL);
  495
+		int fd;
  496
+
  497
+		if (php_stream_cast(output, PHP_STREAM_AS_FD, (void *)&fd, REPORT_ERRORS) == FAILURE) {
  498
+			XG(output_is_tty) = OUTPUT_NOT_TTY;
  499
+		} else if (!isatty(fd)) {
  500
+			XG(output_is_tty) = OUTPUT_NOT_TTY;
  501
+		} else {
  502
+			XG(output_is_tty) = OUTPUT_IS_TTY;
  503
+		}
  504
+		php_stream_close(output);
  505
+	}
  506
+	return (XG(output_is_tty));
  507
+}
  508
+#endif
  509
+
481 510
 
482 511
 PHP_MINIT_FUNCTION(xdebug)
483 512
 {
@@ -584,6 +613,10 @@ PHP_MINIT_FUNCTION(xdebug)
584 613
 	REGISTER_LONG_CONSTANT("XDEBUG_CC_DEAD_CODE", XDEBUG_CC_OPTION_DEAD_CODE, CONST_CS | CONST_PERSISTENT);
585 614
 
586 615
 	XG(breakpoint_count) = 0;
  616
+#ifndef PHP_WIN32
  617
+	XG(output_is_tty) = OUTPUT_NOT_CHECKED;
  618
+#endif
  619
+
587 620
 #ifndef ZTS
588 621
 	if (sapi_module.header_handler != xdebug_header_handler) {
589 622
 		xdebug_orig_header_handler = sapi_module.header_handler;
@@ -1436,7 +1469,15 @@ PHP_FUNCTION(xdebug_var_dump)
1436 1469
 			val = xdebug_get_zval_value_fancy(NULL, (zval*) *args[i], &len, 0, NULL TSRMLS_CC);
1437 1470
 			PHPWRITE(val, len);
1438 1471
 			xdfree(val);
1439  
-		} else {
  1472
+		}
  1473
+#ifndef PHP_WIN32
  1474
+		else if (XG(cli_color) == 1 && xdebug_is_output_tty(TSRMLS_C)) {
  1475
+			val = xdebug_get_zval_value_ansi((zval*) *args[i], 0, NULL TSRMLS_CC);
  1476
+			PHPWRITE(val, strlen(val));
  1477
+			xdfree(val);
  1478
+		} 
  1479
+#endif
  1480
+		else {
1440 1481
 			xdebug_php_var_dump(args[i], 1 TSRMLS_CC);
1441 1482
 		}
1442 1483
 	}
@@ -1478,7 +1519,14 @@ PHP_FUNCTION(xdebug_debug_zval)
1478 1519
 				if (PG(html_errors)) {
1479 1520
 					val = xdebug_get_zval_value_fancy(NULL, debugzval, &len, 1, NULL TSRMLS_CC);
1480 1521
 					PHPWRITE(val, len);
1481  
-				} else {
  1522
+				}
  1523
+#ifndef PHP_WIN32
  1524
+				else if (XG(cli_color) == 1 && xdebug_is_output_tty(TSRMLS_C)) {
  1525
+					val = xdebug_get_zval_value_ansi(debugzval, 1, NULL TSRMLS_CC);
  1526
+					PHPWRITE(val, strlen(val));
  1527
+				}
  1528
+#endif
  1529
+				else {
1482 1530
 					val = xdebug_get_zval_value(debugzval, 1, NULL);
1483 1531
 					PHPWRITE(val, strlen(val));
1484 1532
 				}
48  xdebug_stack.c
@@ -24,6 +24,7 @@
24 24
 #include "xdebug_str.h"
25 25
 #include "xdebug_superglobals.h"
26 26
 #include "xdebug_var.h"
  27
+#include "php_ini.h"
27 28
 
28 29
 #include "main/php_ini.h"
29 30
 
@@ -46,6 +47,25 @@ static char* text_formats[10] = {
46 47
 	"  $%s = *uninitialized*\n"
47 48
 };
48 49
 
  50
+#ifndef PHP_WIN32
  51
+static char* ansi_formats[10] = {
  52
+	"\n",
  53
+	"\e[1m\e[31m%s\e[0m: %s\e[22m in \e[31m%s\e[0m on line \e[32m%d\e[0m\e[22m\n",
  54
+	"\n\e[1mCall Stack:\e[22m\n",
  55
+#if HAVE_PHP_MEMORY_USAGE
  56
+	"%10.4f %10ld %3d. %s(",
  57
+#else
  58
+	"%10.4f %3d. %s(",
  59
+#endif
  60
+	"'%s'",
  61
+	") %s:%d\n",
  62
+	"\n\nVariables in local scope (#%d):\n",
  63
+	"\n",
  64
+	"  $%s = %s\n",
  65
+	"  $%s = *uninitialized*\n"
  66
+};
  67
+#endif
  68
+
49 69
 static char* html_formats[12] = {
50 70
 	"<br />\n<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>\n",
51 71
 	"<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",
@@ -70,6 +90,20 @@ static char* html_formats[12] = {
70 90
 	"<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> %s: %s in <a style='color: black' href='%s'>%s</a> on line <i>%d</i></th></tr>\n"
71 91
 };
72 92
 
  93
+static char** select_formats(int html TSRMLS_DC) {
  94
+	if (html) {
  95
+		return html_formats;
  96
+	} 
  97
+#ifndef PHP_WIN32
  98
+	else if (XG(cli_color) == 1 && xdebug_is_output_tty(TSRMLS_C)) {
  99
+		return ansi_formats;
  100
+	}
  101
+#endif
  102
+	else {
  103
+		return text_formats;
  104
+	}
  105
+}
  106
+
73 107
 static void dump_used_var_with_contents(void *htmlq, xdebug_hash_element* he, void *argument)
74 108
 {
75 109
 	int        html = *(int *)htmlq;
@@ -102,11 +136,7 @@ static void dump_used_var_with_contents(void *htmlq, xdebug_hash_element* he, vo
102 136
 	zvar = xdebug_get_php_symbol(name, strlen(name) + 1);
103 137
 	XG(active_symbol_table) = tmp_ht;
104 138
 
105  
-	if (html) {
106  
-		formats = html_formats;
107  
-	} else {
108  
-		formats = text_formats;
109  
-	}
  139
+	formats = select_formats(PG(html_errors));
110 140
 
111 141
 	if (!zvar) {
112 142
 		xdebug_str_add(str, xdebug_sprintf(formats[9], name), 1);
@@ -218,14 +248,14 @@ static int create_file_link(char **filename, const char *error_filename, int err
218 248
 
219 249
 static void xdebug_append_error_head(xdebug_str *str, int html TSRMLS_DC)
220 250
 {
221  
-	char **formats = html ? html_formats : text_formats;
  251
+	char **formats = select_formats(html TSRMLS_CC);
222 252
  
223 253
 	xdebug_str_add(str, formats[0], 0);
224 254
 }
225 255
 
226 256
 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)
227 257
 {
228  
-	char **formats = html ? html_formats : text_formats;
  258
+	char **formats = select_formats(html TSRMLS_CC);
229 259
 
230 260
 	if (strlen(XG(file_link_format)) > 0 && html) {
231 261
 		char *file_link;
@@ -243,7 +273,7 @@ void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC)
243 273
 	xdebug_llist_element *le;
244 274
 	function_stack_entry *i;
245 275
 	int    len;
246  
-	char **formats = html ? html_formats : text_formats;
  276
+	char **formats = select_formats(html TSRMLS_CC);
247 277
 
248 278
 	if (XG(stack) && XG(stack)->size) {
249 279
 		i = XDEBUG_LLIST_VALP(XDEBUG_LLIST_HEAD(XG(stack)));
@@ -388,7 +418,7 @@ void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC)
388 418
 
389 419
 static void xdebug_append_error_footer(xdebug_str *str, int html)
390 420
 {
391  
-	char **formats = html ? html_formats : text_formats;
  421
+	char **formats = select_formats(html TSRMLS_CC);
392 422
 
393 423
 	xdebug_str_add(str, formats[7], 0);
394 424
 }
306  xdebug_var.c
@@ -503,6 +503,311 @@ char* xdebug_get_zval_synopsis(zval *val, int debug_zval, xdebug_var_export_opti
503 503
 	return str.d;
504 504
 }
505 505
 
  506
+#ifndef PHP_WIN32
  507
+/*****************************************************************************
  508
+** ANSI colored variable printing routines
  509
+*/
  510
+
  511
+#define ANSI_COLOR_POINTER       "\e[30m"
  512
+#define ANSI_COLOR_BOOL          "\e[35m"
  513
+#define ANSI_COLOR_LONG          "\e[32m"
  514
+#define ANSI_COLOR_NULL          "\e[34m"
  515
+#define ANSI_COLOR_DOUBLE        "\e[33m"
  516
+#define ANSI_COLOR_STRING        "\e[31m"
  517
+#define ANSI_COLOR_EMPTY         "\e[30m"
  518
+#define ANSI_COLOR_ARRAY         "\e[33m"
  519
+#define ANSI_COLOR_OBJECT        "\e[31m"
  520
+#define ANSI_COLOR_RESOURCE      "\e[36m"
  521
+#define ANSI_COLOR_MODIFIER      "\e[32m"
  522
+#define ANSI_COLOR_RESET         "\e[0m"
  523
+#define ANSI_COLOR_BOLD          "\e[1m"
  524
+#define ANSI_COLOR_BOLD_OFF      "\e[22m"
  525
+
  526
+static int xdebug_array_element_export_ansi(zval **zv XDEBUG_ZEND_HASH_APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
  527
+{
  528
+	int level, debug_zval;
  529
+	xdebug_str *str;
  530
+	xdebug_var_export_options *options;
  531
+
  532
+	level      = va_arg(args, int);
  533
+	str        = va_arg(args, struct xdebug_str*);
  534
+	debug_zval = va_arg(args, int);
  535
+	options    = va_arg(args, xdebug_var_export_options*);
  536
+
  537
+	if (options->runtime[level].current_element_nr >= options->runtime[level].start_element_nr &&
  538
+		options->runtime[level].current_element_nr < options->runtime[level].end_element_nr)
  539
+	{
  540
+		xdebug_str_add(str, xdebug_sprintf("%*s", (level * 2), ""), 1);
  541
+
  542
+		if (hash_key->nKeyLength==0) { /* numeric key */
  543
+			xdebug_str_add(str, xdebug_sprintf("[%ld] %s=>%s\n", hash_key->h, ANSI_COLOR_POINTER, ANSI_COLOR_RESET), 1);
  544
+		} else { /* string key */
  545
+			int newlen = 0;
  546
+			char *tmp, *tmp2;
  547
+			
  548
+			tmp = php_str_to_str(hash_key->arKey, hash_key->nKeyLength, "'", 1, "\\'", 2, &newlen);
  549
+			tmp2 = php_str_to_str(tmp, newlen - 1, "\0", 1, "\\0", 2, &newlen);
  550
+			if (tmp) {
  551
+				efree(tmp);
  552
+			}
  553
+			xdebug_str_addl(str, "'", 1, 0);
  554
+			if (tmp2) {
  555
+				xdebug_str_addl(str, tmp2, newlen, 0);
  556
+				efree(tmp2);
  557
+			}
  558
+			xdebug_str_add(str, "' =>\n", 0);
  559
+		}
  560
+		xdebug_var_export_ansi(zv, str, level + 1, debug_zval, options TSRMLS_CC);
  561
+	}
  562
+	if (options->runtime[level].current_element_nr == options->runtime[level].end_element_nr) {
  563
+		xdebug_str_addl(str, "...,\n ", 6, 0);
  564
+	}
  565
+	options->runtime[level].current_element_nr++;
  566
+	return 0;
  567
+}
  568
+
  569
+static int xdebug_object_element_export_ansi(zval **zv XDEBUG_ZEND_HASH_APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
  570
+{
  571
+	int level, debug_zval;
  572
+	xdebug_str *str;
  573
+	xdebug_var_export_options *options;
  574
+	char *prop_name, *class_name, *modifier;
  575
+
  576
+	level      = va_arg(args, int);
  577
+	str        = va_arg(args, struct xdebug_str*);
  578
+	debug_zval = va_arg(args, int);
  579
+	options    = va_arg(args, xdebug_var_export_options*);
  580
+
  581
+	if (options->runtime[level].current_element_nr >= options->runtime[level].start_element_nr &&
  582
+		options->runtime[level].current_element_nr < options->runtime[level].end_element_nr)
  583
+	{
  584
+		xdebug_str_add(str, xdebug_sprintf("%*s", (level * 2), ""), 1);
  585
+
  586
+		if (hash_key->nKeyLength != 0) {
  587
+			modifier = xdebug_get_property_info(hash_key->arKey, hash_key->nKeyLength, &prop_name, &class_name);
  588
+			xdebug_str_add(str, xdebug_sprintf("%s%s%s%s%s $%s %s=>%s", 
  589
+			               ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, modifier, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_RESET, 
  590
+			               prop_name, ANSI_COLOR_POINTER, ANSI_COLOR_RESET), 1);
  591
+		}
  592
+		xdebug_var_export_ansi(zv, str, level + 1, debug_zval, options TSRMLS_CC);
  593
+	}
  594
+	if (options->runtime[level].current_element_nr == options->runtime[level].end_element_nr) {
  595
+		xdebug_str_addl(str, "...; ", 5, 0);
  596
+	}
  597
+	options->runtime[level].current_element_nr++;
  598
+	return 0;
  599
+}
  600
+
  601
+void xdebug_var_export_ansi(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
  602
+{
  603
+	HashTable *myht;
  604
+	char*     tmp_str;
  605
+	int       tmp_len;
  606
+
  607
+	if (!struc || !(*struc)) {
  608
+		return;
  609
+	}
  610
+	if (debug_zval) {
  611
+		xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d)=", (*struc)->XDEBUG_REFCOUNT, (*struc)->XDEBUG_IS_REF), 1);
  612
+	}
  613
+	
  614
+	xdebug_str_add(str, xdebug_sprintf("%*s", (level * 2) - 2, ""), 1);
  615
+
  616
+	switch (Z_TYPE_PP(struc)) {
  617
+		case IS_BOOL:
  618
+			xdebug_str_add(str, xdebug_sprintf("%sbool%s(%s%s%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOOL, Z_LVAL_PP(struc) ? "true" : "false", ANSI_COLOR_RESET), 1);
  619
+			break;
  620
+
  621
+		case IS_NULL:
  622
+			xdebug_str_add(str, xdebug_sprintf("%s%sNULL%s%s", ANSI_COLOR_BOLD, ANSI_COLOR_NULL, ANSI_COLOR_RESET, ANSI_COLOR_BOLD_OFF), 1);
  623
+			break;
  624
+
  625
+		case IS_LONG:
  626
+			xdebug_str_add(str, xdebug_sprintf("%sint%s(%s%ld%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, Z_LVAL_PP(struc), ANSI_COLOR_RESET), 1);
  627
+			break;
  628
+
  629
+		case IS_DOUBLE:
  630
+			xdebug_str_add(str, xdebug_sprintf("%sdouble%s(%s%.*G%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_DOUBLE, (int) EG(precision), Z_DVAL_PP(struc), ANSI_COLOR_RESET), 1);
  631
+			break;
  632
+
  633
+		case IS_STRING:
  634
+			tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\\0..\37", 6 TSRMLS_CC);
  635
+			if (options->no_decoration) {
  636
+				xdebug_str_add(str, tmp_str, 0);
  637
+			} else if (options->max_data == 0 || Z_STRLEN_PP(struc) <= options->max_data) {
  638
+				xdebug_str_add(str, xdebug_sprintf("%sstring%s(%s%ld%s) '%s%s%s'", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, 
  639
+				               ANSI_COLOR_LONG, Z_STRLEN_PP(struc), ANSI_COLOR_RESET,
  640
+				               ANSI_COLOR_STRING, tmp_str, ANSI_COLOR_RESET), 1);
  641
+			} else {
  642
+				xdebug_str_addl(str, "'", 1, 0);
  643
+				xdebug_str_addl(str, xdebug_sprintf("%sstring%s(%s%ld%s) %s%s%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, 
  644
+				                ANSI_COLOR_LONG, Z_STRLEN_PP(struc), ANSI_COLOR_RESET,
  645
+				                ANSI_COLOR_STRING, tmp_str, ANSI_COLOR_RESET), options->max_data, 1);
  646
+				xdebug_str_addl(str, "...'", 4, 0);
  647
+			}
  648
+			efree(tmp_str);
  649
+			break;
  650
+
  651
+		case IS_ARRAY:
  652
+			myht = Z_ARRVAL_PP(struc);
  653
+			if (myht->nApplyCount < 1) {
  654
+				xdebug_str_add(str, xdebug_sprintf("%sarray%s(%s%d%s) {\n", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET), 1);
  655
+				if (level <= options->max_depth) {
  656
+					options->runtime[level].current_element_nr = 0;
  657
+					options->runtime[level].start_element_nr = 0;
  658
+					options->runtime[level].end_element_nr = options->max_children;
  659
+
  660
+					zend_hash_apply_with_arguments(myht XDEBUG_ZEND_HASH_APPLY_TSRMLS_CC, (apply_func_args_t) xdebug_array_element_export_ansi, 4, level, str, debug_zval, options);
  661
+				} else {
  662
+					xdebug_str_addl(str, "...", 3, 0);
  663
+				}
  664
+				xdebug_str_add(str, xdebug_sprintf("%*s}", (level * 2) - 2 , ""), 1);
  665
+			} else {
  666
+				xdebug_str_add(str, xdebug_sprintf("&%sarray%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF), 1);
  667
+			}
  668
+			break;
  669
+
  670
+		case IS_OBJECT:
  671
+			myht = Z_OBJPROP_PP(struc);
  672
+			if (myht->nApplyCount < 1) {
  673
+				char *class_name;
  674
+				zend_uint class_name_len;
  675
+
  676
+				zend_get_object_classname(*struc, &class_name, &class_name_len TSRMLS_CC);
  677
+				xdebug_str_add(str, xdebug_sprintf("%sclass%s %s%s%s#%d (%s%d%s) {\n", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_OBJECT, class_name, ANSI_COLOR_RESET,
  678
+							Z_OBJ_HANDLE_PP(struc),
  679
+							ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET), 1);
  680
+				efree(class_name);
  681
+
  682
+				if (level <= options->max_depth) {
  683
+					options->runtime[level].current_element_nr = 0;
  684
+					options->runtime[level].start_element_nr = 0;
  685
+					options->runtime[level].end_element_nr = options->max_children;
  686
+
  687
+					zend_hash_apply_with_arguments(myht XDEBUG_ZEND_HASH_APPLY_TSRMLS_CC, (apply_func_args_t) xdebug_object_element_export_ansi, 4, level, str, debug_zval, options);
  688
+				} else {
  689
+					xdebug_str_addl(str, "...", 3, 0);
  690
+				}
  691
+				xdebug_str_add(str, xdebug_sprintf("%*s}", (level * 2) - 2, ""), 1);
  692
+			} else {
  693
+				xdebug_str_addl(str, "...", 3, 0);
  694
+			}
  695
+			break;
  696
+
  697
+		case IS_RESOURCE: {
  698
+			char *type_name;
  699
+
  700
+			type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC);
  701
+			xdebug_str_add(str, xdebug_sprintf("%sresource%s(%s%ld%s) of type (%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, 
  702
+			               ANSI_COLOR_RESOURCE, Z_LVAL_PP(struc), ANSI_COLOR_RESET, type_name ? type_name : "Unknown"), 1);
  703
+			break;
  704
+		}
  705
+
  706
+		default:
  707
+			xdebug_str_add(str, xdebug_sprintf("%sNULL%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET), 0);
  708
+			break;
  709
+	}
  710
+
  711
+	xdebug_str_addl(str, "\n", 1, 0);
  712
+}
  713
+
  714
+char* xdebug_get_zval_value_ansi(zval *val, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
  715
+{
  716
+	xdebug_str str = {0, 0, NULL};
  717
+	int default_options = 0;
  718
+
  719
+	if (!options) {
  720
+		options = xdebug_var_export_options_from_ini(TSRMLS_C);
  721
+		default_options = 1;
  722
+	}
  723
+
  724
+	xdebug_var_export_ansi(&val, (xdebug_str*) &str, 1, debug_zval, options TSRMLS_CC);
  725
+
  726
+	if (default_options) {
  727
+		xdfree(options->runtime);
  728
+		xdfree(options);
  729
+	}
  730
+
  731
+	return str.d;
  732
+}
  733
+
  734
+static void xdebug_var_synopsis_ansi(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
  735
+{
  736
+	HashTable *myht;
  737
+
  738
+	if (!struc || !(*struc)) {
  739
+		return;
  740
+	}
  741
+	if (debug_zval) {
  742
+		xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d)=", (*struc)->XDEBUG_REFCOUNT, (*struc)->XDEBUG_IS_REF), 1);
  743
+	}
  744
+	switch (Z_TYPE_PP(struc)) {
  745
+		case IS_BOOL:
  746
+			xdebug_str_add(str, xdebug_sprintf("%sbool%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF), 1);
  747
+			break;
  748
+
  749
+		case IS_NULL:
  750
+			xdebug_str_add(str, xdebug_sprintf("%snull%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF), 1);
  751
+			break;
  752
+
  753
+		case IS_LONG:
  754
+			xdebug_str_add(str, xdebug_sprintf("%sint%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF), 1);
  755
+			break;
  756
+
  757
+		case IS_DOUBLE:
  758
+			xdebug_str_add(str, xdebug_sprintf("%sdouble%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF), 1);
  759
+			break;
  760
+
  761
+		case IS_STRING:
  762
+			xdebug_str_add(str, xdebug_sprintf("%sstring%s(%s%d%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, Z_STRLEN_PP(struc), ANSI_COLOR_RESET), 1);
  763
+			break;
  764
+
  765
+		case IS_ARRAY:
  766
+			myht = Z_ARRVAL_PP(struc);
  767
+			xdebug_str_add(str, xdebug_sprintf("array(%s%d%s)", ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET), 1);
  768
+			break;
  769
+
  770
+		case IS_OBJECT: {
  771
+			char *class_name;
  772
+			zend_uint class_name_len;
  773
+
  774
+			zend_get_object_classname(*struc, &class_name, &class_name_len TSRMLS_CC);
  775
+			xdebug_str_add(str, xdebug_sprintf("class %s", class_name), 1);
  776
+			break;
  777
+		}
  778
+
  779
+		case IS_RESOURCE: {
  780
+			char *type_name;
  781
+
  782
+			type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC);
  783
+			xdebug_str_add(str, xdebug_sprintf("resource(%s%ld%s) of type (%s)", ANSI_COLOR_LONG, Z_LVAL_PP(struc), ANSI_COLOR_RESET, type_name ? type_name : "Unknown"), 1);
  784
+			break;
  785
+		}
  786
+	}
  787
+}
  788
+
  789
+char* xdebug_get_zval_synopsis_ansi(zval *val, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
  790
+{
  791
+	xdebug_str str = {0, 0, NULL};
  792
+	int default_options = 0;
  793
+
  794
+	if (!options) {
  795
+		options = xdebug_var_export_options_from_ini(TSRMLS_C);
  796
+		default_options = 1;
  797
+	}
  798
+
  799
+	xdebug_var_synopsis_ansi(&val, (xdebug_str*) &str, 1, debug_zval, options TSRMLS_CC);
  800
+
  801
+	if (default_options) {
  802
+		xdfree(options->runtime);
  803
+		xdfree(options);
  804
+	}
  805
+
  806
+	return str.d;
  807
+}
  808
+#endif
  809
+
  810
+
506 811
 /*****************************************************************************
507 812
 ** XML node printing routines
508 813
 */
@@ -1175,3 +1480,4 @@ char* xdebug_show_fname(xdebug_func f, int html, int flags TSRMLS_DC)
1175 1480
 			return xdstrdup("{unknown}");
1176 1481
 	}
1177 1482
 }
  1483
+
9  xdebug_var.h
@@ -48,6 +48,9 @@ xdebug_var_export_options* xdebug_var_export_options_from_ini(TSRMLS_D);
48 48
 xdebug_var_export_options* xdebug_var_get_nolimit_options(TSRMLS_D);
49 49
 
50 50
 void xdebug_var_export(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC);
  51
+#ifndef PHP_WIN32
  52
+void xdebug_var_export_ansi(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC);
  53
+#endif
51 54
 void xdebug_var_export_xml(zval **struc, xdebug_str *str, int level TSRMLS_DC);
52 55
 void xdebug_var_export_fancy(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC);
53 56
 void xdebug_var_export_xml_node(zval **struc, char *name, xdebug_xml_node *node, xdebug_var_export_options *options, int level TSRMLS_DC);
@@ -56,11 +59,17 @@ char* xdebug_xmlize(char *string, int len, int *newlen);
56 59
 char* xdebug_error_type(int type);
57 60
 zval *xdebug_get_zval(zend_execute_data *zdata, znode *node, temp_variable *Ts, int *is_var);
58 61
 char* xdebug_get_zval_value(zval *val, int debug_zval, xdebug_var_export_options *options);
  62
+#ifndef PHP_WIN32
  63
+char* xdebug_get_zval_value_ansi(zval *val, int debug_zval, xdebug_var_export_options *options TSRMLS_DC);
  64
+#endif
59 65
 char* xdebug_get_zval_value_xml(char *name, zval *val);
60 66
 char* xdebug_get_zval_value_fancy(char *name, zval *val, int *len, int debug_zval, xdebug_var_export_options *options TSRMLS_DC);
61 67
 xdebug_xml_node* xdebug_get_zval_value_xml_node(char *name, zval *val, xdebug_var_export_options *options);
62 68
 
63 69
 char* xdebug_get_zval_synopsis(zval *val, int debug_zval, xdebug_var_export_options *options);
  70
+#ifndef PHP_WIN32
  71
+char* xdebug_get_zval_synopsis_ansi(zval *val, int debug_zval, xdebug_var_export_options *options TSRMLS_DC);
  72
+#endif
64 73
 char* xdebug_get_zval_synopsis_fancy(char *name, zval *val, int *len, int debug_zval, xdebug_var_export_options *options TSRMLS_DC);
65 74
 
66 75
 char* xdebug_show_fname(xdebug_func t, int html, int flags TSRMLS_DC);

0 notes on commit 23c5739

Please sign in to comment.
Something went wrong with that request. Please try again.