derick                                   Wed, 06 Jan 2010 18:02:33 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=3206
Log:
- Fixed bug #501: Xdebug's variable tracing misses POST_INC and variants .
Changed paths:
    A   xdebug/trunk/tests/bug00501.phpt
    U   xdebug/trunk/xdebug.c
Added: xdebug/trunk/tests/bug00501.phpt
===================================================================
--- xdebug/trunk/tests/bug00501.phpt	                        (rev 0)
+++ xdebug/trunk/tests/bug00501.phpt	2010-01-06 18:02:33 UTC (rev 3206)
@@ -0,0 +1,36 @@
+--TEST--
+Test for bug #501: Xdebug's variable tracing misses POST_INC and variants.
+--INI--
+xdebug.default_enable=1
+xdebug.profiler_enable=0
+xdebug.auto_trace=0
+xdebug.trace_format=0
+xdebug.collect_vars=1
+xdebug.collect_params=3
+xdebug.collect_returns=0
+xdebug.collect_assignments=1
+--FILE--
+<?php
+$tf = xdebug_start_trace('/tmp/'. uniqid('xdt', TRUE));
+
+$i = 10;
+$i +=
+    ++$i
+    + $i
+    + $i++;
+
+xdebug_stop_trace();
+echo file_get_contents($tf);
+unlink($tf);
+?>
+--EXPECTF--
+TRACE START [%d-%d-%d %d:%d:%d]
+                         => $tf = '%s' %sbug00501.php:2
+                         => $i = 10 %sbug00501.php:4
+                         => ++$i %sbug00501.php:7
+                         => $i++ %sbug00501.php:8
+                         => $i += 33 %sbug00501.php:8
+%w%f %w%d     -> xdebug_stop_trace() %sbug00501.php:10
+%w%f %w%d
+TRACE END   [%d-%d-%d %d:%d:%d]
+
Modified: xdebug/trunk/xdebug.c
===================================================================
--- xdebug/trunk/xdebug.c	2010-01-05 17:37:21 UTC (rev 3205)
+++ xdebug/trunk/xdebug.c	2010-01-06 18:02:33 UTC (rev 3206)
@@ -637,7 +637,20 @@
         if (XG(do_trace) && XG(trace_file) && XG(collect_assignments)) {
                 full_varname = xdebug_find_var_name(execute_data TSRMLS_CC);
-		if (next_opcode->opcode == ZEND_OP_DATA) {
+		if (cur_opcode->opcode >= ZEND_PRE_INC && cur_opcode->opcode <= ZEND_POST_DEC) {
+			char *tmp_varname;
+
+			switch (cur_opcode->opcode) {
+				case ZEND_PRE_INC:  tmp_varname = xdebug_sprintf("++%s", full_varname); break;
+				case ZEND_POST_INC: tmp_varname = xdebug_sprintf("%s++", full_varname); break;
+				case ZEND_PRE_DEC:  tmp_varname = xdebug_sprintf("--%s", full_varname); break;
+				case ZEND_POST_DEC: tmp_varname = xdebug_sprintf("%s--", full_varname); break;
+			}
+			xdfree(full_varname);
+			full_varname = tmp_varname;
+
+			val = get_zval(execute_data, &cur_opcode->op1, execute_data->Ts, &is_var);
+		} else if (next_opcode->opcode == ZEND_OP_DATA) {
                         val = get_zval(execute_data, &next_opcode->op1, execute_data->Ts, &is_var);
                 } else {
                         val = get_zval(execute_data, &cur_opcode->op2, execute_data->Ts, &is_var);
@@ -677,6 +690,10 @@
 XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_mod,"%=",0)
 XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_sl,"<<=",0)
 XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_sr,">>=",0)
+XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_inc,"",0)
+XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_inc,"",0)
+XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_dec,"",0)
+XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_dec,"",0)
 XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_concat,".=",1)
 XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_bw_or,"|=",0)
 XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_bw_and,"&=",0)
@@ -766,6 +783,11 @@
         XDEBUG_SET_OPCODE_OVERRIDE(assign_dim, ZEND_ASSIGN_DIM);
         XDEBUG_SET_OPCODE_OVERRIDE(assign_obj, ZEND_ASSIGN_OBJ);
+	XDEBUG_SET_OPCODE_OVERRIDE(pre_inc, ZEND_PRE_INC);
+	XDEBUG_SET_OPCODE_OVERRIDE(post_inc, ZEND_POST_INC);
+	XDEBUG_SET_OPCODE_OVERRIDE(pre_dec, ZEND_PRE_DEC);
+	XDEBUG_SET_OPCODE_OVERRIDE(post_dec, ZEND_POST_DEC);
+
         XDEBUG_SET_OPCODE_OVERRIDE(add_array_element, ZEND_ADD_ARRAY_ELEMENT);
         XDEBUG_SET_OPCODE_OVERRIDE(return, ZEND_RETURN);
         XDEBUG_SET_OPCODE_OVERRIDE(ext_stmt, ZEND_EXT_STMT);
@@ -2245,14 +2267,17 @@
         xdebug_str_addl(&str, "   => ", 6, 0);
         xdebug_str_add(&str, varname, 0);
-	xdebug_str_add(&str, xdebug_sprintf(" %s ", op), 1);
-	tmp_value = xdebug_get_zval_value(retval, 0, NULL);
+	if (op[0] != '\0' ) { // pre/post inc/dec ops are special
+		xdebug_str_add(&str, xdebug_sprintf(" %s ", op), 1);
-	if (tmp_value) {
-		xdebug_str_add(&str, tmp_value, 1);
-	} else {
-		xdebug_str_addl(&str, "NULL", 4, 0);
+		tmp_value = xdebug_get_zval_value(retval, 0, NULL);
+
+		if (tmp_value) {
+			xdebug_str_add(&str, tmp_value, 1);
+		} else {
+			xdebug_str_addl(&str, "NULL", 4, 0);
+		}
         }
         xdebug_str_add(&str, xdebug_sprintf(" %s:%d\n", filename, lineno), 1);
Received on Wed Jan 06 2010 - 18:02:34 GMT
This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST