MantisBT - Xdebug
View Issue Details
0001559XdebugCode Coveragepublic2018-06-13 16:522018-10-27 22:53
dtowell 
 
normalmajoralways
newopen 
CentOS7
2.6.0 
 
CentOS 7
7.1.15-7.1.19
0001559: Missing lines from "top level" code
Unexecuted "top level" code lines are not included in coverage report, yet similar unexecuted code lines inside a function is reported are.
<?php
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
$x = 5*5;
if ($x < 20) {
    echo "low\n";
    $x = 1000;
}
function f($y) {
    if ($y < 20) {
        echo "low 2\n";
        $y = 1000;
    }
}
f($x);
print_r(xdebug_get_code_coverage());

produces:

Array
(
    [/var/www/x.php] => Array
        (
            [3] => 1
            [4] => 1
            [8] => 1
            [9] => 1
            [10] => -1
            [11] => -1
            [13] => 1
            [14] => 1
            [15] => 1
        )

)

Observe 5 & 6 are missing.
No tags attached.
Issue History
2018-06-13 16:52dtowellNew Issue
2018-06-18 20:28dtowellNote Added: 0004674
2018-07-11 22:06dtowellNote Added: 0004681
2018-10-27 22:53dtowellNote Added: 0004714

Notes
(0004674)
dtowell   
2018-06-18 20:28   
After poking around xdebug source for a while. I have the following observations that may be helpful, but YMMV.

(1) Changes to xdebug_set_filter() do not effect the results.

(2) A hinting flag may conflict between xdebug and PHP/Zend
PHP/ZEND has:
#define ZEND_ACC_HAS_TYPE_HINTS 0x10000000
xdebug has:
#define ZEND_XDEBUG_VISITED 0x10000000
The PHP comments *imply* that this is for functions only, so it may be a false trail, but it still seems bad.

(3) I think the problem may be in "prefilling" -- prefill_from_oparray(), but cannot easily test without building.

(4) xdebug_func_format() has a default case that seem related (code not in a function or class method), but that might be a false trail too.
(0004681)
dtowell   
2018-07-11 22:06   
In xdebug_compile_file(), the following line prevents file-level processing for code coverage because the globals have not yet been set.

if (XG(do_code_coverage) && XG(code_coverage_unused) && (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO)) {

I worked around the problem using auto_prepend_file for now. I understand why you might not want to address this issue, but it still seems like a bug to me.
(0004714)
dtowell   
2018-10-27 22:53   
appears to be fixed in 2.6.1 (php 7.1.23)