Permalink
Browse files

Fixed issue #756: Added support for ZEND_*_*_OBJ and self::*.

  • Loading branch information...
derickr committed Feb 28, 2012
1 parent a251fd5 commit 8a54fca2be916675262f0aa951b3c05e9080a4f7
Showing with 94 additions and 4 deletions.
  1. +59 −0 tests/bug00756.phpt
  2. +4 −0 xdebug.c
  3. +27 −2 xdebug_code_coverage.c
  4. +4 −0 xdebug_code_coverage.h
  5. +0 −2 xdebug_var.c
View
@@ -0,0 +1,59 @@
+--TEST--
+Test for bug #756: Tracing doesn't always understand the variables and shows IS_VAR
+--INI--
+xdebug.auto_trace=0
+xdebug.trace_options=0
+xdebug.trace_output_dir=/tmp
+xdebug.trace_output_name=trace.%c
+xdebug.collect_return=1
+xdebug.collect_params=3
+xdebug.collect_assignments=1
+xdebug.auto_profile=0
+xdebug.profiler_enable=0
+xdebug.dump_globals=0
+xdebug.show_mem_delta=0
+xdebug.trace_format=0
+--FILE--
+<?php
+class foo
+{
+ static $bar;
+ public $foo;
+
+ static function bar()
+ {
+ self::$bar++;
+ }
+
+ function foo()
+ {
+ $this->foo++;
+ }
+}
+
+$tf = xdebug_start_trace('/tmp/'. uniqid('xdt', TRUE));
+$trace_file = xdebug_get_tracefile_name();
+
+foo::bar();
+$f = new foo;
+$f->foo();
+
+echo file_get_contents($trace_file);
+unlink($trace_file);
+echo "DONE\n";
+?>
+--EXPECTF--
+TRACE START [%d-%d-%d %d:%d:%d]
+ => $tf = '/tmp/xdt%s.%s.xt' %sbug00756.php:18
+%w%f %w%d -> xdebug_get_tracefile_name() %sbug00756.php:19
+ >=> '/tmp/xdt%s.%s.xt'
+ => $trace_file = '/tmp/xdt%s.%s.xt' %sbug00756.php:19
+%w%f %w%d -> foo::bar() %sbug00756.php:21
+ => self::bar++ %sbug00756.php:9
+%w%f %w%d -> foo->foo() %sbug00756.php:22
+ => $this->foo++ %sbug00756.php:14
+ => $f = class foo { public $foo = 1 } %sbug00756.php:22
+%w%f %w%d -> foo->foo() %sbug00756.php:23
+ => $this->foo++ %sbug00756.php:14
+%w%f %w%d -> file_get_contents('/tmp/xdt%s.%s.xt') %sbug00756.php:25
+DONE
View
@@ -577,6 +577,10 @@ PHP_MINIT_FUNCTION(xdebug)
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(post_inc, ZEND_POST_INC);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(pre_dec, ZEND_PRE_DEC);
XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(post_dec, ZEND_POST_DEC);
+ XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(pre_inc_obj, ZEND_PRE_INC_OBJ);
+ XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(post_inc_obj, ZEND_POST_INC_OBJ);
+ XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(pre_dec_obj, ZEND_PRE_DEC_OBJ);
+ XDEBUG_SET_OPCODE_OVERRIDE_ASSIGN(post_dec_obj, ZEND_POST_DEC_OBJ);
zend_set_user_opcode_handler(ZEND_BEGIN_SILENCE, xdebug_silence_handler);
zend_set_user_opcode_handler(ZEND_END_SILENCE, xdebug_silence_handler);
View
@@ -121,6 +121,10 @@ static char *xdebug_find_var_name(zend_execute_data *execute_data TSRMLS_DC)
xdebug_str_add(&name,xdebug_sprintf("[%s]", zval_value), 1);
}
}
+ if (cur_opcode->opcode >= ZEND_PRE_INC_OBJ && cur_opcode->opcode <= ZEND_POST_DEC_OBJ) {
+ zval_value = xdebug_get_zval_value(xdebug_get_zval(execute_data, &cur_opcode->op2, execute_data->Ts, &is_var), 0, options);
+ xdebug_str_add(&name, xdebug_sprintf("$this->%s", zval_value), 1);
+ }
if (zval_value) {
xdfree(zval_value);
zval_value = NULL;
@@ -129,7 +133,7 @@ static char *xdebug_find_var_name(zend_execute_data *execute_data TSRMLS_DC)
/* Scroll back to start of FETCHES */
gohungfound = 0;
opcode_ptr = prev_opcode;
- while (opcode_ptr->opcode == ZEND_FETCH_DIM_W || opcode_ptr->opcode == ZEND_FETCH_OBJ_W || opcode_ptr->opcode == ZEND_FETCH_W) {
+ while (opcode_ptr->opcode == ZEND_FETCH_DIM_W || opcode_ptr->opcode == ZEND_FETCH_OBJ_W || opcode_ptr->opcode == ZEND_FETCH_W || opcode_ptr->opcode == ZEND_FETCH_RW) {
opcode_ptr = opcode_ptr - 1;
gohungfound = 1;
}
@@ -148,6 +152,10 @@ static char *xdebug_find_var_name(zend_execute_data *execute_data TSRMLS_DC)
zval_value = xdebug_get_zval_value(xdebug_get_zval(execute_data, &opcode_ptr->op1, execute_data->Ts, &is_var), 0, options);
xdebug_str_add(&name, xdebug_sprintf("%s", zval_value), 1);
}
+ if (is_static && opcode_ptr->opcode == ZEND_FETCH_RW) {
+ zval_value = xdebug_get_zval_value(xdebug_get_zval(execute_data, &opcode_ptr->op1, execute_data->Ts, &is_var), 0, options);
+ xdebug_str_add(&name, xdebug_sprintf("%s", zval_value), 1);
+ }
if (opcode_ptr->opcode == ZEND_FETCH_DIM_W) {
zval_value = xdebug_get_zval_value(xdebug_get_zval(execute_data, &opcode_ptr->op2, execute_data->Ts, &is_var), 0, NULL);
xdebug_str_add(&name, xdebug_sprintf("[%s]", zval_value), 1);
@@ -160,7 +168,7 @@ static char *xdebug_find_var_name(zend_execute_data *execute_data TSRMLS_DC)
xdfree(zval_value);
zval_value = NULL;
}
- } while (opcode_ptr->opcode == ZEND_FETCH_DIM_W || opcode_ptr->opcode == ZEND_FETCH_OBJ_W || opcode_ptr->opcode == ZEND_FETCH_W);
+ } while (opcode_ptr->opcode == ZEND_FETCH_DIM_W || opcode_ptr->opcode == ZEND_FETCH_OBJ_W || opcode_ptr->opcode == ZEND_FETCH_W || opcode_ptr->opcode == ZEND_FETCH_RW);
}
if (cur_opcode->opcode == ZEND_ASSIGN_OBJ) {
@@ -223,6 +231,19 @@ static int xdebug_common_assign_dim_handler(char *op, int do_cc, ZEND_OPCODE_HAN
full_varname = tmp_varname;
val = xdebug_get_zval(execute_data, &cur_opcode->op1, execute_data->Ts, &is_var);
+ } else if (cur_opcode->opcode >= ZEND_PRE_INC_OBJ && cur_opcode->opcode <= ZEND_POST_DEC_OBJ) {
+ char *tmp_varname;
+
+ switch (cur_opcode->opcode) {
+ case ZEND_PRE_INC_OBJ: tmp_varname = xdebug_sprintf("++%s", full_varname); break;
+ case ZEND_POST_INC_OBJ: tmp_varname = xdebug_sprintf("%s++", full_varname); break;
+ case ZEND_PRE_DEC_OBJ: tmp_varname = xdebug_sprintf("--%s", full_varname); break;
+ case ZEND_POST_DEC_OBJ: tmp_varname = xdebug_sprintf("%s--", full_varname); break;
+ }
+ xdfree(full_varname);
+ full_varname = tmp_varname;
+
+ val = xdebug_get_zval(execute_data, &cur_opcode->op2, execute_data->Ts, &is_var);
} else if (next_opcode->opcode == ZEND_OP_DATA) {
val = xdebug_get_zval(execute_data, &next_opcode->op1, execute_data->Ts, &is_var);
} else {
@@ -257,6 +278,10 @@ 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(pre_inc_obj,"",0)
+XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_inc_obj,"",0)
+XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_dec_obj,"",0)
+XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_dec_obj,"",0)
XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_concat,".=",1)
XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_bw_or,"|=",0)
XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_bw_and,"&=",0)
View
@@ -61,6 +61,10 @@ XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(pre_inc);
XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(post_inc);
XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(pre_dec);
XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(post_dec);
+XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(pre_inc_obj);
+XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(post_inc_obj);
+XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(pre_dec_obj);
+XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(post_dec_obj);
XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(assign_concat);
XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(assign_bw_or);
XDEBUG_OPCODE_OVERRIDE_ASSIGN_DECL(assign_bw_and);
View
@@ -92,8 +92,6 @@ zval *xdebug_get_zval(zend_execute_data *zdata, znode *node, temp_variable *Ts,
*is_var = 1;
if (T(node->u.var).var.ptr) {
return T(node->u.var).var.ptr;
- } else {
- fprintf(stderr, "\nIS_VAR\n");
}
break;

0 comments on commit 8a54fca

Please sign in to comment.