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