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