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