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