Yuchen Wu | c3e6424 | 2013-12-05 22:02:29 +0000 | [diff] [blame] | 1 | //===- GCOV.cpp - LLVM coverage tool --------------------------------------===// |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
NAKAMURA Takumi | 3b55196 | 2013-11-14 11:44:58 +0000 | [diff] [blame] | 10 | // GCOV implements the interface to read and write coverage files that use |
Devang Patel | 8dfb655 | 2011-10-04 17:24:48 +0000 | [diff] [blame] | 11 | // 'gcov' format. |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 12 | // |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Justin Bogner | df82c62 | 2014-02-04 21:03:17 +0000 | [diff] [blame] | 15 | #include "llvm/Support/GCOV.h" |
Devang Patel | a9e8a25 | 2011-09-29 16:46:47 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/STLExtras.h" |
Justin Bogner | df82c62 | 2014-02-04 21:03:17 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Debug.h" |
Justin Bogner | c6af350 | 2014-02-04 10:45:02 +0000 | [diff] [blame] | 18 | #include "llvm/Support/FileSystem.h" |
Justin Bogner | df82c62 | 2014-02-04 21:03:17 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Format.h" |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 20 | #include "llvm/Support/MemoryObject.h" |
Justin Bogner | c6af350 | 2014-02-04 10:45:02 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Path.h" |
Benjamin Kramer | 799003b | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 23 | #include <algorithm> |
Rafael Espindola | a6e9c3e | 2014-06-12 17:38:55 +0000 | [diff] [blame] | 24 | #include <system_error> |
Eugene Zelenko | ecefe5a | 2016-02-02 18:20:45 +0000 | [diff] [blame] | 25 | |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | // GCOVFile implementation. |
| 30 | |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 31 | /// readGCNO - Read GCNO buffer. |
| 32 | bool GCOVFile::readGCNO(GCOVBuffer &Buffer) { |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 33 | if (!Buffer.readGCNOFormat()) |
| 34 | return false; |
| 35 | if (!Buffer.readGCOVVersion(Version)) |
| 36 | return false; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 37 | |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 38 | if (!Buffer.readInt(Checksum)) |
| 39 | return false; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 40 | while (true) { |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 41 | if (!Buffer.readFunctionTag()) |
| 42 | break; |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 43 | auto GFun = make_unique<GCOVFunction>(*this); |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 44 | if (!GFun->readGCNO(Buffer, Version)) |
| 45 | return false; |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 46 | Functions.push_back(std::move(GFun)); |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Yuchen Wu | 21517e4 | 2013-12-04 05:07:36 +0000 | [diff] [blame] | 49 | GCNOInitialized = true; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 50 | return true; |
Devang Patel | e5a8f2f9 | 2011-09-29 17:06:40 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 53 | /// readGCDA - Read GCDA buffer. It is required that readGCDA() can only be |
| 54 | /// called after readGCNO(). |
| 55 | bool GCOVFile::readGCDA(GCOVBuffer &Buffer) { |
Yuchen Wu | 21517e4 | 2013-12-04 05:07:36 +0000 | [diff] [blame] | 56 | assert(GCNOInitialized && "readGCDA() can only be called after readGCNO()"); |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 57 | if (!Buffer.readGCDAFormat()) |
| 58 | return false; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 59 | GCOV::GCOVVersion GCDAVersion; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 60 | if (!Buffer.readGCOVVersion(GCDAVersion)) |
| 61 | return false; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 62 | if (Version != GCDAVersion) { |
| 63 | errs() << "GCOV versions do not match.\n"; |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 64 | return false; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 65 | } |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 66 | |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 67 | uint32_t GCDAChecksum; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 68 | if (!Buffer.readInt(GCDAChecksum)) |
| 69 | return false; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 70 | if (Checksum != GCDAChecksum) { |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 71 | errs() << "File checksums do not match: " << Checksum |
| 72 | << " != " << GCDAChecksum << ".\n"; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | for (size_t i = 0, e = Functions.size(); i < e; ++i) { |
| 76 | if (!Buffer.readFunctionTag()) { |
| 77 | errs() << "Unexpected number of functions.\n"; |
Yuchen Wu | babe749 | 2013-11-20 04:15:05 +0000 | [diff] [blame] | 78 | return false; |
| 79 | } |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 80 | if (!Functions[i]->readGCDA(Buffer, Version)) |
| 81 | return false; |
| 82 | } |
| 83 | if (Buffer.readObjectTag()) { |
| 84 | uint32_t Length; |
| 85 | uint32_t Dummy; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 86 | if (!Buffer.readInt(Length)) |
| 87 | return false; |
| 88 | if (!Buffer.readInt(Dummy)) |
| 89 | return false; // checksum |
| 90 | if (!Buffer.readInt(Dummy)) |
| 91 | return false; // num |
| 92 | if (!Buffer.readInt(RunCount)) |
| 93 | return false; |
| 94 | Buffer.advanceCursor(Length - 3); |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 95 | } |
| 96 | while (Buffer.readProgramTag()) { |
| 97 | uint32_t Length; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 98 | if (!Buffer.readInt(Length)) |
| 99 | return false; |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 100 | Buffer.advanceCursor(Length); |
| 101 | ++ProgramCount; |
Yuchen Wu | 14ae8e6 | 2013-10-25 02:22:21 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 104 | return true; |
| 105 | } |
| 106 | |
Yuchen Wu | 0367815 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 107 | /// dump - Dump GCOVFile content to dbgs() for debugging purposes. |
Yaron Keren | eb2a254 | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 108 | LLVM_DUMP_METHOD void GCOVFile::dump() const { |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 109 | for (const auto &FPtr : Functions) |
| 110 | FPtr->dump(); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /// collectLineCounts - Collect line counts. This must be used after |
| 114 | /// reading .gcno and .gcda files. |
| 115 | void GCOVFile::collectLineCounts(FileInfo &FI) { |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 116 | for (const auto &FPtr : Functions) |
| 117 | FPtr->collectLineCounts(FI); |
Yuchen Wu | 30672d9 | 2013-11-05 01:11:58 +0000 | [diff] [blame] | 118 | FI.setRunCount(RunCount); |
Yuchen Wu | 14ae8e6 | 2013-10-25 02:22:21 +0000 | [diff] [blame] | 119 | FI.setProgramCount(ProgramCount); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | //===----------------------------------------------------------------------===// |
| 123 | // GCOVFunction implementation. |
| 124 | |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 125 | /// readGCNO - Read a function from the GCNO buffer. Return false if an error |
| 126 | /// occurs. |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 127 | bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 128 | uint32_t Dummy; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 129 | if (!Buff.readInt(Dummy)) |
| 130 | return false; // Function header length |
| 131 | if (!Buff.readInt(Ident)) |
| 132 | return false; |
| 133 | if (!Buff.readInt(Checksum)) |
| 134 | return false; |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 135 | if (Version != GCOV::V402) { |
| 136 | uint32_t CfgChecksum; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 137 | if (!Buff.readInt(CfgChecksum)) |
| 138 | return false; |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 139 | if (Parent.getChecksum() != CfgChecksum) { |
| 140 | errs() << "File checksums do not match: " << Parent.getChecksum() |
| 141 | << " != " << CfgChecksum << " in (" << Name << ").\n"; |
| 142 | return false; |
| 143 | } |
| 144 | } |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 145 | if (!Buff.readString(Name)) |
| 146 | return false; |
| 147 | if (!Buff.readString(Filename)) |
| 148 | return false; |
| 149 | if (!Buff.readInt(LineNumber)) |
| 150 | return false; |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 151 | |
| 152 | // read blocks. |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 153 | if (!Buff.readBlockTag()) { |
| 154 | errs() << "Block tag not found.\n"; |
| 155 | return false; |
| 156 | } |
| 157 | uint32_t BlockCount; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 158 | if (!Buff.readInt(BlockCount)) |
| 159 | return false; |
Bob Wilson | 868e6e3 | 2013-10-22 20:02:36 +0000 | [diff] [blame] | 160 | for (uint32_t i = 0, e = BlockCount; i != e; ++i) { |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 161 | if (!Buff.readInt(Dummy)) |
| 162 | return false; // Block flags; |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 163 | Blocks.push_back(make_unique<GCOVBlock>(*this, i)); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | // read edges. |
| 167 | while (Buff.readEdgeTag()) { |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 168 | uint32_t EdgeCount; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 169 | if (!Buff.readInt(EdgeCount)) |
| 170 | return false; |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 171 | EdgeCount = (EdgeCount - 1) / 2; |
| 172 | uint32_t BlockNo; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 173 | if (!Buff.readInt(BlockNo)) |
| 174 | return false; |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 175 | if (BlockNo >= BlockCount) { |
Yuchen Wu | 4c9f19d | 2013-12-05 22:02:33 +0000 | [diff] [blame] | 176 | errs() << "Unexpected block number: " << BlockNo << " (in " << Name |
| 177 | << ").\n"; |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 178 | return false; |
| 179 | } |
Bob Wilson | 868e6e3 | 2013-10-22 20:02:36 +0000 | [diff] [blame] | 180 | for (uint32_t i = 0, e = EdgeCount; i != e; ++i) { |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 181 | uint32_t Dst; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 182 | if (!Buff.readInt(Dst)) |
| 183 | return false; |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 184 | Edges.push_back(make_unique<GCOVEdge>(*Blocks[BlockNo], *Blocks[Dst])); |
| 185 | GCOVEdge *Edge = Edges.back().get(); |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 186 | Blocks[BlockNo]->addDstEdge(Edge); |
| 187 | Blocks[Dst]->addSrcEdge(Edge); |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 188 | if (!Buff.readInt(Dummy)) |
| 189 | return false; // Edge flag |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
| 193 | // read line table. |
| 194 | while (Buff.readLineTag()) { |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 195 | uint32_t LineTableLength; |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 196 | // Read the length of this line table. |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 197 | if (!Buff.readInt(LineTableLength)) |
| 198 | return false; |
| 199 | uint32_t EndPos = Buff.getCursor() + LineTableLength * 4; |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 200 | uint32_t BlockNo; |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 201 | // Read the block number this table is associated with. |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 202 | if (!Buff.readInt(BlockNo)) |
| 203 | return false; |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 204 | if (BlockNo >= BlockCount) { |
Yuchen Wu | 4c9f19d | 2013-12-05 22:02:33 +0000 | [diff] [blame] | 205 | errs() << "Unexpected block number: " << BlockNo << " (in " << Name |
| 206 | << ").\n"; |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 207 | return false; |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 208 | } |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 209 | GCOVBlock &Block = *Blocks[BlockNo]; |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 210 | // Read the word that pads the beginning of the line table. This may be a |
| 211 | // flag of some sort, but seems to always be zero. |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 212 | if (!Buff.readInt(Dummy)) |
| 213 | return false; |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 214 | |
| 215 | // Line information starts here and continues up until the last word. |
| 216 | if (Buff.getCursor() != (EndPos - sizeof(uint32_t))) { |
Yuchen Wu | d738bee | 2013-11-14 00:32:00 +0000 | [diff] [blame] | 217 | StringRef F; |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 218 | // Read the source file name. |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 219 | if (!Buff.readString(F)) |
| 220 | return false; |
Yuchen Wu | 4c9f19d | 2013-12-05 22:02:33 +0000 | [diff] [blame] | 221 | if (Filename != F) { |
| 222 | errs() << "Multiple sources for a single basic block: " << Filename |
| 223 | << " != " << F << " (in " << Name << ").\n"; |
Yuchen Wu | d738bee | 2013-11-14 00:32:00 +0000 | [diff] [blame] | 224 | return false; |
| 225 | } |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 226 | // Read lines up to, but not including, the null terminator. |
| 227 | while (Buff.getCursor() < (EndPos - 2 * sizeof(uint32_t))) { |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 228 | uint32_t Line; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 229 | if (!Buff.readInt(Line)) |
| 230 | return false; |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 231 | // Line 0 means this instruction was injected by the compiler. Skip it. |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 232 | if (!Line) |
| 233 | continue; |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 234 | Block.addLine(Line); |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 235 | } |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 236 | // Read the null terminator. |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 237 | if (!Buff.readInt(Dummy)) |
| 238 | return false; |
Yuchen Wu | e28da84 | 2013-11-14 00:07:15 +0000 | [diff] [blame] | 239 | } |
Justin Bogner | c475e1b | 2014-05-02 20:01:24 +0000 | [diff] [blame] | 240 | // The last word is either a flag or padding, it isn't clear which. Skip |
| 241 | // over it. |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 242 | if (!Buff.readInt(Dummy)) |
| 243 | return false; |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 244 | } |
| 245 | return true; |
| 246 | } |
| 247 | |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 248 | /// readGCDA - Read a function from the GCDA buffer. Return false if an error |
| 249 | /// occurs. |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 250 | bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { |
Justin Bogner | 34a34aa | 2016-02-08 22:49:40 +0000 | [diff] [blame] | 251 | uint32_t HeaderLength; |
| 252 | if (!Buff.readInt(HeaderLength)) |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 253 | return false; // Function header length |
Daniel Jasper | 87a24d5 | 2013-12-04 08:57:17 +0000 | [diff] [blame] | 254 | |
Justin Bogner | 34a34aa | 2016-02-08 22:49:40 +0000 | [diff] [blame] | 255 | uint64_t EndPos = Buff.getCursor() + HeaderLength * sizeof(uint32_t); |
| 256 | |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 257 | uint32_t GCDAIdent; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 258 | if (!Buff.readInt(GCDAIdent)) |
| 259 | return false; |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 260 | if (Ident != GCDAIdent) { |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 261 | errs() << "Function identifiers do not match: " << Ident |
| 262 | << " != " << GCDAIdent << " (in " << Name << ").\n"; |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 263 | return false; |
| 264 | } |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 265 | |
Daniel Jasper | 87a24d5 | 2013-12-04 08:57:17 +0000 | [diff] [blame] | 266 | uint32_t GCDAChecksum; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 267 | if (!Buff.readInt(GCDAChecksum)) |
| 268 | return false; |
Daniel Jasper | 87a24d5 | 2013-12-04 08:57:17 +0000 | [diff] [blame] | 269 | if (Checksum != GCDAChecksum) { |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 270 | errs() << "Function checksums do not match: " << Checksum |
| 271 | << " != " << GCDAChecksum << " (in " << Name << ").\n"; |
Daniel Jasper | 87a24d5 | 2013-12-04 08:57:17 +0000 | [diff] [blame] | 272 | return false; |
| 273 | } |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 274 | |
| 275 | uint32_t CfgChecksum; |
| 276 | if (Version != GCOV::V402) { |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 277 | if (!Buff.readInt(CfgChecksum)) |
| 278 | return false; |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 279 | if (Parent.getChecksum() != CfgChecksum) { |
| 280 | errs() << "File checksums do not match: " << Parent.getChecksum() |
| 281 | << " != " << CfgChecksum << " (in " << Name << ").\n"; |
| 282 | return false; |
| 283 | } |
| 284 | } |
| 285 | |
Justin Bogner | 34a34aa | 2016-02-08 22:49:40 +0000 | [diff] [blame] | 286 | if (Buff.getCursor() < EndPos) { |
| 287 | StringRef GCDAName; |
| 288 | if (!Buff.readString(GCDAName)) |
| 289 | return false; |
| 290 | if (Name != GCDAName) { |
| 291 | errs() << "Function names do not match: " << Name << " != " << GCDAName |
| 292 | << ".\n"; |
| 293 | return false; |
| 294 | } |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 295 | } |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 296 | |
| 297 | if (!Buff.readArcTag()) { |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 298 | errs() << "Arc tag not found (in " << Name << ").\n"; |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 299 | return false; |
| 300 | } |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 301 | |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 302 | uint32_t Count; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 303 | if (!Buff.readInt(Count)) |
| 304 | return false; |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 305 | Count /= 2; |
| 306 | |
| 307 | // This for loop adds the counts for each block. A second nested loop is |
| 308 | // required to combine the edge counts that are contained in the GCDA file. |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 309 | for (uint32_t BlockNo = 0; Count > 0; ++BlockNo) { |
| 310 | // The last block is always reserved for exit block |
Justin Bogner | d0a6243 | 2015-03-17 00:18:51 +0000 | [diff] [blame] | 311 | if (BlockNo >= Blocks.size()) { |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 312 | errs() << "Unexpected number of edges (in " << Name << ").\n"; |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 313 | return false; |
| 314 | } |
Justin Bogner | d0a6243 | 2015-03-17 00:18:51 +0000 | [diff] [blame] | 315 | if (BlockNo == Blocks.size() - 1) |
| 316 | errs() << "(" << Name << ") has arcs from exit block.\n"; |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 317 | GCOVBlock &Block = *Blocks[BlockNo]; |
| 318 | for (size_t EdgeNo = 0, End = Block.getNumDstEdges(); EdgeNo < End; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 319 | ++EdgeNo) { |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 320 | if (Count == 0) { |
Yuchen Wu | 5752997 | 2013-12-04 05:42:28 +0000 | [diff] [blame] | 321 | errs() << "Unexpected number of edges (in " << Name << ").\n"; |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | uint64_t ArcCount; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 325 | if (!Buff.readInt64(ArcCount)) |
| 326 | return false; |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 327 | Block.addCount(EdgeNo, ArcCount); |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 328 | --Count; |
| 329 | } |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 330 | Block.sortDstEdges(); |
Yuchen Wu | ba71833 | 2013-12-03 00:15:49 +0000 | [diff] [blame] | 331 | } |
| 332 | return true; |
| 333 | } |
| 334 | |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 335 | /// getEntryCount - Get the number of times the function was called by |
| 336 | /// retrieving the entry block's count. |
| 337 | uint64_t GCOVFunction::getEntryCount() const { |
| 338 | return Blocks.front()->getCount(); |
| 339 | } |
| 340 | |
| 341 | /// getExitCount - Get the number of times the function returned by retrieving |
| 342 | /// the exit block's count. |
| 343 | uint64_t GCOVFunction::getExitCount() const { |
| 344 | return Blocks.back()->getCount(); |
| 345 | } |
| 346 | |
Yuchen Wu | 0367815 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 347 | /// dump - Dump GCOVFunction content to dbgs() for debugging purposes. |
Yaron Keren | eb2a254 | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 348 | LLVM_DUMP_METHOD void GCOVFunction::dump() const { |
Justin Bogner | 58e4134 | 2014-11-06 06:55:02 +0000 | [diff] [blame] | 349 | dbgs() << "===== " << Name << " (" << Ident << ") @ " << Filename << ":" |
| 350 | << LineNumber << "\n"; |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 351 | for (const auto &Block : Blocks) |
| 352 | Block->dump(); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /// collectLineCounts - Collect line counts. This must be used after |
| 356 | /// reading .gcno and .gcda files. |
| 357 | void GCOVFunction::collectLineCounts(FileInfo &FI) { |
Justin Bogner | 95e0a70 | 2014-03-26 22:03:06 +0000 | [diff] [blame] | 358 | // If the line number is zero, this is a function that doesn't actually appear |
| 359 | // in the source file, so there isn't anything we can do with it. |
| 360 | if (LineNumber == 0) |
| 361 | return; |
| 362 | |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 363 | for (const auto &Block : Blocks) |
| 364 | Block->collectLineCounts(FI); |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 365 | FI.addFunctionLine(Filename, LineNumber, this); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | //===----------------------------------------------------------------------===// |
| 369 | // GCOVBlock implementation. |
| 370 | |
| 371 | /// ~GCOVBlock - Delete GCOVBlock and its content. |
| 372 | GCOVBlock::~GCOVBlock() { |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 373 | SrcEdges.clear(); |
| 374 | DstEdges.clear(); |
Yuchen Wu | d738bee | 2013-11-14 00:32:00 +0000 | [diff] [blame] | 375 | Lines.clear(); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 378 | /// addCount - Add to block counter while storing the edge count. If the |
| 379 | /// destination has no outgoing edges, also update that block's count too. |
| 380 | void GCOVBlock::addCount(size_t DstEdgeNo, uint64_t N) { |
| 381 | assert(DstEdgeNo < DstEdges.size()); // up to caller to ensure EdgeNo is valid |
| 382 | DstEdges[DstEdgeNo]->Count = N; |
| 383 | Counter += N; |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 384 | if (!DstEdges[DstEdgeNo]->Dst.getNumDstEdges()) |
| 385 | DstEdges[DstEdgeNo]->Dst.Counter += N; |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 388 | /// sortDstEdges - Sort destination edges by block number, nop if already |
| 389 | /// sorted. This is required for printing branch info in the correct order. |
| 390 | void GCOVBlock::sortDstEdges() { |
| 391 | if (!DstEdgesAreSorted) { |
| 392 | SortDstEdgesFunctor SortEdges; |
| 393 | std::stable_sort(DstEdges.begin(), DstEdges.end(), SortEdges); |
| 394 | } |
| 395 | } |
| 396 | |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 397 | /// collectLineCounts - Collect line counts. This must be used after |
| 398 | /// reading .gcno and .gcda files. |
| 399 | void GCOVBlock::collectLineCounts(FileInfo &FI) { |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 400 | for (uint32_t N : Lines) |
| 401 | FI.addBlockLine(Parent.getFilename(), N, this); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Yuchen Wu | 0367815 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 404 | /// dump - Dump GCOVBlock content to dbgs() for debugging purposes. |
Yaron Keren | eb2a254 | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 405 | LLVM_DUMP_METHOD void GCOVBlock::dump() const { |
Yuchen Wu | 0367815 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 406 | dbgs() << "Block : " << Number << " Counter : " << Counter << "\n"; |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 407 | if (!SrcEdges.empty()) { |
| 408 | dbgs() << "\tSource Edges : "; |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 409 | for (const GCOVEdge *Edge : SrcEdges) |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 410 | dbgs() << Edge->Src.Number << " (" << Edge->Count << "), "; |
Yuchen Wu | 8ad9b04 | 2013-12-03 00:24:44 +0000 | [diff] [blame] | 411 | dbgs() << "\n"; |
| 412 | } |
| 413 | if (!DstEdges.empty()) { |
| 414 | dbgs() << "\tDestination Edges : "; |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 415 | for (const GCOVEdge *Edge : DstEdges) |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 416 | dbgs() << Edge->Dst.Number << " (" << Edge->Count << "), "; |
Yuchen Wu | 0367815 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 417 | dbgs() << "\n"; |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 418 | } |
| 419 | if (!Lines.empty()) { |
Yuchen Wu | 0367815 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 420 | dbgs() << "\tLines : "; |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 421 | for (uint32_t N : Lines) |
| 422 | dbgs() << (N) << ","; |
Yuchen Wu | d738bee | 2013-11-14 00:32:00 +0000 | [diff] [blame] | 423 | dbgs() << "\n"; |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
| 427 | //===----------------------------------------------------------------------===// |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 428 | // FileInfo implementation. |
| 429 | |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 430 | // Safe integer division, returns 0 if numerator is 0. |
| 431 | static uint32_t safeDiv(uint64_t Numerator, uint64_t Divisor) { |
| 432 | if (!Numerator) |
| 433 | return 0; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 434 | return Numerator / Divisor; |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | // This custom division function mimics gcov's branch ouputs: |
| 438 | // - Round to closest whole number |
| 439 | // - Only output 0% or 100% if it's exactly that value |
| 440 | static uint32_t branchDiv(uint64_t Numerator, uint64_t Divisor) { |
| 441 | if (!Numerator) |
| 442 | return 0; |
| 443 | if (Numerator == Divisor) |
| 444 | return 100; |
| 445 | |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 446 | uint8_t Res = (Numerator * 100 + Divisor / 2) / Divisor; |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 447 | if (Res == 0) |
| 448 | return 1; |
| 449 | if (Res == 100) |
| 450 | return 99; |
| 451 | return Res; |
| 452 | } |
| 453 | |
Benjamin Kramer | b1d8c46 | 2015-03-23 13:59:13 +0000 | [diff] [blame] | 454 | namespace { |
Yuchen Wu | 73dc381 | 2013-12-18 18:40:15 +0000 | [diff] [blame] | 455 | struct formatBranchInfo { |
Richard Smith | e7dc8bf | 2015-10-14 00:04:19 +0000 | [diff] [blame] | 456 | formatBranchInfo(const GCOV::Options &Options, uint64_t Count, uint64_t Total) |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 457 | : Options(Options), Count(Count), Total(Total) {} |
Yuchen Wu | 73dc381 | 2013-12-18 18:40:15 +0000 | [diff] [blame] | 458 | |
| 459 | void print(raw_ostream &OS) const { |
| 460 | if (!Total) |
| 461 | OS << "never executed"; |
| 462 | else if (Options.BranchCount) |
| 463 | OS << "taken " << Count; |
| 464 | else |
| 465 | OS << "taken " << branchDiv(Count, Total) << "%"; |
| 466 | } |
| 467 | |
Richard Smith | e7dc8bf | 2015-10-14 00:04:19 +0000 | [diff] [blame] | 468 | const GCOV::Options &Options; |
Yuchen Wu | 73dc381 | 2013-12-18 18:40:15 +0000 | [diff] [blame] | 469 | uint64_t Count; |
| 470 | uint64_t Total; |
| 471 | }; |
| 472 | |
| 473 | static raw_ostream &operator<<(raw_ostream &OS, const formatBranchInfo &FBI) { |
| 474 | FBI.print(OS); |
| 475 | return OS; |
| 476 | } |
| 477 | |
Justin Bogner | cf27e1b | 2014-05-07 02:11:23 +0000 | [diff] [blame] | 478 | class LineConsumer { |
| 479 | std::unique_ptr<MemoryBuffer> Buffer; |
| 480 | StringRef Remaining; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 481 | |
Justin Bogner | cf27e1b | 2014-05-07 02:11:23 +0000 | [diff] [blame] | 482 | public: |
| 483 | LineConsumer(StringRef Filename) { |
Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 484 | ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = |
| 485 | MemoryBuffer::getFileOrSTDIN(Filename); |
| 486 | if (std::error_code EC = BufferOrErr.getError()) { |
Justin Bogner | cf27e1b | 2014-05-07 02:11:23 +0000 | [diff] [blame] | 487 | errs() << Filename << ": " << EC.message() << "\n"; |
| 488 | Remaining = ""; |
Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 489 | } else { |
| 490 | Buffer = std::move(BufferOrErr.get()); |
Justin Bogner | cf27e1b | 2014-05-07 02:11:23 +0000 | [diff] [blame] | 491 | Remaining = Buffer->getBuffer(); |
Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 492 | } |
Justin Bogner | cf27e1b | 2014-05-07 02:11:23 +0000 | [diff] [blame] | 493 | } |
| 494 | bool empty() { return Remaining.empty(); } |
| 495 | void printNext(raw_ostream &OS, uint32_t LineNum) { |
| 496 | StringRef Line; |
| 497 | if (empty()) |
| 498 | Line = "/*EOF*/"; |
| 499 | else |
| 500 | std::tie(Line, Remaining) = Remaining.split("\n"); |
| 501 | OS << format("%5u:", LineNum) << Line << "\n"; |
| 502 | } |
| 503 | }; |
Eugene Zelenko | ecefe5a | 2016-02-02 18:20:45 +0000 | [diff] [blame] | 504 | } // end anonymous namespace |
Justin Bogner | cf27e1b | 2014-05-07 02:11:23 +0000 | [diff] [blame] | 505 | |
Justin Bogner | c6af350 | 2014-02-04 10:45:02 +0000 | [diff] [blame] | 506 | /// Convert a path to a gcov filename. If PreservePaths is true, this |
| 507 | /// translates "/" to "#", ".." to "^", and drops ".", to match gcov. |
| 508 | static std::string mangleCoveragePath(StringRef Filename, bool PreservePaths) { |
| 509 | if (!PreservePaths) |
Justin Bogner | c67f025 | 2014-04-23 21:44:55 +0000 | [diff] [blame] | 510 | return sys::path::filename(Filename).str(); |
Justin Bogner | c6af350 | 2014-02-04 10:45:02 +0000 | [diff] [blame] | 511 | |
| 512 | // This behaviour is defined by gcov in terms of text replacements, so it's |
| 513 | // not likely to do anything useful on filesystems with different textual |
| 514 | // conventions. |
| 515 | llvm::SmallString<256> Result(""); |
| 516 | StringRef::iterator I, S, E; |
| 517 | for (I = S = Filename.begin(), E = Filename.end(); I != E; ++I) { |
| 518 | if (*I != '/') |
| 519 | continue; |
| 520 | |
| 521 | if (I - S == 1 && *S == '.') { |
| 522 | // ".", the current directory, is skipped. |
| 523 | } else if (I - S == 2 && *S == '.' && *(S + 1) == '.') { |
| 524 | // "..", the parent directory, is replaced with "^". |
| 525 | Result.append("^#"); |
| 526 | } else { |
| 527 | if (S < I) |
| 528 | // Leave other components intact, |
| 529 | Result.append(S, I); |
| 530 | // And separate with "#". |
| 531 | Result.push_back('#'); |
| 532 | } |
| 533 | S = I + 1; |
| 534 | } |
| 535 | |
| 536 | if (S < I) |
| 537 | Result.append(S, I); |
Justin Bogner | c6af350 | 2014-02-04 10:45:02 +0000 | [diff] [blame] | 538 | return Result.str(); |
| 539 | } |
| 540 | |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 541 | std::string FileInfo::getCoveragePath(StringRef Filename, |
| 542 | StringRef MainFilename) { |
| 543 | if (Options.NoOutput) |
| 544 | // This is probably a bug in gcov, but when -n is specified, paths aren't |
| 545 | // mangled at all, and the -l and -p options are ignored. Here, we do the |
| 546 | // same. |
| 547 | return Filename; |
| 548 | |
| 549 | std::string CoveragePath; |
| 550 | if (Options.LongFileNames && !Filename.equals(MainFilename)) |
| 551 | CoveragePath = |
| 552 | mangleCoveragePath(MainFilename, Options.PreservePaths) + "##"; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 553 | CoveragePath += mangleCoveragePath(Filename, Options.PreservePaths) + ".gcov"; |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 554 | return CoveragePath; |
| 555 | } |
| 556 | |
| 557 | std::unique_ptr<raw_ostream> |
| 558 | FileInfo::openCoveragePath(StringRef CoveragePath) { |
| 559 | if (Options.NoOutput) |
Justin Bogner | 7c09373 | 2014-05-07 16:01:27 +0000 | [diff] [blame] | 560 | return llvm::make_unique<raw_null_ostream>(); |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 561 | |
Rafael Espindola | 3fd1e99 | 2014-08-25 18:16:47 +0000 | [diff] [blame] | 562 | std::error_code EC; |
Yaron Keren | 075759a | 2015-03-30 15:42:36 +0000 | [diff] [blame] | 563 | auto OS = llvm::make_unique<raw_fd_ostream>(CoveragePath, EC, |
Rafael Espindola | 3fd1e99 | 2014-08-25 18:16:47 +0000 | [diff] [blame] | 564 | sys::fs::F_Text); |
| 565 | if (EC) { |
| 566 | errs() << EC.message() << "\n"; |
Justin Bogner | 7c09373 | 2014-05-07 16:01:27 +0000 | [diff] [blame] | 567 | return llvm::make_unique<raw_null_ostream>(); |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 568 | } |
| 569 | return std::move(OS); |
| 570 | } |
| 571 | |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 572 | /// print - Print source files with collected line count information. |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 573 | void FileInfo::print(raw_ostream &InfoOS, StringRef MainFilename, |
| 574 | StringRef GCNOFile, StringRef GCDAFile) { |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 575 | for (const auto &LI : LineInfo) { |
| 576 | StringRef Filename = LI.first(); |
Justin Bogner | cf27e1b | 2014-05-07 02:11:23 +0000 | [diff] [blame] | 577 | auto AllLines = LineConsumer(Filename); |
Yuchen Wu | 8aac4f6 | 2013-11-19 20:57:20 +0000 | [diff] [blame] | 578 | |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 579 | std::string CoveragePath = getCoveragePath(Filename, MainFilename); |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 580 | std::unique_ptr<raw_ostream> CovStream = openCoveragePath(CoveragePath); |
| 581 | raw_ostream &CovOS = *CovStream; |
Yuchen Wu | 26326ad | 2013-12-03 00:57:11 +0000 | [diff] [blame] | 582 | |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 583 | CovOS << " -: 0:Source:" << Filename << "\n"; |
| 584 | CovOS << " -: 0:Graph:" << GCNOFile << "\n"; |
| 585 | CovOS << " -: 0:Data:" << GCDAFile << "\n"; |
| 586 | CovOS << " -: 0:Runs:" << RunCount << "\n"; |
| 587 | CovOS << " -: 0:Programs:" << ProgramCount << "\n"; |
Yuchen Wu | 8aac4f6 | 2013-11-19 20:57:20 +0000 | [diff] [blame] | 588 | |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 589 | const LineData &Line = LI.second; |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 590 | GCOVCoverage FileCoverage(Filename); |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 591 | for (uint32_t LineIndex = 0; LineIndex < Line.LastLine || !AllLines.empty(); |
| 592 | ++LineIndex) { |
Yuchen Wu | 73dc381 | 2013-12-18 18:40:15 +0000 | [diff] [blame] | 593 | if (Options.BranchInfo) { |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 594 | FunctionLines::const_iterator FuncsIt = Line.Functions.find(LineIndex); |
| 595 | if (FuncsIt != Line.Functions.end()) |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 596 | printFunctionSummary(CovOS, FuncsIt->second); |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 597 | } |
Yuchen Wu | 1c06816 | 2013-12-03 01:35:31 +0000 | [diff] [blame] | 598 | |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 599 | BlockLines::const_iterator BlocksIt = Line.Blocks.find(LineIndex); |
| 600 | if (BlocksIt == Line.Blocks.end()) { |
| 601 | // No basic blocks are on this line. Not an executable line of code. |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 602 | CovOS << " -:"; |
| 603 | AllLines.printNext(CovOS, LineIndex + 1); |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 604 | } else { |
Yuchen Wu | 8f1c881 | 2013-12-03 00:38:21 +0000 | [diff] [blame] | 605 | const BlockVector &Blocks = BlocksIt->second; |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 606 | |
| 607 | // Add up the block counts to form line counts. |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 608 | DenseMap<const GCOVFunction *, bool> LineExecs; |
Yuchen Wu | 8f1c881 | 2013-12-03 00:38:21 +0000 | [diff] [blame] | 609 | uint64_t LineCount = 0; |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 610 | for (const GCOVBlock *Block : Blocks) { |
Yuchen Wu | 8c6bb5f | 2013-12-10 01:02:07 +0000 | [diff] [blame] | 611 | if (Options.AllBlocks) { |
| 612 | // Only take the highest block count for that line. |
| 613 | uint64_t BlockCount = Block->getCount(); |
| 614 | LineCount = LineCount > BlockCount ? LineCount : BlockCount; |
| 615 | } else { |
| 616 | // Sum up all of the block counts. |
| 617 | LineCount += Block->getCount(); |
| 618 | } |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 619 | |
| 620 | if (Options.FuncCoverage) { |
| 621 | // This is a slightly convoluted way to most accurately gather line |
| 622 | // statistics for functions. Basically what is happening is that we |
| 623 | // don't want to count a single line with multiple blocks more than |
| 624 | // once. However, we also don't simply want to give the total line |
| 625 | // count to every function that starts on the line. Thus, what is |
| 626 | // happening here are two things: |
| 627 | // 1) Ensure that the number of logical lines is only incremented |
| 628 | // once per function. |
| 629 | // 2) If there are multiple blocks on the same line, ensure that the |
| 630 | // number of lines executed is incremented as long as at least |
| 631 | // one of the blocks are executed. |
| 632 | const GCOVFunction *Function = &Block->getParent(); |
| 633 | if (FuncCoverages.find(Function) == FuncCoverages.end()) { |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 634 | std::pair<const GCOVFunction *, GCOVCoverage> KeyValue( |
| 635 | Function, GCOVCoverage(Function->getName())); |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 636 | FuncCoverages.insert(KeyValue); |
| 637 | } |
| 638 | GCOVCoverage &FuncCoverage = FuncCoverages.find(Function)->second; |
| 639 | |
| 640 | if (LineExecs.find(Function) == LineExecs.end()) { |
| 641 | if (Block->getCount()) { |
| 642 | ++FuncCoverage.LinesExec; |
| 643 | LineExecs[Function] = true; |
| 644 | } else { |
| 645 | LineExecs[Function] = false; |
| 646 | } |
| 647 | ++FuncCoverage.LogicalLines; |
| 648 | } else if (!LineExecs[Function] && Block->getCount()) { |
| 649 | ++FuncCoverage.LinesExec; |
| 650 | LineExecs[Function] = true; |
| 651 | } |
| 652 | } |
Yuchen Wu | 8f1c881 | 2013-12-03 00:38:21 +0000 | [diff] [blame] | 653 | } |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 654 | |
Yuchen Wu | 8f1c881 | 2013-12-03 00:38:21 +0000 | [diff] [blame] | 655 | if (LineCount == 0) |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 656 | CovOS << " #####:"; |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 657 | else { |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 658 | CovOS << format("%9" PRIu64 ":", LineCount); |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 659 | ++FileCoverage.LinesExec; |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 660 | } |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 661 | ++FileCoverage.LogicalLines; |
Yuchen Wu | 8c6bb5f | 2013-12-10 01:02:07 +0000 | [diff] [blame] | 662 | |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 663 | AllLines.printNext(CovOS, LineIndex + 1); |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 664 | |
Yuchen Wu | 8c6bb5f | 2013-12-10 01:02:07 +0000 | [diff] [blame] | 665 | uint32_t BlockNo = 0; |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 666 | uint32_t EdgeNo = 0; |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 667 | for (const GCOVBlock *Block : Blocks) { |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 668 | // Only print block and branch information at the end of the block. |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 669 | if (Block->getLastLine() != LineIndex + 1) |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 670 | continue; |
| 671 | if (Options.AllBlocks) |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 672 | printBlockInfo(CovOS, *Block, LineIndex, BlockNo); |
Yuchen Wu | 73dc381 | 2013-12-18 18:40:15 +0000 | [diff] [blame] | 673 | if (Options.BranchInfo) { |
Yuchen Wu | 66d93b8 | 2013-12-16 22:14:02 +0000 | [diff] [blame] | 674 | size_t NumEdges = Block->getNumDstEdges(); |
| 675 | if (NumEdges > 1) |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 676 | printBranchInfo(CovOS, *Block, FileCoverage, EdgeNo); |
Yuchen Wu | 66d93b8 | 2013-12-16 22:14:02 +0000 | [diff] [blame] | 677 | else if (Options.UncondBranch && NumEdges == 1) |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 678 | printUncondBranchInfo(CovOS, EdgeNo, |
| 679 | (*Block->dst_begin())->Count); |
Yuchen Wu | 66d93b8 | 2013-12-16 22:14:02 +0000 | [diff] [blame] | 680 | } |
Yuchen Wu | 8c6bb5f | 2013-12-10 01:02:07 +0000 | [diff] [blame] | 681 | } |
| 682 | } |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 683 | } |
Justin Bogner | c6af350 | 2014-02-04 10:45:02 +0000 | [diff] [blame] | 684 | FileCoverages.push_back(std::make_pair(CoveragePath, FileCoverage)); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 685 | } |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 686 | |
| 687 | // FIXME: There is no way to detect calls given current instrumentation. |
| 688 | if (Options.FuncCoverage) |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 689 | printFuncCoverage(InfoOS); |
| 690 | printFileCoverage(InfoOS); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 691 | } |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 692 | |
| 693 | /// printFunctionSummary - Print function and block summary. |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 694 | void FileInfo::printFunctionSummary(raw_ostream &OS, |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 695 | const FunctionVector &Funcs) const { |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 696 | for (const GCOVFunction *Func : Funcs) { |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 697 | uint64_t EntryCount = Func->getEntryCount(); |
Yuchen Wu | c9b2dcd | 2013-12-18 18:46:25 +0000 | [diff] [blame] | 698 | uint32_t BlocksExec = 0; |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 699 | for (const GCOVBlock &Block : Func->blocks()) |
David Blaikie | 0975749 | 2014-04-21 21:40:16 +0000 | [diff] [blame] | 700 | if (Block.getNumDstEdges() && Block.getCount()) |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 701 | ++BlocksExec; |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 702 | |
| 703 | OS << "function " << Func->getName() << " called " << EntryCount |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 704 | << " returned " << safeDiv(Func->getExitCount() * 100, EntryCount) |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 705 | << "% blocks executed " |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 706 | << safeDiv(BlocksExec * 100, Func->getNumBlocks() - 1) << "%\n"; |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
| 710 | /// printBlockInfo - Output counts for each block. |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 711 | void FileInfo::printBlockInfo(raw_ostream &OS, const GCOVBlock &Block, |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 712 | uint32_t LineIndex, uint32_t &BlockNo) const { |
| 713 | if (Block.getCount() == 0) |
| 714 | OS << " $$$$$:"; |
| 715 | else |
| 716 | OS << format("%9" PRIu64 ":", Block.getCount()); |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 717 | OS << format("%5u-block %2u\n", LineIndex + 1, BlockNo++); |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Yuchen Wu | 66d93b8 | 2013-12-16 22:14:02 +0000 | [diff] [blame] | 720 | /// printBranchInfo - Print conditional branch probabilities. |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 721 | void FileInfo::printBranchInfo(raw_ostream &OS, const GCOVBlock &Block, |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 722 | GCOVCoverage &Coverage, uint32_t &EdgeNo) { |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 723 | SmallVector<uint64_t, 16> BranchCounts; |
| 724 | uint64_t TotalCounts = 0; |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 725 | for (const GCOVEdge *Edge : Block.dsts()) { |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 726 | BranchCounts.push_back(Edge->Count); |
| 727 | TotalCounts += Edge->Count; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 728 | if (Block.getCount()) |
| 729 | ++Coverage.BranchesExec; |
| 730 | if (Edge->Count) |
| 731 | ++Coverage.BranchesTaken; |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 732 | ++Coverage.Branches; |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 733 | |
| 734 | if (Options.FuncCoverage) { |
| 735 | const GCOVFunction *Function = &Block.getParent(); |
| 736 | GCOVCoverage &FuncCoverage = FuncCoverages.find(Function)->second; |
Justin Bogner | 011c742 | 2015-01-23 22:38:01 +0000 | [diff] [blame] | 737 | if (Block.getCount()) |
| 738 | ++FuncCoverage.BranchesExec; |
| 739 | if (Edge->Count) |
| 740 | ++FuncCoverage.BranchesTaken; |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 741 | ++FuncCoverage.Branches; |
| 742 | } |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 745 | for (uint64_t N : BranchCounts) |
Yuchen Wu | 73dc381 | 2013-12-18 18:40:15 +0000 | [diff] [blame] | 746 | OS << format("branch %2u ", EdgeNo++) |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 747 | << formatBranchInfo(Options, N, TotalCounts) << "\n"; |
Yuchen Wu | 342714c | 2013-12-13 01:15:07 +0000 | [diff] [blame] | 748 | } |
Yuchen Wu | 66d93b8 | 2013-12-16 22:14:02 +0000 | [diff] [blame] | 749 | |
| 750 | /// printUncondBranchInfo - Print unconditional branch probabilities. |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 751 | void FileInfo::printUncondBranchInfo(raw_ostream &OS, uint32_t &EdgeNo, |
Yuchen Wu | 66d93b8 | 2013-12-16 22:14:02 +0000 | [diff] [blame] | 752 | uint64_t Count) const { |
Yuchen Wu | 73dc381 | 2013-12-18 18:40:15 +0000 | [diff] [blame] | 753 | OS << format("unconditional %2u ", EdgeNo++) |
| 754 | << formatBranchInfo(Options, Count, Count) << "\n"; |
Yuchen Wu | 66d93b8 | 2013-12-16 22:14:02 +0000 | [diff] [blame] | 755 | } |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 756 | |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 757 | // printCoverage - Print generic coverage info used by both printFuncCoverage |
| 758 | // and printFileCoverage. |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 759 | void FileInfo::printCoverage(raw_ostream &OS, |
| 760 | const GCOVCoverage &Coverage) const { |
| 761 | OS << format("Lines executed:%.2f%% of %u\n", |
| 762 | double(Coverage.LinesExec) * 100 / Coverage.LogicalLines, |
| 763 | Coverage.LogicalLines); |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 764 | if (Options.BranchInfo) { |
| 765 | if (Coverage.Branches) { |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 766 | OS << format("Branches executed:%.2f%% of %u\n", |
| 767 | double(Coverage.BranchesExec) * 100 / Coverage.Branches, |
| 768 | Coverage.Branches); |
| 769 | OS << format("Taken at least once:%.2f%% of %u\n", |
| 770 | double(Coverage.BranchesTaken) * 100 / Coverage.Branches, |
| 771 | Coverage.Branches); |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 772 | } else { |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 773 | OS << "No branches\n"; |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 774 | } |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 775 | OS << "No calls\n"; // to be consistent with gcov |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 776 | } |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | // printFuncCoverage - Print per-function coverage info. |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 780 | void FileInfo::printFuncCoverage(raw_ostream &OS) const { |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 781 | for (const auto &FC : FuncCoverages) { |
| 782 | const GCOVCoverage &Coverage = FC.second; |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 783 | OS << "Function '" << Coverage.Name << "'\n"; |
| 784 | printCoverage(OS, Coverage); |
| 785 | OS << "\n"; |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
| 789 | // printFileCoverage - Print per-file coverage info. |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 790 | void FileInfo::printFileCoverage(raw_ostream &OS) const { |
Justin Bogner | 000b522 | 2015-01-23 22:57:02 +0000 | [diff] [blame] | 791 | for (const auto &FC : FileCoverages) { |
| 792 | const std::string &Filename = FC.first; |
| 793 | const GCOVCoverage &Coverage = FC.second; |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 794 | OS << "File '" << Coverage.Name << "'\n"; |
| 795 | printCoverage(OS, Coverage); |
Justin Bogner | 1a18d7c | 2014-05-07 02:11:18 +0000 | [diff] [blame] | 796 | if (!Options.NoOutput) |
Justin Bogner | 0b9858d | 2015-01-23 23:09:27 +0000 | [diff] [blame] | 797 | OS << Coverage.Name << ":creating '" << Filename << "'\n"; |
| 798 | OS << "\n"; |
Yuchen Wu | bb6a477 | 2013-12-19 00:29:25 +0000 | [diff] [blame] | 799 | } |
Yuchen Wu | 8256ee6 | 2013-12-18 21:12:51 +0000 | [diff] [blame] | 800 | } |