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