Index: test/tools/llvm-cov/native_separators.c =================================================================== --- test/tools/llvm-cov/native_separators.c +++ test/tools/llvm-cov/native_separators.c @@ -19,3 +19,13 @@ // HTML: tools\llvm-cov\Inputs\native_separators.covmapping int main() {} + +// Re-purpose this file to test that "Go to first zero" feature: + +// RUN: llvm-cov show %S/Inputs/native_separators.covmapping -instr-profile %t.profdata -filename-equivalence -format html -o %t.dir %s +// RUN: FileCheck -input-file %t.dir/coverage/tmp/native_separators.c.html %s +// CHECK: Goto first zero count +// CHECK-NOT: +// CHECK: "; + +const char *JSDisableLink = R"( +function disableLink(link) { + link.disabled = true; + link.removeAttribute('href'); +} +)"; + +const char *JSRemoveZeroLink = R"( +var zeroLink = document.getElementById("zeroline"); +disableLink(zeroLink); +)"; + std::string getPathToStyle(StringRef ViewPath) { std::string PathToStyle = ""; std::string PathSep = sys::path::get_separator(); @@ -334,8 +350,11 @@ OS << LineBreak << BeginCenteredDiv << BeginTable; } -void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) { +void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS, + bool RenderJavaScript) { OS << EndTable << EndCenteredDiv; + if (RenderJavaScript) + OS << BeginJavaScript << JSDisableLink << JSRemoveZeroLink << EndJavaScript; } void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile) { @@ -347,15 +366,20 @@ sys::path::remove_dots(SourceText, /*remove_dot_dots=*/true); sys::path::native(SourceText); OS << tag("pre", escape(SourceText, getOptions())); - // Render the object file name for the view. - if (WholeFile) + if (WholeFile) { + // Render the object file name for the view. OS << tag("pre", escape("Binary: " + getOptions().ObjectFilename, getOptions())); + // Render the "Goto First Zero Count" link for the view + OS << tag("pre", + "Goto first zero count"); + } OS << EndSourceNameDiv; } -void SourceCoverageViewHTML::renderLinePrefix(raw_ostream &OS, unsigned) { - OS << ""; +void SourceCoverageViewHTML::renderLinePrefix(raw_ostream &OS, unsigned, + bool IsFirstZeroLine = false) { + OS << (IsFirstZeroLine ? "" : ""); } void SourceCoverageViewHTML::renderLineSuffix(raw_ostream &OS, unsigned) { Index: tools/llvm-cov/SourceCoverageViewText.h =================================================================== --- tools/llvm-cov/SourceCoverageViewText.h +++ tools/llvm-cov/SourceCoverageViewText.h @@ -36,11 +36,11 @@ class SourceCoverageViewText : public SourceCoverageView { void renderViewHeader(raw_ostream &OS) override; - void renderViewFooter(raw_ostream &OS) override; + void renderViewFooter(raw_ostream &OS, bool RenderJavaScript) override; void renderSourceName(raw_ostream &OS, bool WholeFile) override; - void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) override; + void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth, bool IsFirstZeroLine) override; void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) override; Index: tools/llvm-cov/SourceCoverageViewText.cpp =================================================================== --- tools/llvm-cov/SourceCoverageViewText.cpp +++ tools/llvm-cov/SourceCoverageViewText.cpp @@ -61,7 +61,7 @@ void SourceCoverageViewText::renderViewHeader(raw_ostream &) {} -void SourceCoverageViewText::renderViewFooter(raw_ostream &) {} +void SourceCoverageViewText::renderViewFooter(raw_ostream &, bool) {} void SourceCoverageViewText::renderSourceName(raw_ostream &OS, bool WholeFile) { getOptions().colored_ostream(OS, raw_ostream::CYAN) << getSourceName() @@ -73,7 +73,8 @@ } void SourceCoverageViewText::renderLinePrefix(raw_ostream &OS, - unsigned ViewDepth) { + unsigned ViewDepth, + bool IsFirstZeroLine = false) { for (unsigned I = 0; I < ViewDepth; ++I) OS << " |"; }