diff --git a/src/debug/debug-coverage.cc b/src/debug/debug-coverage.cc index 15aad1fcc2..e9a1a986df 100644 --- a/src/debug/debug-coverage.cc +++ b/src/debug/debug-coverage.cc @@ -476,6 +476,25 @@ void CollectBlockCoverage(CoverageFunction* function, SharedFunctionInfo info, ResetAllBlockCounts(info); } +void PrintBlockCoverage(const CoverageFunction* function, + SharedFunctionInfo info, bool has_nonempty_source_range, + bool function_is_relevant) { + DCHECK(FLAG_trace_block_coverage); + std::unique_ptr function_name = + function->name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); + i::PrintF( + "Coverage for function='%s', SFI=%p, has_nonempty_source_range=%d, " + "function_is_relevant=%d\n", + function_name.get(), reinterpret_cast(info.ptr()), + has_nonempty_source_range, function_is_relevant); + i::PrintF("{start: %d, end: %d, count: %d}\n", function->start, function->end, + function->count); + for (const auto& block : function->blocks) { + i::PrintF("{start: %d, end: %d, count: %d}\n", block.start, block.end, + block.count); + } +} + void CollectAndMaybeResetCounts(Isolate* isolate, SharedToCounterMap* counter_map, v8::debug::CoverageMode coverage_mode) { @@ -668,9 +687,7 @@ std::unique_ptr Coverage::Collect( } // Only include a function range if itself or its parent function is - // covered, or if it contains non-trivial block coverage. It must also - // have a non-empty source range (otherwise it is not interesting to - // report). + // covered, or if it contains non-trivial block coverage. bool is_covered = (count != 0); bool parent_is_covered = (!nesting.empty() && functions->at(nesting.back()).count != 0); @@ -678,10 +695,19 @@ std::unique_ptr Coverage::Collect( bool function_is_relevant = (is_covered || parent_is_covered || has_block_coverage); - if (function.HasNonEmptySourceRange() && function_is_relevant) { + // It must also have a non-empty source range (otherwise it is not + // interesting to report). + bool has_nonempty_source_range = function.HasNonEmptySourceRange(); + + if (has_nonempty_source_range && function_is_relevant) { nesting.push_back(functions->size()); functions->emplace_back(function); } + + if (FLAG_trace_block_coverage) { + PrintBlockCoverage(&function, info, has_nonempty_source_range, + function_is_relevant); + } } // Remove entries for scripts that have no coverage.