[xdebug-dev] xdebug xdebug/test.sh xdebug/xdebug.c xdebug/xdebug_code_coverage.c xdebug/tests/coverage3.phpt xdebug/tests/coverage.phpt xdebug/tests/coverage2.phpt - Override some more opcodes as there is not always EXT_STMT when you expect

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Fri, 29 Oct 2004 12:01:18 +0200

Date: Fri Oct 29 12:01:18 CEST 2004
User: Derick Rethans
Directory: xdebug

Log Message:
[2.50]
- Override some more opcodes as there is not always EXT_STMT when you expect
  it. This should give better results for code coverage.

Modified files:
           xdebug/test.sh (version: 1.15)
           xdebug/xdebug.c (version: 1.247)
           xdebug/xdebug_code_coverage.c (version: 1.12)
           xdebug/tests/coverage.phpt (version: 1.2)
           xdebug/tests/coverage2.phpt (version: 1.2)
Added files:
           xdebug/tests/coverage3.phpt (new version: 1.1)

[FILE: /xdebug/test.sh]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- xdebug/test.sh:1.14 Mon Sep 27 06:32:29 2004 GMT
+++ xdebug/test.sh Fri Oct 29 08:01:17 2004 GMT
@@ -1 +1 @@
-TEST_PHP_EXECUTABLE=`which php-5.1dev` php-5.1dev -dxdebug.auto_trace=0 /dat/dev/php/php-5.1dev/run-tests.php tests/*.phpt
+TEST_PHP_EXECUTABLE=`which php-5.0dev` php-5.0dev -dxdebug.auto_trace=0 /dat/dev/php/php-5.0dev/run-tests.php tests/*.phpt

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.246
retrieving revision 1.247
diff -u -r1.246 -r1.247
--- xdebug/xdebug.c:1.246 Tue Oct 26 07:15:54 2004 GMT
+++ xdebug/xdebug.c Fri Oct 29 08:01:17 2004 GMT
@@ -87,8 +87,27 @@
 
 #ifdef ZEND_ENGINE_2
 void xdebug_throw_exception_hook(zval *exception TSRMLS_DC);
+
 int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS);
 int (*old_exit_handler)(ZEND_OPCODE_HANDLER_ARGS);
+
+static int xdebug_jmp_handler(ZEND_OPCODE_HANDLER_ARGS);
+static int (*old_jmp_handler)(ZEND_OPCODE_HANDLER_ARGS);
+static int xdebug_jmpz_handler(ZEND_OPCODE_HANDLER_ARGS);
+static int (*old_jmpz_handler)(ZEND_OPCODE_HANDLER_ARGS);
+
+static int xdebug_is_identical_handler(ZEND_OPCODE_HANDLER_ARGS);
+static int (*old_is_identical_handler)(ZEND_OPCODE_HANDLER_ARGS);
+static int xdebug_is_not_identical_handler(ZEND_OPCODE_HANDLER_ARGS);
+static int (*old_is_not_identical_handler)(ZEND_OPCODE_HANDLER_ARGS);
+static int xdebug_is_equal_handler(ZEND_OPCODE_HANDLER_ARGS);
+static int (*old_is_equal_handler)(ZEND_OPCODE_HANDLER_ARGS);
+static int xdebug_is_not_equal_handler(ZEND_OPCODE_HANDLER_ARGS);
+static int (*old_is_not_equal_handler)(ZEND_OPCODE_HANDLER_ARGS);
+static int xdebug_is_smaller_handler(ZEND_OPCODE_HANDLER_ARGS);
+static int (*old_is_smaller_handler)(ZEND_OPCODE_HANDLER_ARGS);
+static int xdebug_is_smaller_or_equal_handler(ZEND_OPCODE_HANDLER_ARGS);
+static int (*old_is_smaller_or_equal_handler)(ZEND_OPCODE_HANDLER_ARGS);
 #endif
 
 static zval *get_zval(znode *node, temp_variable *Ts, int *is_var);
@@ -437,6 +456,24 @@
 #ifdef ZEND_ENGINE_2
         old_exit_handler = zend_opcode_handlers[ZEND_EXIT];
         zend_opcode_handlers[ZEND_EXIT] = xdebug_exit_handler;
+
+ old_jmp_handler = zend_opcode_handlers[ZEND_JMP];
+ old_jmpz_handler = zend_opcode_handlers[ZEND_JMPZ];
+ old_is_identical_handler = zend_opcode_handlers[ZEND_IS_IDENTICAL];
+ old_is_not_identical_handler = zend_opcode_handlers[ZEND_IS_NOT_IDENTICAL];
+ old_is_equal_handler = zend_opcode_handlers[ZEND_IS_EQUAL];
+ old_is_not_equal_handler = zend_opcode_handlers[ZEND_IS_NOT_EQUAL];
+ old_is_smaller_handler = zend_opcode_handlers[ZEND_IS_SMALLER];
+ old_is_smaller_or_equal_handler = zend_opcode_handlers[ZEND_IS_SMALLER_OR_EQUAL];
+
+ zend_opcode_handlers[ZEND_JMP] = xdebug_jmp_handler;
+ zend_opcode_handlers[ZEND_JMPZ] = xdebug_jmpz_handler;
+ zend_opcode_handlers[ZEND_IS_IDENTICAL] = xdebug_is_identical_handler;
+ zend_opcode_handlers[ZEND_IS_NOT_IDENTICAL] = xdebug_is_not_identical_handler;
+ zend_opcode_handlers[ZEND_IS_EQUAL] = xdebug_is_equal_handler;
+ zend_opcode_handlers[ZEND_IS_NOT_EQUAL] = xdebug_is_not_equal_handler;
+ zend_opcode_handlers[ZEND_IS_SMALLER] = xdebug_is_smaller_handler;
+ zend_opcode_handlers[ZEND_IS_SMALLER_OR_EQUAL] = xdebug_is_smaller_or_equal_handler;
 #endif
 
         if (zend_xdebug_initialised == 0) {
@@ -1506,6 +1543,35 @@
         }
 }
 
+/* Needed for code coverage as Zend doesn't always add EXT_STMT when expected */
+#define XDEBUG_OPCODE_OVERRIDE(f) static int xdebug_##f##_handler(ZEND_OPCODE_HANDLER_ARGS) \
+{ \
+ if (XG(do_code_coverage)) { \
+ zend_op *cur_opcode; \
+ int lineno; \
+ char *file; \
+ int file_len; \
+\
+ cur_opcode = *EG(opline_ptr); \
+ lineno = cur_opcode->lineno; \
+\
+ file = op_array->filename; \
+ file_len = strlen(file); \
+\
+ xdebug_count_line(file, lineno, 0 TSRMLS_CC); \
+ } \
+ return old_##f##_handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); \
+}
+XDEBUG_OPCODE_OVERRIDE(jmp)
+XDEBUG_OPCODE_OVERRIDE(jmpz)
+XDEBUG_OPCODE_OVERRIDE(is_identical)
+XDEBUG_OPCODE_OVERRIDE(is_not_identical)
+XDEBUG_OPCODE_OVERRIDE(is_equal)
+XDEBUG_OPCODE_OVERRIDE(is_not_equal)
+XDEBUG_OPCODE_OVERRIDE(is_smaller)
+XDEBUG_OPCODE_OVERRIDE(is_smaller_or_equal)
+
+/* Opcode handler for exit, to be able to clean up the profiler */
 int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS)
 {
         if (XG(profiler_enabled)) {

[FILE: /xdebug/xdebug_code_coverage.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- xdebug/xdebug_code_coverage.c:1.11 Sun Oct 24 13:53:31 2004 GMT
+++ xdebug/xdebug_code_coverage.c Fri Oct 29 08:01:17 2004 GMT
@@ -114,11 +114,13 @@
         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &cleanup) == FAILURE) {
                 return;
         }
- if (cleanup) {
- xdebug_hash_destroy(XG(code_coverage));
- XG(code_coverage) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor);
+ if (XG(do_code_coverage)) {
+ if (cleanup) {
+ xdebug_hash_destroy(XG(code_coverage));
+ XG(code_coverage) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor);
+ }
+ XG(do_code_coverage) = 0;
         }
- XG(do_code_coverage) = 0;
 }
 
 
@@ -145,7 +147,7 @@
         if (line->executable && (line->count == 0)) {
                 add_index_long(retval, line->lineno, -1);
         } else {
- add_index_long(retval, line->lineno, line->count);
+ add_index_long(retval, line->lineno, 1);
         }
 }
 

[FILE: /xdebug/tests/coverage3.phpt]

--TEST--
Test with Code Coverage with unused lines
--INI--
xdebug.default_enable=1
xdebug.auto_trace=0
xdebug.trace_options=0
xdebug.trace_output_dir=/tmp
xdebug.collect_params=1
xdebug.collect_return=0
xdebug.auto_profile=0
xdebug.profiler_enable=0
xdebug.dump_globals=0
xdebug.show_mem_delta=0
xdebug.trace_format=0
xdebug.extended_info=1
--FILE--
<?php
    function a($b)
    {
        if ($b == 0)
        {
            return true;
        }
        else
        if ($b == 1)
        {
            return false;
        }
    };

    xdebug_start_code_coverage(true);

    a(1);

    xdebug_stop_code_coverage(false);
    var_dump(xdebug_get_code_coverage());
?>
--EXPECTF--
array(1) {
  ["/dat/dev/php/xdebug/tests/coverage3.php"]=>
  array(12) {
    [2]=>
    int(-1)
    [4]=>
    int(1)
    [5]=>
    int(1)
    [6]=>
    int(-1)
    [7]=>
    int(-1)
    [9]=>
    int(1)
    [10]=>
    int(1)
    [11]=>
    int(1)
    [12]=>
    int(-1)
    [13]=>
    int(-1)
    [17]=>
    int(1)
    [19]=>
    int(1)
  }
}

[FILE: /xdebug/tests/coverage.phpt]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xdebug/tests/coverage.phpt:1.1 Sun Oct 03 11:10:56 2004 GMT
+++ xdebug/tests/coverage.phpt Fri Oct 29 08:01:18 2004 GMT
@@ -24,29 +24,35 @@
 --EXPECTF--
 This is a YYYY-MM-DD format.
 This is a YYYYMMDD HHii format.
-array(12) {
+array(15) {
   [2]=>
   int(1)
   [4]=>
- int(4)
+ int(1)
   [7]=>
- int(2)
+ int(1)
   [8]=>
   int(1)
+ [9]=>
+ int(1)
   [10]=>
   int(1)
   [11]=>
   int(1)
+ [12]=>
+ int(1)
   [17]=>
- int(2)
+ int(1)
   [18]=>
- int(2)
+ int(1)
   [20]=>
   int(1)
   [21]=>
   int(1)
   [22]=>
- int(4)
+ int(1)
+ [23]=>
+ int(1)
   [25]=>
   int(1)
 }

[FILE: /xdebug/tests/coverage2.phpt]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xdebug/tests/coverage2.phpt:1.1 Sun Oct 03 11:10:56 2004 GMT
+++ xdebug/tests/coverage2.phpt Fri Oct 29 08:01:18 2004 GMT
@@ -28,37 +28,37 @@
   [2]=>
   int(1)
   [4]=>
- int(4)
+ int(1)
   [5]=>
   int(-1)
   [6]=>
   int(-1)
   [7]=>
- int(2)
+ int(1)
   [8]=>
   int(1)
   [9]=>
- int(-1)
+ int(1)
   [10]=>
   int(1)
   [11]=>
   int(1)
   [12]=>
- int(-1)
+ int(1)
   [14]=>
   int(-1)
   [17]=>
- int(2)
+ int(1)
   [18]=>
- int(2)
+ int(1)
   [20]=>
   int(1)
   [21]=>
   int(1)
   [22]=>
- int(4)
+ int(1)
   [23]=>
- int(-1)
+ int(1)
   [25]=>
   int(1)
 }
Received on Fri Oct 29 2004 - 12:01:22 BST

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