[xdebug-dev] xdebug xdebug/php_xdebug.h xdebug/xdebug.c xdebug/xdebug_handler_gdb.c xdebug/xdebug_superglobals.c xdebug/xdebug_var.c xdebug/xdebug_var.h - Added a function "xdebug_debug_zval" to debug zvals by printing its refcounts

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Tue, 26 Oct 2004 10:41:20 +0200

Date: Tue Oct 26 10:41:19 CEST 2004
User: Derick Rethans
Directory: xdebug

Log Message:
[1.50]
- Added a function "xdebug_debug_zval" to debug zvals by printing its refcounts
  and is_ref values.

Modified files:
           xdebug/php_xdebug.h (version: 1.84)
           xdebug/xdebug.c (version: 1.245)
           xdebug/xdebug_handler_gdb.c (version: 1.77)
           xdebug/xdebug_superglobals.c (version: 1.16)
           xdebug/xdebug_var.c (version: 1.52)
           xdebug/xdebug_var.h (version: 1.19)

[FILE: /xdebug/php_xdebug.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- xdebug/php_xdebug.h:1.83 Tue Oct 12 12:56:09 2004 GMT
+++ xdebug/php_xdebug.h Tue Oct 26 06:41:19 2004 GMT
@@ -64,6 +64,7 @@
 PHP_FUNCTION(xdebug_call_line);
 
 PHP_FUNCTION(xdebug_var_dump);
+PHP_FUNCTION(xdebug_debug_zval);
 
 /* activation functions */
 PHP_FUNCTION(xdebug_enable);

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.244
retrieving revision 1.245
diff -u -r1.244 -r1.245
--- xdebug/xdebug.c:1.244 Thu Oct 21 05:10:09 2004 GMT
+++ xdebug/xdebug.c Tue Oct 26 06:41:19 2004 GMT
@@ -107,6 +107,7 @@
         PHP_FE(xdebug_call_line, NULL)
 
         PHP_FE(xdebug_var_dump, NULL)
+ PHP_FE(xdebug_debug_zval, NULL)
 
         PHP_FE(xdebug_enable, NULL)
         PHP_FE(xdebug_disable, NULL)
@@ -805,7 +806,7 @@
                 if (tmp->function.type == XFUNC_EVAL) {
                         int is_var;
 
- tmp->include_filename = get_zval_value(get_zval(&zdata->opline->op1, zdata->Ts, &is_var));
+ tmp->include_filename = get_zval_value(get_zval(&zdata->opline->op1, zdata->Ts, &is_var), 0);
                 } else if (XG(collect_includes)) {
                         tmp->include_filename = xdstrdup(zend_get_executed_filename(TSRMLS_C));
                 }
@@ -1176,7 +1177,7 @@
                 return;
         }
         if (html) {
- contents = get_zval_value_fancy(NULL, zvar, &len TSRMLS_CC);
+ contents = get_zval_value_fancy(NULL, zvar, &len, 0 TSRMLS_CC);
                 if (contents) {
                         php_printf("<tr><td colspan='2' align='right' bgcolor='#ccffcc'>$%s = </td><td bgcolor='#ccffcc'>", name);
                         PHPWRITE(contents, len);
@@ -1185,7 +1186,7 @@
                         php_printf("<tr><td bgcolor='#ccffcc'>$%s</td><td bgcolor='#ccffcc' colspan='2'><i>Undefined</i></td></tr>\n", name);
                 }
         } else {
- contents = get_zval_value(zvar);
+ contents = get_zval_value(zvar, 0);
                 if (contents) {
                         php_printf(" $%s = %s\n", name, contents);
                 } else {
@@ -1268,10 +1269,10 @@
                                         c = 1;
                                 }
                                 tmp_varname = i->var[j].name ? xdebug_sprintf("$%s = ", i->var[j].name) : xdstrdup("");
- tmp_value = get_zval_value(i->var[j].addr);
+ tmp_value = get_zval_value(i->var[j].addr, 0);
                                 if (!log_only) {
                                         if (html) {
- tmp_fancy_value = get_zval_value_fancy(tmp_varname, i->var[j].addr, &len TSRMLS_CC);
+ tmp_fancy_value = get_zval_value_fancy(tmp_varname, i->var[j].addr, &len, 0 TSRMLS_CC);
                                                 PHPWRITE(tmp_fancy_value, len);
                                                 xdfree(tmp_fancy_value);
                                         } else {
@@ -1357,7 +1358,7 @@
         }
         xdebug_str_addl(&str, " >=> ", 7, 0);
 
- tmp_value = get_zval_value(retval);
+ tmp_value = get_zval_value(retval, 0);
         xdebug_str_add(&str, tmp_value, 1);
         xdebug_str_addl(&str, "\n", 2, 0);
 
@@ -1399,7 +1400,7 @@
                 tmp_varname = i->var[j].name ? xdebug_sprintf("$%s = ", i->var[j].name) : xdstrdup("");
                 xdebug_str_add(&str, tmp_varname, 1);
 
- tmp_value = get_zval_value(i->var[j].addr);
+ tmp_value = get_zval_value(i->var[j].addr, 0);
                 xdebug_str_add(&str, tmp_value, 1);
         }
 
@@ -1643,7 +1644,7 @@
                 MAKE_STD_ZVAL(params);
                 array_init(params);
                 for (j = 0; j < i->varc; j++) {
- argument = get_zval_value(i->var[j].addr);
+ argument = get_zval_value(i->var[j].addr, 0);
                         if (i->var[j].name) {
                                 add_assoc_string_ex(params, i->var[j].name, strlen(i->var[j].name) + 1, argument, 1);
                         } else {
@@ -1771,7 +1772,7 @@
         
         for (i = 0; i < argc; i++) {
                 if (PG(html_errors)) {
- val = get_zval_value_fancy(NULL, (zval*) *args[i], &len TSRMLS_CC);
+ val = get_zval_value_fancy(NULL, (zval*) *args[i], &len, 0 TSRMLS_CC);
                         PHPWRITE(val, len);
                         xdfree(val);
                 } else {
@@ -1783,6 +1784,46 @@
 }
 /* }}} */
 
+/* {{{ proto void xdebug_debug_zval(mixed var [, ...] )
+ Outputs a fancy string representation of a variable */
+PHP_FUNCTION(xdebug_debug_zval)
+{
+ zval ***args;
+ int argc;
+ int i, len;
+ char *val;
+ zval *debugzval;
+
+ argc = ZEND_NUM_ARGS();
+
+ args = (zval ***)emalloc(argc * sizeof(zval **));
+ if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) {
+ efree(args);
+ WRONG_PARAM_COUNT;
+ }
+
+ for (i = 0; i < argc; i++) {
+ if (Z_TYPE_PP(args[i]) == IS_STRING) {
+ debugzval = xdebug_get_php_symbol(Z_STRVAL_PP(args[i]), Z_STRLEN_PP(args[i]) + 1);
+ if (debugzval) {
+ php_printf("%s: ", Z_STRVAL_PP(args[i]));
+ if (PG(html_errors)) {
+ val = get_zval_value_fancy(NULL, debugzval, &len, 1 TSRMLS_CC);
+ PHPWRITE(val, len);
+ } else {
+ val = get_zval_value(debugzval, 1);
+ PHPWRITE(val, strlen(val));
+ }
+ xdfree(val);
+ PHPWRITE("\n", 1);
+ }
+ }
+ }
+
+ efree(args);
+}
+/* }}} */
+
 PHP_FUNCTION(xdebug_enable)
 {
         zend_error_cb = new_error_cb;

[FILE: /xdebug/xdebug_handler_gdb.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- xdebug/xdebug_handler_gdb.c:1.76 Tue Aug 03 18:46:06 2004 GMT
+++ xdebug/xdebug_handler_gdb.c Tue Oct 26 06:41:19 2004 GMT
@@ -335,7 +335,7 @@
         switch (options->response_format) {
                    case XDEBUG_RESPONSE_NORMAL:
                         if (val) {
- str_rep = get_zval_value(val);
+ str_rep = get_zval_value(val, 0);
                         } else {
                                 str_rep = xdstrdup("*uninitialized*");
                         }
@@ -520,7 +520,7 @@
                 if (i->var[j].name) {
                    SENDMSG(h->socket, xdebug_sprintf("$%s = ", i->var[j].name));
                 }
- tmp_value = get_zval_value(i->var[j].addr);
+ tmp_value = get_zval_value(i->var[j].addr, 0);
                 /* we ignore binary safety here */
                 tmp = xmlize(tmp_value, strlen(tmp_value), &len);
                 SSENDL(h->socket, tmp, len);
@@ -577,7 +577,7 @@
                 if (i->var[j].name) {
                    SENDMSG(h->socket, xdebug_sprintf("$%s = ", i->var[j].name));
                 }
- tmp_value = get_zval_value(i->var[j].addr);
+ tmp_value = get_zval_value(i->var[j].addr, 0);
                 /* we ignore binary safety here */
                 tmp = xmlize(tmp_value, strlen(tmp_value), &len);
                 SSENDL(h->socket, tmp, len);
@@ -1334,7 +1334,7 @@
 
 char *xdebug_gdb_get_revision(void)
 {
- return "$Revision: 1.76 $";
+ return "$Revision: 1.77 $";
 }
 
 int xdebug_gdb_init(xdebug_con *context, int mode)

[FILE: /xdebug/xdebug_superglobals.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- xdebug/xdebug_superglobals.c:1.15 Mon Aug 30 04:52:13 2004 GMT
+++ xdebug/xdebug_superglobals.c Tue Oct 26 06:41:19 2004 GMT
@@ -46,12 +46,12 @@
                 char *val;
 
                 if (html) {
- val = get_zval_value_fancy(NULL, z, &len TSRMLS_CC);
+ val = get_zval_value_fancy(NULL, z, &len, 0 TSRMLS_CC);
                         php_printf("<td bgcolor='#ffffcc'>");
                         PHPWRITE(val, len);
                         php_printf("</td>");
                 } else {
- val = get_zval_value(z);
+ val = get_zval_value(z, 0);
                         printf("\n $%s['%s'] = %s", name, elem, val);
                 }
 

[FILE: /xdebug/xdebug_var.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- xdebug/xdebug_var.c:1.51 Tue Aug 17 04:54:02 2004 GMT
+++ xdebug/xdebug_var.c Tue Oct 26 06:41:19 2004 GMT
@@ -120,48 +120,53 @@
 
 static int xdebug_array_element_export(zval **zv, int num_args, va_list args, zend_hash_key *hash_key)
 {
- int level;
+ int level, debug_zval;
         xdebug_str *str;
         TSRMLS_FETCH();
 
- level = va_arg(args, int);
- str = va_arg(args, struct xdebug_str*);
+ level = va_arg(args, int);
+ str = va_arg(args, struct xdebug_str*);
+ debug_zval = va_arg(args, int);
 
         if (hash_key->nKeyLength==0) { /* numeric key */
                 xdebug_str_add(str, xdebug_sprintf("%ld => ", hash_key->h), 1);
         } else { /* string key */
                 xdebug_str_add(str, xdebug_sprintf("'%s' => ", hash_key->arKey), 1);
         }
- xdebug_var_export(zv, str, level + 2 TSRMLS_CC);
+ xdebug_var_export(zv, str, level + 2, debug_zval TSRMLS_CC);
         xdebug_str_addl(str, ", ", 2, 0);
         return 0;
 }
 
 static int xdebug_object_element_export(zval **zv, int num_args, va_list args, zend_hash_key *hash_key)
 {
- int level;
+ int level, debug_zval;
         xdebug_str *str;
         char *prop_name, *modifier;
         TSRMLS_FETCH();
 
- level = va_arg(args, int);
- str = va_arg(args, struct xdebug_str*);
+ level = va_arg(args, int);
+ str = va_arg(args, struct xdebug_str*);
+ debug_zval = va_arg(args, int);
 
         if (hash_key->nKeyLength != 0) {
                 modifier = xdebug_get_property_info(hash_key->arKey, &prop_name);
                 xdebug_str_add(str, xdebug_sprintf("%s $%s = ", modifier, prop_name), 1);
         }
- xdebug_var_export(zv, str, level + 2 TSRMLS_CC);
+ xdebug_var_export(zv, str, level + 2, debug_zval TSRMLS_CC);
         xdebug_str_addl(str, "; ", 2, 0);
         return 0;
 }
 
-void xdebug_var_export(zval **struc, xdebug_str *str, int level TSRMLS_DC)
+void xdebug_var_export(zval **struc, xdebug_str *str, int level, int debug_zval TSRMLS_DC)
 {
         HashTable *myht;
         char* tmp_str;
         int tmp_len;
 
+ if (debug_zval) {
+ xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d),", (*struc)->refcount, (*struc)->is_ref), 1);
+ }
         switch (Z_TYPE_PP(struc)) {
                 case IS_BOOL:
                         xdebug_str_add(str, xdebug_sprintf("%s", Z_LVAL_PP(struc) ? "TRUE" : "FALSE"), 1);
@@ -203,7 +208,7 @@
                         myht = Z_OBJPROP_PP(struc);
                         if (myht->nApplyCount < 1) {
                                 xdebug_str_add(str, xdebug_sprintf("class %s { ", Z_OBJCE_PP(struc)->name), 1);
- zend_hash_apply_with_arguments(myht, (apply_func_args_t) xdebug_object_element_export, 2, level, str);
+ zend_hash_apply_with_arguments(myht, (apply_func_args_t) xdebug_object_element_export, 3, level, str, debug_zval);
                                 if (myht->nNumOfElements > 0) {
                                         xdebug_str_chop(str, 2);
                                 }
@@ -227,12 +232,12 @@
         }
 }
 
-char* get_zval_value(zval *val)
+char* get_zval_value(zval *val, int debug_zval)
 {
         xdebug_str str = {0, 0, NULL};
         TSRMLS_FETCH();
 
- xdebug_var_export(&val, (xdebug_str*) &str, 1 TSRMLS_CC);
+ xdebug_var_export(&val, (xdebug_str*) &str, 1, debug_zval TSRMLS_CC);
 
         return str.d;
 }
@@ -557,12 +562,13 @@
 
 static int xdebug_array_element_export_fancy(zval **zv, int num_args, va_list args, zend_hash_key *hash_key)
 {
- int level;
+ int level, debug_zval;
         xdebug_str *str;
         TSRMLS_FETCH();
 
- level = va_arg(args, int);
- str = va_arg(args, struct xdebug_str*);
+ level = va_arg(args, int);
+ str = va_arg(args, struct xdebug_str*);
+ debug_zval = va_arg(args, int);
 
         xdebug_str_add(str, xdebug_sprintf("%*s", level * 2, ""), 1);
 
@@ -571,21 +577,22 @@
         } else { /* string key */
                 xdebug_str_add(str, xdebug_sprintf("'%s' <font color='%s'>=&gt;</font> ", hash_key->arKey, DGREY), 1);
         }
- xdebug_var_export_fancy(zv, str, level + 2 TSRMLS_CC);
+ xdebug_var_export_fancy(zv, str, level + 2, debug_zval TSRMLS_CC);
 
         return 0;
 }
 
 static int xdebug_object_element_export_fancy(zval **zv, int num_args, va_list args, zend_hash_key *hash_key)
 {
- int level;
+ int level, debug_zval;
         xdebug_str *str;
         char *key;
         char *prop_name, *modifier;
         TSRMLS_FETCH();
 
- level = va_arg(args, int);
- str = va_arg(args, struct xdebug_str*);
+ level = va_arg(args, int);
+ str = va_arg(args, struct xdebug_str*);
+ debug_zval = va_arg(args, int);
 
         xdebug_str_add(str, xdebug_sprintf("%*s", level * 2, ""), 1);
 
@@ -594,16 +601,19 @@
                 modifier = xdebug_get_property_info(hash_key->arKey, &prop_name);
                 xdebug_str_add(str, xdebug_sprintf("<i>%s</i> '%s' <font color='%s'>=&gt;</font> ", modifier, prop_name, DGREY), 1);
         }
- xdebug_var_export_fancy(zv, str, level + 2 TSRMLS_CC);
+ xdebug_var_export_fancy(zv, str, level + 2, debug_zval TSRMLS_CC);
         return 0;
 }
 
-void xdebug_var_export_fancy(zval **struc, xdebug_str *str, int level TSRMLS_DC)
+void xdebug_var_export_fancy(zval **struc, xdebug_str *str, int level, int debug_zval TSRMLS_DC)
 {
         HashTable *myht;
         char* tmp_str;
         int newlen;
 
+ if (debug_zval) {
+ xdebug_str_add(str, xdebug_sprintf("<i>(refcount=%d, is_ref=%d)</i>,", (*struc)->refcount, (*struc)->is_ref), 1);
+ }
         switch (Z_TYPE_PP(struc)) {
                 case IS_BOOL:
                         xdebug_str_add(str, xdebug_sprintf("<font color='%s'>%s</font>", BLUE, Z_LVAL_PP(struc) ? "true" : "false"), 1);
@@ -635,7 +645,7 @@
                         if (myht->nApplyCount < 1) {
                                 xdebug_str_addl(str, "<b>array</b>\n", 13, 0);
                                 if (myht->nNumOfElements) {
- zend_hash_apply_with_arguments(myht, (apply_func_args_t) xdebug_array_element_export_fancy, 2, level, str);
+ zend_hash_apply_with_arguments(myht, (apply_func_args_t) xdebug_array_element_export_fancy, 3, level, str, debug_zval);
                                 } else {
                                         xdebug_str_add(str, xdebug_sprintf("%*s", level * 2, ""), 1);
                                         xdebug_str_add(str, xdebug_sprintf("<i><font color='%s'>empty</font></i>\n", LGREY), 1);
@@ -655,7 +665,7 @@
 #else
                                 xdebug_str_addl(str, "\n", 1, 0);
 #endif
- zend_hash_apply_with_arguments(myht, (apply_func_args_t) xdebug_object_element_export_fancy, 2, level, str);
+ zend_hash_apply_with_arguments(myht, (apply_func_args_t) xdebug_object_element_export_fancy, 3, level, str, debug_zval);
                         } else {
                                 xdebug_str_add(str, xdebug_sprintf("<i>&</i><b>object</b>(<i>%s</i>)", Z_OBJCE_PP(struc)->name), 1);
 #ifdef ZEND_ENGINE_2
@@ -683,12 +693,12 @@
         }
 }
 
-char* get_zval_value_fancy(char *name, zval *val, int *len TSRMLS_DC)
+char* get_zval_value_fancy(char *name, zval *val, int *len, int debug_zval TSRMLS_DC)
 {
         xdebug_str str = {0, 0, NULL};
 
         xdebug_str_addl(&str, "<pre>", 5, 0);
- xdebug_var_export_fancy(&val, (xdebug_str*) &str, 1 TSRMLS_CC);
+ xdebug_var_export_fancy(&val, (xdebug_str*) &str, 1, debug_zval TSRMLS_CC);
         xdebug_str_addl(&str, "</pre>", 6, 0);
 
         *len = str.l;

[FILE: /xdebug/xdebug_var.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- xdebug/xdebug_var.h:1.18 Tue Aug 03 18:46:06 2004 GMT
+++ xdebug/xdebug_var.h Tue Oct 26 06:41:19 2004 GMT
@@ -26,16 +26,16 @@
 
 zval* xdebug_get_php_symbol(char* name, int name_length);
 
-void xdebug_var_export(zval **struc, xdebug_str *str, int level TSRMLS_DC);
+void xdebug_var_export(zval **struc, xdebug_str *str, int level, int debug_zval TSRMLS_DC);
 void xdebug_var_export_xml(zval **struc, xdebug_str *str, int level TSRMLS_DC);
-void xdebug_var_export_fancy(zval **struc, xdebug_str *str, int level TSRMLS_DC);
+void xdebug_var_export_fancy(zval **struc, xdebug_str *str, int level, int debug_zval TSRMLS_DC);
 void xdebug_var_export_xml_node(zval **struc, char *name, xdebug_xml_node *node, int level TSRMLS_DC);
 
 char* xmlize(char *string, int len, int *newlen);
 char* error_type (int type);
-char* get_zval_value (zval *val);
+char* get_zval_value (zval *val, int debug_zval);
 char* get_zval_value_xml (char *name, zval *val);
-char* get_zval_value_fancy(char *name, zval *val, int *len TSRMLS_DC);
+char* get_zval_value_fancy(char *name, zval *val, int *len, int debug_zval TSRMLS_DC);
 xdebug_xml_node* get_zval_value_xml_node (char *name, zval *val);
 char* show_fname (xdebug_func t, int html, int flags TSRMLS_DC);
 
Received on Tue Oct 26 2004 - 10:41:37 BST

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST