[xdebug-dev] xdebug xdebug/php_xdebug.h xdebug/xdebug.c xdebug/xdebug_code_coverage.c xdebug/xdebug_code_coverage.h xdebug/xdebug_private.h xdebug/tests/coverage.inc xdebug/tests/coverage.phpt xdebug/tests/coverage2.phpt - Fixed the exit handler hook to use the new "5.1" way of handling it; which

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Sun, 3 Oct 2004 15:10:56 +0200

Date: Sun Oct 3 15:10:56 CEST 2004
User: Derick Rethans
Directory: xdebug

Log Message:
[4.00]
- Fixed the exit handler hook to use the new "5.1" way of handling it; which
  fortunately also works with PHP 5.0.
- Extended the code-coverage functionality by returning lines with executable
  code on them, but where not executed with a count value of -1.
- Added test-cases for the code-coverage functionality.

Modified files:
           xdebug/php_xdebug.h (version: 1.81)
           xdebug/xdebug.c (version: 1.239)
           xdebug/xdebug_code_coverage.c (version: 1.9)
           xdebug/xdebug_code_coverage.h (version: 1.6)
           xdebug/xdebug_private.h (version: 1.14)
Added files:
           xdebug/tests/coverage.inc (new version: 1.1)
           xdebug/tests/coverage.phpt (new version: 1.1)
           xdebug/tests/coverage2.phpt (new version: 1.1)

[FILE: /xdebug/php_xdebug.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- xdebug/php_xdebug.h:1.80 Mon Sep 27 06:33:42 2004 GMT
+++ xdebug/php_xdebug.h Sun Oct 03 11:10:56 2004 GMT
@@ -119,6 +119,7 @@
         /* used for code coverage */
         zend_bool do_code_coverage;
         xdebug_hash *code_coverage;
+ zend_bool code_coverage_unused;
         unsigned int function_count;
 
         /* superglobals */

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.238
retrieving revision 1.239
diff -u -r1.238 -r1.239
--- xdebug/xdebug.c:1.238 Mon Sep 27 06:33:42 2004 GMT
+++ xdebug/xdebug.c Sun Oct 03 11:10:56 2004 GMT
@@ -85,6 +85,7 @@
 #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);
 #endif
 
 static zval *get_zval(znode *node, temp_variable *Ts, int *is_var);
@@ -405,6 +406,12 @@
         ZEND_INIT_MODULE_GLOBALS(xdebug, php_xdebug_init_globals, php_xdebug_shutdown_globals);
         REGISTER_INI_ENTRIES();
 
+#ifdef ZEND_ENGINE_2
+# if PHP_MINOR_VERSION >= 1
+ zend_vm_use_old_executor();
+# endif
+#endif
+
         /* get xdebug ini entries from the environment also */
         xdebug_env_config();
 
@@ -424,6 +431,7 @@
 
         /* Overload the "exit" opcode */
 #ifdef ZEND_ENGINE_2
+ old_exit_handler = zend_opcode_handlers[ZEND_EXIT];
         zend_opcode_handlers[ZEND_EXIT] = xdebug_exit_handler;
 #endif
 
@@ -434,6 +442,8 @@
         REGISTER_LONG_CONSTANT("XDEBUG_TRACE_APPEND", XDEBUG_TRACE_OPTION_APPEND, CONST_CS | CONST_PERSISTENT);
         REGISTER_LONG_CONSTANT("XDEBUG_TRACE_COMPUTERIZED", XDEBUG_TRACE_OPTION_COMPUTERIZED, CONST_CS | CONST_PERSISTENT);
 
+ REGISTER_LONG_CONSTANT("XDEBUG_CC_UNUSED", XDEBUG_CC_OPTION_UNUSED, CONST_CS | CONST_PERSISTENT);
+
         XG(breakpoint_count) = 0;
         return SUCCESS;
 }
@@ -823,7 +833,7 @@
         }
 
         if (XG(do_code_coverage)) {
- xdebug_count_line(tmp->filename, tmp->lineno TSRMLS_CC);
+ xdebug_count_line(tmp->filename, tmp->lineno, 0 TSRMLS_CC);
         }
 
         if (XDEBUG_LLIST_TAIL(XG(stack))) {
@@ -1040,6 +1050,10 @@
                 }
         }
 
+ if (XG(do_code_coverage) && XG(code_coverage_unused)) {
+ xdebug_prefil_code_coverage(fse, op_array);
+ }
+
         /* Check for entry breakpoints */
         if (XG(remote_enabled) && XG(breakpoints_allowed)) {
                 if (!handle_breakpoints(fse, XDEBUG_BRK_FUNC_CALL)) {
@@ -1499,7 +1513,7 @@
         if (XG(profiler_enabled)) {
                 xdebug_profiler_deinit(TSRMLS_C);
         }
- zend_exit_handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
+ old_exit_handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
 }
 #endif
 
@@ -1775,11 +1789,17 @@
 PHP_FUNCTION(xdebug_enable)
 {
         zend_error_cb = new_error_cb;
+#ifdef ZEND_ENGINE_2
+ zend_opcode_handlers[ZEND_EXIT] = xdebug_exit_handler;
+#endif
 }
 
 PHP_FUNCTION(xdebug_disable)
 {
         zend_error_cb = old_error_cb;
+#ifdef ZEND_ENGINE_2
+ zend_opcode_handlers[ZEND_EXIT] = old_exit_handler;
+#endif
 }
 
 PHP_FUNCTION(xdebug_is_enabled)
@@ -2013,7 +2033,7 @@
         file_len = strlen(file);
 
         if (XG(do_code_coverage)) {
- xdebug_count_line(file, lineno TSRMLS_CC);
+ xdebug_count_line(file, lineno, 0 TSRMLS_CC);
         }
 
         if (XG(remote_enabled)) {

[FILE: /xdebug/xdebug_code_coverage.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- xdebug/xdebug_code_coverage.c:1.8 Wed Feb 18 18:34:07 2004 GMT
+++ xdebug/xdebug_code_coverage.c Sun Oct 03 11:10:56 2004 GMT
@@ -39,7 +39,7 @@
         xdfree(file);
 }
 
-void xdebug_count_line(char *filename, int lineno TSRMLS_DC)
+void xdebug_count_line(char *filename, int lineno, int executable TSRMLS_DC)
 {
         xdebug_coverage_file *file;
         xdebug_coverage_line *line;
@@ -62,18 +62,44 @@
         if (!xdebug_hash_find(file->lines, sline, strlen(sline), (void *) &line)) {
                 line = xdmalloc(sizeof(xdebug_coverage_line));
                 line->lineno = lineno;
- line->count = 0;
+ line->count = 0;
+ line->executable = 0;
 
                 xdebug_hash_add(file->lines, sline, strlen(sline), line);
         }
 
- line->count++;
+ if (executable) {
+ line->executable = 1;
+ } else {
+ line->count++;
+ }
 
         xdfree(sline);
 }
 
+static void prefil_from_opcode(function_stack_entry *fse, char *fn, zend_op opcode)
+{
+ xdebug_count_line(fn, opcode.lineno, 1);
+}
+
+void xdebug_prefil_code_coverage(function_stack_entry *fse, zend_op_array *op_array)
+{
+ unsigned int i;
+
+ for (i = 0; i < op_array->size; i++) {
+ prefil_from_opcode(fse, op_array->filename, op_array->opcodes[i]);
+ }
+}
+
 PHP_FUNCTION(xdebug_start_code_coverage)
 {
+ long options = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &options) == FAILURE) {
+ return;
+ }
+ XG(code_coverage_unused) = (options == XDEBUG_CC_OPTION_UNUSED);
+
         if (XG(extended_info)) {
                 XG(do_code_coverage) = 1;
         } else {
@@ -107,7 +133,11 @@
         xdebug_coverage_line *line = (xdebug_coverage_line*) e->ptr;
         zval *retval = (zval*) ret;
 
- add_index_long(retval, line->lineno, line->count);
+ if (line->executable && (line->count == 0)) {
+ add_index_long(retval, line->lineno, -1);
+ } else {
+ add_index_long(retval, line->lineno, line->count);
+ }
 }
 
 static void add_file(void *ret, xdebug_hash_element *e)

[FILE: /xdebug/xdebug_code_coverage.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- xdebug/xdebug_code_coverage.h:1.5 Wed Feb 18 18:34:07 2004 GMT
+++ xdebug/xdebug_code_coverage.h Sun Oct 03 11:10:56 2004 GMT
@@ -26,6 +26,7 @@
 typedef struct xdebug_coverage_line {
         int lineno;
         int count;
+ int executable;
 } xdebug_coverage_line;
 
 typedef struct xdebug_coverage_file {
@@ -36,7 +37,7 @@
 void xdebug_coverage_line_dtor(void *data);
 void xdebug_coverage_file_dtor(void *data);
 
-void xdebug_count_line(char *file, int lineno TSRMLS_DC);
+void xdebug_count_line(char *file, int lineno, int executable TSRMLS_DC);
 
 PHP_FUNCTION(xdebug_start_code_coverage);
 PHP_FUNCTION(xdebug_stop_code_coverage);

[FILE: /xdebug/xdebug_private.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- xdebug/xdebug_private.h:1.13 Mon Sep 20 21:39:52 2004 GMT
+++ xdebug/xdebug_private.h Sun Oct 03 11:10:56 2004 GMT
@@ -69,6 +69,8 @@
 #define XDEBUG_TRACE_OPTION_APPEND 1
 #define XDEBUG_TRACE_OPTION_COMPUTERIZED 2
 
+#define XDEBUG_CC_OPTION_UNUSED 1
+
 #define STATUS_STARTING 0
 #define STATUS_STOPPING 1
 #define STATUS_STOPPED 2

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

<?php
        function test_parse_time($f)
        {
                if (preg_match("/[0-9]{12}/", $f)) {
                        $type = "YYYYMMDDHHii";
                }
                else if (preg_match("/[0-9]{8}\ [0-9]{4}/", $f)) {
                        $type = "YYYYMMDD HHii";
                }
                else if (preg_match("/[0-9]{4}-[0-9]{2}-[0-9]{2}/", $f)) {
                        $type = "YYYY-MM-DD";
                }
                else {
                        $type = "*unknown*";
                }

                echo "This is a $type format.\n";
        }

        $formats = array('2004-08-17 21:20', '20040817 2120');
        foreach ($formats as $format) {
                test_parse_time($format);
        }
?>

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

--TEST--
Test with Code Coverage
--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
--FILE--
<?php
        xdebug_start_code_coverage();
        $file = realpath('./tests/coverage.inc');
        include $file;
        $cc = xdebug_get_code_coverage();
        xdebug_stop_code_coverage();
        var_dump($cc[$file]);
?>
--EXPECTF--
This is a YYYY-MM-DD format.
This is a YYYYMMDD HHii format.
array(12) {
  [2]=>
  int(1)
  [4]=>
  int(4)
  [7]=>
  int(2)
  [8]=>
  int(1)
  [10]=>
  int(1)
  [11]=>
  int(1)
  [17]=>
  int(2)
  [18]=>
  int(2)
  [20]=>
  int(1)
  [21]=>
  int(1)
  [22]=>
  int(4)
  [25]=>
  int(1)
}

[FILE: /xdebug/tests/coverage2.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
--FILE--
<?php
        xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
        $file = realpath('./tests/coverage.inc');
        include $file;
        $cc = xdebug_get_code_coverage();
        xdebug_stop_code_coverage();
        var_dump($cc[$file]);
?>
--EXPECTF--
This is a YYYY-MM-DD format.
This is a YYYYMMDD HHii format.
array(%d) {
  [2]=>
  int(1)
  [4]=>
  int(4)
  [5]=>
  int(-1)
  [6]=>
  int(-1)
  [7]=>
  int(2)
  [8]=>
  int(1)
  [9]=>
  int(-1)
  [10]=>
  int(1)
  [11]=>
  int(1)
  [12]=>
  int(-1)
  [14]=>
  int(-1)
  [17]=>
  int(2)
  [18]=>
  int(2)
  [20]=>
  int(1)
  [21]=>
  int(1)
  [22]=>
  int(4)
  [23]=>
  int(-1)
  [25]=>
  int(1)
}
Received on Sun Oct 03 2004 - 15:11:08 BST

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