Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 1 | //===- LLVMOutputStyle.cpp ------------------------------------ *- C++ --*-===// |
| 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 | |
| 10 | #include "LLVMOutputStyle.h" |
| 11 | |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 12 | #include "C13DebugFragmentVisitor.h" |
Zachary Turner | 44a643c | 2017-01-12 22:28:15 +0000 | [diff] [blame] | 13 | #include "CompactTypeDumpVisitor.h" |
Zachary Turner | 6ac232c | 2017-03-13 23:28:25 +0000 | [diff] [blame] | 14 | #include "StreamUtil.h" |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 15 | #include "llvm-pdbdump.h" |
Zachary Turner | 44a643c | 2017-01-12 22:28:15 +0000 | [diff] [blame] | 16 | |
Zachary Turner | 629cb7d | 2017-01-11 23:24:22 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/CodeView/EnumTables.h" |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 19 | #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/CodeView/Line.h" |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h" |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h" |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 23 | #include "llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h" |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h" |
| 25 | #include "llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h" |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 26 | #include "llvm/DebugInfo/CodeView/SymbolDumper.h" |
Zachary Turner | 629cb7d | 2017-01-11 23:24:22 +0000 | [diff] [blame] | 27 | #include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h" |
Zachary Turner | 629cb7d | 2017-01-11 23:24:22 +0000 | [diff] [blame] | 28 | #include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h" |
| 29 | #include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h" |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 30 | #include "llvm/DebugInfo/MSF/MappedBlockStream.h" |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 31 | #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 32 | #include "llvm/DebugInfo/PDB/Native/DbiStream.h" |
| 33 | #include "llvm/DebugInfo/PDB/Native/EnumTables.h" |
| 34 | #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" |
| 35 | #include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h" |
| 36 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 37 | #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 38 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 39 | #include "llvm/DebugInfo/PDB/Native/PublicsStream.h" |
| 40 | #include "llvm/DebugInfo/PDB/Native/RawError.h" |
Zachary Turner | bedc85f | 2017-05-04 23:53:54 +0000 | [diff] [blame] | 41 | #include "llvm/DebugInfo/PDB/Native/TpiHashing.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 42 | #include "llvm/DebugInfo/PDB/Native/TpiStream.h" |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 43 | #include "llvm/DebugInfo/PDB/PDBExtras.h" |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 44 | #include "llvm/Object/COFF.h" |
Zachary Turner | d9dc282 | 2017-03-02 20:52:51 +0000 | [diff] [blame] | 45 | #include "llvm/Support/BinaryStreamReader.h" |
Zachary Turner | 44a643c | 2017-01-12 22:28:15 +0000 | [diff] [blame] | 46 | #include "llvm/Support/FormatVariadic.h" |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 47 | |
| 48 | #include <unordered_map> |
| 49 | |
| 50 | using namespace llvm; |
| 51 | using namespace llvm::codeview; |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 52 | using namespace llvm::msf; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 53 | using namespace llvm::pdb; |
| 54 | |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 55 | namespace { |
| 56 | struct PageStats { |
| 57 | explicit PageStats(const BitVector &FreePages) |
| 58 | : Upm(FreePages), ActualUsedPages(FreePages.size()), |
| 59 | MultiUsePages(FreePages.size()), UseAfterFreePages(FreePages.size()) { |
| 60 | const_cast<BitVector &>(Upm).flip(); |
| 61 | // To calculate orphaned pages, we start with the set of pages that the |
| 62 | // MSF thinks are used. Each time we find one that actually *is* used, |
| 63 | // we unset it. Whichever bits remain set at the end are orphaned. |
| 64 | OrphanedPages = Upm; |
| 65 | } |
| 66 | |
| 67 | // The inverse of the MSF File's copy of the Fpm. The basis for which we |
| 68 | // determine the allocation status of each page. |
| 69 | const BitVector Upm; |
| 70 | |
| 71 | // Pages which are marked as used in the FPM and are used at least once. |
| 72 | BitVector ActualUsedPages; |
| 73 | |
| 74 | // Pages which are marked as used in the FPM but are used more than once. |
| 75 | BitVector MultiUsePages; |
| 76 | |
| 77 | // Pages which are marked as used in the FPM but are not used at all. |
| 78 | BitVector OrphanedPages; |
| 79 | |
| 80 | // Pages which are marked free in the FPM but are used. |
| 81 | BitVector UseAfterFreePages; |
| 82 | }; |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 83 | |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 84 | class C13RawVisitor : public C13DebugFragmentVisitor { |
| 85 | public: |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 86 | C13RawVisitor(ScopedPrinter &P, PDBFile &F, LazyRandomTypeCollection &IPI) |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 87 | : C13DebugFragmentVisitor(F), P(P), IPI(IPI) {} |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 88 | |
| 89 | Error handleLines() override { |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 90 | if (Lines.empty()) |
| 91 | return Error::success(); |
| 92 | |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 93 | DictScope DD(P, "Lines"); |
| 94 | |
| 95 | for (const auto &Fragment : Lines) { |
Zachary Turner | 8a2ebfb | 2017-05-01 23:27:42 +0000 | [diff] [blame] | 96 | DictScope DDD(P, "Block"); |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 97 | P.printNumber("RelocSegment", Fragment.header()->RelocSegment); |
| 98 | P.printNumber("RelocOffset", Fragment.header()->RelocOffset); |
| 99 | P.printNumber("CodeSize", Fragment.header()->CodeSize); |
Zachary Turner | 8a2ebfb | 2017-05-01 23:27:42 +0000 | [diff] [blame] | 100 | P.printBoolean("HasColumns", Fragment.hasColumnInfo()); |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 101 | |
| 102 | for (const auto &L : Fragment) { |
| 103 | DictScope DDDD(P, "Lines"); |
| 104 | |
| 105 | if (auto EC = printFileName("FileName", L.NameIndex)) |
| 106 | return EC; |
| 107 | |
| 108 | for (const auto &N : L.LineNumbers) { |
| 109 | DictScope DDD(P, "Line"); |
| 110 | LineInfo LI(N.Flags); |
| 111 | P.printNumber("Offset", N.Offset); |
| 112 | if (LI.isAlwaysStepInto()) |
| 113 | P.printString("StepInto", StringRef("Always")); |
| 114 | else if (LI.isNeverStepInto()) |
| 115 | P.printString("StepInto", StringRef("Never")); |
| 116 | else |
| 117 | P.printNumber("LineNumberStart", LI.getStartLine()); |
| 118 | P.printNumber("EndDelta", LI.getLineDelta()); |
| 119 | P.printBoolean("IsStatement", LI.isStatement()); |
| 120 | } |
| 121 | for (const auto &C : L.Columns) { |
| 122 | DictScope DDD(P, "Column"); |
| 123 | P.printNumber("Start", C.StartColumn); |
| 124 | P.printNumber("End", C.EndColumn); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return Error::success(); |
| 130 | } |
| 131 | |
| 132 | Error handleFileChecksums() override { |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 133 | if (!Checksums.hasValue()) |
| 134 | return Error::success(); |
| 135 | |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 136 | DictScope DD(P, "FileChecksums"); |
| 137 | for (const auto &CS : *Checksums) { |
| 138 | DictScope DDD(P, "Checksum"); |
| 139 | if (auto Result = getNameFromStringTable(CS.FileNameOffset)) |
| 140 | P.printString("FileName", *Result); |
| 141 | else |
| 142 | return Result.takeError(); |
| 143 | P.printEnum("Kind", uint8_t(CS.Kind), getFileChecksumNames()); |
| 144 | P.printBinaryBlock("Checksum", CS.Checksum); |
| 145 | } |
| 146 | return Error::success(); |
| 147 | } |
| 148 | |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 149 | Error handleInlineeLines() override { |
| 150 | if (InlineeLines.empty()) |
| 151 | return Error::success(); |
| 152 | |
| 153 | DictScope D(P, "InlineeLines"); |
| 154 | for (const auto &IL : InlineeLines) { |
| 155 | P.printBoolean("HasExtraFiles", IL.hasExtraFiles()); |
| 156 | ListScope LS(P, "Lines"); |
| 157 | for (const auto &L : IL) { |
| 158 | DictScope DDD(P, "Inlinee"); |
| 159 | if (auto EC = printFileName("FileName", L.Header->FileID)) |
| 160 | return EC; |
| 161 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 162 | if (auto EC = dumpTypeRecord("Function", L.Header->Inlinee)) |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 163 | return EC; |
| 164 | P.printNumber("SourceLine", L.Header->SourceLineNum); |
| 165 | if (IL.hasExtraFiles()) { |
| 166 | ListScope DDDD(P, "ExtraFiles"); |
| 167 | for (const auto &EF : L.ExtraFiles) { |
| 168 | if (auto EC = printFileName("File", EF)) |
| 169 | return EC; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | return Error::success(); |
| 175 | } |
| 176 | |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 177 | private: |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 178 | Error dumpTypeRecord(StringRef Label, TypeIndex Index) { |
| 179 | CompactTypeDumpVisitor CTDV(IPI, Index, &P); |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 180 | DictScope D(P, Label); |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 181 | if (IPI.contains(Index)) { |
| 182 | CVType Type = IPI.getType(Index); |
Zachary Turner | 1d795c4 | 2017-05-17 16:39:06 +0000 | [diff] [blame] | 183 | if (auto EC = codeview::visitTypeRecord(Type, CTDV)) |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 184 | return EC; |
| 185 | } else { |
| 186 | P.printString( |
| 187 | llvm::formatv("Index: {0:x} (unknown function)", Index.getIndex()) |
| 188 | .str()); |
| 189 | } |
| 190 | return Error::success(); |
| 191 | } |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 192 | Error printFileName(StringRef Label, uint32_t Offset) { |
| 193 | if (auto Result = getNameFromChecksumsBuffer(Offset)) { |
| 194 | P.printString(Label, *Result); |
| 195 | return Error::success(); |
| 196 | } else |
| 197 | return Result.takeError(); |
| 198 | } |
| 199 | |
| 200 | ScopedPrinter &P; |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 201 | LazyRandomTypeCollection &IPI; |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 202 | }; |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static void recordKnownUsedPage(PageStats &Stats, uint32_t UsedIndex) { |
| 206 | if (Stats.Upm.test(UsedIndex)) { |
| 207 | if (Stats.ActualUsedPages.test(UsedIndex)) |
| 208 | Stats.MultiUsePages.set(UsedIndex); |
| 209 | Stats.ActualUsedPages.set(UsedIndex); |
| 210 | Stats.OrphanedPages.reset(UsedIndex); |
| 211 | } else { |
| 212 | // The MSF doesn't think this page is used, but it is. |
| 213 | Stats.UseAfterFreePages.set(UsedIndex); |
| 214 | } |
| 215 | } |
| 216 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 217 | static void printSectionOffset(llvm::raw_ostream &OS, |
| 218 | const SectionOffset &Off) { |
| 219 | OS << Off.Off << ", " << Off.Isect; |
| 220 | } |
| 221 | |
Zachary Turner | 629cb7d | 2017-01-11 23:24:22 +0000 | [diff] [blame] | 222 | LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) : File(File), P(outs()) {} |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 223 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 224 | Error LLVMOutputStyle::dump() { |
| 225 | if (auto EC = dumpFileHeaders()) |
| 226 | return EC; |
| 227 | |
| 228 | if (auto EC = dumpStreamSummary()) |
| 229 | return EC; |
| 230 | |
Rui Ueyama | 7a5cdc6 | 2016-07-29 21:38:00 +0000 | [diff] [blame] | 231 | if (auto EC = dumpFreePageMap()) |
| 232 | return EC; |
| 233 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 234 | if (auto EC = dumpStreamBlocks()) |
| 235 | return EC; |
| 236 | |
Zachary Turner | 72c5b64 | 2016-09-09 18:17:52 +0000 | [diff] [blame] | 237 | if (auto EC = dumpBlockRanges()) |
| 238 | return EC; |
| 239 | |
| 240 | if (auto EC = dumpStreamBytes()) |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 241 | return EC; |
| 242 | |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 243 | if (auto EC = dumpStringTable()) |
| 244 | return EC; |
| 245 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 246 | if (auto EC = dumpInfoStream()) |
| 247 | return EC; |
| 248 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 249 | if (auto EC = dumpTpiStream(StreamTPI)) |
| 250 | return EC; |
| 251 | |
| 252 | if (auto EC = dumpTpiStream(StreamIPI)) |
| 253 | return EC; |
| 254 | |
| 255 | if (auto EC = dumpDbiStream()) |
| 256 | return EC; |
| 257 | |
| 258 | if (auto EC = dumpSectionContribs()) |
| 259 | return EC; |
| 260 | |
| 261 | if (auto EC = dumpSectionMap()) |
| 262 | return EC; |
| 263 | |
Bob Haarman | 653baa2 | 2016-10-21 19:43:19 +0000 | [diff] [blame] | 264 | if (auto EC = dumpGlobalsStream()) |
| 265 | return EC; |
| 266 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 267 | if (auto EC = dumpPublicsStream()) |
| 268 | return EC; |
| 269 | |
| 270 | if (auto EC = dumpSectionHeaders()) |
| 271 | return EC; |
| 272 | |
| 273 | if (auto EC = dumpFpoStream()) |
| 274 | return EC; |
| 275 | |
| 276 | flush(); |
| 277 | |
| 278 | return Error::success(); |
| 279 | } |
| 280 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 281 | Error LLVMOutputStyle::dumpFileHeaders() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 282 | if (!opts::raw::DumpHeaders) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 283 | return Error::success(); |
| 284 | |
| 285 | DictScope D(P, "FileHeaders"); |
| 286 | P.printNumber("BlockSize", File.getBlockSize()); |
Zachary Turner | b927e02 | 2016-07-15 22:17:19 +0000 | [diff] [blame] | 287 | P.printNumber("FreeBlockMap", File.getFreeBlockMapBlock()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 288 | P.printNumber("NumBlocks", File.getBlockCount()); |
| 289 | P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes()); |
| 290 | P.printNumber("Unknown1", File.getUnknown1()); |
| 291 | P.printNumber("BlockMapAddr", File.getBlockMapIndex()); |
| 292 | P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 293 | |
| 294 | // The directory is not contiguous. Instead, the block map contains a |
| 295 | // contiguous list of block numbers whose contents, when concatenated in |
| 296 | // order, make up the directory. |
| 297 | P.printList("DirectoryBlocks", File.getDirectoryBlockArray()); |
| 298 | P.printNumber("NumStreams", File.getNumStreams()); |
| 299 | return Error::success(); |
| 300 | } |
| 301 | |
Zachary Turner | 36efbfa | 2016-09-09 19:00:49 +0000 | [diff] [blame] | 302 | Error LLVMOutputStyle::dumpStreamSummary() { |
| 303 | if (!opts::raw::DumpStreamSummary) |
| 304 | return Error::success(); |
| 305 | |
Zachary Turner | 6ac232c | 2017-03-13 23:28:25 +0000 | [diff] [blame] | 306 | if (StreamPurposes.empty()) |
| 307 | discoverStreamPurposes(File, StreamPurposes); |
Zachary Turner | 36efbfa | 2016-09-09 19:00:49 +0000 | [diff] [blame] | 308 | |
| 309 | uint32_t StreamCount = File.getNumStreams(); |
| 310 | |
| 311 | ListScope L(P, "Streams"); |
| 312 | for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) { |
| 313 | std::string Label("Stream "); |
| 314 | Label += to_string(StreamIdx); |
| 315 | |
| 316 | std::string Value = "[" + StreamPurposes[StreamIdx] + "] ("; |
| 317 | Value += to_string(File.getStreamByteSize(StreamIdx)); |
| 318 | Value += " bytes)"; |
| 319 | |
| 320 | P.printString(Label, Value); |
| 321 | } |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 322 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 323 | P.flush(); |
| 324 | return Error::success(); |
| 325 | } |
| 326 | |
Rui Ueyama | 7a5cdc6 | 2016-07-29 21:38:00 +0000 | [diff] [blame] | 327 | Error LLVMOutputStyle::dumpFreePageMap() { |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 328 | if (!opts::raw::DumpPageStats) |
Rui Ueyama | 7a5cdc6 | 2016-07-29 21:38:00 +0000 | [diff] [blame] | 329 | return Error::success(); |
Rui Ueyama | 7a5cdc6 | 2016-07-29 21:38:00 +0000 | [diff] [blame] | 330 | |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 331 | // Start with used pages instead of free pages because |
Rui Ueyama | 7a5cdc6 | 2016-07-29 21:38:00 +0000 | [diff] [blame] | 332 | // the number of free pages is far larger than used pages. |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 333 | BitVector FPM = File.getMsfLayout().FreePageMap; |
| 334 | |
| 335 | PageStats PS(FPM); |
| 336 | |
| 337 | recordKnownUsedPage(PS, 0); // MSF Super Block |
| 338 | |
Zachary Turner | 8cf51c3 | 2016-08-03 16:53:21 +0000 | [diff] [blame] | 339 | uint32_t BlocksPerSection = msf::getFpmIntervalLength(File.getMsfLayout()); |
| 340 | uint32_t NumSections = msf::getNumFpmIntervals(File.getMsfLayout()); |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 341 | for (uint32_t I = 0; I < NumSections; ++I) { |
| 342 | uint32_t Fpm0 = 1 + BlocksPerSection * I; |
| 343 | // 2 Fpm blocks spaced at `getBlockSize()` block intervals |
| 344 | recordKnownUsedPage(PS, Fpm0); |
| 345 | recordKnownUsedPage(PS, Fpm0 + 1); |
| 346 | } |
| 347 | |
| 348 | recordKnownUsedPage(PS, File.getBlockMapIndex()); // Stream Table |
| 349 | |
Rui Ueyama | 22e6738 | 2016-08-02 23:22:46 +0000 | [diff] [blame] | 350 | for (auto DB : File.getDirectoryBlockArray()) |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 351 | recordKnownUsedPage(PS, DB); |
Rui Ueyama | 22e6738 | 2016-08-02 23:22:46 +0000 | [diff] [blame] | 352 | |
| 353 | // Record pages used by streams. Note that pages for stream 0 |
| 354 | // are considered being unused because that's what MSVC tools do. |
| 355 | // Stream 0 doesn't contain actual data, so it makes some sense, |
| 356 | // though it's a bit confusing to us. |
| 357 | for (auto &SE : File.getStreamMap().drop_front(1)) |
| 358 | for (auto &S : SE) |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 359 | recordKnownUsedPage(PS, S); |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 360 | |
| 361 | dumpBitVector("Msf Free Pages", FPM); |
| 362 | dumpBitVector("Orphaned Pages", PS.OrphanedPages); |
| 363 | dumpBitVector("Multiply Used Pages", PS.MultiUsePages); |
| 364 | dumpBitVector("Use After Free Pages", PS.UseAfterFreePages); |
Rui Ueyama | 7a5cdc6 | 2016-07-29 21:38:00 +0000 | [diff] [blame] | 365 | return Error::success(); |
| 366 | } |
| 367 | |
Zachary Turner | d3c7b8e | 2016-08-01 21:19:45 +0000 | [diff] [blame] | 368 | void LLVMOutputStyle::dumpBitVector(StringRef Name, const BitVector &V) { |
| 369 | std::vector<uint32_t> Vec; |
| 370 | for (uint32_t I = 0, E = V.size(); I != E; ++I) |
| 371 | if (V[I]) |
| 372 | Vec.push_back(I); |
| 373 | P.printList(Name, Vec); |
| 374 | } |
| 375 | |
Bob Haarman | 653baa2 | 2016-10-21 19:43:19 +0000 | [diff] [blame] | 376 | Error LLVMOutputStyle::dumpGlobalsStream() { |
| 377 | if (!opts::raw::DumpGlobals) |
| 378 | return Error::success(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 379 | if (!File.hasPDBGlobalsStream()) { |
| 380 | P.printString("Globals Stream not present"); |
| 381 | return Error::success(); |
| 382 | } |
Bob Haarman | 653baa2 | 2016-10-21 19:43:19 +0000 | [diff] [blame] | 383 | |
Bob Haarman | 653baa2 | 2016-10-21 19:43:19 +0000 | [diff] [blame] | 384 | auto Globals = File.getPDBGlobalsStream(); |
| 385 | if (!Globals) |
Bob Haarman | 312fd0e | 2016-12-06 00:55:55 +0000 | [diff] [blame] | 386 | return Globals.takeError(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 387 | DictScope D(P, "Globals Stream"); |
Bob Haarman | 653baa2 | 2016-10-21 19:43:19 +0000 | [diff] [blame] | 388 | |
| 389 | auto Dbi = File.getPDBDbiStream(); |
| 390 | if (!Dbi) |
| 391 | return Dbi.takeError(); |
| 392 | |
| 393 | P.printNumber("Stream number", Dbi->getGlobalSymbolStreamIndex()); |
| 394 | P.printNumber("Number of buckets", Globals->getNumBuckets()); |
| 395 | P.printList("Hash Buckets", Globals->getHashBuckets()); |
| 396 | |
| 397 | return Error::success(); |
| 398 | } |
| 399 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 400 | Error LLVMOutputStyle::dumpStreamBlocks() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 401 | if (!opts::raw::DumpStreamBlocks) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 402 | return Error::success(); |
| 403 | |
| 404 | ListScope L(P, "StreamBlocks"); |
| 405 | uint32_t StreamCount = File.getNumStreams(); |
| 406 | for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) { |
| 407 | std::string Name("Stream "); |
| 408 | Name += to_string(StreamIdx); |
| 409 | auto StreamBlocks = File.getStreamBlockList(StreamIdx); |
| 410 | P.printList(Name, StreamBlocks); |
| 411 | } |
| 412 | return Error::success(); |
| 413 | } |
| 414 | |
Zachary Turner | 72c5b64 | 2016-09-09 18:17:52 +0000 | [diff] [blame] | 415 | Error LLVMOutputStyle::dumpBlockRanges() { |
| 416 | if (!opts::raw::DumpBlockRange.hasValue()) |
| 417 | return Error::success(); |
| 418 | auto &R = *opts::raw::DumpBlockRange; |
| 419 | uint32_t Max = R.Max.getValueOr(R.Min); |
| 420 | |
| 421 | if (Max < R.Min) |
| 422 | return make_error<StringError>( |
| 423 | "Invalid block range specified. Max < Min", |
| 424 | std::make_error_code(std::errc::bad_address)); |
| 425 | if (Max >= File.getBlockCount()) |
| 426 | return make_error<StringError>( |
| 427 | "Invalid block range specified. Requested block out of bounds", |
| 428 | std::make_error_code(std::errc::bad_address)); |
| 429 | |
| 430 | DictScope D(P, "Block Data"); |
| 431 | for (uint32_t I = R.Min; I <= Max; ++I) { |
| 432 | auto ExpectedData = File.getBlockData(I, File.getBlockSize()); |
| 433 | if (!ExpectedData) |
| 434 | return ExpectedData.takeError(); |
| 435 | std::string Label; |
| 436 | llvm::raw_string_ostream S(Label); |
| 437 | S << "Block " << I; |
| 438 | S.flush(); |
| 439 | P.printBinaryBlock(Label, *ExpectedData); |
| 440 | } |
| 441 | |
| 442 | return Error::success(); |
| 443 | } |
| 444 | |
Zachary Turner | 7159ab9 | 2017-04-28 00:43:38 +0000 | [diff] [blame] | 445 | static Error parseStreamSpec(StringRef Str, uint32_t &SI, uint32_t &Offset, |
| 446 | uint32_t &Size) { |
| 447 | if (Str.consumeInteger(0, SI)) |
| 448 | return make_error<RawError>(raw_error_code::invalid_format, |
| 449 | "Invalid Stream Specification"); |
| 450 | if (Str.consume_front(":")) { |
| 451 | if (Str.consumeInteger(0, Offset)) |
| 452 | return make_error<RawError>(raw_error_code::invalid_format, |
| 453 | "Invalid Stream Specification"); |
| 454 | } |
| 455 | if (Str.consume_front("@")) { |
| 456 | if (Str.consumeInteger(0, Size)) |
| 457 | return make_error<RawError>(raw_error_code::invalid_format, |
| 458 | "Invalid Stream Specification"); |
| 459 | } |
| 460 | if (!Str.empty()) |
| 461 | return make_error<RawError>(raw_error_code::invalid_format, |
| 462 | "Invalid Stream Specification"); |
| 463 | return Error::success(); |
| 464 | } |
| 465 | |
Zachary Turner | 72c5b64 | 2016-09-09 18:17:52 +0000 | [diff] [blame] | 466 | Error LLVMOutputStyle::dumpStreamBytes() { |
| 467 | if (opts::raw::DumpStreamData.empty()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 468 | return Error::success(); |
| 469 | |
Zachary Turner | 6ac232c | 2017-03-13 23:28:25 +0000 | [diff] [blame] | 470 | if (StreamPurposes.empty()) |
| 471 | discoverStreamPurposes(File, StreamPurposes); |
Zachary Turner | 36efbfa | 2016-09-09 19:00:49 +0000 | [diff] [blame] | 472 | |
Zachary Turner | 72c5b64 | 2016-09-09 18:17:52 +0000 | [diff] [blame] | 473 | DictScope D(P, "Stream Data"); |
Zachary Turner | 7159ab9 | 2017-04-28 00:43:38 +0000 | [diff] [blame] | 474 | for (auto &Str : opts::raw::DumpStreamData) { |
| 475 | uint32_t SI = 0; |
| 476 | uint32_t Begin = 0; |
| 477 | uint32_t Size = 0; |
| 478 | uint32_t End = 0; |
| 479 | |
| 480 | if (auto EC = parseStreamSpec(Str, SI, Begin, Size)) |
| 481 | return EC; |
| 482 | |
Zachary Turner | 72c5b64 | 2016-09-09 18:17:52 +0000 | [diff] [blame] | 483 | if (SI >= File.getNumStreams()) |
| 484 | return make_error<RawError>(raw_error_code::no_stream); |
Zachary Turner | d2b2bfe | 2016-06-08 00:25:08 +0000 | [diff] [blame] | 485 | |
Zachary Turner | 72c5b64 | 2016-09-09 18:17:52 +0000 | [diff] [blame] | 486 | auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(), |
| 487 | File.getMsfBuffer(), SI); |
| 488 | if (!S) |
| 489 | continue; |
Zachary Turner | 36efbfa | 2016-09-09 19:00:49 +0000 | [diff] [blame] | 490 | DictScope DD(P, "Stream"); |
Zachary Turner | 7159ab9 | 2017-04-28 00:43:38 +0000 | [diff] [blame] | 491 | if (Size == 0) |
| 492 | End = S->getLength(); |
| 493 | else { |
| 494 | End = Begin + Size; |
| 495 | if (End >= S->getLength()) |
| 496 | return make_error<RawError>(raw_error_code::index_out_of_bounds, |
| 497 | "Stream is not long enough!"); |
| 498 | } |
Zachary Turner | 36efbfa | 2016-09-09 19:00:49 +0000 | [diff] [blame] | 499 | |
| 500 | P.printNumber("Index", SI); |
| 501 | P.printString("Type", StreamPurposes[SI]); |
| 502 | P.printNumber("Size", S->getLength()); |
| 503 | auto Blocks = File.getMsfLayout().StreamMap[SI]; |
| 504 | P.printList("Blocks", Blocks); |
| 505 | |
Zachary Turner | 120faca | 2017-02-27 22:11:43 +0000 | [diff] [blame] | 506 | BinaryStreamReader R(*S); |
Zachary Turner | 72c5b64 | 2016-09-09 18:17:52 +0000 | [diff] [blame] | 507 | ArrayRef<uint8_t> StreamData; |
| 508 | if (auto EC = R.readBytes(StreamData, S->getLength())) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 509 | return EC; |
Zachary Turner | 7159ab9 | 2017-04-28 00:43:38 +0000 | [diff] [blame] | 510 | Size = End - Begin; |
| 511 | StreamData = StreamData.slice(Begin, Size); |
| 512 | P.printBinaryBlock("Data", StreamData, Begin); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 513 | } |
| 514 | return Error::success(); |
| 515 | } |
| 516 | |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 517 | Error LLVMOutputStyle::dumpStringTable() { |
| 518 | if (!opts::raw::DumpStringTable) |
| 519 | return Error::success(); |
| 520 | |
| 521 | auto IS = File.getStringTable(); |
| 522 | if (!IS) |
| 523 | return IS.takeError(); |
| 524 | |
| 525 | DictScope D(P, "String Table"); |
| 526 | for (uint32_t I : IS->name_ids()) { |
Zachary Turner | 2d5c2cd | 2017-05-03 17:11:11 +0000 | [diff] [blame] | 527 | auto ES = IS->getStringForID(I); |
| 528 | if (!ES) |
| 529 | return ES.takeError(); |
| 530 | |
| 531 | if (ES->empty()) |
| 532 | continue; |
| 533 | llvm::SmallString<32> Str; |
| 534 | Str.append("'"); |
| 535 | Str.append(*ES); |
| 536 | Str.append("'"); |
| 537 | P.printString(Str); |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 538 | } |
| 539 | return Error::success(); |
| 540 | } |
| 541 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 542 | Error LLVMOutputStyle::dumpInfoStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 543 | if (!opts::raw::DumpHeaders) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 544 | return Error::success(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 545 | if (!File.hasPDBInfoStream()) { |
| 546 | P.printString("PDB Stream not present"); |
| 547 | return Error::success(); |
| 548 | } |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 549 | auto IS = File.getPDBInfoStream(); |
| 550 | if (!IS) |
| 551 | return IS.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 552 | |
| 553 | DictScope D(P, "PDB Stream"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 554 | P.printNumber("Version", IS->getVersion()); |
| 555 | P.printHex("Signature", IS->getSignature()); |
| 556 | P.printNumber("Age", IS->getAge()); |
| 557 | P.printObject("Guid", IS->getGuid()); |
Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 558 | P.printHex("Features", IS->getFeatures()); |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 559 | { |
| 560 | DictScope DD(P, "Named Streams"); |
| 561 | for (const auto &S : IS->getNamedStreams().entries()) |
| 562 | P.printObject(S.getKey(), S.getValue()); |
| 563 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 564 | return Error::success(); |
| 565 | } |
| 566 | |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 567 | namespace { |
| 568 | class RecordBytesVisitor : public TypeVisitorCallbacks { |
| 569 | public: |
| 570 | explicit RecordBytesVisitor(ScopedPrinter &P) : P(P) {} |
| 571 | |
| 572 | Error visitTypeEnd(CVType &Record) override { |
| 573 | P.printBinaryBlock("Bytes", Record.content()); |
| 574 | return Error::success(); |
| 575 | } |
| 576 | |
| 577 | private: |
| 578 | ScopedPrinter &P; |
| 579 | }; |
Rui Ueyama | fd97bf1 | 2016-06-03 20:48:51 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 582 | Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) { |
| 583 | assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI); |
| 584 | |
| 585 | bool DumpRecordBytes = false; |
| 586 | bool DumpRecords = false; |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 587 | bool DumpTpiHash = false; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 588 | StringRef Label; |
| 589 | StringRef VerLabel; |
| 590 | if (StreamIdx == StreamTPI) { |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 591 | if (!File.hasPDBTpiStream()) { |
| 592 | P.printString("Type Info Stream (TPI) not present"); |
| 593 | return Error::success(); |
| 594 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 595 | DumpRecordBytes = opts::raw::DumpTpiRecordBytes; |
| 596 | DumpRecords = opts::raw::DumpTpiRecords; |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 597 | DumpTpiHash = opts::raw::DumpTpiHash; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 598 | Label = "Type Info Stream (TPI)"; |
| 599 | VerLabel = "TPI Version"; |
| 600 | } else if (StreamIdx == StreamIPI) { |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 601 | if (!File.hasPDBIpiStream()) { |
| 602 | P.printString("Type Info Stream (IPI) not present"); |
| 603 | return Error::success(); |
| 604 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 605 | DumpRecordBytes = opts::raw::DumpIpiRecordBytes; |
| 606 | DumpRecords = opts::raw::DumpIpiRecords; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 607 | Label = "Type Info Stream (IPI)"; |
| 608 | VerLabel = "IPI Version"; |
| 609 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 610 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 611 | auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream() |
| 612 | : File.getPDBIpiStream(); |
| 613 | if (!Tpi) |
| 614 | return Tpi.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 615 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 616 | auto ExpectedTypes = initializeTypeDatabase(StreamIdx); |
| 617 | if (!ExpectedTypes) |
| 618 | return ExpectedTypes.takeError(); |
| 619 | auto &Types = *ExpectedTypes; |
| 620 | |
| 621 | if (!DumpRecordBytes && !DumpRecords && !DumpTpiHash) |
| 622 | return Error::success(); |
| 623 | |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 624 | std::unique_ptr<DictScope> StreamScope; |
| 625 | std::unique_ptr<ListScope> RecordScope; |
| 626 | |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 627 | StreamScope = llvm::make_unique<DictScope>(P, Label); |
| 628 | P.printNumber(VerLabel, Tpi->getTpiVersion()); |
Zachary Turner | bedc85f | 2017-05-04 23:53:54 +0000 | [diff] [blame] | 629 | P.printNumber("Record count", Tpi->getNumTypeRecords()); |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 630 | |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 631 | std::vector<std::unique_ptr<TypeVisitorCallbacks>> Visitors; |
| 632 | |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 633 | // If we're in dump mode, add a dumper with the appropriate detail level. |
| 634 | if (DumpRecords) { |
| 635 | std::unique_ptr<TypeVisitorCallbacks> Dumper; |
| 636 | if (opts::raw::CompactRecords) |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 637 | Dumper = make_unique<CompactTypeDumpVisitor>(Types, &P); |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 638 | else { |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 639 | assert(TpiTypes); |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 640 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 641 | auto X = make_unique<TypeDumpVisitor>(*TpiTypes, &P, false); |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 642 | if (StreamIdx == StreamIPI) |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 643 | X->setIpiTypes(*IpiTypes); |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 644 | Dumper = std::move(X); |
| 645 | } |
| 646 | Visitors.push_back(std::move(Dumper)); |
| 647 | } |
| 648 | if (DumpRecordBytes) |
| 649 | Visitors.push_back(make_unique<RecordBytesVisitor>(P)); |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 650 | |
| 651 | // We always need to deserialize and add it to the type database. This is |
| 652 | // true if even if we're not dumping anything, because we could need the |
| 653 | // type database for the purposes of dumping symbols. |
Zachary Turner | 44a643c | 2017-01-12 22:28:15 +0000 | [diff] [blame] | 654 | TypeVisitorCallbackPipeline Pipeline; |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 655 | for (const auto &V : Visitors) |
| 656 | Pipeline.addCallbackToPipeline(*V); |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 657 | |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 658 | if (DumpRecords || DumpRecordBytes) |
| 659 | RecordScope = llvm::make_unique<ListScope>(P, "Records"); |
| 660 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 661 | Optional<TypeIndex> I = Types.getFirst(); |
| 662 | do { |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 663 | std::unique_ptr<DictScope> OneRecordScope; |
| 664 | |
| 665 | if ((DumpRecords || DumpRecordBytes) && !opts::raw::CompactRecords) |
| 666 | OneRecordScope = llvm::make_unique<DictScope>(P, ""); |
| 667 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 668 | auto T = Types.getType(*I); |
| 669 | if (auto EC = codeview::visitTypeRecord(T, *I, Pipeline)) |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 670 | return EC; |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 671 | } while (I = Types.getNext(*I)); |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 672 | |
| 673 | if (DumpTpiHash) { |
| 674 | DictScope DD(P, "Hash"); |
Zachary Turner | bedc85f | 2017-05-04 23:53:54 +0000 | [diff] [blame] | 675 | P.printNumber("Number of Hash Buckets", Tpi->getNumHashBuckets()); |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 676 | P.printNumber("Hash Key Size", Tpi->getHashKeySize()); |
| 677 | P.printList("Values", Tpi->getHashValues()); |
| 678 | |
| 679 | ListScope LHA(P, "Adjusters"); |
| 680 | auto ExpectedST = File.getStringTable(); |
| 681 | if (!ExpectedST) |
| 682 | return ExpectedST.takeError(); |
| 683 | const auto &ST = *ExpectedST; |
| 684 | for (const auto &E : Tpi->getHashAdjusters()) { |
| 685 | DictScope DHA(P); |
Zachary Turner | 2d5c2cd | 2017-05-03 17:11:11 +0000 | [diff] [blame] | 686 | auto Name = ST.getStringForID(E.first); |
| 687 | if (!Name) |
| 688 | return Name.takeError(); |
| 689 | |
| 690 | P.printString("Type", *Name); |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 691 | P.printHex("TI", E.second); |
| 692 | } |
| 693 | } |
| 694 | |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 695 | ListScope L(P, "TypeIndexOffsets"); |
| 696 | for (const auto &IO : Tpi->getTypeIndexOffsets()) { |
| 697 | P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(), |
| 698 | (uint32_t)IO.Offset) |
| 699 | .str()); |
Zachary Turner | 29da5db | 2017-01-25 21:17:40 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 702 | P.flush(); |
| 703 | return Error::success(); |
| 704 | } |
| 705 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 706 | Expected<codeview::LazyRandomTypeCollection &> |
| 707 | LLVMOutputStyle::initializeTypeDatabase(uint32_t SN) { |
| 708 | auto &TypeCollection = (SN == StreamTPI) ? TpiTypes : IpiTypes; |
Zachary Turner | bedc85f | 2017-05-04 23:53:54 +0000 | [diff] [blame] | 709 | auto Tpi = |
| 710 | (SN == StreamTPI) ? File.getPDBTpiStream() : File.getPDBIpiStream(); |
Zachary Turner | bedc85f | 2017-05-04 23:53:54 +0000 | [diff] [blame] | 711 | if (!Tpi) |
| 712 | return Tpi.takeError(); |
| 713 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 714 | if (!TypeCollection) { |
| 715 | // Initialize the type collection, even if we're not going to dump it. This |
| 716 | // way if some other part of the dumper decides it wants to use some or all |
| 717 | // of the records for whatever purposes, it can still access them lazily. |
| 718 | auto &Types = Tpi->typeArray(); |
| 719 | uint32_t Count = Tpi->getNumTypeRecords(); |
| 720 | auto Offsets = Tpi->getTypeIndexOffsets(); |
| 721 | TypeCollection = |
| 722 | llvm::make_unique<LazyRandomTypeCollection>(Types, Count, Offsets); |
| 723 | } |
Zachary Turner | 8c74673 | 2017-05-05 22:02:37 +0000 | [diff] [blame] | 724 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 725 | return *TypeCollection; |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 728 | Error LLVMOutputStyle::dumpDbiStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 729 | bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms || |
| 730 | opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo; |
| 731 | if (!opts::raw::DumpHeaders && !DumpModules) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 732 | return Error::success(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 733 | if (!File.hasPDBDbiStream()) { |
| 734 | P.printString("DBI Stream not present"); |
| 735 | return Error::success(); |
| 736 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 737 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 738 | auto DS = File.getPDBDbiStream(); |
| 739 | if (!DS) |
| 740 | return DS.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 741 | |
| 742 | DictScope D(P, "DBI Stream"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 743 | P.printNumber("Dbi Version", DS->getDbiVersion()); |
| 744 | P.printNumber("Age", DS->getAge()); |
| 745 | P.printBoolean("Incremental Linking", DS->isIncrementallyLinked()); |
| 746 | P.printBoolean("Has CTypes", DS->hasCTypes()); |
| 747 | P.printBoolean("Is Stripped", DS->isStripped()); |
| 748 | P.printObject("Machine Type", DS->getMachineType()); |
| 749 | P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex()); |
| 750 | P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex()); |
| 751 | P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 752 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 753 | uint16_t Major = DS->getBuildMajorVersion(); |
| 754 | uint16_t Minor = DS->getBuildMinorVersion(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 755 | P.printVersion("Toolchain Version", Major, Minor); |
| 756 | |
| 757 | std::string DllName; |
| 758 | raw_string_ostream DllStream(DllName); |
| 759 | DllStream << "mspdb" << Major << Minor << ".dll version"; |
| 760 | DllStream.flush(); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 761 | P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 762 | |
| 763 | if (DumpModules) { |
| 764 | ListScope L(P, "Modules"); |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 765 | const DbiModuleList &Modules = DS->modules(); |
| 766 | for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) { |
| 767 | const DbiModuleDescriptor &Modi = Modules.getModuleDescriptor(I); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 768 | DictScope DD(P); |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 769 | P.printString("Name", Modi.getModuleName().str()); |
| 770 | P.printNumber("Debug Stream Index", Modi.getModuleStreamIndex()); |
| 771 | P.printString("Object File Name", Modi.getObjFileName().str()); |
| 772 | P.printNumber("Num Files", Modi.getNumberOfFiles()); |
| 773 | P.printNumber("Source File Name Idx", Modi.getSourceFileNameIndex()); |
| 774 | P.printNumber("Pdb File Name Idx", Modi.getPdbFilePathNameIndex()); |
| 775 | P.printNumber("Line Info Byte Size", Modi.getC11LineInfoByteSize()); |
| 776 | P.printNumber("C13 Line Info Byte Size", Modi.getC13LineInfoByteSize()); |
| 777 | P.printNumber("Symbol Byte Size", Modi.getSymbolDebugInfoByteSize()); |
| 778 | P.printNumber("Type Server Index", Modi.getTypeServerIndex()); |
| 779 | P.printBoolean("Has EC Info", Modi.hasECInfo()); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 780 | if (opts::raw::DumpModuleFiles) { |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 781 | std::string FileListName = to_string(Modules.getSourceFileCount(I)) + |
| 782 | " Contributing Source Files"; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 783 | ListScope LL(P, FileListName); |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 784 | for (auto File : Modules.source_files(I)) |
| 785 | P.printString(File); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 786 | } |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 787 | bool HasModuleDI = (Modi.getModuleStreamIndex() < File.getNumStreams()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 788 | bool ShouldDumpSymbols = |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 789 | (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes); |
| 790 | if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 791 | auto ModStreamData = MappedBlockStream::createIndexedStream( |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 792 | File.getMsfLayout(), File.getMsfBuffer(), |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 793 | Modi.getModuleStreamIndex()); |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 794 | |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 795 | ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData)); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 796 | if (auto EC = ModS.reload()) |
| 797 | return EC; |
| 798 | |
| 799 | if (ShouldDumpSymbols) { |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 800 | auto ExpectedTypes = initializeTypeDatabase(StreamTPI); |
| 801 | if (!ExpectedTypes) |
| 802 | return ExpectedTypes.takeError(); |
| 803 | auto &Types = *ExpectedTypes; |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 804 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 805 | ListScope SS(P, "Symbols"); |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 806 | codeview::CVSymbolDumper SD(P, Types, nullptr, false); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 807 | bool HadError = false; |
Zachary Turner | 0d84074 | 2016-10-07 21:34:46 +0000 | [diff] [blame] | 808 | for (auto S : ModS.symbols(&HadError)) { |
| 809 | DictScope LL(P, ""); |
| 810 | if (opts::raw::DumpModuleSyms) { |
| 811 | if (auto EC = SD.dump(S)) { |
| 812 | llvm::consumeError(std::move(EC)); |
| 813 | HadError = true; |
| 814 | break; |
| 815 | } |
| 816 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 817 | if (opts::raw::DumpSymRecordBytes) |
Zachary Turner | c67b00c | 2016-09-14 23:00:16 +0000 | [diff] [blame] | 818 | P.printBinaryBlock("Bytes", S.content()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 819 | } |
| 820 | if (HadError) |
| 821 | return make_error<RawError>( |
| 822 | raw_error_code::corrupt_file, |
| 823 | "DBI stream contained corrupt symbol record"); |
| 824 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 825 | if (opts::raw::DumpLineInfo) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 826 | ListScope SS(P, "LineInfo"); |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 827 | auto ExpectedTypes = initializeTypeDatabase(StreamIPI); |
| 828 | if (!ExpectedTypes) |
| 829 | return ExpectedTypes.takeError(); |
| 830 | auto &IpiItems = *ExpectedTypes; |
| 831 | C13RawVisitor V(P, File, IpiItems); |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 832 | if (auto EC = codeview::visitModuleDebugFragments( |
| 833 | ModS.linesAndChecksums(), V)) |
| 834 | return EC; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | return Error::success(); |
| 840 | } |
| 841 | |
| 842 | Error LLVMOutputStyle::dumpSectionContribs() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 843 | if (!opts::raw::DumpSectionContribs) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 844 | return Error::success(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 845 | if (!File.hasPDBDbiStream()) { |
| 846 | P.printString("DBI Stream not present"); |
| 847 | return Error::success(); |
| 848 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 849 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 850 | auto Dbi = File.getPDBDbiStream(); |
| 851 | if (!Dbi) |
| 852 | return Dbi.takeError(); |
| 853 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 854 | ListScope L(P, "Section Contributions"); |
| 855 | class Visitor : public ISectionContribVisitor { |
| 856 | public: |
| 857 | Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {} |
| 858 | void visit(const SectionContrib &SC) override { |
| 859 | DictScope D(P, "Contribution"); |
| 860 | P.printNumber("ISect", SC.ISect); |
| 861 | P.printNumber("Off", SC.Off); |
| 862 | P.printNumber("Size", SC.Size); |
| 863 | P.printFlags("Characteristics", SC.Characteristics, |
| 864 | codeview::getImageSectionCharacteristicNames(), |
| 865 | COFF::SectionCharacteristics(0x00F00000)); |
| 866 | { |
| 867 | DictScope DD(P, "Module"); |
| 868 | P.printNumber("Index", SC.Imod); |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 869 | const DbiModuleList &Modules = DS.modules(); |
| 870 | if (Modules.getModuleCount() > SC.Imod) { |
| 871 | P.printString("Name", |
| 872 | Modules.getModuleDescriptor(SC.Imod).getModuleName()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | P.printNumber("Data CRC", SC.DataCrc); |
| 876 | P.printNumber("Reloc CRC", SC.RelocCrc); |
| 877 | P.flush(); |
| 878 | } |
| 879 | void visit(const SectionContrib2 &SC) override { |
| 880 | visit(SC.Base); |
| 881 | P.printNumber("ISect Coff", SC.ISectCoff); |
| 882 | P.flush(); |
| 883 | } |
| 884 | |
| 885 | private: |
| 886 | ScopedPrinter &P; |
| 887 | DbiStream &DS; |
| 888 | }; |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 889 | Visitor V(P, *Dbi); |
| 890 | Dbi->visitSectionContributions(V); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 891 | return Error::success(); |
| 892 | } |
| 893 | |
| 894 | Error LLVMOutputStyle::dumpSectionMap() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 895 | if (!opts::raw::DumpSectionMap) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 896 | return Error::success(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 897 | if (!File.hasPDBDbiStream()) { |
| 898 | P.printString("DBI Stream not present"); |
| 899 | return Error::success(); |
| 900 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 901 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 902 | auto Dbi = File.getPDBDbiStream(); |
| 903 | if (!Dbi) |
| 904 | return Dbi.takeError(); |
| 905 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 906 | ListScope L(P, "Section Map"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 907 | for (auto &M : Dbi->getSectionMap()) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 908 | DictScope D(P, "Entry"); |
| 909 | P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 910 | P.printNumber("Ovl", M.Ovl); |
| 911 | P.printNumber("Group", M.Group); |
| 912 | P.printNumber("Frame", M.Frame); |
| 913 | P.printNumber("SecName", M.SecName); |
| 914 | P.printNumber("ClassName", M.ClassName); |
| 915 | P.printNumber("Offset", M.Offset); |
| 916 | P.printNumber("SecByteLength", M.SecByteLength); |
| 917 | P.flush(); |
| 918 | } |
| 919 | return Error::success(); |
| 920 | } |
| 921 | |
| 922 | Error LLVMOutputStyle::dumpPublicsStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 923 | if (!opts::raw::DumpPublics) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 924 | return Error::success(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 925 | if (!File.hasPDBPublicsStream()) { |
| 926 | P.printString("Publics Stream not present"); |
| 927 | return Error::success(); |
| 928 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 929 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 930 | auto Publics = File.getPDBPublicsStream(); |
| 931 | if (!Publics) |
| 932 | return Publics.takeError(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 933 | DictScope D(P, "Publics Stream"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 934 | |
| 935 | auto Dbi = File.getPDBDbiStream(); |
| 936 | if (!Dbi) |
| 937 | return Dbi.takeError(); |
| 938 | |
| 939 | P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex()); |
| 940 | P.printNumber("SymHash", Publics->getSymHash()); |
| 941 | P.printNumber("AddrMap", Publics->getAddrMap()); |
| 942 | P.printNumber("Number of buckets", Publics->getNumBuckets()); |
| 943 | P.printList("Hash Buckets", Publics->getHashBuckets()); |
| 944 | P.printList("Address Map", Publics->getAddressMap()); |
| 945 | P.printList("Thunk Map", Publics->getThunkMap()); |
| 946 | P.printList("Section Offsets", Publics->getSectionOffsets(), |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 947 | printSectionOffset); |
| 948 | ListScope L(P, "Symbols"); |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 949 | auto ExpectedTypes = initializeTypeDatabase(StreamTPI); |
| 950 | if (!ExpectedTypes) |
| 951 | return ExpectedTypes.takeError(); |
| 952 | auto &Tpi = *ExpectedTypes; |
Zachary Turner | 20d773c | 2017-05-04 23:53:01 +0000 | [diff] [blame] | 953 | |
Zachary Turner | 0c60f26 | 2017-05-18 23:03:06 +0000 | [diff] [blame^] | 954 | codeview::CVSymbolDumper SD(P, Tpi, nullptr, false); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 955 | bool HadError = false; |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 956 | for (auto S : Publics->getSymbols(&HadError)) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 957 | DictScope DD(P, ""); |
| 958 | |
Zachary Turner | 0d84074 | 2016-10-07 21:34:46 +0000 | [diff] [blame] | 959 | if (auto EC = SD.dump(S)) { |
| 960 | HadError = true; |
| 961 | break; |
| 962 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 963 | if (opts::raw::DumpSymRecordBytes) |
Zachary Turner | c67b00c | 2016-09-14 23:00:16 +0000 | [diff] [blame] | 964 | P.printBinaryBlock("Bytes", S.content()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 965 | } |
| 966 | if (HadError) |
| 967 | return make_error<RawError>( |
| 968 | raw_error_code::corrupt_file, |
| 969 | "Public symbol stream contained corrupt record"); |
| 970 | |
| 971 | return Error::success(); |
| 972 | } |
| 973 | |
| 974 | Error LLVMOutputStyle::dumpSectionHeaders() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 975 | if (!opts::raw::DumpSectionHeaders) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 976 | return Error::success(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 977 | if (!File.hasPDBDbiStream()) { |
| 978 | P.printString("DBI Stream not present"); |
| 979 | return Error::success(); |
| 980 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 981 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 982 | auto Dbi = File.getPDBDbiStream(); |
| 983 | if (!Dbi) |
| 984 | return Dbi.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 985 | |
| 986 | ListScope D(P, "Section Headers"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 987 | for (const object::coff_section &Section : Dbi->getSectionHeaders()) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 988 | DictScope DD(P, ""); |
| 989 | |
| 990 | // If a name is 8 characters long, there is no NUL character at end. |
| 991 | StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name))); |
| 992 | P.printString("Name", Name); |
| 993 | P.printNumber("Virtual Size", Section.VirtualSize); |
| 994 | P.printNumber("Virtual Address", Section.VirtualAddress); |
| 995 | P.printNumber("Size of Raw Data", Section.SizeOfRawData); |
| 996 | P.printNumber("File Pointer to Raw Data", Section.PointerToRawData); |
| 997 | P.printNumber("File Pointer to Relocations", Section.PointerToRelocations); |
| 998 | P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers); |
| 999 | P.printNumber("Number of Relocations", Section.NumberOfRelocations); |
| 1000 | P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers); |
Rui Ueyama | 2c5384a | 2016-06-06 21:34:55 +0000 | [diff] [blame] | 1001 | P.printFlags("Characteristics", Section.Characteristics, |
| 1002 | getImageSectionCharacteristicNames()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 1003 | } |
| 1004 | return Error::success(); |
| 1005 | } |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 1006 | |
| 1007 | Error LLVMOutputStyle::dumpFpoStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 1008 | if (!opts::raw::DumpFpo) |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 1009 | return Error::success(); |
Bob Haarman | a5b4358 | 2016-12-05 22:44:00 +0000 | [diff] [blame] | 1010 | if (!File.hasPDBDbiStream()) { |
| 1011 | P.printString("DBI Stream not present"); |
| 1012 | return Error::success(); |
| 1013 | } |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 1014 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 1015 | auto Dbi = File.getPDBDbiStream(); |
| 1016 | if (!Dbi) |
| 1017 | return Dbi.takeError(); |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 1018 | |
| 1019 | ListScope D(P, "New FPO"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 1020 | for (const object::FpoData &Fpo : Dbi->getFpoRecords()) { |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 1021 | DictScope DD(P, ""); |
| 1022 | P.printNumber("Offset", Fpo.Offset); |
| 1023 | P.printNumber("Size", Fpo.Size); |
| 1024 | P.printNumber("Number of locals", Fpo.NumLocals); |
| 1025 | P.printNumber("Number of params", Fpo.NumParams); |
| 1026 | P.printNumber("Size of Prolog", Fpo.getPrologSize()); |
| 1027 | P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs()); |
| 1028 | P.printBoolean("Has SEH", Fpo.hasSEH()); |
| 1029 | P.printBoolean("Use BP", Fpo.useBP()); |
| 1030 | P.printNumber("Frame Pointer", Fpo.getFP()); |
| 1031 | } |
| 1032 | return Error::success(); |
| 1033 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 1034 | |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 1035 | void LLVMOutputStyle::flush() { P.flush(); } |