View Issue Details

IDProjectCategoryView StatusLast Update
0001559XdebugCode Coveragepublic2019-02-01 17:03
ReporterdtowellAssigned Toderick 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
PlatformOSCentOSOS Version7
Product Version2.6.0 
Target VersionFixed in Version 
Summary0001559: Missing lines from "top level" code
DescriptionUnexecuted "top level" code lines are not included in coverage report, yet similar unexecuted code lines inside a function is reported are.
Steps To Reproduce<?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.
TagsNo tags attached.
Operating SystemCentOS 7
PHP Version7.1.15-7.1.19

Activities

dtowell

2018-06-18 19:28

reporter   ~0004674

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.

dtowell

2018-07-11 21:06

reporter   ~0004681

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.

dtowell

2018-10-27 21:53

reporter   ~0004714

appears to be fixed in 2.6.1 (php 7.1.23)

derick

2019-02-01 17:03

administrator   ~0004866

I don't think there were any changes related to this between Xdebug 2.6.0 and 2.6.1, but I'll take the "it works" now.

thanks for reporting!

Issue History

Date Modified Username Field Change
2018-06-13 15:52 dtowell New Issue
2018-06-18 19:28 dtowell Note Added: 0004674
2018-07-11 21:06 dtowell Note Added: 0004681
2018-10-27 21:53 dtowell Note Added: 0004714
2019-02-01 17:03 derick Note Added: 0004866
2019-02-01 17:03 derick Status new => resolved
2019-02-01 17:03 derick Resolution open => no change required
2019-02-01 17:03 derick Assigned To => derick