Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 1 | //===-- COFFDumper.cpp - COFF-specific dumper -------------------*- 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 | /// \file |
| 11 | /// \brief This file implements the COFF-specific dumper for llvm-readobj. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm-readobj.h" |
Rafael Espindola | a6e9c3e | 2014-06-12 17:38:55 +0000 | [diff] [blame] | 16 | #include "ARMWinEHPrinter.h" |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 17 | #include "CodeView.h" |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 18 | #include "Error.h" |
Chandler Carruth | 07baed5 | 2014-01-13 08:04:33 +0000 | [diff] [blame] | 19 | #include "ObjDumper.h" |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 20 | #include "StackMapPrinter.h" |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 21 | #include "StreamWriter.h" |
Saleem Abdulrasool | e8839a7 | 2014-05-25 20:26:45 +0000 | [diff] [blame] | 22 | #include "Win64EHDumper.h" |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/DenseMap.h" |
| 24 | #include "llvm/ADT/SmallString.h" |
Colin LeMahieu | 9fbffee | 2014-11-19 17:10:39 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringSet.h" |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 27 | #include "llvm/DebugInfo/CodeView/CodeView.h" |
Reid Kleckner | e9ab349 | 2016-01-14 19:20:17 +0000 | [diff] [blame] | 28 | #include "llvm/DebugInfo/CodeView/Line.h" |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 29 | #include "llvm/DebugInfo/CodeView/TypeIndex.h" |
| 30 | #include "llvm/DebugInfo/CodeView/TypeRecord.h" |
| 31 | #include "llvm/DebugInfo/CodeView/SymbolRecord.h" |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 32 | #include "llvm/Object/COFF.h" |
| 33 | #include "llvm/Object/ObjectFile.h" |
Chandler Carruth | 07baed5 | 2014-01-13 08:04:33 +0000 | [diff] [blame] | 34 | #include "llvm/Support/COFF.h" |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 35 | #include "llvm/Support/Casting.h" |
| 36 | #include "llvm/Support/Compiler.h" |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 37 | #include "llvm/Support/DataExtractor.h" |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Format.h" |
| 39 | #include "llvm/Support/SourceMgr.h" |
| 40 | #include "llvm/Support/Win64EH.h" |
| 41 | #include "llvm/Support/raw_ostream.h" |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 42 | #include <algorithm> |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 43 | #include <cstring> |
Rafael Espindola | a6e9c3e | 2014-06-12 17:38:55 +0000 | [diff] [blame] | 44 | #include <system_error> |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 45 | #include <time.h> |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 46 | |
| 47 | using namespace llvm; |
| 48 | using namespace llvm::object; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 49 | using namespace llvm::codeview; |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 50 | using namespace llvm::support; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 51 | using namespace llvm::Win64EH; |
| 52 | |
| 53 | namespace { |
| 54 | |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 55 | class CVTypeDumper { |
| 56 | public: |
| 57 | CVTypeDumper(StreamWriter &W) : W(W) {} |
| 58 | |
| 59 | StringRef getTypeName(TypeIndex TI); |
| 60 | void printTypeIndex(StringRef FieldName, TypeIndex TI); |
| 61 | |
| 62 | void dump(StringRef Data); |
| 63 | |
| 64 | private: |
| 65 | void printCodeViewFieldList(StringRef FieldData); |
| 66 | void printMemberAttributes(MemberAttributes Attrs); |
| 67 | |
| 68 | StreamWriter &W; |
| 69 | |
| 70 | /// All user defined type records in .debug$T live in here. Type indices |
| 71 | /// greater than 0x1000 are user defined. Subtract 0x1000 from the index to |
| 72 | /// index into this vector. |
| 73 | SmallVector<StringRef, 10> CVUDTNames; |
| 74 | |
| 75 | StringSet<> TypeNames; |
| 76 | }; |
| 77 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 78 | class COFFDumper : public ObjDumper { |
| 79 | public: |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 80 | COFFDumper(const llvm::object::COFFObjectFile *Obj, StreamWriter &Writer) |
| 81 | : ObjDumper(Writer), Obj(Obj), CVTD(Writer) {} |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 82 | |
Craig Topper | fd38cbe | 2014-08-30 16:48:34 +0000 | [diff] [blame] | 83 | void printFileHeaders() override; |
| 84 | void printSections() override; |
| 85 | void printRelocations() override; |
| 86 | void printSymbols() override; |
| 87 | void printDynamicSymbols() override; |
| 88 | void printUnwindInfo() override; |
Rui Ueyama | 1e152d5 | 2014-10-02 17:02:18 +0000 | [diff] [blame] | 89 | void printCOFFImports() override; |
Saleem Abdulrasool | ddd9264 | 2015-01-03 21:35:09 +0000 | [diff] [blame] | 90 | void printCOFFExports() override; |
Saleem Abdulrasool | f957863 | 2014-10-07 19:37:52 +0000 | [diff] [blame] | 91 | void printCOFFDirectives() override; |
Rui Ueyama | 74e8513 | 2014-11-19 00:18:07 +0000 | [diff] [blame] | 92 | void printCOFFBaseReloc() override; |
Reid Kleckner | 83ebad3 | 2015-12-16 18:28:12 +0000 | [diff] [blame] | 93 | void printCodeViewDebugInfo() override; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 94 | void printStackMap() const override; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 95 | private: |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 96 | void printSymbol(const SymbolRef &Sym); |
Reid Kleckner | 1c7a9cd | 2016-01-14 17:51:57 +0000 | [diff] [blame] | 97 | void printRelocation(const SectionRef &Section, const RelocationRef &Reloc, |
| 98 | uint64_t Bias = 0); |
Rui Ueyama | ed64342b | 2013-07-19 23:23:29 +0000 | [diff] [blame] | 99 | void printDataDirectory(uint32_t Index, const std::string &FieldName); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 100 | |
David Majnemer | 5026722 | 2014-11-05 06:24:35 +0000 | [diff] [blame] | 101 | void printDOSHeader(const dos_header *DH); |
Rui Ueyama | 10ed9dd | 2014-01-26 04:15:52 +0000 | [diff] [blame] | 102 | template <class PEHeader> void printPEHeader(const PEHeader *Hdr); |
| 103 | void printBaseOfDataField(const pe32_header *Hdr); |
| 104 | void printBaseOfDataField(const pe32plus_header *Hdr); |
| 105 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 106 | void printCodeViewSymbolSection(StringRef SectionName, const SectionRef &Section); |
| 107 | void printCodeViewTypeSection(StringRef SectionName, const SectionRef &Section); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 108 | StringRef getTypeName(TypeIndex Ty); |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 109 | StringRef getFileNameForFileOffset(uint32_t FileOffset); |
| 110 | void printFileNameForOffset(StringRef Label, uint32_t FileOffset); |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 111 | void printTypeIndex(StringRef FieldName, TypeIndex TI) { |
| 112 | // Forward to CVTypeDumper for simplicity. |
| 113 | CVTD.printTypeIndex(FieldName, TI); |
| 114 | } |
David Majnemer | d74490f | 2016-02-03 22:45:21 +0000 | [diff] [blame] | 115 | void printLocalVariableAddrRange(const LocalVariableAddrRange &Range, |
| 116 | const coff_section *Sec, |
| 117 | StringRef SectionContents); |
David Majnemer | 4d12351 | 2016-02-04 17:37:30 +0000 | [diff] [blame] | 118 | void printLocalVariableAddrGap(StringRef &SymData); |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 119 | |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 120 | void printCodeViewSymbolsSubsection(StringRef Subsection, |
| 121 | const SectionRef &Section, |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 122 | StringRef SectionContents); |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 123 | |
Reid Kleckner | c31f530 | 2016-01-15 18:06:25 +0000 | [diff] [blame] | 124 | void printCodeViewFileChecksums(StringRef Subsection); |
| 125 | |
Reid Kleckner | e9ab349 | 2016-01-14 19:20:17 +0000 | [diff] [blame] | 126 | void printCodeViewInlineeLines(StringRef Subsection); |
| 127 | |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 128 | void printRelocatedField(StringRef Label, const coff_section *Sec, |
| 129 | StringRef SectionContents, const ulittle32_t *Field, |
| 130 | StringRef *RelocSym = nullptr); |
| 131 | |
Reid Kleckner | 1c7a9cd | 2016-01-14 17:51:57 +0000 | [diff] [blame] | 132 | void printBinaryBlockWithRelocs(StringRef Label, const SectionRef &Sec, |
| 133 | StringRef SectionContents, StringRef Block); |
| 134 | |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 135 | /// Given a .debug$S section, find the string table and file checksum table. |
| 136 | void initializeFileAndStringTables(StringRef Data); |
| 137 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 138 | void cacheRelocations(); |
| 139 | |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 140 | std::error_code resolveSymbol(const coff_section *Section, uint64_t Offset, |
| 141 | SymbolRef &Sym); |
| 142 | std::error_code resolveSymbolName(const coff_section *Section, |
| 143 | uint64_t Offset, StringRef &Name); |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 144 | std::error_code resolveSymbolName(const coff_section *Section, |
| 145 | StringRef SectionContents, |
| 146 | const void *RelocPtr, StringRef &Name); |
Rui Ueyama | 979fb40 | 2014-10-09 02:16:38 +0000 | [diff] [blame] | 147 | void printImportedSymbols(iterator_range<imported_symbol_iterator> Range); |
Rui Ueyama | ffa4ceb | 2014-11-13 03:22:54 +0000 | [diff] [blame] | 148 | void printDelayImportedSymbols( |
| 149 | const DelayImportDirectoryEntryRef &I, |
| 150 | iterator_range<imported_symbol_iterator> Range); |
Rui Ueyama | 15d9935 | 2014-10-03 00:41:58 +0000 | [diff] [blame] | 151 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 152 | typedef DenseMap<const coff_section*, std::vector<RelocationRef> > RelocMapTy; |
| 153 | |
| 154 | const llvm::object::COFFObjectFile *Obj; |
Rafael Espindola | 76d650e | 2015-07-06 14:26:07 +0000 | [diff] [blame] | 155 | bool RelocCached = false; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 156 | RelocMapTy RelocMap; |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 157 | StringRef CVFileChecksumTable; |
Timur Iskhodzhanov | 1160333 | 2014-10-06 16:59:44 +0000 | [diff] [blame] | 158 | StringRef CVStringTable; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 159 | |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 160 | CVTypeDumper CVTD; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 163 | } // namespace |
| 164 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 165 | |
| 166 | namespace llvm { |
| 167 | |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 168 | std::error_code createCOFFDumper(const object::ObjectFile *Obj, |
| 169 | StreamWriter &Writer, |
| 170 | std::unique_ptr<ObjDumper> &Result) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 171 | const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(Obj); |
| 172 | if (!COFFObj) |
| 173 | return readobj_error::unsupported_obj_file_format; |
| 174 | |
| 175 | Result.reset(new COFFDumper(COFFObj, Writer)); |
| 176 | return readobj_error::success; |
| 177 | } |
| 178 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 179 | } // namespace llvm |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 180 | |
Saleem Abdulrasool | 5dd27f4 | 2014-05-25 20:26:37 +0000 | [diff] [blame] | 181 | // Given a a section and an offset into this section the function returns the |
| 182 | // symbol used for the relocation at the offset. |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 183 | std::error_code COFFDumper::resolveSymbol(const coff_section *Section, |
| 184 | uint64_t Offset, SymbolRef &Sym) { |
Rafael Espindola | 76d650e | 2015-07-06 14:26:07 +0000 | [diff] [blame] | 185 | cacheRelocations(); |
Saleem Abdulrasool | 5dd27f4 | 2014-05-25 20:26:37 +0000 | [diff] [blame] | 186 | const auto &Relocations = RelocMap[Section]; |
| 187 | for (const auto &Relocation : Relocations) { |
Rafael Espindola | 96d071c | 2015-06-29 23:29:12 +0000 | [diff] [blame] | 188 | uint64_t RelocationOffset = Relocation.getOffset(); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 189 | |
Saleem Abdulrasool | 5dd27f4 | 2014-05-25 20:26:37 +0000 | [diff] [blame] | 190 | if (RelocationOffset == Offset) { |
Saleem Abdulrasool | 4a6f583 | 2014-05-20 05:18:06 +0000 | [diff] [blame] | 191 | Sym = *Relocation.getSymbol(); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 192 | return readobj_error::success; |
| 193 | } |
| 194 | } |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 195 | return readobj_error::unknown_symbol; |
| 196 | } |
| 197 | |
Saleem Abdulrasool | 5dd27f4 | 2014-05-25 20:26:37 +0000 | [diff] [blame] | 198 | // Given a section and an offset into this section the function returns the name |
| 199 | // of the symbol used for the relocation at the offset. |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 200 | std::error_code COFFDumper::resolveSymbolName(const coff_section *Section, |
| 201 | uint64_t Offset, |
| 202 | StringRef &Name) { |
Saleem Abdulrasool | 5dd27f4 | 2014-05-25 20:26:37 +0000 | [diff] [blame] | 203 | SymbolRef Symbol; |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 204 | if (std::error_code EC = resolveSymbol(Section, Offset, Symbol)) |
Saleem Abdulrasool | 5dd27f4 | 2014-05-25 20:26:37 +0000 | [diff] [blame] | 205 | return EC; |
Kevin Enderby | 81e8b7d | 2016-04-20 21:24:34 +0000 | [diff] [blame] | 206 | Expected<StringRef> NameOrErr = Symbol.getName(); |
| 207 | if (!NameOrErr) |
| 208 | return errorToErrorCode(NameOrErr.takeError()); |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 209 | Name = *NameOrErr; |
Rui Ueyama | 7d09919 | 2015-06-09 15:20:42 +0000 | [diff] [blame] | 210 | return std::error_code(); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 213 | // Helper for when you have a pointer to real data and you want to know about |
| 214 | // relocations against it. |
| 215 | std::error_code COFFDumper::resolveSymbolName(const coff_section *Section, |
| 216 | StringRef SectionContents, |
| 217 | const void *RelocPtr, |
| 218 | StringRef &Name) { |
| 219 | assert(SectionContents.data() < RelocPtr && |
| 220 | RelocPtr < SectionContents.data() + SectionContents.size() && |
| 221 | "pointer to relocated object is not in section"); |
| 222 | uint64_t Offset = ptrdiff_t(reinterpret_cast<const char *>(RelocPtr) - |
| 223 | SectionContents.data()); |
| 224 | return resolveSymbolName(Section, Offset, Name); |
| 225 | } |
| 226 | |
| 227 | void COFFDumper::printRelocatedField(StringRef Label, const coff_section *Sec, |
| 228 | StringRef SectionContents, |
| 229 | const ulittle32_t *Field, |
| 230 | StringRef *RelocSym) { |
| 231 | StringRef SymStorage; |
| 232 | StringRef &Symbol = RelocSym ? *RelocSym : SymStorage; |
| 233 | if (!resolveSymbolName(Sec, SectionContents, Field, Symbol)) |
| 234 | W.printSymbolOffset(Label, Symbol, *Field); |
| 235 | else |
| 236 | W.printHex(Label, *Field); |
| 237 | } |
| 238 | |
Reid Kleckner | 1c7a9cd | 2016-01-14 17:51:57 +0000 | [diff] [blame] | 239 | void COFFDumper::printBinaryBlockWithRelocs(StringRef Label, |
| 240 | const SectionRef &Sec, |
| 241 | StringRef SectionContents, |
| 242 | StringRef Block) { |
| 243 | W.printBinaryBlock(Label, Block); |
| 244 | |
| 245 | assert(SectionContents.begin() < Block.begin() && |
| 246 | SectionContents.end() >= Block.end() && |
| 247 | "Block is not contained in SectionContents"); |
| 248 | uint64_t OffsetStart = Block.data() - SectionContents.data(); |
| 249 | uint64_t OffsetEnd = OffsetStart + Block.size(); |
| 250 | |
| 251 | cacheRelocations(); |
| 252 | ListScope D(W, "BlockRelocations"); |
| 253 | const coff_section *Section = Obj->getCOFFSection(Sec); |
| 254 | const auto &Relocations = RelocMap[Section]; |
| 255 | for (const auto &Relocation : Relocations) { |
| 256 | uint64_t RelocationOffset = Relocation.getOffset(); |
| 257 | if (OffsetStart <= RelocationOffset && RelocationOffset < OffsetEnd) |
| 258 | printRelocation(Sec, Relocation, OffsetStart); |
| 259 | } |
| 260 | } |
| 261 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 262 | static const EnumEntry<COFF::MachineTypes> ImageFileMachineType[] = { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 263 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_UNKNOWN ), |
| 264 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_AM33 ), |
| 265 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_AMD64 ), |
| 266 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_ARM ), |
Saleem Abdulrasool | 5e1780e | 2014-03-11 03:08:37 +0000 | [diff] [blame] | 267 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_ARMNT ), |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 268 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_EBC ), |
| 269 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_I386 ), |
| 270 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_IA64 ), |
| 271 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_M32R ), |
| 272 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_MIPS16 ), |
| 273 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_MIPSFPU ), |
| 274 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_MIPSFPU16), |
| 275 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_POWERPC ), |
| 276 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_POWERPCFP), |
| 277 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_R4000 ), |
| 278 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_SH3 ), |
| 279 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_SH3DSP ), |
| 280 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_SH4 ), |
| 281 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_SH5 ), |
| 282 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_THUMB ), |
| 283 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_WCEMIPSV2) |
| 284 | }; |
| 285 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 286 | static const EnumEntry<COFF::Characteristics> ImageFileCharacteristics[] = { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 287 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_RELOCS_STRIPPED ), |
| 288 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_EXECUTABLE_IMAGE ), |
| 289 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_LINE_NUMS_STRIPPED ), |
| 290 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_LOCAL_SYMS_STRIPPED ), |
| 291 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_AGGRESSIVE_WS_TRIM ), |
| 292 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_LARGE_ADDRESS_AWARE ), |
| 293 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_BYTES_REVERSED_LO ), |
| 294 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_32BIT_MACHINE ), |
| 295 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_DEBUG_STRIPPED ), |
| 296 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP), |
| 297 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_NET_RUN_FROM_SWAP ), |
| 298 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_SYSTEM ), |
| 299 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_DLL ), |
| 300 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_UP_SYSTEM_ONLY ), |
| 301 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_BYTES_REVERSED_HI ) |
| 302 | }; |
| 303 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 304 | static const EnumEntry<COFF::WindowsSubsystem> PEWindowsSubsystem[] = { |
Rui Ueyama | 82ebd8e | 2013-06-12 19:10:33 +0000 | [diff] [blame] | 305 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_UNKNOWN ), |
| 306 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_NATIVE ), |
| 307 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_WINDOWS_GUI ), |
| 308 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_WINDOWS_CUI ), |
| 309 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_POSIX_CUI ), |
| 310 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_WINDOWS_CE_GUI ), |
| 311 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_EFI_APPLICATION ), |
| 312 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER), |
| 313 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER ), |
| 314 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_EFI_ROM ), |
| 315 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_XBOX ), |
| 316 | }; |
| 317 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 318 | static const EnumEntry<COFF::DLLCharacteristics> PEDLLCharacteristics[] = { |
Rui Ueyama | 06dc5e7 | 2014-01-27 04:22:24 +0000 | [diff] [blame] | 319 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA ), |
Rui Ueyama | 82ebd8e | 2013-06-12 19:10:33 +0000 | [diff] [blame] | 320 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE ), |
| 321 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY ), |
| 322 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT ), |
| 323 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION ), |
| 324 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_NO_SEH ), |
| 325 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_NO_BIND ), |
Saleem Abdulrasool | d90f86d | 2014-06-27 03:11:18 +0000 | [diff] [blame] | 326 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_APPCONTAINER ), |
Rui Ueyama | 82ebd8e | 2013-06-12 19:10:33 +0000 | [diff] [blame] | 327 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER ), |
Saleem Abdulrasool | d90f86d | 2014-06-27 03:11:18 +0000 | [diff] [blame] | 328 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_GUARD_CF ), |
Rui Ueyama | 82ebd8e | 2013-06-12 19:10:33 +0000 | [diff] [blame] | 329 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE), |
| 330 | }; |
| 331 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 332 | static const EnumEntry<COFF::SectionCharacteristics> |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 333 | ImageSectionCharacteristics[] = { |
David Majnemer | d323888 | 2015-07-30 16:47:56 +0000 | [diff] [blame] | 334 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NOLOAD ), |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 335 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NO_PAD ), |
| 336 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_CNT_CODE ), |
| 337 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_CNT_INITIALIZED_DATA ), |
| 338 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_CNT_UNINITIALIZED_DATA), |
| 339 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_OTHER ), |
| 340 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_INFO ), |
| 341 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_REMOVE ), |
| 342 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_COMDAT ), |
| 343 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_GPREL ), |
| 344 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_PURGEABLE ), |
| 345 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_16BIT ), |
| 346 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_LOCKED ), |
| 347 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_PRELOAD ), |
| 348 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_1BYTES ), |
| 349 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_2BYTES ), |
| 350 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_4BYTES ), |
| 351 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_8BYTES ), |
| 352 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_16BYTES ), |
| 353 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_32BYTES ), |
| 354 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_64BYTES ), |
| 355 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_128BYTES ), |
| 356 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_256BYTES ), |
| 357 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_512BYTES ), |
| 358 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_1024BYTES ), |
| 359 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_2048BYTES ), |
| 360 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_4096BYTES ), |
| 361 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_8192BYTES ), |
| 362 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_LNK_NRELOC_OVFL ), |
| 363 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_DISCARDABLE ), |
| 364 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_NOT_CACHED ), |
| 365 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_NOT_PAGED ), |
| 366 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_SHARED ), |
| 367 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_EXECUTE ), |
| 368 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_READ ), |
| 369 | LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_WRITE ) |
| 370 | }; |
| 371 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 372 | static const EnumEntry<COFF::SymbolBaseType> ImageSymType[] = { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 373 | { "Null" , COFF::IMAGE_SYM_TYPE_NULL }, |
| 374 | { "Void" , COFF::IMAGE_SYM_TYPE_VOID }, |
| 375 | { "Char" , COFF::IMAGE_SYM_TYPE_CHAR }, |
| 376 | { "Short" , COFF::IMAGE_SYM_TYPE_SHORT }, |
| 377 | { "Int" , COFF::IMAGE_SYM_TYPE_INT }, |
| 378 | { "Long" , COFF::IMAGE_SYM_TYPE_LONG }, |
| 379 | { "Float" , COFF::IMAGE_SYM_TYPE_FLOAT }, |
| 380 | { "Double", COFF::IMAGE_SYM_TYPE_DOUBLE }, |
| 381 | { "Struct", COFF::IMAGE_SYM_TYPE_STRUCT }, |
| 382 | { "Union" , COFF::IMAGE_SYM_TYPE_UNION }, |
| 383 | { "Enum" , COFF::IMAGE_SYM_TYPE_ENUM }, |
| 384 | { "MOE" , COFF::IMAGE_SYM_TYPE_MOE }, |
| 385 | { "Byte" , COFF::IMAGE_SYM_TYPE_BYTE }, |
| 386 | { "Word" , COFF::IMAGE_SYM_TYPE_WORD }, |
| 387 | { "UInt" , COFF::IMAGE_SYM_TYPE_UINT }, |
| 388 | { "DWord" , COFF::IMAGE_SYM_TYPE_DWORD } |
| 389 | }; |
| 390 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 391 | static const EnumEntry<COFF::SymbolComplexType> ImageSymDType[] = { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 392 | { "Null" , COFF::IMAGE_SYM_DTYPE_NULL }, |
| 393 | { "Pointer" , COFF::IMAGE_SYM_DTYPE_POINTER }, |
| 394 | { "Function", COFF::IMAGE_SYM_DTYPE_FUNCTION }, |
| 395 | { "Array" , COFF::IMAGE_SYM_DTYPE_ARRAY } |
| 396 | }; |
| 397 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 398 | static const EnumEntry<COFF::SymbolStorageClass> ImageSymClass[] = { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 399 | { "EndOfFunction" , COFF::IMAGE_SYM_CLASS_END_OF_FUNCTION }, |
| 400 | { "Null" , COFF::IMAGE_SYM_CLASS_NULL }, |
| 401 | { "Automatic" , COFF::IMAGE_SYM_CLASS_AUTOMATIC }, |
| 402 | { "External" , COFF::IMAGE_SYM_CLASS_EXTERNAL }, |
| 403 | { "Static" , COFF::IMAGE_SYM_CLASS_STATIC }, |
| 404 | { "Register" , COFF::IMAGE_SYM_CLASS_REGISTER }, |
| 405 | { "ExternalDef" , COFF::IMAGE_SYM_CLASS_EXTERNAL_DEF }, |
| 406 | { "Label" , COFF::IMAGE_SYM_CLASS_LABEL }, |
| 407 | { "UndefinedLabel" , COFF::IMAGE_SYM_CLASS_UNDEFINED_LABEL }, |
| 408 | { "MemberOfStruct" , COFF::IMAGE_SYM_CLASS_MEMBER_OF_STRUCT }, |
| 409 | { "Argument" , COFF::IMAGE_SYM_CLASS_ARGUMENT }, |
| 410 | { "StructTag" , COFF::IMAGE_SYM_CLASS_STRUCT_TAG }, |
| 411 | { "MemberOfUnion" , COFF::IMAGE_SYM_CLASS_MEMBER_OF_UNION }, |
| 412 | { "UnionTag" , COFF::IMAGE_SYM_CLASS_UNION_TAG }, |
| 413 | { "TypeDefinition" , COFF::IMAGE_SYM_CLASS_TYPE_DEFINITION }, |
| 414 | { "UndefinedStatic", COFF::IMAGE_SYM_CLASS_UNDEFINED_STATIC }, |
| 415 | { "EnumTag" , COFF::IMAGE_SYM_CLASS_ENUM_TAG }, |
| 416 | { "MemberOfEnum" , COFF::IMAGE_SYM_CLASS_MEMBER_OF_ENUM }, |
| 417 | { "RegisterParam" , COFF::IMAGE_SYM_CLASS_REGISTER_PARAM }, |
| 418 | { "BitField" , COFF::IMAGE_SYM_CLASS_BIT_FIELD }, |
| 419 | { "Block" , COFF::IMAGE_SYM_CLASS_BLOCK }, |
| 420 | { "Function" , COFF::IMAGE_SYM_CLASS_FUNCTION }, |
| 421 | { "EndOfStruct" , COFF::IMAGE_SYM_CLASS_END_OF_STRUCT }, |
| 422 | { "File" , COFF::IMAGE_SYM_CLASS_FILE }, |
| 423 | { "Section" , COFF::IMAGE_SYM_CLASS_SECTION }, |
| 424 | { "WeakExternal" , COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL }, |
| 425 | { "CLRToken" , COFF::IMAGE_SYM_CLASS_CLR_TOKEN } |
| 426 | }; |
| 427 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 428 | static const EnumEntry<COFF::COMDATType> ImageCOMDATSelect[] = { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 429 | { "NoDuplicates", COFF::IMAGE_COMDAT_SELECT_NODUPLICATES }, |
| 430 | { "Any" , COFF::IMAGE_COMDAT_SELECT_ANY }, |
| 431 | { "SameSize" , COFF::IMAGE_COMDAT_SELECT_SAME_SIZE }, |
| 432 | { "ExactMatch" , COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH }, |
| 433 | { "Associative" , COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE }, |
| 434 | { "Largest" , COFF::IMAGE_COMDAT_SELECT_LARGEST }, |
| 435 | { "Newest" , COFF::IMAGE_COMDAT_SELECT_NEWEST } |
| 436 | }; |
| 437 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 438 | static const EnumEntry<COFF::WeakExternalCharacteristics> |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 439 | WeakExternalCharacteristics[] = { |
| 440 | { "NoLibrary", COFF::IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY }, |
| 441 | { "Library" , COFF::IMAGE_WEAK_EXTERN_SEARCH_LIBRARY }, |
| 442 | { "Alias" , COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS } |
| 443 | }; |
| 444 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 445 | static const EnumEntry<CompileSym3::Flags> CompileSym3Flags[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 446 | LLVM_READOBJ_ENUM_ENT(CompileSym3, EC), |
| 447 | LLVM_READOBJ_ENUM_ENT(CompileSym3, NoDbgInfo), |
| 448 | LLVM_READOBJ_ENUM_ENT(CompileSym3, LTCG), |
| 449 | LLVM_READOBJ_ENUM_ENT(CompileSym3, NoDataAlign), |
| 450 | LLVM_READOBJ_ENUM_ENT(CompileSym3, ManagedPresent), |
| 451 | LLVM_READOBJ_ENUM_ENT(CompileSym3, SecurityChecks), |
| 452 | LLVM_READOBJ_ENUM_ENT(CompileSym3, HotPatch), |
| 453 | LLVM_READOBJ_ENUM_ENT(CompileSym3, CVTCIL), |
| 454 | LLVM_READOBJ_ENUM_ENT(CompileSym3, MSILModule), |
| 455 | LLVM_READOBJ_ENUM_ENT(CompileSym3, Sdl), |
| 456 | LLVM_READOBJ_ENUM_ENT(CompileSym3, PGO), |
| 457 | LLVM_READOBJ_ENUM_ENT(CompileSym3, Exp), |
| 458 | }; |
| 459 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 460 | static const EnumEntry<codeview::SourceLanguage> SourceLanguages[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 461 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, C), |
| 462 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Cpp), |
| 463 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Fortran), |
| 464 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Masm), |
| 465 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Pascal), |
| 466 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Basic), |
| 467 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Cobol), |
| 468 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Link), |
| 469 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Cvtres), |
| 470 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Cvtpgd), |
| 471 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, CSharp), |
| 472 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, VB), |
| 473 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, ILAsm), |
| 474 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, Java), |
| 475 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, JScript), |
| 476 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, MSIL), |
| 477 | LLVM_READOBJ_ENUM_ENT(SourceLanguage, HLSL), |
| 478 | }; |
| 479 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 480 | static const EnumEntry<uint32_t> SubSectionTypes[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 481 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, Symbols), |
| 482 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, Lines), |
| 483 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, StringTable), |
| 484 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, FileChecksums), |
| 485 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, FrameData), |
| 486 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, InlineeLines), |
| 487 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, CrossScopeImports), |
| 488 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, CrossScopeExports), |
| 489 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, ILLines), |
| 490 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, FuncMDTokenMap), |
| 491 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, TypeMDTokenMap), |
| 492 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, MergedAssemblyInput), |
| 493 | LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, CoffSymbolRVA), |
| 494 | }; |
| 495 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 496 | static const EnumEntry<unsigned> CPUTypeNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 497 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel8080), |
| 498 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel8086), |
| 499 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel80286), |
| 500 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel80386), |
| 501 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel80486), |
| 502 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Pentium), |
| 503 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, PentiumPro), |
| 504 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Pentium3), |
| 505 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPS), |
| 506 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPS16), |
| 507 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPS32), |
| 508 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPS64), |
| 509 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPSI), |
| 510 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPSII), |
| 511 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPSIII), |
| 512 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPSIV), |
| 513 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, MIPSV), |
| 514 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, M68000), |
| 515 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, M68010), |
| 516 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, M68020), |
| 517 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, M68030), |
| 518 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, M68040), |
| 519 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Alpha), |
| 520 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Alpha21164), |
| 521 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Alpha21164A), |
| 522 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Alpha21264), |
| 523 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Alpha21364), |
| 524 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, PPC601), |
| 525 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, PPC603), |
| 526 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, PPC604), |
| 527 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, PPC620), |
| 528 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, PPCFP), |
| 529 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, PPCBE), |
| 530 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, SH3), |
| 531 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, SH3E), |
| 532 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, SH3DSP), |
| 533 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, SH4), |
| 534 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, SHMedia), |
| 535 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM3), |
| 536 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM4), |
| 537 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM4T), |
| 538 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM5), |
| 539 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM5T), |
| 540 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM6), |
| 541 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM_XMAC), |
| 542 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM_WMMX), |
| 543 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARM7), |
| 544 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Omni), |
| 545 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Ia64), |
| 546 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Ia64_2), |
| 547 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, CEE), |
| 548 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, AM33), |
| 549 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, M32R), |
| 550 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, TriCore), |
| 551 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, X64), |
| 552 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, EBC), |
| 553 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Thumb), |
| 554 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, ARMNT), |
| 555 | LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, D3D11_Shader), |
| 556 | }; |
| 557 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 558 | static const EnumEntry<uint8_t> ProcSymFlags[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 559 | LLVM_READOBJ_ENUM_ENT(ProcFlags, HasFP), |
| 560 | LLVM_READOBJ_ENUM_ENT(ProcFlags, HasIRET), |
| 561 | LLVM_READOBJ_ENUM_ENT(ProcFlags, HasFRET), |
| 562 | LLVM_READOBJ_ENUM_ENT(ProcFlags, IsNoReturn), |
| 563 | LLVM_READOBJ_ENUM_ENT(ProcFlags, IsUnreachable), |
| 564 | LLVM_READOBJ_ENUM_ENT(ProcFlags, HasCustomCallingConv), |
| 565 | LLVM_READOBJ_ENUM_ENT(ProcFlags, IsNoInline), |
| 566 | LLVM_READOBJ_ENUM_ENT(ProcFlags, HasOptimizedDebugInfo), |
| 567 | }; |
| 568 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 569 | static const EnumEntry<uint32_t> FrameProcSymFlags[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 570 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasAlloca), |
| 571 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasSetJmp), |
| 572 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasLongJmp), |
| 573 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasInlineAssembly), |
| 574 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasExceptionHandling), |
| 575 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, MarkedInline), |
| 576 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, |
| 577 | HasStructuredExceptionHandling), |
| 578 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, Naked), |
| 579 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, SecurityChecks), |
| 580 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, |
| 581 | AsynchronousExceptionHandling), |
| 582 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, |
| 583 | NoStackOrderingForSecurityChecks), |
| 584 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, Inlined), |
| 585 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, StrictSecurityChecks), |
| 586 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, SafeBuffers), |
| 587 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, |
| 588 | ProfileGuidedOptimization), |
| 589 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, ValidProfileCounts), |
| 590 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, OptimizedForSpeed), |
| 591 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, GuardCfg), |
| 592 | LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, GuardCfw), |
| 593 | }; |
| 594 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 595 | static const EnumEntry<uint32_t> FrameDataFlags[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 596 | LLVM_READOBJ_ENUM_ENT(FrameData, HasSEH), |
| 597 | LLVM_READOBJ_ENUM_ENT(FrameData, HasEH), |
| 598 | LLVM_READOBJ_ENUM_ENT(FrameData, IsFunctionStart), |
| 599 | }; |
| 600 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 601 | static const EnumEntry<uint16_t> LocalFlags[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 602 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsParameter), |
| 603 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsAddressTaken), |
| 604 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsCompilerGenerated), |
| 605 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsAggregate), |
| 606 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsAggregated), |
| 607 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsAliased), |
| 608 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsAlias), |
| 609 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsReturnValue), |
| 610 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsOptimizedOut), |
| 611 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsEnregisteredGlobal), |
| 612 | LLVM_READOBJ_ENUM_ENT(LocalSym, IsEnregisteredStatic), |
| 613 | }; |
| 614 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 615 | static const EnumEntry<uint16_t> FrameCookieKinds[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 616 | LLVM_READOBJ_ENUM_ENT(FrameCookieSym, Copy), |
| 617 | LLVM_READOBJ_ENUM_ENT(FrameCookieSym, XorStackPointer), |
| 618 | LLVM_READOBJ_ENUM_ENT(FrameCookieSym, XorFramePointer), |
| 619 | LLVM_READOBJ_ENUM_ENT(FrameCookieSym, XorR13), |
| 620 | }; |
| 621 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 622 | static const EnumEntry<uint16_t> ClassOptionNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 623 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Packed), |
| 624 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasConstructorOrDestructor), |
| 625 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasOverloadedOperator), |
| 626 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Nested), |
| 627 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, ContainsNestedClass), |
| 628 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasOverloadedAssignmentOperator), |
| 629 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasConversionOperator), |
| 630 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, ForwardReference), |
| 631 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Scoped), |
| 632 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasUniqueName), |
| 633 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Sealed), |
| 634 | LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Intrinsic), |
| 635 | }; |
| 636 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 637 | static const EnumEntry<uint8_t> MemberAccessNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 638 | LLVM_READOBJ_ENUM_CLASS_ENT(MemberAccess, None), |
| 639 | LLVM_READOBJ_ENUM_CLASS_ENT(MemberAccess, Private), |
| 640 | LLVM_READOBJ_ENUM_CLASS_ENT(MemberAccess, Protected), |
| 641 | LLVM_READOBJ_ENUM_CLASS_ENT(MemberAccess, Public), |
| 642 | }; |
| 643 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 644 | static const EnumEntry<uint16_t> MethodOptionNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 645 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, Pseudo), |
| 646 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, NoInherit), |
| 647 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, NoConstruct), |
| 648 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, CompilerGenerated), |
| 649 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, Sealed), |
| 650 | }; |
| 651 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 652 | static const EnumEntry<uint16_t> MemberKindNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 653 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Vanilla), |
| 654 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Virtual), |
| 655 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Static), |
| 656 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Friend), |
| 657 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, IntroducingVirtual), |
| 658 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, PureVirtual), |
| 659 | LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, PureIntroducingVirtual), |
| 660 | }; |
| 661 | |
| 662 | /// The names here all end in "*". If the simple type is a pointer type, we |
| 663 | /// return the whole name. Otherwise we lop off the last character in our |
| 664 | /// StringRef. |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 665 | static const EnumEntry<SimpleTypeKind> SimpleTypeNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 666 | {"void*", SimpleTypeKind::Void}, |
| 667 | {"<not translated>*", SimpleTypeKind::NotTranslated}, |
| 668 | {"HRESULT*", SimpleTypeKind::HResult}, |
| 669 | {"signed char*", SimpleTypeKind::SignedCharacter}, |
| 670 | {"unsigned char*", SimpleTypeKind::UnsignedCharacter}, |
| 671 | {"char*", SimpleTypeKind::NarrowCharacter}, |
| 672 | {"wchar_t*", SimpleTypeKind::WideCharacter}, |
Reid Kleckner | f9f1c56 | 2016-04-15 18:26:45 +0000 | [diff] [blame] | 673 | {"char16_t*", SimpleTypeKind::Character16}, |
| 674 | {"char32_t*", SimpleTypeKind::Character32}, |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 675 | {"__int8*", SimpleTypeKind::SByte}, |
| 676 | {"unsigned __int8*", SimpleTypeKind::Byte}, |
| 677 | {"short*", SimpleTypeKind::Int16Short}, |
| 678 | {"unsigned short*", SimpleTypeKind::UInt16Short}, |
| 679 | {"__int16*", SimpleTypeKind::Int16}, |
| 680 | {"unsigned __int16*", SimpleTypeKind::UInt16}, |
| 681 | {"long*", SimpleTypeKind::Int32Long}, |
| 682 | {"unsigned long*", SimpleTypeKind::UInt32Long}, |
| 683 | {"int*", SimpleTypeKind::Int32}, |
| 684 | {"unsigned*", SimpleTypeKind::UInt32}, |
| 685 | {"__int64*", SimpleTypeKind::Int64Quad}, |
| 686 | {"unsigned __int64*", SimpleTypeKind::UInt64Quad}, |
| 687 | {"__int64*", SimpleTypeKind::Int64}, |
| 688 | {"unsigned __int64*", SimpleTypeKind::UInt64}, |
| 689 | {"__int128*", SimpleTypeKind::Int128}, |
| 690 | {"unsigned __int128*", SimpleTypeKind::UInt128}, |
| 691 | {"__half*", SimpleTypeKind::Float16}, |
| 692 | {"float*", SimpleTypeKind::Float32}, |
| 693 | {"float*", SimpleTypeKind::Float32PartialPrecision}, |
| 694 | {"__float48*", SimpleTypeKind::Float48}, |
| 695 | {"double*", SimpleTypeKind::Float64}, |
| 696 | {"long double*", SimpleTypeKind::Float80}, |
| 697 | {"__float128*", SimpleTypeKind::Float128}, |
| 698 | {"_Complex float*", SimpleTypeKind::Complex32}, |
| 699 | {"_Complex double*", SimpleTypeKind::Complex64}, |
| 700 | {"_Complex long double*", SimpleTypeKind::Complex80}, |
| 701 | {"_Complex __float128*", SimpleTypeKind::Complex128}, |
| 702 | {"bool*", SimpleTypeKind::Boolean8}, |
| 703 | {"__bool16*", SimpleTypeKind::Boolean16}, |
| 704 | {"__bool32*", SimpleTypeKind::Boolean32}, |
| 705 | {"__bool64*", SimpleTypeKind::Boolean64}, |
| 706 | }; |
| 707 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 708 | static const EnumEntry<TypeLeafKind> LeafTypeNames[] = { |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 709 | #define LEAF_TYPE(name, val) LLVM_READOBJ_ENUM_ENT(TypeLeafKind, name), |
| 710 | #include "llvm/DebugInfo/CodeView/CVLeafTypes.def" |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 711 | }; |
| 712 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 713 | static const EnumEntry<uint8_t> PtrKindNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 714 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Near16), |
| 715 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Far16), |
| 716 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Huge16), |
| 717 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, BasedOnSegment), |
| 718 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, BasedOnValue), |
| 719 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, BasedOnSegmentValue), |
| 720 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, BasedOnAddress), |
| 721 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, BasedOnSegmentAddress), |
| 722 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, BasedOnType), |
| 723 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, BasedOnSelf), |
| 724 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Near32), |
| 725 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Far32), |
| 726 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Near64), |
| 727 | }; |
| 728 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 729 | static const EnumEntry<uint8_t> PtrModeNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 730 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, Pointer), |
| 731 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, LValueReference), |
| 732 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, PointerToDataMember), |
| 733 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, PointerToMemberFunction), |
| 734 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, RValueReference), |
| 735 | }; |
| 736 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 737 | static const EnumEntry<uint16_t> PtrMemberRepNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 738 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, Unknown), |
| 739 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, |
| 740 | SingleInheritanceData), |
| 741 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, |
| 742 | MultipleInheritanceData), |
| 743 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, |
| 744 | VirtualInheritanceData), |
| 745 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, GeneralData), |
| 746 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, |
| 747 | SingleInheritanceFunction), |
| 748 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, |
| 749 | MultipleInheritanceFunction), |
| 750 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, |
| 751 | VirtualInheritanceFunction), |
| 752 | LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, GeneralFunction), |
| 753 | }; |
| 754 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 755 | static const EnumEntry<uint16_t> TypeModifierNames[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 756 | LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Const), |
| 757 | LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Volatile), |
| 758 | LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Unaligned), |
| 759 | }; |
| 760 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 761 | static const EnumEntry<uint8_t> CallingConventions[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 762 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearC), |
| 763 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, FarC), |
| 764 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearPascal), |
| 765 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, FarPascal), |
| 766 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearFast), |
| 767 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, FarFast), |
| 768 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearStdCall), |
| 769 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, FarStdCall), |
| 770 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearSysCall), |
| 771 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, FarSysCall), |
| 772 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, ThisCall), |
| 773 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, MipsCall), |
| 774 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, Generic), |
| 775 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, AlphaCall), |
| 776 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, PpcCall), |
| 777 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, SHCall), |
| 778 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, ArmCall), |
| 779 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, AM33Call), |
| 780 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, TriCall), |
| 781 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, SH5Call), |
| 782 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, M32RCall), |
| 783 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, ClrCall), |
| 784 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, Inline), |
| 785 | LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearVector), |
| 786 | }; |
| 787 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 788 | static const EnumEntry<uint8_t> FunctionOptionEnum[] = { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 789 | LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, CxxReturnUdt), |
| 790 | LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, Constructor), |
| 791 | LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, ConstructorWithVirtualBases), |
| 792 | }; |
| 793 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 794 | static const EnumEntry<uint8_t> FileChecksumKindNames[] = { |
Reid Kleckner | c31f530 | 2016-01-15 18:06:25 +0000 | [diff] [blame] | 795 | LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, None), |
| 796 | LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, MD5), |
| 797 | LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA1), |
| 798 | LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA256), |
| 799 | }; |
| 800 | |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 801 | template <typename T> |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 802 | static std::error_code getSymbolAuxData(const COFFObjectFile *Obj, |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 803 | COFFSymbolRef Symbol, |
| 804 | uint8_t AuxSymbolIdx, const T *&Aux) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 805 | ArrayRef<uint8_t> AuxData = Obj->getSymbolAuxData(Symbol); |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 806 | AuxData = AuxData.slice(AuxSymbolIdx * Obj->getSymbolTableEntrySize()); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 807 | Aux = reinterpret_cast<const T*>(AuxData.data()); |
| 808 | return readobj_error::success; |
| 809 | } |
| 810 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 811 | void COFFDumper::cacheRelocations() { |
Rafael Espindola | 76d650e | 2015-07-06 14:26:07 +0000 | [diff] [blame] | 812 | if (RelocCached) |
| 813 | return; |
| 814 | RelocCached = true; |
| 815 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 816 | for (const SectionRef &S : Obj->sections()) { |
| 817 | const coff_section *Section = Obj->getCOFFSection(S); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 818 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 819 | for (const RelocationRef &Reloc : S.relocations()) |
Alexey Samsonov | aa4d295 | 2014-03-14 14:22:49 +0000 | [diff] [blame] | 820 | RelocMap[Section].push_back(Reloc); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 821 | |
| 822 | // Sort relocations by address. |
| 823 | std::sort(RelocMap[Section].begin(), RelocMap[Section].end(), |
| 824 | relocAddressLess); |
| 825 | } |
| 826 | } |
| 827 | |
Rui Ueyama | ed64342b | 2013-07-19 23:23:29 +0000 | [diff] [blame] | 828 | void COFFDumper::printDataDirectory(uint32_t Index, const std::string &FieldName) { |
| 829 | const data_directory *Data; |
| 830 | if (Obj->getDataDirectory(Index, Data)) |
| 831 | return; |
| 832 | W.printHex(FieldName + "RVA", Data->RelativeVirtualAddress); |
| 833 | W.printHex(FieldName + "Size", Data->Size); |
| 834 | } |
| 835 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 836 | void COFFDumper::printFileHeaders() { |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 837 | time_t TDS = Obj->getTimeDateStamp(); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 838 | char FormattedTime[20] = { }; |
| 839 | strftime(FormattedTime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&TDS)); |
| 840 | |
| 841 | { |
| 842 | DictScope D(W, "ImageFileHeader"); |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 843 | W.printEnum ("Machine", Obj->getMachine(), |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 844 | makeArrayRef(ImageFileMachineType)); |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 845 | W.printNumber("SectionCount", Obj->getNumberOfSections()); |
| 846 | W.printHex ("TimeDateStamp", FormattedTime, Obj->getTimeDateStamp()); |
| 847 | W.printHex ("PointerToSymbolTable", Obj->getPointerToSymbolTable()); |
| 848 | W.printNumber("SymbolCount", Obj->getNumberOfSymbols()); |
| 849 | W.printNumber("OptionalHeaderSize", Obj->getSizeOfOptionalHeader()); |
| 850 | W.printFlags ("Characteristics", Obj->getCharacteristics(), |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 851 | makeArrayRef(ImageFileCharacteristics)); |
| 852 | } |
Rui Ueyama | 82ebd8e | 2013-06-12 19:10:33 +0000 | [diff] [blame] | 853 | |
| 854 | // Print PE header. This header does not exist if this is an object file and |
| 855 | // not an executable. |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 856 | const pe32_header *PEHeader = nullptr; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 857 | error(Obj->getPE32Header(PEHeader)); |
Rui Ueyama | 10ed9dd | 2014-01-26 04:15:52 +0000 | [diff] [blame] | 858 | if (PEHeader) |
| 859 | printPEHeader<pe32_header>(PEHeader); |
Rui Ueyama | 82ebd8e | 2013-06-12 19:10:33 +0000 | [diff] [blame] | 860 | |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 861 | const pe32plus_header *PEPlusHeader = nullptr; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 862 | error(Obj->getPE32PlusHeader(PEPlusHeader)); |
Rui Ueyama | 10ed9dd | 2014-01-26 04:15:52 +0000 | [diff] [blame] | 863 | if (PEPlusHeader) |
| 864 | printPEHeader<pe32plus_header>(PEPlusHeader); |
David Majnemer | 5026722 | 2014-11-05 06:24:35 +0000 | [diff] [blame] | 865 | |
| 866 | if (const dos_header *DH = Obj->getDOSHeader()) |
| 867 | printDOSHeader(DH); |
| 868 | } |
| 869 | |
| 870 | void COFFDumper::printDOSHeader(const dos_header *DH) { |
| 871 | DictScope D(W, "DOSHeader"); |
| 872 | W.printString("Magic", StringRef(DH->Magic, sizeof(DH->Magic))); |
| 873 | W.printNumber("UsedBytesInTheLastPage", DH->UsedBytesInTheLastPage); |
| 874 | W.printNumber("FileSizeInPages", DH->FileSizeInPages); |
| 875 | W.printNumber("NumberOfRelocationItems", DH->NumberOfRelocationItems); |
| 876 | W.printNumber("HeaderSizeInParagraphs", DH->HeaderSizeInParagraphs); |
| 877 | W.printNumber("MinimumExtraParagraphs", DH->MinimumExtraParagraphs); |
| 878 | W.printNumber("MaximumExtraParagraphs", DH->MaximumExtraParagraphs); |
| 879 | W.printNumber("InitialRelativeSS", DH->InitialRelativeSS); |
| 880 | W.printNumber("InitialSP", DH->InitialSP); |
| 881 | W.printNumber("Checksum", DH->Checksum); |
| 882 | W.printNumber("InitialIP", DH->InitialIP); |
| 883 | W.printNumber("InitialRelativeCS", DH->InitialRelativeCS); |
| 884 | W.printNumber("AddressOfRelocationTable", DH->AddressOfRelocationTable); |
| 885 | W.printNumber("OverlayNumber", DH->OverlayNumber); |
| 886 | W.printNumber("OEMid", DH->OEMid); |
| 887 | W.printNumber("OEMinfo", DH->OEMinfo); |
| 888 | W.printNumber("AddressOfNewExeHeader", DH->AddressOfNewExeHeader); |
Rui Ueyama | 10ed9dd | 2014-01-26 04:15:52 +0000 | [diff] [blame] | 889 | } |
Rui Ueyama | ed64342b | 2013-07-19 23:23:29 +0000 | [diff] [blame] | 890 | |
Rui Ueyama | 10ed9dd | 2014-01-26 04:15:52 +0000 | [diff] [blame] | 891 | template <class PEHeader> |
| 892 | void COFFDumper::printPEHeader(const PEHeader *Hdr) { |
| 893 | DictScope D(W, "ImageOptionalHeader"); |
| 894 | W.printNumber("MajorLinkerVersion", Hdr->MajorLinkerVersion); |
| 895 | W.printNumber("MinorLinkerVersion", Hdr->MinorLinkerVersion); |
| 896 | W.printNumber("SizeOfCode", Hdr->SizeOfCode); |
| 897 | W.printNumber("SizeOfInitializedData", Hdr->SizeOfInitializedData); |
| 898 | W.printNumber("SizeOfUninitializedData", Hdr->SizeOfUninitializedData); |
| 899 | W.printHex ("AddressOfEntryPoint", Hdr->AddressOfEntryPoint); |
| 900 | W.printHex ("BaseOfCode", Hdr->BaseOfCode); |
| 901 | printBaseOfDataField(Hdr); |
| 902 | W.printHex ("ImageBase", Hdr->ImageBase); |
| 903 | W.printNumber("SectionAlignment", Hdr->SectionAlignment); |
| 904 | W.printNumber("FileAlignment", Hdr->FileAlignment); |
| 905 | W.printNumber("MajorOperatingSystemVersion", |
| 906 | Hdr->MajorOperatingSystemVersion); |
| 907 | W.printNumber("MinorOperatingSystemVersion", |
| 908 | Hdr->MinorOperatingSystemVersion); |
| 909 | W.printNumber("MajorImageVersion", Hdr->MajorImageVersion); |
| 910 | W.printNumber("MinorImageVersion", Hdr->MinorImageVersion); |
| 911 | W.printNumber("MajorSubsystemVersion", Hdr->MajorSubsystemVersion); |
| 912 | W.printNumber("MinorSubsystemVersion", Hdr->MinorSubsystemVersion); |
| 913 | W.printNumber("SizeOfImage", Hdr->SizeOfImage); |
| 914 | W.printNumber("SizeOfHeaders", Hdr->SizeOfHeaders); |
| 915 | W.printEnum ("Subsystem", Hdr->Subsystem, makeArrayRef(PEWindowsSubsystem)); |
David Majnemer | 774aadf | 2014-11-18 02:45:28 +0000 | [diff] [blame] | 916 | W.printFlags ("Characteristics", Hdr->DLLCharacteristics, |
Rui Ueyama | 10ed9dd | 2014-01-26 04:15:52 +0000 | [diff] [blame] | 917 | makeArrayRef(PEDLLCharacteristics)); |
| 918 | W.printNumber("SizeOfStackReserve", Hdr->SizeOfStackReserve); |
| 919 | W.printNumber("SizeOfStackCommit", Hdr->SizeOfStackCommit); |
| 920 | W.printNumber("SizeOfHeapReserve", Hdr->SizeOfHeapReserve); |
| 921 | W.printNumber("SizeOfHeapCommit", Hdr->SizeOfHeapCommit); |
| 922 | W.printNumber("NumberOfRvaAndSize", Hdr->NumberOfRvaAndSize); |
Rui Ueyama | ed64342b | 2013-07-19 23:23:29 +0000 | [diff] [blame] | 923 | |
Rui Ueyama | 10ed9dd | 2014-01-26 04:15:52 +0000 | [diff] [blame] | 924 | if (Hdr->NumberOfRvaAndSize > 0) { |
| 925 | DictScope D(W, "DataDirectory"); |
| 926 | static const char * const directory[] = { |
| 927 | "ExportTable", "ImportTable", "ResourceTable", "ExceptionTable", |
| 928 | "CertificateTable", "BaseRelocationTable", "Debug", "Architecture", |
| 929 | "GlobalPtr", "TLSTable", "LoadConfigTable", "BoundImport", "IAT", |
| 930 | "DelayImportDescriptor", "CLRRuntimeHeader", "Reserved" |
| 931 | }; |
| 932 | |
| 933 | for (uint32_t i = 0; i < Hdr->NumberOfRvaAndSize; ++i) { |
| 934 | printDataDirectory(i, directory[i]); |
Rui Ueyama | ed64342b | 2013-07-19 23:23:29 +0000 | [diff] [blame] | 935 | } |
Rui Ueyama | 82ebd8e | 2013-06-12 19:10:33 +0000 | [diff] [blame] | 936 | } |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Rui Ueyama | 10ed9dd | 2014-01-26 04:15:52 +0000 | [diff] [blame] | 939 | void COFFDumper::printBaseOfDataField(const pe32_header *Hdr) { |
| 940 | W.printHex("BaseOfData", Hdr->BaseOfData); |
| 941 | } |
| 942 | |
| 943 | void COFFDumper::printBaseOfDataField(const pe32plus_header *) {} |
| 944 | |
Reid Kleckner | 83ebad3 | 2015-12-16 18:28:12 +0000 | [diff] [blame] | 945 | void COFFDumper::printCodeViewDebugInfo() { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 946 | // Print types first to build CVUDTNames, then print symbols. |
Reid Kleckner | 83ebad3 | 2015-12-16 18:28:12 +0000 | [diff] [blame] | 947 | for (const SectionRef &S : Obj->sections()) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 948 | StringRef SectionName; |
| 949 | error(S.getName(SectionName)); |
| 950 | if (SectionName == ".debug$T") |
| 951 | printCodeViewTypeSection(SectionName, S); |
| 952 | } |
| 953 | for (const SectionRef &S : Obj->sections()) { |
| 954 | StringRef SectionName; |
| 955 | error(S.getName(SectionName)); |
| 956 | if (SectionName == ".debug$S") |
| 957 | printCodeViewSymbolSection(SectionName, S); |
Reid Kleckner | 83ebad3 | 2015-12-16 18:28:12 +0000 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 961 | /// Consumes sizeof(T) bytes from the given byte sequence. Returns an error if |
| 962 | /// there are not enough bytes remaining. Reinterprets the consumed bytes as a |
| 963 | /// T object and points 'Res' at them. |
| 964 | template <typename T> |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 965 | static std::error_code consumeObject(StringRef &Data, const T *&Res) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 966 | if (Data.size() < sizeof(*Res)) |
| 967 | return object_error::parse_failed; |
| 968 | Res = reinterpret_cast<const T *>(Data.data()); |
| 969 | Data = Data.drop_front(sizeof(*Res)); |
| 970 | return std::error_code(); |
| 971 | } |
| 972 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 973 | static std::error_code consumeUInt32(StringRef &Data, uint32_t &Res) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 974 | const ulittle32_t *IntPtr; |
| 975 | if (auto EC = consumeObject(Data, IntPtr)) |
| 976 | return EC; |
| 977 | Res = *IntPtr; |
| 978 | return std::error_code(); |
| 979 | } |
| 980 | |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 981 | void COFFDumper::initializeFileAndStringTables(StringRef Data) { |
| 982 | while (!Data.empty() && (CVFileChecksumTable.data() == nullptr || |
| 983 | CVStringTable.data() == nullptr)) { |
| 984 | // The section consists of a number of subsection in the following format: |
| 985 | // |SubSectionType|SubSectionSize|Contents...| |
| 986 | uint32_t SubType, SubSectionSize; |
| 987 | error(consumeUInt32(Data, SubType)); |
| 988 | error(consumeUInt32(Data, SubSectionSize)); |
| 989 | if (SubSectionSize > Data.size()) |
| 990 | return error(object_error::parse_failed); |
| 991 | switch (ModuleSubstreamKind(SubType)) { |
| 992 | case ModuleSubstreamKind::FileChecksums: |
| 993 | CVFileChecksumTable = Data.substr(0, SubSectionSize); |
| 994 | break; |
| 995 | case ModuleSubstreamKind::StringTable: |
| 996 | CVStringTable = Data.substr(0, SubSectionSize); |
| 997 | break; |
| 998 | default: |
| 999 | break; |
| 1000 | } |
| 1001 | Data = Data.drop_front(alignTo(SubSectionSize, 4)); |
| 1002 | } |
| 1003 | } |
| 1004 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1005 | void COFFDumper::printCodeViewSymbolSection(StringRef SectionName, |
| 1006 | const SectionRef &Section) { |
| 1007 | StringRef SectionContents; |
| 1008 | error(Section.getContents(SectionContents)); |
| 1009 | StringRef Data = SectionContents; |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1010 | |
| 1011 | SmallVector<StringRef, 10> FunctionNames; |
| 1012 | StringMap<StringRef> FunctionLineTables; |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1013 | |
Zachary Turner | 99f0215 | 2015-02-18 19:32:05 +0000 | [diff] [blame] | 1014 | ListScope D(W, "CodeViewDebugInfo"); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1015 | // Print the section to allow correlation with printSections. |
| 1016 | W.printNumber("Section", SectionName, Obj->getSectionID(Section)); |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1017 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1018 | uint32_t Magic; |
| 1019 | error(consumeUInt32(Data, Magic)); |
| 1020 | W.printHex("Magic", Magic); |
| 1021 | if (Magic != COFF::DEBUG_SECTION_MAGIC) |
| 1022 | return error(object_error::parse_failed); |
| 1023 | |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 1024 | initializeFileAndStringTables(Data); |
| 1025 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1026 | while (!Data.empty()) { |
| 1027 | // The section consists of a number of subsection in the following format: |
| 1028 | // |SubSectionType|SubSectionSize|Contents...| |
| 1029 | uint32_t SubType, SubSectionSize; |
| 1030 | error(consumeUInt32(Data, SubType)); |
| 1031 | error(consumeUInt32(Data, SubSectionSize)); |
| 1032 | |
| 1033 | ListScope S(W, "Subsection"); |
| 1034 | W.printEnum("SubSectionType", SubType, makeArrayRef(SubSectionTypes)); |
| 1035 | W.printHex("SubSectionSize", SubSectionSize); |
| 1036 | |
| 1037 | // Get the contents of the subsection. |
| 1038 | if (SubSectionSize > Data.size()) |
| 1039 | return error(object_error::parse_failed); |
| 1040 | StringRef Contents = Data.substr(0, SubSectionSize); |
| 1041 | |
| 1042 | // Add SubSectionSize to the current offset and align that offset to find |
| 1043 | // the next subsection. |
| 1044 | size_t SectionOffset = Data.data() - SectionContents.data(); |
| 1045 | size_t NextOffset = SectionOffset + SubSectionSize; |
Rui Ueyama | da00f2f | 2016-01-14 21:06:47 +0000 | [diff] [blame] | 1046 | NextOffset = alignTo(NextOffset, 4); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1047 | Data = SectionContents.drop_front(NextOffset); |
| 1048 | |
| 1049 | // Optionally print the subsection bytes in case our parsing gets confused |
| 1050 | // later. |
| 1051 | if (opts::CodeViewSubsectionBytes) |
Reid Kleckner | af49ecb | 2016-01-15 22:09:13 +0000 | [diff] [blame] | 1052 | printBinaryBlockWithRelocs("SubSectionContents", Section, SectionContents, |
| 1053 | Contents); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1054 | |
| 1055 | switch (ModuleSubstreamKind(SubType)) { |
| 1056 | case ModuleSubstreamKind::Symbols: |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1057 | printCodeViewSymbolsSubsection(Contents, Section, SectionContents); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1058 | break; |
Reid Kleckner | e9ab349 | 2016-01-14 19:20:17 +0000 | [diff] [blame] | 1059 | |
| 1060 | case ModuleSubstreamKind::InlineeLines: |
| 1061 | printCodeViewInlineeLines(Contents); |
| 1062 | break; |
| 1063 | |
Reid Kleckner | c31f530 | 2016-01-15 18:06:25 +0000 | [diff] [blame] | 1064 | case ModuleSubstreamKind::FileChecksums: |
| 1065 | printCodeViewFileChecksums(Contents); |
| 1066 | break; |
| 1067 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1068 | case ModuleSubstreamKind::Lines: { |
| 1069 | // Holds a PC to file:line table. Some data to parse this subsection is |
| 1070 | // stored in the other subsections, so just check sanity and store the |
| 1071 | // pointers for deferred processing. |
| 1072 | |
| 1073 | if (SubSectionSize < 12) { |
| 1074 | // There should be at least three words to store two function |
| 1075 | // relocations and size of the code. |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1076 | error(object_error::parse_failed); |
| 1077 | return; |
| 1078 | } |
| 1079 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1080 | StringRef LinkageName; |
| 1081 | error(resolveSymbolName(Obj->getCOFFSection(Section), SectionOffset, |
| 1082 | LinkageName)); |
| 1083 | W.printString("LinkageName", LinkageName); |
| 1084 | if (FunctionLineTables.count(LinkageName) != 0) { |
| 1085 | // Saw debug info for this function already? |
| 1086 | error(object_error::parse_failed); |
| 1087 | return; |
Zachary Turner | 99f0215 | 2015-02-18 19:32:05 +0000 | [diff] [blame] | 1088 | } |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1089 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1090 | FunctionLineTables[LinkageName] = Contents; |
| 1091 | FunctionNames.push_back(LinkageName); |
| 1092 | break; |
| 1093 | } |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1094 | case ModuleSubstreamKind::FrameData: { |
Reid Kleckner | af49ecb | 2016-01-15 22:09:13 +0000 | [diff] [blame] | 1095 | // First four bytes is a relocation against the function. |
| 1096 | const uint32_t *CodePtr; |
| 1097 | error(consumeObject(Contents, CodePtr)); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1098 | StringRef LinkageName; |
Reid Kleckner | af49ecb | 2016-01-15 22:09:13 +0000 | [diff] [blame] | 1099 | error(resolveSymbolName(Obj->getCOFFSection(Section), SectionContents, |
| 1100 | CodePtr, LinkageName)); |
| 1101 | W.printString("LinkageName", LinkageName); |
| 1102 | |
| 1103 | // To find the active frame description, search this array for the |
| 1104 | // smallest PC range that includes the current PC. |
| 1105 | while (!Contents.empty()) { |
| 1106 | const FrameData *FD; |
| 1107 | error(consumeObject(Contents, FD)); |
| 1108 | DictScope S(W, "FrameData"); |
| 1109 | W.printHex("RvaStart", FD->RvaStart); |
| 1110 | W.printHex("CodeSize", FD->CodeSize); |
| 1111 | W.printHex("LocalSize", FD->LocalSize); |
| 1112 | W.printHex("ParamsSize", FD->ParamsSize); |
| 1113 | W.printHex("MaxStackSize", FD->MaxStackSize); |
| 1114 | W.printString("FrameFunc", |
| 1115 | CVStringTable.drop_front(FD->FrameFunc).split('\0').first); |
| 1116 | W.printHex("PrologSize", FD->PrologSize); |
| 1117 | W.printHex("SavedRegsSize", FD->SavedRegsSize); |
| 1118 | W.printFlags("Flags", FD->Flags, makeArrayRef(FrameDataFlags)); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1119 | } |
| 1120 | break; |
| 1121 | } |
| 1122 | |
| 1123 | // Do nothing for unrecognized subsections. |
| 1124 | default: |
| 1125 | break; |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1126 | } |
Reid Kleckner | af49ecb | 2016-01-15 22:09:13 +0000 | [diff] [blame] | 1127 | W.flush(); |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | // Dump the line tables now that we've read all the subsections and know all |
| 1131 | // the required information. |
| 1132 | for (unsigned I = 0, E = FunctionNames.size(); I != E; ++I) { |
| 1133 | StringRef Name = FunctionNames[I]; |
| 1134 | ListScope S(W, "FunctionLineTable"); |
Reid Kleckner | 7c0c0c0 | 2015-12-15 01:23:55 +0000 | [diff] [blame] | 1135 | W.printString("LinkageName", Name); |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1136 | |
| 1137 | DataExtractor DE(FunctionLineTables[Name], true, 4); |
David Majnemer | 3f49e66 | 2015-07-09 00:19:51 +0000 | [diff] [blame] | 1138 | uint32_t Offset = 6; // Skip relocations. |
| 1139 | uint16_t Flags = DE.getU16(&Offset); |
| 1140 | W.printHex("Flags", Flags); |
Reid Kleckner | 2214ed8 | 2016-01-29 00:49:42 +0000 | [diff] [blame] | 1141 | bool HasColumnInformation = Flags & codeview::LineFlags::HaveColumns; |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1142 | uint32_t FunctionSize = DE.getU32(&Offset); |
| 1143 | W.printHex("CodeSize", FunctionSize); |
| 1144 | while (DE.isValidOffset(Offset)) { |
| 1145 | // For each range of lines with the same filename, we have a segment |
| 1146 | // in the line table. The filename string is accessed using double |
| 1147 | // indirection to the string table subsection using the index subsection. |
| 1148 | uint32_t OffsetInIndex = DE.getU32(&Offset), |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1149 | NumLines = DE.getU32(&Offset), |
David Majnemer | 0373d53 | 2015-07-09 18:14:31 +0000 | [diff] [blame] | 1150 | FullSegmentSize = DE.getU32(&Offset); |
| 1151 | |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1152 | uint32_t ColumnOffset = Offset + 8 * NumLines; |
| 1153 | DataExtractor ColumnDE(DE.getData(), true, 4); |
| 1154 | |
David Majnemer | 0373d53 | 2015-07-09 18:14:31 +0000 | [diff] [blame] | 1155 | if (FullSegmentSize != |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1156 | 12 + 8 * NumLines + (HasColumnInformation ? 4 * NumLines : 0)) { |
David Majnemer | 0373d53 | 2015-07-09 18:14:31 +0000 | [diff] [blame] | 1157 | error(object_error::parse_failed); |
| 1158 | return; |
| 1159 | } |
Justin Bogner | a1413db | 2015-07-09 04:27:36 +0000 | [diff] [blame] | 1160 | |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1161 | ListScope S(W, "FilenameSegment"); |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 1162 | printFileNameForOffset("Filename", OffsetInIndex); |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1163 | for (unsigned LineIdx = 0; |
| 1164 | LineIdx != NumLines && DE.isValidOffset(Offset); ++LineIdx) { |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1165 | // Then go the (PC, LineNumber) pairs. The line number is stored in the |
| 1166 | // least significant 31 bits of the respective word in the table. |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1167 | uint32_t PC = DE.getU32(&Offset), LineData = DE.getU32(&Offset); |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1168 | if (PC >= FunctionSize) { |
| 1169 | error(object_error::parse_failed); |
| 1170 | return; |
| 1171 | } |
| 1172 | char Buffer[32]; |
| 1173 | format("+0x%X", PC).snprint(Buffer, 32); |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1174 | ListScope PCScope(W, Buffer); |
David Majnemer | a4859df | 2016-02-04 17:57:12 +0000 | [diff] [blame] | 1175 | LineInfo LI(LineData); |
| 1176 | if (LI.isAlwaysStepInto()) |
| 1177 | W.printString("StepInto", StringRef("Always")); |
| 1178 | else if (LI.isNeverStepInto()) |
| 1179 | W.printString("StepInto", StringRef("Never")); |
| 1180 | else |
| 1181 | W.printNumber("LineNumberStart", LI.getStartLine()); |
| 1182 | W.printNumber("LineNumberEndDelta", LI.getLineDelta()); |
| 1183 | W.printBoolean("IsStatement", LI.isStatement()); |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1184 | if (HasColumnInformation && |
| 1185 | ColumnDE.isValidOffsetForDataOfSize(ColumnOffset, 4)) { |
| 1186 | uint16_t ColStart = ColumnDE.getU16(&ColumnOffset); |
David Majnemer | 3f49e66 | 2015-07-09 00:19:51 +0000 | [diff] [blame] | 1187 | W.printNumber("ColStart", ColStart); |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1188 | uint16_t ColEnd = ColumnDE.getU16(&ColumnOffset); |
David Majnemer | 3f49e66 | 2015-07-09 00:19:51 +0000 | [diff] [blame] | 1189 | W.printNumber("ColEnd", ColEnd); |
| 1190 | } |
| 1191 | } |
David Majnemer | 0494836 | 2016-01-13 01:05:16 +0000 | [diff] [blame] | 1192 | // Skip over the column data. |
| 1193 | if (HasColumnInformation) { |
| 1194 | for (unsigned LineIdx = 0; |
| 1195 | LineIdx != NumLines && DE.isValidOffset(Offset); ++LineIdx) { |
| 1196 | DE.getU32(&Offset); |
| 1197 | } |
| 1198 | } |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1199 | } |
| 1200 | } |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 1203 | static std::error_code decodeNumerictLeaf(StringRef &Data, APSInt &Num) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1204 | // Used to avoid overload ambiguity on APInt construtor. |
| 1205 | bool FalseVal = false; |
| 1206 | if (Data.size() < 2) |
| 1207 | return object_error::parse_failed; |
| 1208 | uint16_t Short = *reinterpret_cast<const ulittle16_t *>(Data.data()); |
| 1209 | Data = Data.drop_front(2); |
| 1210 | if (Short < LF_NUMERIC) { |
| 1211 | Num = APSInt(APInt(/*numBits=*/16, Short, /*isSigned=*/false), |
| 1212 | /*isUnsigned=*/true); |
| 1213 | return std::error_code(); |
| 1214 | } |
| 1215 | switch (Short) { |
| 1216 | case LF_CHAR: |
| 1217 | Num = APSInt(APInt(/*numBits=*/8, |
| 1218 | *reinterpret_cast<const int8_t *>(Data.data()), |
| 1219 | /*isSigned=*/true), |
| 1220 | /*isUnsigned=*/false); |
| 1221 | Data = Data.drop_front(1); |
| 1222 | return std::error_code(); |
| 1223 | case LF_SHORT: |
| 1224 | Num = APSInt(APInt(/*numBits=*/16, |
| 1225 | *reinterpret_cast<const little16_t *>(Data.data()), |
| 1226 | /*isSigned=*/true), |
| 1227 | /*isUnsigned=*/false); |
| 1228 | Data = Data.drop_front(2); |
| 1229 | return std::error_code(); |
| 1230 | case LF_USHORT: |
| 1231 | Num = APSInt(APInt(/*numBits=*/16, |
| 1232 | *reinterpret_cast<const ulittle16_t *>(Data.data()), |
| 1233 | /*isSigned=*/false), |
| 1234 | /*isUnsigned=*/true); |
| 1235 | Data = Data.drop_front(2); |
| 1236 | return std::error_code(); |
| 1237 | case LF_LONG: |
| 1238 | Num = APSInt(APInt(/*numBits=*/32, |
| 1239 | *reinterpret_cast<const little32_t *>(Data.data()), |
| 1240 | /*isSigned=*/true), |
| 1241 | /*isUnsigned=*/false); |
| 1242 | Data = Data.drop_front(4); |
| 1243 | return std::error_code(); |
| 1244 | case LF_ULONG: |
| 1245 | Num = APSInt(APInt(/*numBits=*/32, |
| 1246 | *reinterpret_cast<const ulittle32_t *>(Data.data()), |
| 1247 | /*isSigned=*/FalseVal), |
| 1248 | /*isUnsigned=*/true); |
| 1249 | Data = Data.drop_front(4); |
| 1250 | return std::error_code(); |
| 1251 | case LF_QUADWORD: |
| 1252 | Num = APSInt(APInt(/*numBits=*/64, |
| 1253 | *reinterpret_cast<const little64_t *>(Data.data()), |
| 1254 | /*isSigned=*/true), |
| 1255 | /*isUnsigned=*/false); |
| 1256 | Data = Data.drop_front(8); |
| 1257 | return std::error_code(); |
| 1258 | case LF_UQUADWORD: |
| 1259 | Num = APSInt(APInt(/*numBits=*/64, |
| 1260 | *reinterpret_cast<const ulittle64_t *>(Data.data()), |
| 1261 | /*isSigned=*/false), |
| 1262 | /*isUnsigned=*/true); |
| 1263 | Data = Data.drop_front(8); |
| 1264 | return std::error_code(); |
| 1265 | } |
| 1266 | return object_error::parse_failed; |
| 1267 | } |
| 1268 | |
| 1269 | /// Decode an unsigned integer numeric leaf value. |
| 1270 | std::error_code decodeUIntLeaf(StringRef &Data, uint64_t &Num) { |
| 1271 | APSInt N; |
| 1272 | if (std::error_code err = decodeNumerictLeaf(Data, N)) |
| 1273 | return err; |
| 1274 | if (N.isSigned() || !N.isIntN(64)) |
| 1275 | return object_error::parse_failed; |
| 1276 | Num = N.getLimitedValue(); |
| 1277 | return std::error_code(); |
Timur Iskhodzhanov | 48703be | 2013-12-19 11:37:14 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1280 | void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, |
| 1281 | const SectionRef &Section, |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1282 | StringRef SectionContents) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1283 | if (Subsection.size() < sizeof(SymRecord)) |
| 1284 | return error(object_error::parse_failed); |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1285 | |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1286 | const coff_section *Sec = Obj->getCOFFSection(Section); |
| 1287 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1288 | // This holds the remaining data to parse. |
| 1289 | StringRef Data = Subsection; |
| 1290 | |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1291 | bool InFunctionScope = false; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1292 | while (!Data.empty()) { |
| 1293 | const SymRecord *Rec; |
| 1294 | error(consumeObject(Data, Rec)); |
| 1295 | |
| 1296 | StringRef SymData = Data.substr(0, Rec->RecordLength - 2); |
Reid Kleckner | 1c7a9cd | 2016-01-14 17:51:57 +0000 | [diff] [blame] | 1297 | StringRef OrigSymData = SymData; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1298 | |
| 1299 | Data = Data.drop_front(Rec->RecordLength - 2); |
| 1300 | |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 1301 | SymbolRecordKind Kind = Rec->getKind(); |
| 1302 | switch (Kind) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1303 | case S_LPROC32: |
| 1304 | case S_GPROC32: |
| 1305 | case S_GPROC32_ID: |
| 1306 | case S_LPROC32_ID: |
| 1307 | case S_LPROC32_DPC: |
| 1308 | case S_LPROC32_DPC_ID: { |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1309 | DictScope S(W, "ProcStart"); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1310 | const ProcSym *Proc; |
| 1311 | error(consumeObject(SymData, Proc)); |
| 1312 | if (InFunctionScope) |
| 1313 | return error(object_error::parse_failed); |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1314 | InFunctionScope = true; |
| 1315 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1316 | StringRef LinkageName; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1317 | StringRef DisplayName = SymData.split('\0').first; |
| 1318 | W.printHex("PtrParent", Proc->PtrParent); |
| 1319 | W.printHex("PtrEnd", Proc->PtrEnd); |
| 1320 | W.printHex("PtrNext", Proc->PtrNext); |
| 1321 | W.printHex("CodeSize", Proc->CodeSize); |
| 1322 | W.printHex("DbgStart", Proc->DbgStart); |
| 1323 | W.printHex("DbgEnd", Proc->DbgEnd); |
| 1324 | printTypeIndex("FunctionType", Proc->FunctionType); |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1325 | printRelocatedField("CodeOffset", Sec, SectionContents, &Proc->CodeOffset, |
| 1326 | &LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1327 | W.printHex("Segment", Proc->Segment); |
| 1328 | W.printFlags("Flags", Proc->Flags, makeArrayRef(ProcSymFlags)); |
| 1329 | W.printString("DisplayName", DisplayName); |
| 1330 | W.printString("LinkageName", LinkageName); |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | } |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1333 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 1334 | case S_PROC_ID_END: { |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1335 | W.startLine() << "ProcEnd\n"; |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1336 | InFunctionScope = false; |
| 1337 | break; |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 1338 | } |
Zachary Turner | 99f0215 | 2015-02-18 19:32:05 +0000 | [diff] [blame] | 1339 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1340 | case S_BLOCK32: { |
| 1341 | DictScope S(W, "BlockStart"); |
| 1342 | const BlockSym *Block; |
| 1343 | error(consumeObject(SymData, Block)); |
| 1344 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1345 | StringRef BlockName = SymData.split('\0').first; |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1346 | StringRef LinkageName; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1347 | W.printHex("PtrParent", Block->PtrParent); |
| 1348 | W.printHex("PtrEnd", Block->PtrEnd); |
| 1349 | W.printHex("CodeSize", Block->CodeSize); |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1350 | printRelocatedField("CodeOffset", Sec, SectionContents, |
| 1351 | &Block->CodeOffset, &LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1352 | W.printHex("Segment", Block->Segment); |
| 1353 | W.printString("BlockName", BlockName); |
| 1354 | W.printString("LinkageName", LinkageName); |
| 1355 | break; |
| 1356 | } |
| 1357 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 1358 | case S_END: { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1359 | W.startLine() << "BlockEnd\n"; |
| 1360 | InFunctionScope = false; |
| 1361 | break; |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 1362 | } |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1363 | |
| 1364 | case S_LABEL32: { |
| 1365 | DictScope S(W, "Label"); |
| 1366 | const LabelSym *Label; |
| 1367 | error(consumeObject(SymData, Label)); |
| 1368 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1369 | StringRef DisplayName = SymData.split('\0').first; |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1370 | StringRef LinkageName; |
| 1371 | printRelocatedField("CodeOffset", Sec, SectionContents, |
| 1372 | &Label->CodeOffset, &LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1373 | W.printHex("Segment", Label->Segment); |
| 1374 | W.printHex("Flags", Label->Flags); |
| 1375 | W.printFlags("Flags", Label->Flags, makeArrayRef(ProcSymFlags)); |
| 1376 | W.printString("DisplayName", DisplayName); |
| 1377 | W.printString("LinkageName", LinkageName); |
| 1378 | break; |
| 1379 | } |
| 1380 | |
| 1381 | case S_INLINESITE: { |
| 1382 | DictScope S(W, "InlineSite"); |
| 1383 | const InlineSiteSym *InlineSite; |
| 1384 | error(consumeObject(SymData, InlineSite)); |
| 1385 | W.printHex("PtrParent", InlineSite->PtrParent); |
| 1386 | W.printHex("PtrEnd", InlineSite->PtrEnd); |
| 1387 | printTypeIndex("Inlinee", InlineSite->Inlinee); |
David Majnemer | e21e909 | 2016-01-14 06:12:30 +0000 | [diff] [blame] | 1388 | |
| 1389 | auto GetCompressedAnnotation = [&]() -> uint32_t { |
| 1390 | if (SymData.empty()) |
| 1391 | return -1; |
| 1392 | |
| 1393 | uint8_t FirstByte = SymData.front(); |
| 1394 | SymData = SymData.drop_front(); |
| 1395 | |
| 1396 | if ((FirstByte & 0x80) == 0x00) |
| 1397 | return FirstByte; |
| 1398 | |
| 1399 | if (SymData.empty()) |
| 1400 | return -1; |
| 1401 | |
| 1402 | uint8_t SecondByte = SymData.front(); |
| 1403 | SymData = SymData.drop_front(); |
| 1404 | |
| 1405 | if ((FirstByte & 0xC0) == 0x80) |
| 1406 | return ((FirstByte & 0x3F) << 8) | SecondByte; |
| 1407 | |
| 1408 | if (SymData.empty()) |
| 1409 | return -1; |
| 1410 | |
| 1411 | uint8_t ThirdByte = SymData.front(); |
| 1412 | SymData = SymData.drop_front(); |
| 1413 | |
| 1414 | if (SymData.empty()) |
| 1415 | return -1; |
| 1416 | |
| 1417 | uint8_t FourthByte = SymData.front(); |
| 1418 | SymData = SymData.drop_front(); |
| 1419 | |
| 1420 | if ((FirstByte & 0xE0) == 0xC0) |
| 1421 | return ((FirstByte & 0x1F) << 24) | (SecondByte << 16) | |
| 1422 | (ThirdByte << 8) | FourthByte; |
| 1423 | |
| 1424 | return -1; |
| 1425 | }; |
| 1426 | auto DecodeSignedOperand = [](uint32_t Operand) -> int32_t { |
| 1427 | if (Operand & 1) |
| 1428 | return -(Operand >> 1); |
| 1429 | return Operand >> 1; |
| 1430 | }; |
| 1431 | |
| 1432 | ListScope BinaryAnnotations(W, "BinaryAnnotations"); |
| 1433 | while (!SymData.empty()) { |
| 1434 | uint32_t OpCode = GetCompressedAnnotation(); |
| 1435 | switch (OpCode) { |
| 1436 | default: |
| 1437 | case Invalid: |
| 1438 | return error(object_error::parse_failed); |
| 1439 | case CodeOffset: |
Reid Kleckner | 43842b5 | 2016-01-14 21:50:05 +0000 | [diff] [blame] | 1440 | W.printHex("CodeOffset", GetCompressedAnnotation()); |
David Majnemer | e21e909 | 2016-01-14 06:12:30 +0000 | [diff] [blame] | 1441 | break; |
| 1442 | case ChangeCodeOffsetBase: |
| 1443 | W.printNumber("ChangeCodeOffsetBase", GetCompressedAnnotation()); |
| 1444 | break; |
| 1445 | case ChangeCodeOffset: |
Reid Kleckner | 43842b5 | 2016-01-14 21:50:05 +0000 | [diff] [blame] | 1446 | W.printHex("ChangeCodeOffset", GetCompressedAnnotation()); |
David Majnemer | e21e909 | 2016-01-14 06:12:30 +0000 | [diff] [blame] | 1447 | break; |
| 1448 | case ChangeCodeLength: |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 1449 | W.printHex("ChangeCodeLength", GetCompressedAnnotation()); |
David Majnemer | e21e909 | 2016-01-14 06:12:30 +0000 | [diff] [blame] | 1450 | break; |
| 1451 | case ChangeFile: |
Reid Kleckner | af49ecb | 2016-01-15 22:09:13 +0000 | [diff] [blame] | 1452 | printFileNameForOffset("ChangeFile", GetCompressedAnnotation()); |
David Majnemer | e21e909 | 2016-01-14 06:12:30 +0000 | [diff] [blame] | 1453 | break; |
| 1454 | case ChangeLineOffset: |
| 1455 | W.printNumber("ChangeLineOffset", |
| 1456 | DecodeSignedOperand(GetCompressedAnnotation())); |
| 1457 | break; |
| 1458 | case ChangeLineEndDelta: |
| 1459 | W.printNumber("ChangeLineEndDelta", GetCompressedAnnotation()); |
| 1460 | break; |
| 1461 | case ChangeRangeKind: |
| 1462 | W.printNumber("ChangeRangeKind", GetCompressedAnnotation()); |
| 1463 | break; |
| 1464 | case ChangeColumnStart: |
| 1465 | W.printNumber("ChangeColumnStart", GetCompressedAnnotation()); |
| 1466 | break; |
| 1467 | case ChangeColumnEndDelta: |
| 1468 | W.printNumber("ChangeColumnEndDelta", |
| 1469 | DecodeSignedOperand(GetCompressedAnnotation())); |
| 1470 | break; |
| 1471 | case ChangeCodeOffsetAndLineOffset: { |
| 1472 | uint32_t Annotation = GetCompressedAnnotation(); |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 1473 | int32_t LineOffset = DecodeSignedOperand(Annotation >> 4); |
Reid Kleckner | 43842b5 | 2016-01-14 21:50:05 +0000 | [diff] [blame] | 1474 | uint32_t CodeOffset = Annotation & 0xf; |
Reid Kleckner | 400f393 | 2016-01-20 23:21:14 +0000 | [diff] [blame] | 1475 | W.startLine() << "ChangeCodeOffsetAndLineOffset: {CodeOffset: " |
| 1476 | << W.hex(CodeOffset) << ", LineOffset: " << LineOffset |
Reid Kleckner | 43842b5 | 2016-01-14 21:50:05 +0000 | [diff] [blame] | 1477 | << "}\n"; |
David Majnemer | e21e909 | 2016-01-14 06:12:30 +0000 | [diff] [blame] | 1478 | break; |
| 1479 | } |
| 1480 | case ChangeCodeLengthAndCodeOffset: { |
Reid Kleckner | 43842b5 | 2016-01-14 21:50:05 +0000 | [diff] [blame] | 1481 | uint32_t Length = GetCompressedAnnotation(); |
| 1482 | uint32_t CodeOffset = GetCompressedAnnotation(); |
Reid Kleckner | 400f393 | 2016-01-20 23:21:14 +0000 | [diff] [blame] | 1483 | W.startLine() << "ChangeCodeLengthAndCodeOffset: {CodeOffset: " |
| 1484 | << W.hex(CodeOffset) << ", Length: " << W.hex(Length) |
| 1485 | << "}\n"; |
David Majnemer | e21e909 | 2016-01-14 06:12:30 +0000 | [diff] [blame] | 1486 | break; |
| 1487 | } |
| 1488 | case ChangeColumnEnd: |
| 1489 | W.printNumber("ChangeColumnEnd", GetCompressedAnnotation()); |
| 1490 | break; |
| 1491 | } |
| 1492 | } |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1493 | break; |
| 1494 | } |
| 1495 | |
| 1496 | case S_INLINESITE_END: { |
| 1497 | DictScope S(W, "InlineSiteEnd"); |
| 1498 | break; |
| 1499 | } |
| 1500 | |
Reid Kleckner | 43842b5 | 2016-01-14 21:50:05 +0000 | [diff] [blame] | 1501 | case S_CALLERS: |
| 1502 | case S_CALLEES: { |
| 1503 | ListScope S(W, Kind == S_CALLEES ? "Callees" : "Callers"); |
| 1504 | uint32_t Count; |
| 1505 | error(consumeUInt32(SymData, Count)); |
| 1506 | for (uint32_t I = 0; I < Count; ++I) { |
| 1507 | const TypeIndex *FuncID; |
| 1508 | error(consumeObject(SymData, FuncID)); |
| 1509 | printTypeIndex("FuncID", *FuncID); |
| 1510 | } |
| 1511 | break; |
| 1512 | } |
| 1513 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1514 | case S_LOCAL: { |
| 1515 | DictScope S(W, "Local"); |
| 1516 | const LocalSym *Local; |
| 1517 | error(consumeObject(SymData, Local)); |
| 1518 | printTypeIndex("Type", Local->Type); |
| 1519 | W.printFlags("Flags", uint16_t(Local->Flags), makeArrayRef(LocalFlags)); |
| 1520 | StringRef VarName = SymData.split('\0').first; |
| 1521 | W.printString("VarName", VarName); |
| 1522 | break; |
| 1523 | } |
| 1524 | |
David Majnemer | 4d12351 | 2016-02-04 17:37:30 +0000 | [diff] [blame] | 1525 | case S_DEFRANGE: { |
| 1526 | DictScope S(W, "DefRange"); |
| 1527 | const DefRangeSym *DefRange; |
| 1528 | error(consumeObject(SymData, DefRange)); |
| 1529 | W.printString( |
| 1530 | "Program", |
| 1531 | CVStringTable.drop_front(DefRange->Program).split('\0').first); |
| 1532 | printLocalVariableAddrRange(DefRange->Range, Sec, SectionContents); |
| 1533 | printLocalVariableAddrGap(SymData); |
| 1534 | break; |
| 1535 | } |
| 1536 | case S_DEFRANGE_SUBFIELD: { |
| 1537 | DictScope S(W, "DefRangeSubfield"); |
| 1538 | const DefRangeSubfieldSym *DefRangeSubfield; |
| 1539 | error(consumeObject(SymData, DefRangeSubfield)); |
| 1540 | W.printString("Program", |
| 1541 | CVStringTable.drop_front(DefRangeSubfield->Program) |
| 1542 | .split('\0') |
| 1543 | .first); |
| 1544 | W.printNumber("OffsetInParent", DefRangeSubfield->OffsetInParent); |
| 1545 | printLocalVariableAddrRange(DefRangeSubfield->Range, Sec, |
| 1546 | SectionContents); |
| 1547 | printLocalVariableAddrGap(SymData); |
| 1548 | break; |
| 1549 | } |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1550 | case S_DEFRANGE_REGISTER: { |
| 1551 | DictScope S(W, "DefRangeRegister"); |
| 1552 | const DefRangeRegisterSym *DefRangeRegister; |
| 1553 | error(consumeObject(SymData, DefRangeRegister)); |
| 1554 | W.printNumber("Register", DefRangeRegister->Register); |
| 1555 | W.printNumber("MayHaveNoName", DefRangeRegister->MayHaveNoName); |
David Majnemer | d74490f | 2016-02-03 22:45:21 +0000 | [diff] [blame] | 1556 | printLocalVariableAddrRange(DefRangeRegister->Range, Sec, |
| 1557 | SectionContents); |
David Majnemer | 6f01e05 | 2016-02-04 17:29:13 +0000 | [diff] [blame] | 1558 | printLocalVariableAddrGap(SymData); |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1559 | break; |
| 1560 | } |
| 1561 | case S_DEFRANGE_SUBFIELD_REGISTER: { |
| 1562 | DictScope S(W, "DefRangeSubfieldRegister"); |
| 1563 | const DefRangeSubfieldRegisterSym *DefRangeSubfieldRegisterSym; |
| 1564 | error(consumeObject(SymData, DefRangeSubfieldRegisterSym)); |
| 1565 | W.printNumber("Register", DefRangeSubfieldRegisterSym->Register); |
| 1566 | W.printNumber("MayHaveNoName", |
| 1567 | DefRangeSubfieldRegisterSym->MayHaveNoName); |
| 1568 | W.printNumber("OffsetInParent", |
| 1569 | DefRangeSubfieldRegisterSym->OffsetInParent); |
David Majnemer | d74490f | 2016-02-03 22:45:21 +0000 | [diff] [blame] | 1570 | printLocalVariableAddrRange(DefRangeSubfieldRegisterSym->Range, Sec, |
| 1571 | SectionContents); |
David Majnemer | 6f01e05 | 2016-02-04 17:29:13 +0000 | [diff] [blame] | 1572 | printLocalVariableAddrGap(SymData); |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1573 | break; |
| 1574 | } |
| 1575 | case S_DEFRANGE_FRAMEPOINTER_REL: { |
| 1576 | DictScope S(W, "DefRangeFramePointerRel"); |
| 1577 | const DefRangeFramePointerRelSym *DefRangeFramePointerRel; |
| 1578 | error(consumeObject(SymData, DefRangeFramePointerRel)); |
| 1579 | W.printNumber("Offset", DefRangeFramePointerRel->Offset); |
David Majnemer | d74490f | 2016-02-03 22:45:21 +0000 | [diff] [blame] | 1580 | printLocalVariableAddrRange(DefRangeFramePointerRel->Range, Sec, |
| 1581 | SectionContents); |
David Majnemer | 6f01e05 | 2016-02-04 17:29:13 +0000 | [diff] [blame] | 1582 | printLocalVariableAddrGap(SymData); |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1583 | break; |
| 1584 | } |
| 1585 | case S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE: { |
| 1586 | DictScope S(W, "DefRangeFramePointerRelFullScope"); |
| 1587 | const DefRangeFramePointerRelFullScopeSym |
| 1588 | *DefRangeFramePointerRelFullScope; |
| 1589 | error(consumeObject(SymData, DefRangeFramePointerRelFullScope)); |
| 1590 | W.printNumber("Offset", DefRangeFramePointerRelFullScope->Offset); |
| 1591 | break; |
| 1592 | } |
| 1593 | case S_DEFRANGE_REGISTER_REL: { |
| 1594 | DictScope S(W, "DefRangeRegisterRel"); |
| 1595 | const DefRangeRegisterRelSym *DefRangeRegisterRel; |
| 1596 | error(consumeObject(SymData, DefRangeRegisterRel)); |
| 1597 | W.printNumber("BaseRegister", DefRangeRegisterRel->BaseRegister); |
| 1598 | W.printBoolean("HasSpilledUDTMember", |
| 1599 | DefRangeRegisterRel->hasSpilledUDTMember()); |
| 1600 | W.printNumber("OffsetInParent", DefRangeRegisterRel->offsetInParent()); |
Reid Kleckner | 98762d2 | 2016-02-05 19:15:45 +0000 | [diff] [blame] | 1601 | W.printNumber("BasePointerOffset", |
| 1602 | DefRangeRegisterRel->BasePointerOffset); |
David Majnemer | d74490f | 2016-02-03 22:45:21 +0000 | [diff] [blame] | 1603 | printLocalVariableAddrRange(DefRangeRegisterRel->Range, Sec, |
| 1604 | SectionContents); |
David Majnemer | 6f01e05 | 2016-02-04 17:29:13 +0000 | [diff] [blame] | 1605 | printLocalVariableAddrGap(SymData); |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1606 | break; |
| 1607 | } |
| 1608 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1609 | case S_CALLSITEINFO: { |
| 1610 | DictScope S(W, "CallSiteInfo"); |
| 1611 | const CallSiteInfoSym *CallSiteInfo; |
| 1612 | error(consumeObject(SymData, CallSiteInfo)); |
| 1613 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1614 | StringRef LinkageName; |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1615 | printRelocatedField("CodeOffset", Sec, SectionContents, |
| 1616 | &CallSiteInfo->CodeOffset, &LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1617 | W.printHex("Segment", CallSiteInfo->Segment); |
| 1618 | W.printHex("Reserved", CallSiteInfo->Reserved); |
| 1619 | printTypeIndex("Type", CallSiteInfo->Type); |
| 1620 | W.printString("LinkageName", LinkageName); |
| 1621 | break; |
| 1622 | } |
| 1623 | |
| 1624 | case S_HEAPALLOCSITE: { |
| 1625 | DictScope S(W, "HeapAllocationSite"); |
| 1626 | const HeapAllocationSiteSym *HeapAllocationSite; |
| 1627 | error(consumeObject(SymData, HeapAllocationSite)); |
| 1628 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1629 | StringRef LinkageName; |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1630 | printRelocatedField("CodeOffset", Sec, SectionContents, |
| 1631 | &HeapAllocationSite->CodeOffset, &LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1632 | W.printHex("Segment", HeapAllocationSite->Segment); |
| 1633 | W.printHex("CallInstructionSize", |
| 1634 | HeapAllocationSite->CallInstructionSize); |
| 1635 | printTypeIndex("Type", HeapAllocationSite->Type); |
| 1636 | W.printString("LinkageName", LinkageName); |
| 1637 | break; |
| 1638 | } |
| 1639 | |
| 1640 | case S_FRAMECOOKIE: { |
| 1641 | DictScope S(W, "FrameCookie"); |
| 1642 | const FrameCookieSym *FrameCookie; |
| 1643 | error(consumeObject(SymData, FrameCookie)); |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1644 | |
| 1645 | StringRef LinkageName; |
| 1646 | printRelocatedField("CodeOffset", Sec, SectionContents, |
| 1647 | &FrameCookie->CodeOffset, &LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1648 | W.printHex("Register", FrameCookie->Register); |
| 1649 | W.printEnum("CookieKind", uint16_t(FrameCookie->CookieKind), |
| 1650 | makeArrayRef(FrameCookieKinds)); |
| 1651 | break; |
| 1652 | } |
| 1653 | |
| 1654 | case S_LDATA32: |
| 1655 | case S_GDATA32: |
| 1656 | case S_LMANDATA: |
| 1657 | case S_GMANDATA: { |
| 1658 | DictScope S(W, "DataSym"); |
| 1659 | const DataSym *Data; |
| 1660 | error(consumeObject(SymData, Data)); |
| 1661 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1662 | StringRef DisplayName = SymData.split('\0').first; |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1663 | StringRef LinkageName; |
| 1664 | printRelocatedField("DataOffset", Sec, SectionContents, &Data->DataOffset, |
| 1665 | &LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1666 | printTypeIndex("Type", Data->Type); |
| 1667 | W.printString("DisplayName", DisplayName); |
| 1668 | W.printString("LinkageName", LinkageName); |
| 1669 | break; |
| 1670 | } |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1671 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1672 | case S_LTHREAD32: |
| 1673 | case S_GTHREAD32: { |
| 1674 | DictScope S(W, "ThreadLocalDataSym"); |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1675 | const ThreadLocalDataSym *Data; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1676 | error(consumeObject(SymData, Data)); |
| 1677 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1678 | StringRef DisplayName = SymData.split('\0').first; |
Reid Kleckner | 2893fd1 | 2016-01-14 17:51:54 +0000 | [diff] [blame] | 1679 | StringRef LinkageName; |
| 1680 | printRelocatedField("DataOffset", Sec, SectionContents, &Data->DataOffset, |
| 1681 | &LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1682 | printTypeIndex("Type", Data->Type); |
| 1683 | W.printString("DisplayName", DisplayName); |
| 1684 | W.printString("LinkageName", LinkageName); |
| 1685 | break; |
| 1686 | } |
| 1687 | |
| 1688 | case S_OBJNAME: { |
| 1689 | DictScope S(W, "ObjectName"); |
| 1690 | const ObjNameSym *ObjName; |
| 1691 | error(consumeObject(SymData, ObjName)); |
| 1692 | W.printHex("Signature", ObjName->Signature); |
| 1693 | StringRef ObjectName = SymData.split('\0').first; |
| 1694 | W.printString("ObjectName", ObjectName); |
| 1695 | break; |
| 1696 | } |
| 1697 | |
| 1698 | case S_COMPILE3: { |
| 1699 | DictScope S(W, "CompilerFlags"); |
| 1700 | const CompileSym3 *CompFlags; |
| 1701 | error(consumeObject(SymData, CompFlags)); |
| 1702 | W.printEnum("Language", CompFlags->getLanguage(), |
| 1703 | makeArrayRef(SourceLanguages)); |
| 1704 | W.printFlags("Flags", CompFlags->flags & ~0xff, |
| 1705 | makeArrayRef(CompileSym3Flags)); |
| 1706 | W.printEnum("Machine", unsigned(CompFlags->Machine), |
| 1707 | makeArrayRef(CPUTypeNames)); |
| 1708 | std::string FrontendVersion; |
| 1709 | { |
| 1710 | raw_string_ostream Out(FrontendVersion); |
| 1711 | Out << CompFlags->VersionFrontendMajor << '.' |
| 1712 | << CompFlags->VersionFrontendMinor << '.' |
| 1713 | << CompFlags->VersionFrontendBuild << '.' |
| 1714 | << CompFlags->VersionFrontendQFE; |
Zachary Turner | 99f0215 | 2015-02-18 19:32:05 +0000 | [diff] [blame] | 1715 | } |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1716 | std::string BackendVersion; |
| 1717 | { |
| 1718 | raw_string_ostream Out(BackendVersion); |
| 1719 | Out << CompFlags->VersionBackendMajor << '.' |
| 1720 | << CompFlags->VersionBackendMinor << '.' |
| 1721 | << CompFlags->VersionBackendBuild << '.' |
| 1722 | << CompFlags->VersionBackendQFE; |
| 1723 | } |
| 1724 | W.printString("FrontendVersion", FrontendVersion); |
| 1725 | W.printString("BackendVersion", BackendVersion); |
| 1726 | StringRef VersionName = SymData.split('\0').first; |
| 1727 | W.printString("VersionName", VersionName); |
| 1728 | break; |
| 1729 | } |
Zachary Turner | 99f0215 | 2015-02-18 19:32:05 +0000 | [diff] [blame] | 1730 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1731 | case S_FRAMEPROC: { |
| 1732 | DictScope S(W, "FrameProc"); |
| 1733 | const FrameProcSym *FrameProc; |
| 1734 | error(consumeObject(SymData, FrameProc)); |
| 1735 | W.printHex("TotalFrameBytes", FrameProc->TotalFrameBytes); |
| 1736 | W.printHex("PaddingFrameBytes", FrameProc->PaddingFrameBytes); |
| 1737 | W.printHex("OffsetToPadding", FrameProc->OffsetToPadding); |
| 1738 | W.printHex("BytesOfCalleeSavedRegisters", FrameProc->BytesOfCalleeSavedRegisters); |
| 1739 | W.printHex("OffsetOfExceptionHandler", FrameProc->OffsetOfExceptionHandler); |
| 1740 | W.printHex("SectionIdOfExceptionHandler", FrameProc->SectionIdOfExceptionHandler); |
| 1741 | W.printFlags("Flags", FrameProc->Flags, makeArrayRef(FrameProcSymFlags)); |
| 1742 | break; |
| 1743 | } |
| 1744 | |
| 1745 | case S_UDT: |
| 1746 | case S_COBOLUDT: { |
| 1747 | DictScope S(W, "UDT"); |
| 1748 | const UDTSym *UDT; |
| 1749 | error(consumeObject(SymData, UDT)); |
| 1750 | printTypeIndex("Type", UDT->Type); |
| 1751 | StringRef UDTName = SymData.split('\0').first; |
| 1752 | W.printString("UDTName", UDTName); |
| 1753 | break; |
| 1754 | } |
| 1755 | |
| 1756 | case S_BPREL32: { |
| 1757 | DictScope S(W, "BPRelativeSym"); |
| 1758 | const BPRelativeSym *BPRel; |
| 1759 | error(consumeObject(SymData, BPRel)); |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1760 | W.printNumber("Offset", BPRel->Offset); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1761 | printTypeIndex("Type", BPRel->Type); |
| 1762 | StringRef VarName = SymData.split('\0').first; |
| 1763 | W.printString("VarName", VarName); |
| 1764 | break; |
| 1765 | } |
| 1766 | |
| 1767 | case S_REGREL32: { |
| 1768 | DictScope S(W, "RegRelativeSym"); |
| 1769 | const RegRelativeSym *RegRel; |
| 1770 | error(consumeObject(SymData, RegRel)); |
| 1771 | W.printHex("Offset", RegRel->Offset); |
| 1772 | printTypeIndex("Type", RegRel->Type); |
| 1773 | W.printHex("Register", RegRel->Register); |
| 1774 | StringRef VarName = SymData.split('\0').first; |
| 1775 | W.printString("VarName", VarName); |
| 1776 | break; |
| 1777 | } |
| 1778 | |
| 1779 | case S_BUILDINFO: { |
| 1780 | DictScope S(W, "BuildInfo"); |
| 1781 | const BuildInfoSym *BuildInfo; |
| 1782 | error(consumeObject(SymData, BuildInfo)); |
| 1783 | W.printNumber("BuildId", BuildInfo->BuildId); |
| 1784 | break; |
| 1785 | } |
| 1786 | |
| 1787 | case S_CONSTANT: |
| 1788 | case S_MANCONSTANT: { |
| 1789 | DictScope S(W, "Constant"); |
| 1790 | const ConstantSym *Constant; |
| 1791 | error(consumeObject(SymData, Constant)); |
| 1792 | printTypeIndex("Type", Constant->Type); |
| 1793 | APSInt Value; |
| 1794 | error(decodeNumerictLeaf(SymData, Value)); |
| 1795 | W.printNumber("Value", Value); |
| 1796 | StringRef Name = SymData.split('\0').first; |
| 1797 | W.printString("Name", Name); |
| 1798 | break; |
| 1799 | } |
| 1800 | |
| 1801 | default: { |
| 1802 | DictScope S(W, "UnknownSym"); |
Reid Kleckner | 6b3faef | 2016-01-13 23:44:57 +0000 | [diff] [blame] | 1803 | W.printHex("Kind", unsigned(Kind)); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1804 | W.printHex("Size", Rec->RecordLength); |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1805 | break; |
| 1806 | } |
Zachary Turner | 99f0215 | 2015-02-18 19:32:05 +0000 | [diff] [blame] | 1807 | } |
Reid Kleckner | 1c7a9cd | 2016-01-14 17:51:57 +0000 | [diff] [blame] | 1808 | |
| 1809 | if (opts::CodeViewSubsectionBytes) |
| 1810 | printBinaryBlockWithRelocs("SymData", Section, SectionContents, |
| 1811 | OrigSymData); |
Reid Kleckner | af49ecb | 2016-01-15 22:09:13 +0000 | [diff] [blame] | 1812 | W.flush(); |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1813 | } |
Reid Kleckner | af49ecb | 2016-01-15 22:09:13 +0000 | [diff] [blame] | 1814 | W.flush(); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1815 | } |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 1816 | |
Reid Kleckner | c31f530 | 2016-01-15 18:06:25 +0000 | [diff] [blame] | 1817 | void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) { |
| 1818 | StringRef Data = Subsection; |
| 1819 | while (!Data.empty()) { |
| 1820 | DictScope S(W, "FileChecksum"); |
| 1821 | const FileChecksum *FC; |
| 1822 | error(consumeObject(Data, FC)); |
| 1823 | if (FC->FileNameOffset >= CVStringTable.size()) |
| 1824 | error(object_error::parse_failed); |
| 1825 | StringRef Filename = |
| 1826 | CVStringTable.drop_front(FC->FileNameOffset).split('\0').first; |
| 1827 | W.printHex("Filename", Filename, FC->FileNameOffset); |
| 1828 | W.printHex("ChecksumSize", FC->ChecksumSize); |
| 1829 | W.printEnum("ChecksumKind", uint8_t(FC->ChecksumKind), |
| 1830 | makeArrayRef(FileChecksumKindNames)); |
| 1831 | if (FC->ChecksumSize >= Data.size()) |
| 1832 | error(object_error::parse_failed); |
| 1833 | StringRef ChecksumBytes = Data.substr(0, FC->ChecksumSize); |
| 1834 | W.printBinary("ChecksumBytes", ChecksumBytes); |
Rafael Espindola | a79078c | 2016-01-18 20:55:24 +0000 | [diff] [blame] | 1835 | unsigned PaddedSize = alignTo(FC->ChecksumSize + sizeof(FileChecksum), 4) - |
| 1836 | sizeof(FileChecksum); |
Reid Kleckner | c31f530 | 2016-01-15 18:06:25 +0000 | [diff] [blame] | 1837 | Data = Data.drop_front(PaddedSize); |
| 1838 | } |
| 1839 | } |
| 1840 | |
Reid Kleckner | e9ab349 | 2016-01-14 19:20:17 +0000 | [diff] [blame] | 1841 | void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) { |
| 1842 | StringRef Data = Subsection; |
| 1843 | uint32_t Signature; |
| 1844 | error(consumeUInt32(Data, Signature)); |
| 1845 | bool HasExtraFiles = Signature == unsigned(InlineeLinesSignature::ExtraFiles); |
| 1846 | |
| 1847 | while (!Data.empty()) { |
| 1848 | const InlineeSourceLine *ISL; |
| 1849 | error(consumeObject(Data, ISL)); |
| 1850 | DictScope S(W, "InlineeSourceLine"); |
| 1851 | printTypeIndex("Inlinee", ISL->Inlinee); |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 1852 | printFileNameForOffset("FileID", ISL->FileID); |
Reid Kleckner | e9ab349 | 2016-01-14 19:20:17 +0000 | [diff] [blame] | 1853 | W.printNumber("SourceLineNum", ISL->SourceLineNum); |
| 1854 | |
| 1855 | if (HasExtraFiles) { |
| 1856 | uint32_t ExtraFileCount; |
| 1857 | error(consumeUInt32(Data, ExtraFileCount)); |
| 1858 | W.printNumber("ExtraFileCount", ExtraFileCount); |
| 1859 | ListScope ExtraFiles(W, "ExtraFiles"); |
| 1860 | for (unsigned I = 0; I < ExtraFileCount; ++I) { |
| 1861 | uint32_t FileID; |
| 1862 | error(consumeUInt32(Data, FileID)); |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 1863 | printFileNameForOffset("FileID", FileID); |
Reid Kleckner | e9ab349 | 2016-01-14 19:20:17 +0000 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 1869 | StringRef getLeafDataBytesAsString(StringRef LeafData) { |
| 1870 | StringRef Leading; |
| 1871 | std::tie(Leading, std::ignore) = LeafData.split('\0'); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1872 | return Leading; |
| 1873 | } |
| 1874 | |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 1875 | StringRef CVTypeDumper::getTypeName(TypeIndex TI) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1876 | if (TI.isNoType()) |
| 1877 | return "<no type>"; |
| 1878 | |
| 1879 | if (TI.isSimple()) { |
| 1880 | // This is a simple type. |
| 1881 | for (const auto &SimpleTypeName : SimpleTypeNames) { |
| 1882 | if (SimpleTypeName.Value == TI.getSimpleKind()) { |
| 1883 | if (TI.getSimpleMode() == SimpleTypeMode::Direct) |
| 1884 | return SimpleTypeName.Name.drop_back(1); |
| 1885 | // Otherwise, this is a pointer type. We gloss over the distinction |
| 1886 | // between near, far, 64, 32, etc, and just give a pointer type. |
| 1887 | return SimpleTypeName.Name; |
| 1888 | } |
| 1889 | } |
| 1890 | return "<unknown simple type>"; |
| 1891 | } |
| 1892 | |
| 1893 | // User-defined type. |
| 1894 | StringRef UDTName; |
| 1895 | unsigned UDTIndex = TI.getIndex() - 0x1000; |
| 1896 | if (UDTIndex < CVUDTNames.size()) |
| 1897 | return CVUDTNames[UDTIndex]; |
| 1898 | |
| 1899 | return "<unknown UDT>"; |
| 1900 | } |
| 1901 | |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 1902 | void CVTypeDumper::printTypeIndex(StringRef FieldName, TypeIndex TI) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1903 | StringRef TypeName; |
| 1904 | if (!TI.isNoType()) |
| 1905 | TypeName = getTypeName(TI); |
| 1906 | if (!TypeName.empty()) |
| 1907 | W.printHex(FieldName, TypeName, TI.getIndex()); |
| 1908 | else |
| 1909 | W.printHex(FieldName, TI.getIndex()); |
| 1910 | } |
| 1911 | |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1912 | void COFFDumper::printLocalVariableAddrRange( |
David Majnemer | d74490f | 2016-02-03 22:45:21 +0000 | [diff] [blame] | 1913 | const LocalVariableAddrRange &Range, const coff_section *Sec, |
| 1914 | StringRef SectionContents) { |
David Majnemer | 6f01e05 | 2016-02-04 17:29:13 +0000 | [diff] [blame] | 1915 | DictScope S(W, "LocalVariableAddrRange"); |
David Majnemer | d74490f | 2016-02-03 22:45:21 +0000 | [diff] [blame] | 1916 | printRelocatedField("OffsetStart", Sec, SectionContents, &Range.OffsetStart); |
| 1917 | W.printHex("ISectStart", Range.ISectStart); |
Reid Kleckner | 4ab992d | 2016-02-11 23:40:14 +0000 | [diff] [blame] | 1918 | W.printHex("Range", Range.Range); |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
David Majnemer | 4d12351 | 2016-02-04 17:37:30 +0000 | [diff] [blame] | 1921 | void COFFDumper::printLocalVariableAddrGap(StringRef &SymData) { |
David Majnemer | 6f01e05 | 2016-02-04 17:29:13 +0000 | [diff] [blame] | 1922 | while (!SymData.empty()) { |
| 1923 | const LocalVariableAddrGap *Gap; |
| 1924 | error(consumeObject(SymData, Gap)); |
| 1925 | ListScope S(W, "LocalVariableAddrGap"); |
Reid Kleckner | 4ab992d | 2016-02-11 23:40:14 +0000 | [diff] [blame] | 1926 | W.printHex("GapStartOffset", Gap->GapStartOffset); |
| 1927 | W.printHex("Range", Gap->Range); |
David Majnemer | 6f01e05 | 2016-02-04 17:29:13 +0000 | [diff] [blame] | 1928 | } |
David Majnemer | ac10cfd | 2016-02-03 22:36:46 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
Reid Kleckner | 8e7275c | 2016-01-15 00:11:21 +0000 | [diff] [blame] | 1931 | StringRef COFFDumper::getFileNameForFileOffset(uint32_t FileOffset) { |
| 1932 | // The file checksum subsection should precede all references to it. |
| 1933 | if (!CVFileChecksumTable.data() || !CVStringTable.data()) |
| 1934 | error(object_error::parse_failed); |
| 1935 | // Check if the file checksum table offset is valid. |
| 1936 | if (FileOffset >= CVFileChecksumTable.size()) |
| 1937 | error(object_error::parse_failed); |
| 1938 | |
| 1939 | // The string table offset comes first before the file checksum. |
| 1940 | StringRef Data = CVFileChecksumTable.drop_front(FileOffset); |
| 1941 | uint32_t StringOffset; |
| 1942 | error(consumeUInt32(Data, StringOffset)); |
| 1943 | |
| 1944 | // Check if the string table offset is valid. |
| 1945 | if (StringOffset >= CVStringTable.size()) |
| 1946 | error(object_error::parse_failed); |
| 1947 | |
| 1948 | // Return the null-terminated string. |
| 1949 | return CVStringTable.drop_front(StringOffset).split('\0').first; |
| 1950 | } |
| 1951 | |
| 1952 | void COFFDumper::printFileNameForOffset(StringRef Label, uint32_t FileOffset) { |
| 1953 | W.printHex(Label, getFileNameForFileOffset(FileOffset), FileOffset); |
| 1954 | } |
| 1955 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 1956 | static StringRef getLeafTypeName(TypeLeafKind LT) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 1957 | switch (LT) { |
| 1958 | case LF_STRING_ID: return "StringId"; |
| 1959 | case LF_FIELDLIST: return "FieldList"; |
| 1960 | case LF_ARGLIST: |
| 1961 | case LF_SUBSTR_LIST: return "ArgList"; |
| 1962 | case LF_CLASS: |
| 1963 | case LF_STRUCTURE: |
| 1964 | case LF_INTERFACE: return "ClassType"; |
| 1965 | case LF_UNION: return "UnionType"; |
| 1966 | case LF_ENUM: return "EnumType"; |
| 1967 | case LF_ARRAY: return "ArrayType"; |
| 1968 | case LF_VFTABLE: return "VFTableType"; |
| 1969 | case LF_MFUNC_ID: return "MemberFuncId"; |
| 1970 | case LF_PROCEDURE: return "ProcedureType"; |
| 1971 | case LF_MFUNCTION: return "MemberFunctionType"; |
| 1972 | case LF_METHODLIST: return "MethodListEntry"; |
| 1973 | case LF_FUNC_ID: return "FuncId"; |
| 1974 | case LF_TYPESERVER2: return "TypeServer2"; |
| 1975 | case LF_POINTER: return "PointerType"; |
| 1976 | case LF_MODIFIER: return "TypeModifier"; |
| 1977 | case LF_VTSHAPE: return "VTableShape"; |
| 1978 | case LF_UDT_SRC_LINE: return "UDTSrcLine"; |
| 1979 | case LF_BUILDINFO: return "BuildInfo"; |
| 1980 | default: break; |
| 1981 | } |
| 1982 | return "UnknownLeaf"; |
| 1983 | } |
| 1984 | |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 1985 | // A const input iterator interface to the CodeView type stream. |
| 1986 | class CodeViewTypeIterator { |
| 1987 | public: |
| 1988 | struct TypeRecord { |
| 1989 | std::size_t Length; |
| 1990 | TypeLeafKind Leaf; |
| 1991 | StringRef LeafData; |
| 1992 | }; |
| 1993 | |
| 1994 | explicit CodeViewTypeIterator(const StringRef &SectionData) |
| 1995 | : Data(SectionData), AtEnd(false) { |
| 1996 | if (Data.size() >= 4) { |
| 1997 | Magic = *reinterpret_cast<const ulittle32_t *>(Data.data()); |
| 1998 | Data = Data.drop_front(4); |
| 1999 | } |
| 2000 | next(); // Prime the pump |
| 2001 | } |
| 2002 | |
| 2003 | CodeViewTypeIterator() : AtEnd(true) {} |
| 2004 | |
| 2005 | // For iterators to compare equal, they must both point at the same record |
| 2006 | // in the same data stream, or they must both be at the end of a stream. |
| 2007 | friend bool operator==(const CodeViewTypeIterator &lhs, |
| 2008 | const CodeViewTypeIterator &rhs); |
| 2009 | |
| 2010 | friend bool operator!=(const CodeViewTypeIterator &lhs, |
| 2011 | const CodeViewTypeIterator &rhs); |
| 2012 | |
| 2013 | unsigned getMagic() const { return Magic; } |
| 2014 | |
| 2015 | const TypeRecord &operator*() const { |
| 2016 | assert(!AtEnd); |
| 2017 | return Current; |
| 2018 | } |
| 2019 | |
| 2020 | const TypeRecord *operator->() const { |
| 2021 | assert(!AtEnd); |
| 2022 | return &Current; |
| 2023 | } |
| 2024 | |
| 2025 | CodeViewTypeIterator operator++() { |
| 2026 | next(); |
| 2027 | return *this; |
| 2028 | } |
| 2029 | |
| 2030 | CodeViewTypeIterator operator++(int) { |
| 2031 | CodeViewTypeIterator Original = *this; |
| 2032 | ++*this; |
| 2033 | return Original; |
| 2034 | } |
| 2035 | |
| 2036 | private: |
| 2037 | void next() { |
| 2038 | assert(!AtEnd && "Attempted to advance more than one past the last rec"); |
| 2039 | if (Data.empty()) { |
| 2040 | // We've advanced past the last record. |
| 2041 | AtEnd = true; |
| 2042 | return; |
| 2043 | } |
| 2044 | |
| 2045 | const TypeRecordPrefix *Rec; |
| 2046 | if (consumeObject(Data, Rec)) |
| 2047 | return; |
| 2048 | Current.Length = Rec->Len; |
| 2049 | Current.Leaf = static_cast<TypeLeafKind>(uint16_t(Rec->Leaf)); |
| 2050 | Current.LeafData = Data.substr(0, Current.Length - 2); |
| 2051 | |
| 2052 | // The next record starts immediately after this one. |
| 2053 | Data = Data.drop_front(Current.LeafData.size()); |
| 2054 | |
| 2055 | // FIXME: The stream contains LF_PAD bytes that we need to ignore, but those |
| 2056 | // are typically included in LeafData. We may need to call skipPadding() if |
| 2057 | // we ever find a record that doesn't count those bytes. |
| 2058 | |
| 2059 | return; |
| 2060 | } |
| 2061 | |
| 2062 | StringRef Data; |
| 2063 | unsigned Magic = 0; |
| 2064 | TypeRecord Current; |
| 2065 | bool AtEnd; |
| 2066 | }; |
| 2067 | |
| 2068 | bool operator==(const CodeViewTypeIterator &lhs, |
| 2069 | const CodeViewTypeIterator &rhs) { |
| 2070 | return (lhs.Data.begin() == rhs.Data.begin()) || (lhs.AtEnd && rhs.AtEnd); |
| 2071 | } |
| 2072 | |
| 2073 | bool operator!=(const CodeViewTypeIterator &lhs, |
| 2074 | const CodeViewTypeIterator &rhs) { |
| 2075 | return !(lhs == rhs); |
| 2076 | } |
| 2077 | |
| 2078 | struct CodeViewTypeStream { |
| 2079 | CodeViewTypeIterator begin; |
| 2080 | CodeViewTypeIterator end; |
| 2081 | unsigned Magic; |
| 2082 | }; |
| 2083 | |
| 2084 | CodeViewTypeStream CreateCodeViewTypeIter(const StringRef &Data) { |
| 2085 | CodeViewTypeStream Stream; |
| 2086 | Stream.begin = CodeViewTypeIterator(Data); |
| 2087 | Stream.end = CodeViewTypeIterator(); |
| 2088 | Stream.Magic = Stream.begin.getMagic(); |
| 2089 | |
| 2090 | return Stream; |
| 2091 | } |
| 2092 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2093 | void COFFDumper::printCodeViewTypeSection(StringRef SectionName, |
| 2094 | const SectionRef &Section) { |
| 2095 | ListScope D(W, "CodeViewTypes"); |
| 2096 | W.printNumber("Section", SectionName, Obj->getSectionID(Section)); |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2097 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2098 | StringRef Data; |
| 2099 | error(Section.getContents(Data)); |
Reid Kleckner | b2bd281 | 2016-05-02 18:10:00 +0000 | [diff] [blame] | 2100 | if (opts::CodeViewSubsectionBytes) |
| 2101 | W.printBinaryBlock("Data", Data); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2102 | |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 2103 | CVTD.dump(Data); |
| 2104 | } |
| 2105 | |
| 2106 | void CVTypeDumper::dump(StringRef Data) { |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2107 | CodeViewTypeStream Stream = CreateCodeViewTypeIter(Data); |
| 2108 | W.printHex("Magic", Stream.Magic); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2109 | |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2110 | for (auto Iter = Stream.begin; Iter != Stream.end; ++Iter) { |
| 2111 | StringRef LeafData = Iter->LeafData; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2112 | |
| 2113 | // Find the name of this leaf type. |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2114 | StringRef LeafName = getLeafTypeName(Iter->Leaf); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2115 | DictScope S(W, LeafName); |
| 2116 | unsigned NextTypeIndex = 0x1000 + CVUDTNames.size(); |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2117 | W.printEnum("TypeLeafKind", unsigned(Iter->Leaf), |
| 2118 | makeArrayRef(LeafTypeNames)); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2119 | W.printHex("TypeIndex", NextTypeIndex); |
| 2120 | |
| 2121 | // Fill this in inside the switch to get something in CVUDTNames. |
| 2122 | StringRef Name; |
| 2123 | |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2124 | switch (Iter->Leaf) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2125 | default: { |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2126 | W.printHex("Size", Iter->Length); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2127 | break; |
| 2128 | } |
| 2129 | |
| 2130 | case LF_STRING_ID: { |
| 2131 | const StringId *String; |
| 2132 | error(consumeObject(LeafData, String)); |
| 2133 | W.printHex("Id", String->id.getIndex()); |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2134 | StringRef StringData = getLeafDataBytesAsString(LeafData); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2135 | W.printString("StringData", StringData); |
| 2136 | // Put this in CVUDTNames so it gets printed with LF_UDT_SRC_LINE. |
| 2137 | Name = StringData; |
| 2138 | break; |
| 2139 | } |
| 2140 | |
| 2141 | case LF_FIELDLIST: { |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2142 | W.printHex("Size", Iter->Length); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2143 | // FieldList has no fixed prefix that can be described with a struct. All |
| 2144 | // the bytes must be interpreted as more records. |
| 2145 | printCodeViewFieldList(LeafData); |
| 2146 | break; |
| 2147 | } |
| 2148 | |
| 2149 | case LF_ARGLIST: |
| 2150 | case LF_SUBSTR_LIST: { |
| 2151 | const ArgList *Args; |
| 2152 | error(consumeObject(LeafData, Args)); |
| 2153 | W.printNumber("NumArgs", Args->NumArgs); |
| 2154 | ListScope Arguments(W, "Arguments"); |
| 2155 | SmallString<256> TypeName("("); |
| 2156 | for (uint32_t ArgI = 0; ArgI != Args->NumArgs; ++ArgI) { |
| 2157 | const TypeIndex *Type; |
| 2158 | error(consumeObject(LeafData, Type)); |
| 2159 | printTypeIndex("ArgType", *Type); |
| 2160 | StringRef ArgTypeName = getTypeName(*Type); |
| 2161 | TypeName.append(ArgTypeName); |
| 2162 | if (ArgI + 1 != Args->NumArgs) |
| 2163 | TypeName.append(", "); |
| 2164 | } |
| 2165 | TypeName.push_back(')'); |
| 2166 | Name = TypeNames.insert(TypeName).first->getKey(); |
| 2167 | break; |
| 2168 | } |
| 2169 | |
| 2170 | case LF_CLASS: |
| 2171 | case LF_STRUCTURE: |
| 2172 | case LF_INTERFACE: { |
| 2173 | const ClassType *Class; |
| 2174 | error(consumeObject(LeafData, Class)); |
| 2175 | W.printNumber("MemberCount", Class->MemberCount); |
| 2176 | uint16_t Props = Class->Properties; |
| 2177 | W.printFlags("Properties", Props, makeArrayRef(ClassOptionNames)); |
| 2178 | printTypeIndex("FieldList", Class->FieldList); |
| 2179 | printTypeIndex("DerivedFrom", Class->DerivedFrom); |
| 2180 | printTypeIndex("VShape", Class->VShape); |
| 2181 | uint64_t SizeOf; |
| 2182 | error(decodeUIntLeaf(LeafData, SizeOf)); |
| 2183 | W.printNumber("SizeOf", SizeOf); |
| 2184 | StringRef LinkageName; |
| 2185 | std::tie(Name, LinkageName) = LeafData.split('\0'); |
| 2186 | W.printString("Name", Name); |
| 2187 | if (Props & uint16_t(ClassOptions::HasUniqueName)) { |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2188 | LinkageName = getLeafDataBytesAsString(LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2189 | if (LinkageName.empty()) |
| 2190 | return error(object_error::parse_failed); |
| 2191 | W.printString("LinkageName", LinkageName); |
| 2192 | } |
| 2193 | break; |
| 2194 | } |
| 2195 | |
| 2196 | case LF_UNION: { |
| 2197 | const UnionType *Union; |
| 2198 | error(consumeObject(LeafData, Union)); |
| 2199 | W.printNumber("MemberCount", Union->MemberCount); |
| 2200 | uint16_t Props = Union->Properties; |
| 2201 | W.printFlags("Properties", Props, makeArrayRef(ClassOptionNames)); |
| 2202 | printTypeIndex("FieldList", Union->FieldList); |
| 2203 | uint64_t SizeOf; |
| 2204 | error(decodeUIntLeaf(LeafData, SizeOf)); |
| 2205 | W.printNumber("SizeOf", SizeOf); |
| 2206 | StringRef LinkageName; |
| 2207 | std::tie(Name, LinkageName) = LeafData.split('\0'); |
| 2208 | W.printString("Name", Name); |
| 2209 | if (Props & uint16_t(ClassOptions::HasUniqueName)) { |
Adrian McCarthy | 963a331 | 2016-05-02 23:45:03 +0000 | [diff] [blame] | 2210 | LinkageName = getLeafDataBytesAsString(LinkageName); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2211 | if (LinkageName.empty()) |
| 2212 | return error(object_error::parse_failed); |
| 2213 | W.printString("LinkageName", LinkageName); |
| 2214 | } |
| 2215 | break; |
| 2216 | } |
| 2217 | |
| 2218 | case LF_ENUM: { |
| 2219 | const EnumType *Enum; |
| 2220 | error(consumeObject(LeafData, Enum)); |
| 2221 | W.printNumber("NumEnumerators", Enum->NumEnumerators); |
| 2222 | W.printFlags("Properties", uint16_t(Enum->Properties), |
| 2223 | makeArrayRef(ClassOptionNames)); |
| 2224 | printTypeIndex("UnderlyingType", Enum->UnderlyingType); |
| 2225 | printTypeIndex("FieldListType", Enum->FieldListType); |
| 2226 | Name = LeafData.split('\0').first; |
| 2227 | W.printString("Name", Name); |
| 2228 | break; |
| 2229 | } |
| 2230 | |
| 2231 | case LF_ARRAY: { |
| 2232 | const ArrayType *AT; |
| 2233 | error(consumeObject(LeafData, AT)); |
| 2234 | printTypeIndex("ElementType", AT->ElementType); |
| 2235 | printTypeIndex("IndexType", AT->IndexType); |
| 2236 | uint64_t SizeOf; |
| 2237 | error(decodeUIntLeaf(LeafData, SizeOf)); |
| 2238 | W.printNumber("SizeOf", SizeOf); |
| 2239 | Name = LeafData.split('\0').first; |
| 2240 | W.printString("Name", Name); |
| 2241 | break; |
| 2242 | } |
| 2243 | |
| 2244 | case LF_VFTABLE: { |
| 2245 | const VFTableType *VFT; |
| 2246 | error(consumeObject(LeafData, VFT)); |
| 2247 | printTypeIndex("CompleteClass", VFT->CompleteClass); |
| 2248 | printTypeIndex("OverriddenVFTable", VFT->OverriddenVFTable); |
| 2249 | W.printHex("VFPtrOffset", VFT->VFPtrOffset); |
| 2250 | StringRef NamesData = LeafData.substr(0, VFT->NamesLen); |
| 2251 | std::tie(Name, NamesData) = NamesData.split('\0'); |
| 2252 | W.printString("VFTableName", Name); |
| 2253 | while (!NamesData.empty()) { |
| 2254 | StringRef MethodName; |
| 2255 | std::tie(MethodName, NamesData) = NamesData.split('\0'); |
| 2256 | W.printString("MethodName", MethodName); |
| 2257 | } |
| 2258 | break; |
| 2259 | } |
| 2260 | |
| 2261 | case LF_MFUNC_ID: { |
| 2262 | const MemberFuncId *Id; |
| 2263 | error(consumeObject(LeafData, Id)); |
| 2264 | printTypeIndex("ClassType", Id->ClassType); |
| 2265 | printTypeIndex("FunctionType", Id->FunctionType); |
| 2266 | Name = LeafData.split('\0').first; |
| 2267 | W.printString("Name", Name); |
| 2268 | break; |
| 2269 | } |
| 2270 | |
| 2271 | case LF_PROCEDURE: { |
| 2272 | const ProcedureType *Proc; |
| 2273 | error(consumeObject(LeafData, Proc)); |
| 2274 | printTypeIndex("ReturnType", Proc->ReturnType); |
| 2275 | W.printEnum("CallingConvention", uint8_t(Proc->CallConv), |
| 2276 | makeArrayRef(CallingConventions)); |
| 2277 | W.printFlags("FunctionOptions", uint8_t(Proc->Options), |
| 2278 | makeArrayRef(FunctionOptionEnum)); |
| 2279 | W.printNumber("NumParameters", Proc->NumParameters); |
| 2280 | printTypeIndex("ArgListType", Proc->ArgListType); |
| 2281 | |
| 2282 | StringRef ReturnTypeName = getTypeName(Proc->ReturnType); |
| 2283 | StringRef ArgListTypeName = getTypeName(Proc->ArgListType); |
| 2284 | SmallString<256> TypeName(ReturnTypeName); |
| 2285 | TypeName.push_back(' '); |
| 2286 | TypeName.append(ArgListTypeName); |
| 2287 | Name = TypeNames.insert(TypeName).first->getKey(); |
| 2288 | break; |
| 2289 | } |
| 2290 | |
| 2291 | case LF_MFUNCTION: { |
| 2292 | const MemberFunctionType *MemberFunc; |
| 2293 | error(consumeObject(LeafData, MemberFunc)); |
| 2294 | printTypeIndex("ReturnType", MemberFunc->ReturnType); |
| 2295 | printTypeIndex("ClassType", MemberFunc->ClassType); |
| 2296 | printTypeIndex("ThisType", MemberFunc->ThisType); |
| 2297 | W.printEnum("CallingConvention", uint8_t(MemberFunc->CallConv), |
| 2298 | makeArrayRef(CallingConventions)); |
| 2299 | W.printFlags("FunctionOptions", uint8_t(MemberFunc->Options), |
| 2300 | makeArrayRef(FunctionOptionEnum)); |
| 2301 | W.printNumber("NumParameters", MemberFunc->NumParameters); |
| 2302 | printTypeIndex("ArgListType", MemberFunc->ArgListType); |
| 2303 | W.printNumber("ThisAdjustment", MemberFunc->ThisAdjustment); |
| 2304 | |
| 2305 | StringRef ReturnTypeName = getTypeName(MemberFunc->ReturnType); |
| 2306 | StringRef ClassTypeName = getTypeName(MemberFunc->ClassType); |
| 2307 | StringRef ArgListTypeName = getTypeName(MemberFunc->ArgListType); |
| 2308 | SmallString<256> TypeName(ReturnTypeName); |
| 2309 | TypeName.push_back(' '); |
| 2310 | TypeName.append(ClassTypeName); |
| 2311 | TypeName.append("::"); |
| 2312 | TypeName.append(ArgListTypeName); |
| 2313 | Name = TypeNames.insert(TypeName).first->getKey(); |
| 2314 | break; |
| 2315 | } |
| 2316 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 2317 | case LF_METHODLIST: { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2318 | while (!LeafData.empty()) { |
| 2319 | const MethodListEntry *Method; |
| 2320 | error(consumeObject(LeafData, Method)); |
| 2321 | ListScope S(W, "Method"); |
| 2322 | printMemberAttributes(Method->Attrs); |
| 2323 | printTypeIndex("Type", Method->Type); |
| 2324 | if (Method->isIntroducedVirtual()) { |
| 2325 | const little32_t *VFTOffsetPtr; |
| 2326 | error(consumeObject(LeafData, VFTOffsetPtr)); |
| 2327 | W.printHex("VFTableOffset", *VFTOffsetPtr); |
| 2328 | } |
| 2329 | } |
| 2330 | break; |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 2331 | } |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2332 | |
| 2333 | case LF_FUNC_ID: { |
| 2334 | const FuncId *Func; |
| 2335 | error(consumeObject(LeafData, Func)); |
| 2336 | printTypeIndex("ParentScope", Func->ParentScope); |
| 2337 | printTypeIndex("FunctionType", Func->FunctionType); |
Reid Kleckner | 089db21 | 2016-01-14 17:52:01 +0000 | [diff] [blame] | 2338 | StringRef Null; |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2339 | std::tie(Name, Null) = LeafData.split('\0'); |
| 2340 | W.printString("Name", Name); |
| 2341 | break; |
| 2342 | } |
| 2343 | |
| 2344 | case LF_TYPESERVER2: { |
| 2345 | const TypeServer2 *TypeServer; |
| 2346 | error(consumeObject(LeafData, TypeServer)); |
| 2347 | W.printBinary("Signature", StringRef(TypeServer->Signature, 16)); |
| 2348 | W.printNumber("Age", TypeServer->Age); |
| 2349 | Name = LeafData.split('\0').first; |
| 2350 | W.printString("Name", Name); |
| 2351 | break; |
| 2352 | } |
| 2353 | |
| 2354 | case LF_POINTER: { |
| 2355 | const PointerType *Ptr; |
| 2356 | error(consumeObject(LeafData, Ptr)); |
| 2357 | printTypeIndex("PointeeType", Ptr->PointeeType); |
| 2358 | W.printHex("PointerAttributes", Ptr->Attrs); |
| 2359 | W.printEnum("PtrType", unsigned(Ptr->getPtrKind()), |
| 2360 | makeArrayRef(PtrKindNames)); |
| 2361 | W.printEnum("PtrMode", unsigned(Ptr->getPtrMode()), |
| 2362 | makeArrayRef(PtrModeNames)); |
| 2363 | W.printNumber("IsFlat", Ptr->isFlat()); |
| 2364 | W.printNumber("IsConst", Ptr->isConst()); |
| 2365 | W.printNumber("IsVolatile", Ptr->isVolatile()); |
| 2366 | W.printNumber("IsUnaligned", Ptr->isUnaligned()); |
| 2367 | |
| 2368 | if (Ptr->isPointerToMember()) { |
| 2369 | const PointerToMemberTail *PMT; |
| 2370 | error(consumeObject(LeafData, PMT)); |
| 2371 | printTypeIndex("ClassType", PMT->ClassType); |
| 2372 | W.printEnum("Representation", PMT->Representation, |
| 2373 | makeArrayRef(PtrMemberRepNames)); |
| 2374 | |
| 2375 | StringRef PointeeName = getTypeName(Ptr->PointeeType); |
| 2376 | StringRef ClassName = getTypeName(PMT->ClassType); |
| 2377 | SmallString<256> TypeName(PointeeName); |
| 2378 | TypeName.push_back(' '); |
| 2379 | TypeName.append(ClassName); |
| 2380 | TypeName.append("::*"); |
| 2381 | Name = TypeNames.insert(TypeName).first->getKey(); |
| 2382 | } else { |
| 2383 | W.printBinaryBlock("TailData", LeafData); |
| 2384 | |
| 2385 | SmallString<256> TypeName; |
| 2386 | if (Ptr->isConst()) |
| 2387 | TypeName.append("const "); |
| 2388 | if (Ptr->isVolatile()) |
| 2389 | TypeName.append("volatile "); |
| 2390 | if (Ptr->isUnaligned()) |
| 2391 | TypeName.append("__unaligned "); |
| 2392 | |
| 2393 | TypeName.append(getTypeName(Ptr->PointeeType)); |
| 2394 | |
| 2395 | if (Ptr->getPtrMode() == PointerMode::LValueReference) |
| 2396 | TypeName.append("&"); |
| 2397 | else if (Ptr->getPtrMode() == PointerMode::RValueReference) |
| 2398 | TypeName.append("&&"); |
| 2399 | else if (Ptr->getPtrMode() == PointerMode::Pointer) |
| 2400 | TypeName.append("*"); |
| 2401 | |
| 2402 | Name = TypeNames.insert(TypeName).first->getKey(); |
| 2403 | } |
| 2404 | break; |
| 2405 | } |
| 2406 | |
| 2407 | case LF_MODIFIER: { |
| 2408 | const TypeModifier *Mod; |
| 2409 | error(consumeObject(LeafData, Mod)); |
| 2410 | printTypeIndex("ModifiedType", Mod->ModifiedType); |
| 2411 | W.printFlags("Modifiers", Mod->Modifiers, |
| 2412 | makeArrayRef(TypeModifierNames)); |
| 2413 | |
| 2414 | StringRef ModifiedName = getTypeName(Mod->ModifiedType); |
| 2415 | SmallString<256> TypeName; |
| 2416 | if (Mod->Modifiers & uint16_t(ModifierOptions::Const)) |
| 2417 | TypeName.append("const "); |
| 2418 | if (Mod->Modifiers & uint16_t(ModifierOptions::Volatile)) |
| 2419 | TypeName.append("volatile "); |
| 2420 | if (Mod->Modifiers & uint16_t(ModifierOptions::Unaligned)) |
| 2421 | TypeName.append("__unaligned "); |
| 2422 | TypeName.append(ModifiedName); |
| 2423 | Name = TypeNames.insert(TypeName).first->getKey(); |
| 2424 | break; |
| 2425 | } |
| 2426 | |
| 2427 | case LF_VTSHAPE: { |
| 2428 | const VTableShape *Shape; |
| 2429 | error(consumeObject(LeafData, Shape)); |
| 2430 | unsigned VFEntryCount = Shape->VFEntryCount; |
| 2431 | W.printNumber("VFEntryCount", VFEntryCount); |
| 2432 | // We could print out whether the methods are near or far, but in practice |
| 2433 | // today everything is CV_VTS_near32, so it's just noise. |
| 2434 | break; |
| 2435 | } |
| 2436 | |
| 2437 | case LF_UDT_SRC_LINE: { |
| 2438 | const UDTSrcLine *Line; |
| 2439 | error(consumeObject(LeafData, Line)); |
| 2440 | printTypeIndex("UDT", Line->UDT); |
| 2441 | printTypeIndex("SourceFile", Line->SourceFile); |
| 2442 | W.printNumber("LineNumber", Line->LineNumber); |
| 2443 | break; |
| 2444 | } |
| 2445 | |
| 2446 | case LF_BUILDINFO: { |
| 2447 | const BuildInfo *Args; |
| 2448 | error(consumeObject(LeafData, Args)); |
| 2449 | W.printNumber("NumArgs", Args->NumArgs); |
| 2450 | |
| 2451 | ListScope Arguments(W, "Arguments"); |
| 2452 | for (uint32_t ArgI = 0; ArgI != Args->NumArgs; ++ArgI) { |
| 2453 | const TypeIndex *Type; |
| 2454 | error(consumeObject(LeafData, Type)); |
| 2455 | printTypeIndex("ArgType", *Type); |
| 2456 | } |
| 2457 | break; |
| 2458 | } |
| 2459 | } |
| 2460 | |
Reid Kleckner | 1c7a9cd | 2016-01-14 17:51:57 +0000 | [diff] [blame] | 2461 | if (opts::CodeViewSubsectionBytes) |
| 2462 | W.printBinaryBlock("LeafData", LeafData); |
| 2463 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2464 | CVUDTNames.push_back(Name); |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2465 | } |
| 2466 | } |
| 2467 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 2468 | static StringRef skipPadding(StringRef Data) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2469 | if (Data.empty()) |
| 2470 | return Data; |
| 2471 | uint8_t Leaf = Data.front(); |
| 2472 | if (Leaf < LF_PAD0) |
| 2473 | return Data; |
| 2474 | // Leaf is greater than 0xf0. We should advance by the number of bytes in the |
| 2475 | // low 4 bits. |
| 2476 | return Data.drop_front(Leaf & 0x0F); |
| 2477 | } |
| 2478 | |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 2479 | void CVTypeDumper::printMemberAttributes(MemberAttributes Attrs) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2480 | W.printEnum("AccessSpecifier", uint8_t(Attrs.getAccess()), |
| 2481 | makeArrayRef(MemberAccessNames)); |
| 2482 | auto MK = Attrs.getMethodKind(); |
| 2483 | // Data members will be vanilla. Don't try to print a method kind for them. |
| 2484 | if (MK != MethodKind::Vanilla) |
| 2485 | W.printEnum("MethodKind", unsigned(MK), makeArrayRef(MemberKindNames)); |
| 2486 | if (Attrs.getFlags() != MethodOptions::None) { |
| 2487 | W.printFlags("MethodOptions", unsigned(Attrs.getFlags()), |
| 2488 | makeArrayRef(MethodOptionNames)); |
| 2489 | } |
| 2490 | } |
| 2491 | |
Reid Kleckner | 5cb2b6b | 2016-05-02 20:30:47 +0000 | [diff] [blame] | 2492 | void CVTypeDumper::printCodeViewFieldList(StringRef FieldData) { |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 2493 | while (!FieldData.empty()) { |
| 2494 | const ulittle16_t *LeafPtr; |
| 2495 | error(consumeObject(FieldData, LeafPtr)); |
| 2496 | uint16_t Leaf = *LeafPtr; |
| 2497 | switch (Leaf) { |
| 2498 | default: |
| 2499 | W.printHex("UnknownMember", Leaf); |
| 2500 | // We can't advance once we hit an unknown field. The size is not encoded. |
| 2501 | return; |
| 2502 | |
| 2503 | case LF_NESTTYPE: { |
| 2504 | const NestedType *Nested; |
| 2505 | error(consumeObject(FieldData, Nested)); |
| 2506 | DictScope S(W, "NestedType"); |
| 2507 | printTypeIndex("Type", Nested->Type); |
| 2508 | StringRef Name; |
| 2509 | std::tie(Name, FieldData) = FieldData.split('\0'); |
| 2510 | W.printString("Name", Name); |
| 2511 | break; |
| 2512 | } |
| 2513 | |
| 2514 | case LF_ONEMETHOD: { |
| 2515 | const OneMethod *Method; |
| 2516 | error(consumeObject(FieldData, Method)); |
| 2517 | DictScope S(W, "OneMethod"); |
| 2518 | printMemberAttributes(Method->Attrs); |
| 2519 | printTypeIndex("Type", Method->Type); |
| 2520 | // If virtual, then read the vftable offset. |
| 2521 | if (Method->isIntroducedVirtual()) { |
| 2522 | const little32_t *VFTOffsetPtr; |
| 2523 | error(consumeObject(FieldData, VFTOffsetPtr)); |
| 2524 | W.printHex("VFTableOffset", *VFTOffsetPtr); |
| 2525 | } |
| 2526 | StringRef Name; |
| 2527 | std::tie(Name, FieldData) = FieldData.split('\0'); |
| 2528 | W.printString("Name", Name); |
| 2529 | break; |
| 2530 | } |
| 2531 | |
| 2532 | case LF_METHOD: { |
| 2533 | const OverloadedMethod *Method; |
| 2534 | error(consumeObject(FieldData, Method)); |
| 2535 | DictScope S(W, "OverloadedMethod"); |
| 2536 | W.printHex("MethodCount", Method->MethodCount); |
| 2537 | W.printHex("MethodListIndex", Method->MethList.getIndex()); |
| 2538 | StringRef Name; |
| 2539 | std::tie(Name, FieldData) = FieldData.split('\0'); |
| 2540 | W.printString("Name", Name); |
| 2541 | break; |
| 2542 | } |
| 2543 | |
| 2544 | case LF_MEMBER: { |
| 2545 | const DataMember *Field; |
| 2546 | error(consumeObject(FieldData, Field)); |
| 2547 | DictScope S(W, "DataMember"); |
| 2548 | printMemberAttributes(Field->Attrs); |
| 2549 | printTypeIndex("Type", Field->Type); |
| 2550 | uint64_t FieldOffset; |
| 2551 | error(decodeUIntLeaf(FieldData, FieldOffset)); |
| 2552 | W.printHex("FieldOffset", FieldOffset); |
| 2553 | StringRef Name; |
| 2554 | std::tie(Name, FieldData) = FieldData.split('\0'); |
| 2555 | W.printString("Name", Name); |
| 2556 | break; |
| 2557 | } |
| 2558 | |
| 2559 | case LF_STMEMBER: { |
| 2560 | const StaticDataMember *Field; |
| 2561 | error(consumeObject(FieldData, Field)); |
| 2562 | DictScope S(W, "StaticDataMember"); |
| 2563 | printMemberAttributes(Field->Attrs); |
| 2564 | printTypeIndex("Type", Field->Type); |
| 2565 | StringRef Name; |
| 2566 | std::tie(Name, FieldData) = FieldData.split('\0'); |
| 2567 | W.printString("Name", Name); |
| 2568 | break; |
| 2569 | } |
| 2570 | |
| 2571 | case LF_VFUNCTAB: { |
| 2572 | const VirtualFunctionPointer *VFTable; |
| 2573 | error(consumeObject(FieldData, VFTable)); |
| 2574 | DictScope S(W, "VirtualFunctionPointer"); |
| 2575 | printTypeIndex("Type", VFTable->Type); |
| 2576 | break; |
| 2577 | } |
| 2578 | |
| 2579 | case LF_ENUMERATE: { |
| 2580 | const Enumerator *Enum; |
| 2581 | error(consumeObject(FieldData, Enum)); |
| 2582 | DictScope S(W, "Enumerator"); |
| 2583 | printMemberAttributes(Enum->Attrs); |
| 2584 | APSInt EnumValue; |
| 2585 | error(decodeNumerictLeaf(FieldData, EnumValue)); |
| 2586 | W.printNumber("EnumValue", EnumValue); |
| 2587 | StringRef Name; |
| 2588 | std::tie(Name, FieldData) = FieldData.split('\0'); |
| 2589 | W.printString("Name", Name); |
| 2590 | break; |
| 2591 | } |
| 2592 | |
| 2593 | case LF_BCLASS: |
| 2594 | case LF_BINTERFACE: { |
| 2595 | const BaseClass *Base; |
| 2596 | error(consumeObject(FieldData, Base)); |
| 2597 | DictScope S(W, "BaseClass"); |
| 2598 | printMemberAttributes(Base->Attrs); |
| 2599 | printTypeIndex("BaseType", Base->BaseType); |
| 2600 | uint64_t BaseOffset; |
| 2601 | error(decodeUIntLeaf(FieldData, BaseOffset)); |
| 2602 | W.printHex("BaseOffset", BaseOffset); |
| 2603 | break; |
| 2604 | } |
| 2605 | |
| 2606 | case LF_VBCLASS: |
| 2607 | case LF_IVBCLASS: { |
| 2608 | const VirtualBaseClass *Base; |
| 2609 | error(consumeObject(FieldData, Base)); |
| 2610 | DictScope S(W, "VirtualBaseClass"); |
| 2611 | printMemberAttributes(Base->Attrs); |
| 2612 | printTypeIndex("BaseType", Base->BaseType); |
| 2613 | printTypeIndex("VBPtrType", Base->VBPtrType); |
| 2614 | uint64_t VBPtrOffset, VBTableIndex; |
| 2615 | error(decodeUIntLeaf(FieldData, VBPtrOffset)); |
| 2616 | error(decodeUIntLeaf(FieldData, VBTableIndex)); |
| 2617 | W.printHex("VBPtrOffset", VBPtrOffset); |
| 2618 | W.printHex("VBTableIndex", VBTableIndex); |
| 2619 | break; |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | // Handle padding. |
| 2624 | FieldData = skipPadding(FieldData); |
| 2625 | } |
Timur Iskhodzhanov | 56af52f | 2014-10-23 22:25:31 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2628 | void COFFDumper::printSections() { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2629 | ListScope SectionsD(W, "Sections"); |
| 2630 | int SectionNumber = 0; |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2631 | for (const SectionRef &Sec : Obj->sections()) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2632 | ++SectionNumber; |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2633 | const coff_section *Section = Obj->getCOFFSection(Sec); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2634 | |
| 2635 | StringRef Name; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2636 | error(Sec.getName(Name)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2637 | |
| 2638 | DictScope D(W, "Section"); |
| 2639 | W.printNumber("Number", SectionNumber); |
| 2640 | W.printBinary("Name", Name, Section->Name); |
| 2641 | W.printHex ("VirtualSize", Section->VirtualSize); |
| 2642 | W.printHex ("VirtualAddress", Section->VirtualAddress); |
| 2643 | W.printNumber("RawDataSize", Section->SizeOfRawData); |
| 2644 | W.printHex ("PointerToRawData", Section->PointerToRawData); |
| 2645 | W.printHex ("PointerToRelocations", Section->PointerToRelocations); |
| 2646 | W.printHex ("PointerToLineNumbers", Section->PointerToLinenumbers); |
| 2647 | W.printNumber("RelocationCount", Section->NumberOfRelocations); |
| 2648 | W.printNumber("LineNumberCount", Section->NumberOfLinenumbers); |
| 2649 | W.printFlags ("Characteristics", Section->Characteristics, |
| 2650 | makeArrayRef(ImageSectionCharacteristics), |
| 2651 | COFF::SectionCharacteristics(0x00F00000)); |
| 2652 | |
| 2653 | if (opts::SectionRelocations) { |
| 2654 | ListScope D(W, "Relocations"); |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2655 | for (const RelocationRef &Reloc : Sec.relocations()) |
| 2656 | printRelocation(Sec, Reloc); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | if (opts::SectionSymbols) { |
| 2660 | ListScope D(W, "Symbols"); |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2661 | for (const SymbolRef &Symbol : Obj->symbols()) { |
Rafael Espindola | 8029127 | 2014-10-08 15:28:58 +0000 | [diff] [blame] | 2662 | if (!Sec.containsSymbol(Symbol)) |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2663 | continue; |
| 2664 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2665 | printSymbol(Symbol); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2666 | } |
| 2667 | } |
| 2668 | |
David Majnemer | dac3985 | 2014-09-26 22:32:16 +0000 | [diff] [blame] | 2669 | if (opts::SectionData && |
| 2670 | !(Section->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2671 | StringRef Data; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2672 | error(Sec.getContents(Data)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2673 | |
| 2674 | W.printBinaryBlock("SectionData", Data); |
| 2675 | } |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | void COFFDumper::printRelocations() { |
| 2680 | ListScope D(W, "Relocations"); |
| 2681 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2682 | int SectionNumber = 0; |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2683 | for (const SectionRef &Section : Obj->sections()) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2684 | ++SectionNumber; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2685 | StringRef Name; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2686 | error(Section.getName(Name)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2687 | |
| 2688 | bool PrintedGroup = false; |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2689 | for (const RelocationRef &Reloc : Section.relocations()) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2690 | if (!PrintedGroup) { |
| 2691 | W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n"; |
| 2692 | W.indent(); |
| 2693 | PrintedGroup = true; |
| 2694 | } |
| 2695 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2696 | printRelocation(Section, Reloc); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | if (PrintedGroup) { |
| 2700 | W.unindent(); |
| 2701 | W.startLine() << "}\n"; |
| 2702 | } |
| 2703 | } |
| 2704 | } |
| 2705 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2706 | void COFFDumper::printRelocation(const SectionRef &Section, |
Reid Kleckner | 1c7a9cd | 2016-01-14 17:51:57 +0000 | [diff] [blame] | 2707 | const RelocationRef &Reloc, uint64_t Bias) { |
| 2708 | uint64_t Offset = Reloc.getOffset() - Bias; |
Rafael Espindola | 99c041b | 2015-06-30 01:53:01 +0000 | [diff] [blame] | 2709 | uint64_t RelocType = Reloc.getType(); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2710 | SmallString<32> RelocName; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2711 | StringRef SymbolName; |
Rafael Espindola | 41bb432 | 2015-06-30 04:08:37 +0000 | [diff] [blame] | 2712 | Reloc.getTypeName(RelocName); |
Alexey Samsonov | aa4d295 | 2014-03-14 14:22:49 +0000 | [diff] [blame] | 2713 | symbol_iterator Symbol = Reloc.getSymbol(); |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 2714 | if (Symbol != Obj->symbol_end()) { |
Kevin Enderby | 81e8b7d | 2016-04-20 21:24:34 +0000 | [diff] [blame] | 2715 | Expected<StringRef> SymbolNameOrErr = Symbol->getName(); |
| 2716 | error(errorToErrorCode(SymbolNameOrErr.takeError())); |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 2717 | SymbolName = *SymbolNameOrErr; |
| 2718 | } |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2719 | |
Nico Rieck | f3f0b79 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 2720 | if (opts::ExpandRelocs) { |
| 2721 | DictScope Group(W, "Relocation"); |
| 2722 | W.printHex("Offset", Offset); |
| 2723 | W.printNumber("Type", RelocName, RelocType); |
David Majnemer | 1f80b0a | 2014-11-13 07:42:11 +0000 | [diff] [blame] | 2724 | W.printString("Symbol", SymbolName.empty() ? "-" : SymbolName); |
Nico Rieck | f3f0b79 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 2725 | } else { |
| 2726 | raw_ostream& OS = W.startLine(); |
| 2727 | OS << W.hex(Offset) |
| 2728 | << " " << RelocName |
David Majnemer | 1f80b0a | 2014-11-13 07:42:11 +0000 | [diff] [blame] | 2729 | << " " << (SymbolName.empty() ? "-" : SymbolName) |
Nico Rieck | f3f0b79 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 2730 | << "\n"; |
| 2731 | } |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | void COFFDumper::printSymbols() { |
| 2735 | ListScope Group(W, "Symbols"); |
| 2736 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2737 | for (const SymbolRef &Symbol : Obj->symbols()) |
| 2738 | printSymbol(Symbol); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2741 | void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); } |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2742 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 2743 | static ErrorOr<StringRef> |
David Majnemer | 236b0ca | 2014-11-17 11:17:17 +0000 | [diff] [blame] | 2744 | getSectionName(const llvm::object::COFFObjectFile *Obj, int32_t SectionNumber, |
| 2745 | const coff_section *Section) { |
David Majnemer | f4dc456 | 2014-09-20 00:25:06 +0000 | [diff] [blame] | 2746 | if (Section) { |
| 2747 | StringRef SectionName; |
David Majnemer | 236b0ca | 2014-11-17 11:17:17 +0000 | [diff] [blame] | 2748 | if (std::error_code EC = Obj->getSectionName(Section, SectionName)) |
| 2749 | return EC; |
David Majnemer | f4dc456 | 2014-09-20 00:25:06 +0000 | [diff] [blame] | 2750 | return SectionName; |
| 2751 | } |
David Majnemer | f4dc456 | 2014-09-20 00:25:06 +0000 | [diff] [blame] | 2752 | if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG) |
David Majnemer | 236b0ca | 2014-11-17 11:17:17 +0000 | [diff] [blame] | 2753 | return StringRef("IMAGE_SYM_DEBUG"); |
David Majnemer | f4dc456 | 2014-09-20 00:25:06 +0000 | [diff] [blame] | 2754 | if (SectionNumber == llvm::COFF::IMAGE_SYM_ABSOLUTE) |
David Majnemer | 236b0ca | 2014-11-17 11:17:17 +0000 | [diff] [blame] | 2755 | return StringRef("IMAGE_SYM_ABSOLUTE"); |
David Majnemer | f4dc456 | 2014-09-20 00:25:06 +0000 | [diff] [blame] | 2756 | if (SectionNumber == llvm::COFF::IMAGE_SYM_UNDEFINED) |
David Majnemer | 236b0ca | 2014-11-17 11:17:17 +0000 | [diff] [blame] | 2757 | return StringRef("IMAGE_SYM_UNDEFINED"); |
| 2758 | return StringRef(""); |
David Majnemer | f4dc456 | 2014-09-20 00:25:06 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 2761 | void COFFDumper::printSymbol(const SymbolRef &Sym) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2762 | DictScope D(W, "Symbol"); |
| 2763 | |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2764 | COFFSymbolRef Symbol = Obj->getCOFFSymbol(Sym); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2765 | const coff_section *Section; |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2766 | if (std::error_code EC = Obj->getSection(Symbol.getSectionNumber(), Section)) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2767 | W.startLine() << "Invalid section number: " << EC.message() << "\n"; |
| 2768 | W.flush(); |
| 2769 | return; |
| 2770 | } |
| 2771 | |
| 2772 | StringRef SymbolName; |
| 2773 | if (Obj->getSymbolName(Symbol, SymbolName)) |
| 2774 | SymbolName = ""; |
| 2775 | |
David Majnemer | 236b0ca | 2014-11-17 11:17:17 +0000 | [diff] [blame] | 2776 | StringRef SectionName = ""; |
| 2777 | ErrorOr<StringRef> Res = |
| 2778 | getSectionName(Obj, Symbol.getSectionNumber(), Section); |
| 2779 | if (Res) |
| 2780 | SectionName = *Res; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2781 | |
| 2782 | W.printString("Name", SymbolName); |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2783 | W.printNumber("Value", Symbol.getValue()); |
| 2784 | W.printNumber("Section", SectionName, Symbol.getSectionNumber()); |
| 2785 | W.printEnum ("BaseType", Symbol.getBaseType(), makeArrayRef(ImageSymType)); |
| 2786 | W.printEnum ("ComplexType", Symbol.getComplexType(), |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2787 | makeArrayRef(ImageSymDType)); |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2788 | W.printEnum ("StorageClass", Symbol.getStorageClass(), |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2789 | makeArrayRef(ImageSymClass)); |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2790 | W.printNumber("AuxSymbolCount", Symbol.getNumberOfAuxSymbols()); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2791 | |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2792 | for (uint8_t I = 0; I < Symbol.getNumberOfAuxSymbols(); ++I) { |
| 2793 | if (Symbol.isFunctionDefinition()) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2794 | const coff_aux_function_definition *Aux; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2795 | error(getSymbolAuxData(Obj, Symbol, I, Aux)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2796 | |
| 2797 | DictScope AS(W, "AuxFunctionDef"); |
| 2798 | W.printNumber("TagIndex", Aux->TagIndex); |
| 2799 | W.printNumber("TotalSize", Aux->TotalSize); |
David Majnemer | f3a2af5 | 2014-03-19 04:33:27 +0000 | [diff] [blame] | 2800 | W.printHex("PointerToLineNumber", Aux->PointerToLinenumber); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2801 | W.printHex("PointerToNextFunction", Aux->PointerToNextFunction); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2802 | |
David Majnemer | c7d7c6f | 2014-10-31 05:07:00 +0000 | [diff] [blame] | 2803 | } else if (Symbol.isAnyUndefined()) { |
David Majnemer | f3a2af5 | 2014-03-19 04:33:27 +0000 | [diff] [blame] | 2804 | const coff_aux_weak_external *Aux; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2805 | error(getSymbolAuxData(Obj, Symbol, I, Aux)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2806 | |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2807 | ErrorOr<COFFSymbolRef> Linked = Obj->getSymbol(Aux->TagIndex); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2808 | StringRef LinkedName; |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2809 | std::error_code EC = Linked.getError(); |
| 2810 | if (EC || (EC = Obj->getSymbolName(*Linked, LinkedName))) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2811 | LinkedName = ""; |
| 2812 | error(EC); |
| 2813 | } |
| 2814 | |
| 2815 | DictScope AS(W, "AuxWeakExternal"); |
| 2816 | W.printNumber("Linked", LinkedName, Aux->TagIndex); |
| 2817 | W.printEnum ("Search", Aux->Characteristics, |
| 2818 | makeArrayRef(WeakExternalCharacteristics)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2819 | |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2820 | } else if (Symbol.isFileRecord()) { |
| 2821 | const char *FileName; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2822 | error(getSymbolAuxData(Obj, Symbol, I, FileName)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2823 | |
Nico Rieck | 0ab8e60 | 2013-04-22 08:35:11 +0000 | [diff] [blame] | 2824 | DictScope AS(W, "AuxFileRecord"); |
Saleem Abdulrasool | d38c6b1 | 2014-04-14 02:37:23 +0000 | [diff] [blame] | 2825 | |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2826 | StringRef Name(FileName, Symbol.getNumberOfAuxSymbols() * |
| 2827 | Obj->getSymbolTableEntrySize()); |
Saleem Abdulrasool | d38c6b1 | 2014-04-14 02:37:23 +0000 | [diff] [blame] | 2828 | W.printString("FileName", Name.rtrim(StringRef("\0", 1))); |
Saleem Abdulrasool | 3b5e001 | 2014-04-16 04:15:29 +0000 | [diff] [blame] | 2829 | break; |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2830 | } else if (Symbol.isSectionDefinition()) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2831 | const coff_aux_section_definition *Aux; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2832 | error(getSymbolAuxData(Obj, Symbol, I, Aux)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2833 | |
David Majnemer | 4d57159 | 2014-09-15 19:42:42 +0000 | [diff] [blame] | 2834 | int32_t AuxNumber = Aux->getNumber(Symbol.isBigObj()); |
| 2835 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2836 | DictScope AS(W, "AuxSectionDef"); |
| 2837 | W.printNumber("Length", Aux->Length); |
| 2838 | W.printNumber("RelocationCount", Aux->NumberOfRelocations); |
| 2839 | W.printNumber("LineNumberCount", Aux->NumberOfLinenumbers); |
| 2840 | W.printHex("Checksum", Aux->CheckSum); |
David Majnemer | 4d57159 | 2014-09-15 19:42:42 +0000 | [diff] [blame] | 2841 | W.printNumber("Number", AuxNumber); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2842 | W.printEnum("Selection", Aux->Selection, makeArrayRef(ImageCOMDATSelect)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2843 | |
Nico Rieck | a711dee | 2013-04-22 08:34:59 +0000 | [diff] [blame] | 2844 | if (Section && Section->Characteristics & COFF::IMAGE_SCN_LNK_COMDAT |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2845 | && Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) { |
| 2846 | const coff_section *Assoc; |
David Majnemer | 236b0ca | 2014-11-17 11:17:17 +0000 | [diff] [blame] | 2847 | StringRef AssocName = ""; |
| 2848 | std::error_code EC = Obj->getSection(AuxNumber, Assoc); |
| 2849 | ErrorOr<StringRef> Res = getSectionName(Obj, AuxNumber, Assoc); |
| 2850 | if (Res) |
| 2851 | AssocName = *Res; |
| 2852 | if (!EC) |
| 2853 | EC = Res.getError(); |
| 2854 | if (EC) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2855 | AssocName = ""; |
| 2856 | error(EC); |
| 2857 | } |
| 2858 | |
David Majnemer | 4d57159 | 2014-09-15 19:42:42 +0000 | [diff] [blame] | 2859 | W.printNumber("AssocSection", AssocName, AuxNumber); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2860 | } |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2861 | } else if (Symbol.isCLRToken()) { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2862 | const coff_aux_clr_token *Aux; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2863 | error(getSymbolAuxData(Obj, Symbol, I, Aux)); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2864 | |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2865 | ErrorOr<COFFSymbolRef> ReferredSym = |
| 2866 | Obj->getSymbol(Aux->SymbolTableIndex); |
Nico Rieck | 8678acd | 2014-03-17 01:46:52 +0000 | [diff] [blame] | 2867 | StringRef ReferredName; |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2868 | std::error_code EC = ReferredSym.getError(); |
| 2869 | if (EC || (EC = Obj->getSymbolName(*ReferredSym, ReferredName))) { |
Nico Rieck | 8678acd | 2014-03-17 01:46:52 +0000 | [diff] [blame] | 2870 | ReferredName = ""; |
| 2871 | error(EC); |
| 2872 | } |
| 2873 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2874 | DictScope AS(W, "AuxCLRToken"); |
| 2875 | W.printNumber("AuxType", Aux->AuxType); |
| 2876 | W.printNumber("Reserved", Aux->Reserved); |
Nico Rieck | 8678acd | 2014-03-17 01:46:52 +0000 | [diff] [blame] | 2877 | W.printNumber("SymbolTableIndex", ReferredName, Aux->SymbolTableIndex); |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2878 | |
| 2879 | } else { |
| 2880 | W.startLine() << "<unhandled auxiliary record>\n"; |
| 2881 | } |
| 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | void COFFDumper::printUnwindInfo() { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2886 | ListScope D(W, "UnwindInformation"); |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2887 | switch (Obj->getMachine()) { |
Saleem Abdulrasool | e8839a7 | 2014-05-25 20:26:45 +0000 | [diff] [blame] | 2888 | case COFF::IMAGE_FILE_MACHINE_AMD64: { |
| 2889 | Win64EH::Dumper Dumper(W); |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 2890 | Win64EH::Dumper::SymbolResolver |
| 2891 | Resolver = [](const object::coff_section *Section, uint64_t Offset, |
| 2892 | SymbolRef &Symbol, void *user_data) -> std::error_code { |
| 2893 | COFFDumper *Dumper = reinterpret_cast<COFFDumper *>(user_data); |
| 2894 | return Dumper->resolveSymbol(Section, Offset, Symbol); |
| 2895 | }; |
Saleem Abdulrasool | 65dbbb5 | 2014-05-25 21:37:59 +0000 | [diff] [blame] | 2896 | Win64EH::Dumper::Context Ctx(*Obj, Resolver, this); |
Saleem Abdulrasool | e8839a7 | 2014-05-25 20:26:45 +0000 | [diff] [blame] | 2897 | Dumper.printData(Ctx); |
| 2898 | break; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2899 | } |
Saleem Abdulrasool | e6971ca | 2014-06-04 15:47:15 +0000 | [diff] [blame] | 2900 | case COFF::IMAGE_FILE_MACHINE_ARMNT: { |
| 2901 | ARM::WinEH::Decoder Decoder(W); |
| 2902 | Decoder.dumpProcedureData(*Obj); |
| 2903 | break; |
| 2904 | } |
Saleem Abdulrasool | e8839a7 | 2014-05-25 20:26:45 +0000 | [diff] [blame] | 2905 | default: |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 2906 | W.printEnum("unsupported Image Machine", Obj->getMachine(), |
Saleem Abdulrasool | e8839a7 | 2014-05-25 20:26:45 +0000 | [diff] [blame] | 2907 | makeArrayRef(ImageFileMachineType)); |
| 2908 | break; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 2909 | } |
| 2910 | } |
| 2911 | |
Rui Ueyama | 979fb40 | 2014-10-09 02:16:38 +0000 | [diff] [blame] | 2912 | void COFFDumper::printImportedSymbols( |
| 2913 | iterator_range<imported_symbol_iterator> Range) { |
| 2914 | for (const ImportedSymbolRef &I : Range) { |
Rui Ueyama | 15d9935 | 2014-10-03 00:41:58 +0000 | [diff] [blame] | 2915 | StringRef Sym; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2916 | error(I.getSymbolName(Sym)); |
Rui Ueyama | 15d9935 | 2014-10-03 00:41:58 +0000 | [diff] [blame] | 2917 | uint16_t Ordinal; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2918 | error(I.getOrdinal(Ordinal)); |
Rui Ueyama | 15d9935 | 2014-10-03 00:41:58 +0000 | [diff] [blame] | 2919 | W.printNumber("Symbol", Sym, Ordinal); |
| 2920 | } |
| 2921 | } |
| 2922 | |
Rui Ueyama | ffa4ceb | 2014-11-13 03:22:54 +0000 | [diff] [blame] | 2923 | void COFFDumper::printDelayImportedSymbols( |
| 2924 | const DelayImportDirectoryEntryRef &I, |
| 2925 | iterator_range<imported_symbol_iterator> Range) { |
| 2926 | int Index = 0; |
| 2927 | for (const ImportedSymbolRef &S : Range) { |
| 2928 | DictScope Import(W, "Import"); |
| 2929 | StringRef Sym; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2930 | error(S.getSymbolName(Sym)); |
Rui Ueyama | ffa4ceb | 2014-11-13 03:22:54 +0000 | [diff] [blame] | 2931 | uint16_t Ordinal; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2932 | error(S.getOrdinal(Ordinal)); |
Rui Ueyama | ffa4ceb | 2014-11-13 03:22:54 +0000 | [diff] [blame] | 2933 | W.printNumber("Symbol", Sym, Ordinal); |
| 2934 | uint64_t Addr; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2935 | error(I.getImportAddress(Index++, Addr)); |
Rui Ueyama | ffa4ceb | 2014-11-13 03:22:54 +0000 | [diff] [blame] | 2936 | W.printHex("Address", Addr); |
| 2937 | } |
| 2938 | } |
| 2939 | |
Rui Ueyama | 1e152d5 | 2014-10-02 17:02:18 +0000 | [diff] [blame] | 2940 | void COFFDumper::printCOFFImports() { |
Rui Ueyama | 15d9935 | 2014-10-03 00:41:58 +0000 | [diff] [blame] | 2941 | // Regular imports |
Rui Ueyama | 979fb40 | 2014-10-09 02:16:38 +0000 | [diff] [blame] | 2942 | for (const ImportDirectoryEntryRef &I : Obj->import_directories()) { |
Rui Ueyama | 1e152d5 | 2014-10-02 17:02:18 +0000 | [diff] [blame] | 2943 | DictScope Import(W, "Import"); |
| 2944 | StringRef Name; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2945 | error(I.getName(Name)); |
Rui Ueyama | 1e152d5 | 2014-10-02 17:02:18 +0000 | [diff] [blame] | 2946 | W.printString("Name", Name); |
| 2947 | uint32_t Addr; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2948 | error(I.getImportLookupTableRVA(Addr)); |
Rui Ueyama | 1e152d5 | 2014-10-02 17:02:18 +0000 | [diff] [blame] | 2949 | W.printHex("ImportLookupTableRVA", Addr); |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2950 | error(I.getImportAddressTableRVA(Addr)); |
Rui Ueyama | 1e152d5 | 2014-10-02 17:02:18 +0000 | [diff] [blame] | 2951 | W.printHex("ImportAddressTableRVA", Addr); |
Rui Ueyama | 979fb40 | 2014-10-09 02:16:38 +0000 | [diff] [blame] | 2952 | printImportedSymbols(I.imported_symbols()); |
Rui Ueyama | 15d9935 | 2014-10-03 00:41:58 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | // Delay imports |
Rui Ueyama | 979fb40 | 2014-10-09 02:16:38 +0000 | [diff] [blame] | 2956 | for (const DelayImportDirectoryEntryRef &I : Obj->delay_import_directories()) { |
Rui Ueyama | 15d9935 | 2014-10-03 00:41:58 +0000 | [diff] [blame] | 2957 | DictScope Import(W, "DelayImport"); |
| 2958 | StringRef Name; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2959 | error(I.getName(Name)); |
Rui Ueyama | 15d9935 | 2014-10-03 00:41:58 +0000 | [diff] [blame] | 2960 | W.printString("Name", Name); |
Rui Ueyama | 1af0865 | 2014-10-03 18:07:18 +0000 | [diff] [blame] | 2961 | const delay_import_directory_table_entry *Table; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2962 | error(I.getDelayImportTable(Table)); |
Rui Ueyama | 1af0865 | 2014-10-03 18:07:18 +0000 | [diff] [blame] | 2963 | W.printHex("Attributes", Table->Attributes); |
| 2964 | W.printHex("ModuleHandle", Table->ModuleHandle); |
| 2965 | W.printHex("ImportAddressTable", Table->DelayImportAddressTable); |
| 2966 | W.printHex("ImportNameTable", Table->DelayImportNameTable); |
| 2967 | W.printHex("BoundDelayImportTable", Table->BoundDelayImportTable); |
| 2968 | W.printHex("UnloadDelayImportTable", Table->UnloadDelayImportTable); |
Rui Ueyama | ffa4ceb | 2014-11-13 03:22:54 +0000 | [diff] [blame] | 2969 | printDelayImportedSymbols(I, I.imported_symbols()); |
Rui Ueyama | 1e152d5 | 2014-10-02 17:02:18 +0000 | [diff] [blame] | 2970 | } |
| 2971 | } |
Saleem Abdulrasool | f957863 | 2014-10-07 19:37:52 +0000 | [diff] [blame] | 2972 | |
Saleem Abdulrasool | ddd9264 | 2015-01-03 21:35:09 +0000 | [diff] [blame] | 2973 | void COFFDumper::printCOFFExports() { |
| 2974 | for (const ExportDirectoryEntryRef &E : Obj->export_directories()) { |
| 2975 | DictScope Export(W, "Export"); |
| 2976 | |
| 2977 | StringRef Name; |
| 2978 | uint32_t Ordinal, RVA; |
| 2979 | |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2980 | error(E.getSymbolName(Name)); |
| 2981 | error(E.getOrdinal(Ordinal)); |
| 2982 | error(E.getExportRVA(RVA)); |
Saleem Abdulrasool | ddd9264 | 2015-01-03 21:35:09 +0000 | [diff] [blame] | 2983 | |
| 2984 | W.printNumber("Ordinal", Ordinal); |
| 2985 | W.printString("Name", Name); |
| 2986 | W.printHex("RVA", RVA); |
| 2987 | } |
| 2988 | } |
| 2989 | |
Saleem Abdulrasool | f957863 | 2014-10-07 19:37:52 +0000 | [diff] [blame] | 2990 | void COFFDumper::printCOFFDirectives() { |
| 2991 | for (const SectionRef &Section : Obj->sections()) { |
| 2992 | StringRef Contents; |
| 2993 | StringRef Name; |
| 2994 | |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2995 | error(Section.getName(Name)); |
Saleem Abdulrasool | f957863 | 2014-10-07 19:37:52 +0000 | [diff] [blame] | 2996 | if (Name != ".drectve") |
| 2997 | continue; |
| 2998 | |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 2999 | error(Section.getContents(Contents)); |
Saleem Abdulrasool | f957863 | 2014-10-07 19:37:52 +0000 | [diff] [blame] | 3000 | |
| 3001 | W.printString("Directive(s)", Contents); |
| 3002 | } |
| 3003 | } |
Rui Ueyama | 74e8513 | 2014-11-19 00:18:07 +0000 | [diff] [blame] | 3004 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 3005 | static StringRef getBaseRelocTypeName(uint8_t Type) { |
Rui Ueyama | 74e8513 | 2014-11-19 00:18:07 +0000 | [diff] [blame] | 3006 | switch (Type) { |
| 3007 | case COFF::IMAGE_REL_BASED_ABSOLUTE: return "ABSOLUTE"; |
| 3008 | case COFF::IMAGE_REL_BASED_HIGH: return "HIGH"; |
| 3009 | case COFF::IMAGE_REL_BASED_LOW: return "LOW"; |
| 3010 | case COFF::IMAGE_REL_BASED_HIGHLOW: return "HIGHLOW"; |
| 3011 | case COFF::IMAGE_REL_BASED_HIGHADJ: return "HIGHADJ"; |
Saleem Abdulrasool | 5a41c37 | 2015-01-16 20:16:09 +0000 | [diff] [blame] | 3012 | case COFF::IMAGE_REL_BASED_ARM_MOV32T: return "ARM_MOV32(T)"; |
Rui Ueyama | 74e8513 | 2014-11-19 00:18:07 +0000 | [diff] [blame] | 3013 | case COFF::IMAGE_REL_BASED_DIR64: return "DIR64"; |
Colin LeMahieu | 9fbffee | 2014-11-19 17:10:39 +0000 | [diff] [blame] | 3014 | default: return "unknown (" + llvm::utostr(Type) + ")"; |
Rui Ueyama | 74e8513 | 2014-11-19 00:18:07 +0000 | [diff] [blame] | 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | void COFFDumper::printCOFFBaseReloc() { |
| 3019 | ListScope D(W, "BaseReloc"); |
| 3020 | for (const BaseRelocRef &I : Obj->base_relocs()) { |
| 3021 | uint8_t Type; |
| 3022 | uint32_t RVA; |
Rafael Espindola | fb3acd6 | 2015-07-20 03:23:55 +0000 | [diff] [blame] | 3023 | error(I.getRVA(RVA)); |
| 3024 | error(I.getType(Type)); |
Rui Ueyama | 74e8513 | 2014-11-19 00:18:07 +0000 | [diff] [blame] | 3025 | DictScope Import(W, "Entry"); |
| 3026 | W.printString("Type", getBaseRelocTypeName(Type)); |
| 3027 | W.printHex("Address", RVA); |
| 3028 | } |
| 3029 | } |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 3030 | |
| 3031 | void COFFDumper::printStackMap() const { |
| 3032 | object::SectionRef StackMapSection; |
| 3033 | for (auto Sec : Obj->sections()) { |
| 3034 | StringRef Name; |
| 3035 | Sec.getName(Name); |
| 3036 | if (Name == ".llvm_stackmaps") { |
| 3037 | StackMapSection = Sec; |
| 3038 | break; |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | if (StackMapSection == object::SectionRef()) |
| 3043 | return; |
| 3044 | |
| 3045 | StringRef StackMapContents; |
| 3046 | StackMapSection.getContents(StackMapContents); |
| 3047 | ArrayRef<uint8_t> StackMapContentsArray( |
| 3048 | reinterpret_cast<const uint8_t*>(StackMapContents.data()), |
| 3049 | StackMapContents.size()); |
| 3050 | |
| 3051 | if (Obj->isLittleEndian()) |
| 3052 | prettyPrintStackMap( |
| 3053 | llvm::outs(), |
| 3054 | StackMapV1Parser<support::little>(StackMapContentsArray)); |
| 3055 | else |
| 3056 | prettyPrintStackMap(llvm::outs(), |
| 3057 | StackMapV1Parser<support::big>(StackMapContentsArray)); |
| 3058 | } |