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