David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 1 | //===- llvm-cxxdump.cpp - Dump C++ data in an Object File -------*- C++ -*-===// |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 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 | // |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 10 | // Dumps C++ data resident in object files and archives. |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 14 | #include "llvm-cxxdump.h" |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 15 | #include "Error.h" |
| 16 | #include "llvm/ADT/ArrayRef.h" |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 17 | #include "llvm/Object/Archive.h" |
| 18 | #include "llvm/Object/ObjectFile.h" |
Rafael Espindola | a4a4093 | 2015-06-23 02:20:37 +0000 | [diff] [blame] | 19 | #include "llvm/Object/SymbolSize.h" |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
| 21 | #include "llvm/Support/Endian.h" |
| 22 | #include "llvm/Support/FileSystem.h" |
| 23 | #include "llvm/Support/ManagedStatic.h" |
| 24 | #include "llvm/Support/PrettyStackTrace.h" |
| 25 | #include "llvm/Support/Signals.h" |
| 26 | #include "llvm/Support/TargetRegistry.h" |
| 27 | #include "llvm/Support/TargetSelect.h" |
Benjamin Kramer | 16132e6 | 2015-03-23 18:07:13 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 29 | #include <map> |
| 30 | #include <string> |
| 31 | #include <system_error> |
| 32 | |
| 33 | using namespace llvm; |
| 34 | using namespace llvm::object; |
| 35 | using namespace llvm::support; |
| 36 | |
| 37 | namespace opts { |
| 38 | cl::list<std::string> InputFilenames(cl::Positional, |
| 39 | cl::desc("<input object files>"), |
| 40 | cl::ZeroOrMore); |
| 41 | } // namespace opts |
| 42 | |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 43 | namespace llvm { |
| 44 | |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 45 | static void error(std::error_code EC) { |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 46 | if (!EC) |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 47 | return; |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 48 | outs() << "\nError reading file: " << EC.message() << ".\n"; |
| 49 | outs().flush(); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 50 | exit(1); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | } // namespace llvm |
| 54 | |
| 55 | static void reportError(StringRef Input, StringRef Message) { |
| 56 | if (Input == "-") |
| 57 | Input = "<stdin>"; |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 58 | errs() << Input << ": " << Message << "\n"; |
| 59 | errs().flush(); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 60 | exit(1); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static void reportError(StringRef Input, std::error_code EC) { |
| 64 | reportError(Input, EC.message()); |
| 65 | } |
| 66 | |
David Majnemer | d7fafa0 | 2015-08-13 18:31:43 +0000 | [diff] [blame^] | 67 | static std::map<SectionRef, SmallVector<SectionRef, 1>> SectionRelocMap; |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 68 | |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 69 | static void collectRelocatedSymbols(const ObjectFile *Obj, |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 70 | const SectionRef &Sec, uint64_t SecAddress, |
| 71 | uint64_t SymAddress, uint64_t SymSize, |
| 72 | StringRef *I, StringRef *E) { |
| 73 | uint64_t SymOffset = SymAddress - SecAddress; |
| 74 | uint64_t SymEnd = SymOffset + SymSize; |
David Majnemer | d7fafa0 | 2015-08-13 18:31:43 +0000 | [diff] [blame^] | 75 | for (const SectionRef &SR : SectionRelocMap[Sec]) { |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 76 | for (const object::RelocationRef &Reloc : SR.relocations()) { |
| 77 | if (I == E) |
| 78 | break; |
| 79 | const object::symbol_iterator RelocSymI = Reloc.getSymbol(); |
| 80 | if (RelocSymI == Obj->symbol_end()) |
| 81 | continue; |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 82 | ErrorOr<StringRef> RelocSymName = RelocSymI->getName(); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 83 | error(RelocSymName.getError()); |
Rafael Espindola | 96d071c | 2015-06-29 23:29:12 +0000 | [diff] [blame] | 84 | uint64_t Offset = Reloc.getOffset(); |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 85 | if (Offset >= SymOffset && Offset < SymEnd) { |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 86 | *I = *RelocSymName; |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 87 | ++I; |
| 88 | } |
| 89 | } |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 90 | } |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 93 | static void collectRelocationOffsets( |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 94 | const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress, |
| 95 | uint64_t SymAddress, uint64_t SymSize, StringRef SymName, |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 96 | std::map<std::pair<StringRef, uint64_t>, StringRef> &Collection) { |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 97 | uint64_t SymOffset = SymAddress - SecAddress; |
| 98 | uint64_t SymEnd = SymOffset + SymSize; |
David Majnemer | d7fafa0 | 2015-08-13 18:31:43 +0000 | [diff] [blame^] | 99 | for (const SectionRef &SR : SectionRelocMap[Sec]) { |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 100 | for (const object::RelocationRef &Reloc : SR.relocations()) { |
| 101 | const object::symbol_iterator RelocSymI = Reloc.getSymbol(); |
| 102 | if (RelocSymI == Obj->symbol_end()) |
| 103 | continue; |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 104 | ErrorOr<StringRef> RelocSymName = RelocSymI->getName(); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 105 | error(RelocSymName.getError()); |
Rafael Espindola | 96d071c | 2015-06-29 23:29:12 +0000 | [diff] [blame] | 106 | uint64_t Offset = Reloc.getOffset(); |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 107 | if (Offset >= SymOffset && Offset < SymEnd) |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 108 | Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName; |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 109 | } |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 110 | } |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 111 | } |
| 112 | |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 113 | static void dumpCXXData(const ObjectFile *Obj) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 114 | struct CompleteObjectLocator { |
| 115 | StringRef Symbols[2]; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 116 | ArrayRef<little32_t> Data; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 117 | }; |
| 118 | struct ClassHierarchyDescriptor { |
| 119 | StringRef Symbols[1]; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 120 | ArrayRef<little32_t> Data; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 121 | }; |
| 122 | struct BaseClassDescriptor { |
| 123 | StringRef Symbols[2]; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 124 | ArrayRef<little32_t> Data; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 125 | }; |
| 126 | struct TypeDescriptor { |
| 127 | StringRef Symbols[1]; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 128 | uint64_t AlwaysZero; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 129 | StringRef MangledName; |
| 130 | }; |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 131 | struct ThrowInfo { |
| 132 | uint32_t Flags; |
| 133 | }; |
| 134 | struct CatchableTypeArray { |
| 135 | uint32_t NumEntries; |
| 136 | }; |
| 137 | struct CatchableType { |
| 138 | uint32_t Flags; |
| 139 | uint32_t NonVirtualBaseAdjustmentOffset; |
| 140 | int32_t VirtualBasePointerOffset; |
| 141 | uint32_t VirtualBaseAdjustmentOffset; |
David Majnemer | 86ee173 | 2015-02-27 22:35:25 +0000 | [diff] [blame] | 142 | uint32_t Size; |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 143 | StringRef Symbols[2]; |
| 144 | }; |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 145 | std::map<std::pair<StringRef, uint64_t>, StringRef> VFTableEntries; |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 146 | std::map<std::pair<StringRef, uint64_t>, StringRef> TIEntries; |
| 147 | std::map<std::pair<StringRef, uint64_t>, StringRef> CTAEntries; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 148 | std::map<StringRef, ArrayRef<little32_t>> VBTables; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 149 | std::map<StringRef, CompleteObjectLocator> COLs; |
| 150 | std::map<StringRef, ClassHierarchyDescriptor> CHDs; |
| 151 | std::map<std::pair<StringRef, uint64_t>, StringRef> BCAEntries; |
| 152 | std::map<StringRef, BaseClassDescriptor> BCDs; |
| 153 | std::map<StringRef, TypeDescriptor> TDs; |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 154 | std::map<StringRef, ThrowInfo> TIs; |
| 155 | std::map<StringRef, CatchableTypeArray> CTAs; |
| 156 | std::map<StringRef, CatchableType> CTs; |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 157 | |
| 158 | std::map<std::pair<StringRef, uint64_t>, StringRef> VTableSymEntries; |
| 159 | std::map<std::pair<StringRef, uint64_t>, int64_t> VTableDataEntries; |
| 160 | std::map<std::pair<StringRef, uint64_t>, StringRef> VTTEntries; |
| 161 | std::map<StringRef, StringRef> TINames; |
| 162 | |
David Majnemer | d7fafa0 | 2015-08-13 18:31:43 +0000 | [diff] [blame^] | 163 | SectionRelocMap.clear(); |
| 164 | for (const SectionRef &Section : Obj->sections()) { |
| 165 | section_iterator Sec2 = Section.getRelocatedSection(); |
| 166 | if (Sec2 != Obj->section_end()) |
| 167 | SectionRelocMap[*Sec2].push_back(Section); |
| 168 | } |
| 169 | |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 170 | uint8_t BytesInAddress = Obj->getBytesInAddress(); |
| 171 | |
Rafael Espindola | 6bf3221 | 2015-06-24 19:57:32 +0000 | [diff] [blame] | 172 | std::vector<std::pair<SymbolRef, uint64_t>> SymAddr = |
Rafael Espindola | a4a4093 | 2015-06-23 02:20:37 +0000 | [diff] [blame] | 173 | object::computeSymbolSizes(*Obj); |
Rafael Espindola | a4a4093 | 2015-06-23 02:20:37 +0000 | [diff] [blame] | 174 | |
Rafael Espindola | 6bf3221 | 2015-06-24 19:57:32 +0000 | [diff] [blame] | 175 | for (auto &P : SymAddr) { |
Rafael Espindola | a4a4093 | 2015-06-23 02:20:37 +0000 | [diff] [blame] | 176 | object::SymbolRef Sym = P.first; |
| 177 | uint64_t SymSize = P.second; |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 178 | ErrorOr<StringRef> SymNameOrErr = Sym.getName(); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 179 | error(SymNameOrErr.getError()); |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 180 | StringRef SymName = *SymNameOrErr; |
Rafael Espindola | 8bab889 | 2015-08-07 23:27:14 +0000 | [diff] [blame] | 181 | ErrorOr<object::section_iterator> SecIOrErr = Sym.getSection(); |
| 182 | error(SecIOrErr.getError()); |
| 183 | object::section_iterator SecI = *SecIOrErr; |
David Majnemer | 601327c | 2014-09-26 22:32:19 +0000 | [diff] [blame] | 184 | // Skip external symbols. |
| 185 | if (SecI == Obj->section_end()) |
| 186 | continue; |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 187 | const SectionRef &Sec = *SecI; |
David Majnemer | 601327c | 2014-09-26 22:32:19 +0000 | [diff] [blame] | 188 | // Skip virtual or BSS sections. |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 189 | if (Sec.isBSS() || Sec.isVirtual()) |
David Majnemer | 601327c | 2014-09-26 22:32:19 +0000 | [diff] [blame] | 190 | continue; |
| 191 | StringRef SecContents; |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 192 | error(Sec.getContents(SecContents)); |
Rafael Espindola | ed067c4 | 2015-07-03 18:19:00 +0000 | [diff] [blame] | 193 | ErrorOr<uint64_t> SymAddressOrErr = Sym.getAddress(); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 194 | error(SymAddressOrErr.getError()); |
Rafael Espindola | ed067c4 | 2015-07-03 18:19:00 +0000 | [diff] [blame] | 195 | uint64_t SymAddress = *SymAddressOrErr; |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 196 | uint64_t SecAddress = Sec.getAddress(); |
| 197 | uint64_t SecSize = Sec.getSize(); |
| 198 | uint64_t SymOffset = SymAddress - SecAddress; |
| 199 | StringRef SymContents = SecContents.substr(SymOffset, SymSize); |
| 200 | |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 201 | // VFTables in the MS-ABI start with '??_7' and are contained within their |
| 202 | // own COMDAT section. We then determine the contents of the VFTable by |
| 203 | // looking at each relocation in the section. |
| 204 | if (SymName.startswith("??_7")) { |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 205 | // Each relocation either names a virtual method or a thunk. We note the |
| 206 | // offset into the section and the symbol used for the relocation. |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 207 | collectRelocationOffsets(Obj, Sec, SecAddress, SecAddress, SecSize, |
| 208 | SymName, VFTableEntries); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 209 | } |
| 210 | // VBTables in the MS-ABI start with '??_8' and are filled with 32-bit |
| 211 | // offsets of virtual bases. |
| 212 | else if (SymName.startswith("??_8")) { |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 213 | ArrayRef<little32_t> VBTableData( |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 214 | reinterpret_cast<const little32_t *>(SymContents.data()), |
| 215 | SymContents.size() / sizeof(little32_t)); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 216 | VBTables[SymName] = VBTableData; |
| 217 | } |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 218 | // Complete object locators in the MS-ABI start with '??_R4' |
| 219 | else if (SymName.startswith("??_R4")) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 220 | CompleteObjectLocator COL; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 221 | COL.Data = ArrayRef<little32_t>( |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 222 | reinterpret_cast<const little32_t *>(SymContents.data()), 3); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 223 | StringRef *I = std::begin(COL.Symbols), *E = std::end(COL.Symbols); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 224 | collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 225 | COLs[SymName] = COL; |
| 226 | } |
| 227 | // Class hierarchy descriptors in the MS-ABI start with '??_R3' |
| 228 | else if (SymName.startswith("??_R3")) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 229 | ClassHierarchyDescriptor CHD; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 230 | CHD.Data = ArrayRef<little32_t>( |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 231 | reinterpret_cast<const little32_t *>(SymContents.data()), 3); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 232 | StringRef *I = std::begin(CHD.Symbols), *E = std::end(CHD.Symbols); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 233 | collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 234 | CHDs[SymName] = CHD; |
| 235 | } |
| 236 | // Class hierarchy descriptors in the MS-ABI start with '??_R2' |
| 237 | else if (SymName.startswith("??_R2")) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 238 | // Each relocation names a base class descriptor. We note the offset into |
| 239 | // the section and the symbol used for the relocation. |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 240 | collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize, |
| 241 | SymName, BCAEntries); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 242 | } |
| 243 | // Base class descriptors in the MS-ABI start with '??_R1' |
| 244 | else if (SymName.startswith("??_R1")) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 245 | BaseClassDescriptor BCD; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 246 | BCD.Data = ArrayRef<little32_t>( |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 247 | reinterpret_cast<const little32_t *>(SymContents.data()) + 1, 5); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 248 | StringRef *I = std::begin(BCD.Symbols), *E = std::end(BCD.Symbols); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 249 | collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 250 | BCDs[SymName] = BCD; |
| 251 | } |
| 252 | // Type descriptors in the MS-ABI start with '??_R0' |
| 253 | else if (SymName.startswith("??_R0")) { |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 254 | const char *DataPtr = SymContents.drop_front(BytesInAddress).data(); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 255 | TypeDescriptor TD; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 256 | if (BytesInAddress == 8) |
| 257 | TD.AlwaysZero = *reinterpret_cast<const little64_t *>(DataPtr); |
| 258 | else |
| 259 | TD.AlwaysZero = *reinterpret_cast<const little32_t *>(DataPtr); |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 260 | TD.MangledName = SymContents.drop_front(BytesInAddress * 2); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 261 | StringRef *I = std::begin(TD.Symbols), *E = std::end(TD.Symbols); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 262 | collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 263 | TDs[SymName] = TD; |
| 264 | } |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 265 | // Throw descriptors in the MS-ABI start with '_TI' |
| 266 | else if (SymName.startswith("_TI") || SymName.startswith("__TI")) { |
| 267 | ThrowInfo TI; |
| 268 | TI.Flags = *reinterpret_cast<const little32_t *>(SymContents.data()); |
| 269 | collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize, |
| 270 | SymName, TIEntries); |
| 271 | TIs[SymName] = TI; |
| 272 | } |
| 273 | // Catchable type arrays in the MS-ABI start with _CTA or __CTA. |
| 274 | else if (SymName.startswith("_CTA") || SymName.startswith("__CTA")) { |
| 275 | CatchableTypeArray CTA; |
| 276 | CTA.NumEntries = |
| 277 | *reinterpret_cast<const little32_t *>(SymContents.data()); |
| 278 | collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize, |
| 279 | SymName, CTAEntries); |
| 280 | CTAs[SymName] = CTA; |
| 281 | } |
| 282 | // Catchable types in the MS-ABI start with _CT or __CT. |
| 283 | else if (SymName.startswith("_CT") || SymName.startswith("__CT")) { |
| 284 | const little32_t *DataPtr = |
| 285 | reinterpret_cast<const little32_t *>(SymContents.data()); |
| 286 | CatchableType CT; |
| 287 | CT.Flags = DataPtr[0]; |
| 288 | CT.NonVirtualBaseAdjustmentOffset = DataPtr[2]; |
| 289 | CT.VirtualBasePointerOffset = DataPtr[3]; |
| 290 | CT.VirtualBaseAdjustmentOffset = DataPtr[4]; |
David Majnemer | 86ee173 | 2015-02-27 22:35:25 +0000 | [diff] [blame] | 291 | CT.Size = DataPtr[5]; |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 292 | StringRef *I = std::begin(CT.Symbols), *E = std::end(CT.Symbols); |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 293 | collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 294 | CTs[SymName] = CT; |
| 295 | } |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 296 | // Construction vtables in the Itanium ABI start with '_ZTT' or '__ZTT'. |
| 297 | else if (SymName.startswith("_ZTT") || SymName.startswith("__ZTT")) { |
| 298 | collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize, |
| 299 | SymName, VTTEntries); |
| 300 | } |
| 301 | // Typeinfo names in the Itanium ABI start with '_ZTS' or '__ZTS'. |
| 302 | else if (SymName.startswith("_ZTS") || SymName.startswith("__ZTS")) { |
| 303 | TINames[SymName] = SymContents.slice(0, SymContents.find('\0')); |
| 304 | } |
| 305 | // Vtables in the Itanium ABI start with '_ZTV' or '__ZTV'. |
| 306 | else if (SymName.startswith("_ZTV") || SymName.startswith("__ZTV")) { |
| 307 | collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize, |
| 308 | SymName, VTableSymEntries); |
| 309 | for (uint64_t SymOffI = 0; SymOffI < SymSize; SymOffI += BytesInAddress) { |
| 310 | auto Key = std::make_pair(SymName, SymOffI); |
| 311 | if (VTableSymEntries.count(Key)) |
| 312 | continue; |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 313 | const char *DataPtr = |
| 314 | SymContents.substr(SymOffI, BytesInAddress).data(); |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 315 | int64_t VData; |
| 316 | if (BytesInAddress == 8) |
| 317 | VData = *reinterpret_cast<const little64_t *>(DataPtr); |
| 318 | else |
| 319 | VData = *reinterpret_cast<const little32_t *>(DataPtr); |
| 320 | VTableDataEntries[Key] = VData; |
| 321 | } |
| 322 | } |
| 323 | // Typeinfo structures in the Itanium ABI start with '_ZTI' or '__ZTI'. |
| 324 | else if (SymName.startswith("_ZTI") || SymName.startswith("__ZTI")) { |
| 325 | // FIXME: Do something with these! |
| 326 | } |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 327 | } |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 328 | for (const auto &VFTableEntry : VFTableEntries) { |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 329 | StringRef VFTableName = VFTableEntry.first.first; |
| 330 | uint64_t Offset = VFTableEntry.first.second; |
| 331 | StringRef SymName = VFTableEntry.second; |
| 332 | outs() << VFTableName << '[' << Offset << "]: " << SymName << '\n'; |
| 333 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 334 | for (const auto &VBTable : VBTables) { |
David Majnemer | bf32f77 | 2014-07-25 04:30:11 +0000 | [diff] [blame] | 335 | StringRef VBTableName = VBTable.first; |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 336 | uint32_t Idx = 0; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 337 | for (little32_t Offset : VBTable.second) { |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 338 | outs() << VBTableName << '[' << Idx << "]: " << Offset << '\n'; |
David Majnemer | bf32f77 | 2014-07-25 04:30:11 +0000 | [diff] [blame] | 339 | Idx += sizeof(Offset); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 342 | for (const auto &COLPair : COLs) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 343 | StringRef COLName = COLPair.first; |
| 344 | const CompleteObjectLocator &COL = COLPair.second; |
| 345 | outs() << COLName << "[IsImageRelative]: " << COL.Data[0] << '\n'; |
| 346 | outs() << COLName << "[OffsetToTop]: " << COL.Data[1] << '\n'; |
| 347 | outs() << COLName << "[VFPtrOffset]: " << COL.Data[2] << '\n'; |
| 348 | outs() << COLName << "[TypeDescriptor]: " << COL.Symbols[0] << '\n'; |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 349 | outs() << COLName << "[ClassHierarchyDescriptor]: " << COL.Symbols[1] |
| 350 | << '\n'; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 351 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 352 | for (const auto &CHDPair : CHDs) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 353 | StringRef CHDName = CHDPair.first; |
| 354 | const ClassHierarchyDescriptor &CHD = CHDPair.second; |
| 355 | outs() << CHDName << "[AlwaysZero]: " << CHD.Data[0] << '\n'; |
| 356 | outs() << CHDName << "[Flags]: " << CHD.Data[1] << '\n'; |
| 357 | outs() << CHDName << "[NumClasses]: " << CHD.Data[2] << '\n'; |
| 358 | outs() << CHDName << "[BaseClassArray]: " << CHD.Symbols[0] << '\n'; |
| 359 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 360 | for (const auto &BCAEntry : BCAEntries) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 361 | StringRef BCAName = BCAEntry.first.first; |
| 362 | uint64_t Offset = BCAEntry.first.second; |
| 363 | StringRef SymName = BCAEntry.second; |
| 364 | outs() << BCAName << '[' << Offset << "]: " << SymName << '\n'; |
| 365 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 366 | for (const auto &BCDPair : BCDs) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 367 | StringRef BCDName = BCDPair.first; |
| 368 | const BaseClassDescriptor &BCD = BCDPair.second; |
| 369 | outs() << BCDName << "[TypeDescriptor]: " << BCD.Symbols[0] << '\n'; |
| 370 | outs() << BCDName << "[NumBases]: " << BCD.Data[0] << '\n'; |
| 371 | outs() << BCDName << "[OffsetInVBase]: " << BCD.Data[1] << '\n'; |
| 372 | outs() << BCDName << "[VBPtrOffset]: " << BCD.Data[2] << '\n'; |
| 373 | outs() << BCDName << "[OffsetInVBTable]: " << BCD.Data[3] << '\n'; |
| 374 | outs() << BCDName << "[Flags]: " << BCD.Data[4] << '\n'; |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 375 | outs() << BCDName << "[ClassHierarchyDescriptor]: " << BCD.Symbols[1] |
| 376 | << '\n'; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 377 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 378 | for (const auto &TDPair : TDs) { |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 379 | StringRef TDName = TDPair.first; |
| 380 | const TypeDescriptor &TD = TDPair.second; |
| 381 | outs() << TDName << "[VFPtr]: " << TD.Symbols[0] << '\n'; |
David Majnemer | 6887a25 | 2014-09-26 08:01:23 +0000 | [diff] [blame] | 382 | outs() << TDName << "[AlwaysZero]: " << TD.AlwaysZero << '\n'; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 383 | outs() << TDName << "[MangledName]: "; |
David Majnemer | 56167c3 | 2014-09-26 05:50:45 +0000 | [diff] [blame] | 384 | outs().write_escaped(TD.MangledName.rtrim(StringRef("\0", 1)), |
| 385 | /*UseHexEscapes=*/true) |
| 386 | << '\n'; |
David Majnemer | 1ac52eb | 2014-09-26 04:21:51 +0000 | [diff] [blame] | 387 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 388 | for (const auto &TIPair : TIs) { |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 389 | StringRef TIName = TIPair.first; |
| 390 | const ThrowInfo &TI = TIPair.second; |
| 391 | auto dumpThrowInfoFlag = [&](const char *Name, uint32_t Flag) { |
| 392 | outs() << TIName << "[Flags." << Name |
| 393 | << "]: " << (TI.Flags & Flag ? "true" : "false") << '\n'; |
| 394 | }; |
| 395 | auto dumpThrowInfoSymbol = [&](const char *Name, int Offset) { |
| 396 | outs() << TIName << '[' << Name << "]: "; |
| 397 | auto Entry = TIEntries.find(std::make_pair(TIName, Offset)); |
| 398 | outs() << (Entry == TIEntries.end() ? "null" : Entry->second) << '\n'; |
| 399 | }; |
| 400 | outs() << TIName << "[Flags]: " << TI.Flags << '\n'; |
| 401 | dumpThrowInfoFlag("Const", 1); |
| 402 | dumpThrowInfoFlag("Volatile", 2); |
| 403 | dumpThrowInfoSymbol("CleanupFn", 4); |
| 404 | dumpThrowInfoSymbol("ForwardCompat", 8); |
| 405 | dumpThrowInfoSymbol("CatchableTypeArray", 12); |
| 406 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 407 | for (const auto &CTAPair : CTAs) { |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 408 | StringRef CTAName = CTAPair.first; |
| 409 | const CatchableTypeArray &CTA = CTAPair.second; |
| 410 | |
| 411 | outs() << CTAName << "[NumEntries]: " << CTA.NumEntries << '\n'; |
| 412 | |
| 413 | unsigned Idx = 0; |
| 414 | for (auto I = CTAEntries.lower_bound(std::make_pair(CTAName, 0)), |
| 415 | E = CTAEntries.upper_bound(std::make_pair(CTAName, UINT64_MAX)); |
| 416 | I != E; ++I) |
| 417 | outs() << CTAName << '[' << Idx++ << "]: " << I->second << '\n'; |
| 418 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 419 | for (const auto &CTPair : CTs) { |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 420 | StringRef CTName = CTPair.first; |
| 421 | const CatchableType &CT = CTPair.second; |
| 422 | auto dumpCatchableTypeFlag = [&](const char *Name, uint32_t Flag) { |
| 423 | outs() << CTName << "[Flags." << Name |
| 424 | << "]: " << (CT.Flags & Flag ? "true" : "false") << '\n'; |
| 425 | }; |
| 426 | outs() << CTName << "[Flags]: " << CT.Flags << '\n'; |
| 427 | dumpCatchableTypeFlag("ScalarType", 1); |
| 428 | dumpCatchableTypeFlag("VirtualInheritance", 4); |
| 429 | outs() << CTName << "[TypeDescriptor]: " << CT.Symbols[0] << '\n'; |
| 430 | outs() << CTName << "[NonVirtualBaseAdjustmentOffset]: " |
| 431 | << CT.NonVirtualBaseAdjustmentOffset << '\n'; |
| 432 | outs() << CTName |
| 433 | << "[VirtualBasePointerOffset]: " << CT.VirtualBasePointerOffset |
| 434 | << '\n'; |
| 435 | outs() << CTName << "[VirtualBaseAdjustmentOffset]: " |
| 436 | << CT.VirtualBaseAdjustmentOffset << '\n'; |
David Majnemer | 86ee173 | 2015-02-27 22:35:25 +0000 | [diff] [blame] | 437 | outs() << CTName << "[Size]: " << CT.Size << '\n'; |
David Majnemer | f50d0a5 | 2015-02-27 00:43:58 +0000 | [diff] [blame] | 438 | outs() << CTName |
| 439 | << "[CopyCtor]: " << (CT.Symbols[1].empty() ? "null" : CT.Symbols[1]) |
| 440 | << '\n'; |
| 441 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 442 | for (const auto &VTTPair : VTTEntries) { |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 443 | StringRef VTTName = VTTPair.first.first; |
| 444 | uint64_t VTTOffset = VTTPair.first.second; |
| 445 | StringRef VTTEntry = VTTPair.second; |
| 446 | outs() << VTTName << '[' << VTTOffset << "]: " << VTTEntry << '\n'; |
| 447 | } |
Richard Trieu | 46f2cc9 | 2015-04-15 03:17:49 +0000 | [diff] [blame] | 448 | for (const auto &TIPair : TINames) { |
David Majnemer | e268361 | 2014-11-03 07:23:25 +0000 | [diff] [blame] | 449 | StringRef TIName = TIPair.first; |
| 450 | outs() << TIName << ": " << TIPair.second << '\n'; |
| 451 | } |
| 452 | auto VTableSymI = VTableSymEntries.begin(); |
| 453 | auto VTableSymE = VTableSymEntries.end(); |
| 454 | auto VTableDataI = VTableDataEntries.begin(); |
| 455 | auto VTableDataE = VTableDataEntries.end(); |
| 456 | for (;;) { |
| 457 | bool SymDone = VTableSymI == VTableSymE; |
| 458 | bool DataDone = VTableDataI == VTableDataE; |
| 459 | if (SymDone && DataDone) |
| 460 | break; |
| 461 | if (!SymDone && (DataDone || VTableSymI->first < VTableDataI->first)) { |
| 462 | StringRef VTableName = VTableSymI->first.first; |
| 463 | uint64_t Offset = VTableSymI->first.second; |
| 464 | StringRef VTableEntry = VTableSymI->second; |
| 465 | outs() << VTableName << '[' << Offset << "]: "; |
| 466 | outs() << VTableEntry; |
| 467 | outs() << '\n'; |
| 468 | ++VTableSymI; |
| 469 | continue; |
| 470 | } |
| 471 | if (!DataDone && (SymDone || VTableDataI->first < VTableSymI->first)) { |
| 472 | StringRef VTableName = VTableDataI->first.first; |
| 473 | uint64_t Offset = VTableDataI->first.second; |
| 474 | int64_t VTableEntry = VTableDataI->second; |
| 475 | outs() << VTableName << '[' << Offset << "]: "; |
| 476 | outs() << VTableEntry; |
| 477 | outs() << '\n'; |
| 478 | ++VTableDataI; |
| 479 | continue; |
| 480 | } |
| 481 | } |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void dumpArchive(const Archive *Arc) { |
David Majnemer | eac48b6 | 2014-09-25 22:56:54 +0000 | [diff] [blame] | 485 | for (const Archive::Child &ArcC : Arc->children()) { |
| 486 | ErrorOr<std::unique_ptr<Binary>> ChildOrErr = ArcC.getAsBinary(); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 487 | if (std::error_code EC = ChildOrErr.getError()) { |
| 488 | // Ignore non-object files. |
| 489 | if (EC != object_error::invalid_file_type) |
| 490 | reportError(Arc->getFileName(), EC.message()); |
| 491 | continue; |
| 492 | } |
| 493 | |
| 494 | if (ObjectFile *Obj = dyn_cast<ObjectFile>(&*ChildOrErr.get())) |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 495 | dumpCXXData(Obj); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 496 | else |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 497 | reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| 501 | static void dumpInput(StringRef File) { |
| 502 | // If file isn't stdin, check that it exists. |
| 503 | if (File != "-" && !sys::fs::exists(File)) { |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 504 | reportError(File, cxxdump_error::file_not_found); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 505 | return; |
| 506 | } |
| 507 | |
| 508 | // Attempt to open the binary. |
Rafael Espindola | 48af1c2 | 2014-08-19 18:44:46 +0000 | [diff] [blame] | 509 | ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(File); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 510 | if (std::error_code EC = BinaryOrErr.getError()) { |
| 511 | reportError(File, EC); |
| 512 | return; |
| 513 | } |
Rafael Espindola | 48af1c2 | 2014-08-19 18:44:46 +0000 | [diff] [blame] | 514 | Binary &Binary = *BinaryOrErr.get().getBinary(); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 515 | |
Rafael Espindola | 3f6481d | 2014-08-01 14:31:55 +0000 | [diff] [blame] | 516 | if (Archive *Arc = dyn_cast<Archive>(&Binary)) |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 517 | dumpArchive(Arc); |
Rafael Espindola | 3f6481d | 2014-08-01 14:31:55 +0000 | [diff] [blame] | 518 | else if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary)) |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 519 | dumpCXXData(Obj); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 520 | else |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 521 | reportError(File, cxxdump_error::unrecognized_file_format); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | int main(int argc, const char *argv[]) { |
| 525 | sys::PrintStackTraceOnErrorSignal(); |
| 526 | PrettyStackTraceProgram X(argc, argv); |
| 527 | llvm_shutdown_obj Y; |
| 528 | |
| 529 | // Initialize targets. |
| 530 | llvm::InitializeAllTargetInfos(); |
| 531 | |
| 532 | // Register the target printer for --version. |
| 533 | cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); |
| 534 | |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 535 | cl::ParseCommandLineOptions(argc, argv, "LLVM C++ ABI Data Dumper\n"); |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 536 | |
| 537 | // Default to stdin if no filename is specified. |
| 538 | if (opts::InputFilenames.size() == 0) |
| 539 | opts::InputFilenames.push_back("-"); |
| 540 | |
| 541 | std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(), |
| 542 | dumpInput); |
| 543 | |
Davide Italiano | 8103294 | 2015-07-17 06:18:36 +0000 | [diff] [blame] | 544 | return EXIT_SUCCESS; |
David Majnemer | 72ab1a5 | 2014-07-24 23:14:40 +0000 | [diff] [blame] | 545 | } |