diff --git a/hphp/runtime/base/code-coverage.h b/hphp/runtime/base/code-coverage.h index 1775ef6e0f3e7..5da9e55f8628c 100644 --- a/hphp/runtime/base/code-coverage.h +++ b/hphp/runtime/base/code-coverage.h @@ -28,6 +28,8 @@ namespace HPHP { struct Array; struct CodeCoverage { + static constexpr int kLineExecuted = 1; + void Record(const char* filename, int line0, int line1); /* diff --git a/hphp/runtime/ext/xdebug/ext_xdebug.cpp b/hphp/runtime/ext/xdebug/ext_xdebug.cpp index 8fbe6a2bbe0a8..61f24409f81f8 100644 --- a/hphp/runtime/ext/xdebug/ext_xdebug.cpp +++ b/hphp/runtime/ext/xdebug/ext_xdebug.cpp @@ -467,10 +467,24 @@ static void HHVM_FUNCTION(xdebug_enable) { static Array HHVM_FUNCTION(xdebug_get_code_coverage) { auto ti = ThreadInfo::s_threadInfo.getNoCheck(); - if (ti->m_reqInjectionData.getCoverage()) { - return ti->m_coverage->Report(false); + if (!ti->m_reqInjectionData.getCoverage()) { + return Array::Create(); + } + + auto ret = Array::Create(); + auto const reports = ti->m_coverage->Report(false); + for (ArrayIter report(reports); report; ++report) { + auto tmp = Array::Create(); + auto const lines = report.second().toArray(); + for (ArrayIter line(lines); line; ++line) { + auto const count = line.second().toInt64(); + if (count > 0) { + tmp.set(line.first(), Variant(CodeCoverage::kLineExecuted)); + } + } + ret.set(report.first(), tmp); } - return Array::Create(); + return ret; } // TODO(#3704) see xdebug_start_error_collection() diff --git a/hphp/test/slow/ext_xdebug/code_coverage_started.php.expectf b/hphp/test/slow/ext_xdebug/code_coverage_started.php.expectf index a8b28b17e6511..7a09b0bd9a06c 100644 --- a/hphp/test/slow/ext_xdebug/code_coverage_started.php.expectf +++ b/hphp/test/slow/ext_xdebug/code_coverage_started.php.expectf @@ -6,7 +6,7 @@ array(1) { [5]=> int(1) [6]=> - int(3) + int(1) [8]=> int(1) } @@ -19,9 +19,9 @@ array(1) { [11]=> int(1) [12]=> - int(3) + int(1) [14]=> - int(2) + int(1) [15]=> int(1) } @@ -32,15 +32,15 @@ array(1) { [11]=> int(1) [12]=> - int(3) + int(1) [14]=> - int(2) + int(1) [15]=> - int(3) + int(1) [16]=> - int(2) + int(1) [17]=> - int(2) + int(1) [18]=> int(1) } diff --git a/hphp/test/slow/ext_xdebug/get_code_coverage.php.expectf b/hphp/test/slow/ext_xdebug/get_code_coverage.php.expectf index afe40ced85046..95bec1ab33391 100644 --- a/hphp/test/slow/ext_xdebug/get_code_coverage.php.expectf +++ b/hphp/test/slow/ext_xdebug/get_code_coverage.php.expectf @@ -20,21 +20,21 @@ array(1) { [2]=> int(1) [5]=> - int(32) + int(1) [6]=> - int(16) + int(1) [9]=> - int(36) + int(1) [10]=> - int(32) + int(1) [11]=> - int(18) + int(1) [12]=> - int(2) + int(1) [14]=> - int(2) + int(1) [15]=> - int(2) + int(1) [17]=> int(1) } diff --git a/hphp/test/slow/ext_xdebug/xdebug/coverage.php.expectf b/hphp/test/slow/ext_xdebug/xdebug/coverage.php.expectf index 3ccdf7cb77bde..1c86fcdf236e8 100644 --- a/hphp/test/slow/ext_xdebug/xdebug/coverage.php.expectf +++ b/hphp/test/slow/ext_xdebug/xdebug/coverage.php.expectf @@ -4,34 +4,34 @@ array(2) { ["%s/test/slow/ext_xdebug/xdebug/coverage.inc"]=> array(11) { [4]=> - int(%d) + int(1) [7]=> - int(%d) + int(1) [8]=> int(1) [10]=> - int(%d) + int(1) [11]=> int(1) [15]=> - int(2) + int(1) [17]=> - int(2) + int(1) [18]=> - int(2) + int(1) [20]=> int(1) [22]=> - int(4) + int(1) [23]=> - int(3) + int(1) } ["%s/test/slow/ext_xdebug/xdebug/coverage.php"]=> array(3) { [2]=> int(1) [3]=> - int(2) + int(1) [4]=> int(1) }