Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 1 | //===-- MachODump.cpp - Object file dumping utility for llvm --------------===// |
| 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 | // This file implements the MachO-specific dumper for llvm-readobj. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm-readobj.h" |
| 15 | #include "Error.h" |
| 16 | #include "ObjDumper.h" |
| 17 | #include "StreamWriter.h" |
| 18 | |
| 19 | #include "llvm/ADT/SmallString.h" |
| 20 | #include "llvm/Object/MachO.h" |
| 21 | #include "llvm/Support/Casting.h" |
| 22 | |
| 23 | using namespace llvm; |
| 24 | using namespace object; |
| 25 | |
| 26 | namespace { |
| 27 | |
| 28 | class MachODumper : public ObjDumper { |
| 29 | public: |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 30 | MachODumper(const MachOObjectFile *Obj, StreamWriter& Writer) |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 31 | : ObjDumper(Writer) |
| 32 | , Obj(Obj) { } |
| 33 | |
| 34 | virtual void printFileHeaders() LLVM_OVERRIDE; |
| 35 | virtual void printSections() LLVM_OVERRIDE; |
| 36 | virtual void printRelocations() LLVM_OVERRIDE; |
| 37 | virtual void printSymbols() LLVM_OVERRIDE; |
| 38 | virtual void printDynamicSymbols() LLVM_OVERRIDE; |
| 39 | virtual void printUnwindInfo() LLVM_OVERRIDE; |
| 40 | |
| 41 | private: |
| 42 | void printSymbol(symbol_iterator SymI); |
| 43 | |
| 44 | void printRelocation(section_iterator SecI, relocation_iterator RelI); |
| 45 | |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 46 | void printRelocation(const MachOObjectFile *Obj, |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 47 | section_iterator SecI, relocation_iterator RelI); |
| 48 | |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 49 | void printSections(const MachOObjectFile *Obj); |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 50 | |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 51 | const MachOObjectFile *Obj; |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | } // namespace |
| 55 | |
| 56 | |
| 57 | namespace llvm { |
| 58 | |
| 59 | error_code createMachODumper(const object::ObjectFile *Obj, |
| 60 | StreamWriter& Writer, |
| 61 | OwningPtr<ObjDumper> &Result) { |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 62 | const MachOObjectFile *MachOObj = dyn_cast<MachOObjectFile>(Obj); |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 63 | if (!MachOObj) |
| 64 | return readobj_error::unsupported_obj_file_format; |
| 65 | |
| 66 | Result.reset(new MachODumper(MachOObj, Writer)); |
| 67 | return readobj_error::success; |
| 68 | } |
| 69 | |
| 70 | } // namespace llvm |
| 71 | |
| 72 | |
| 73 | static const EnumEntry<unsigned> MachOSectionTypes[] = { |
| 74 | { "Regular" , 0x00 }, |
| 75 | { "ZeroFill" , 0x01 }, |
| 76 | { "CStringLiterals" , 0x02 }, |
| 77 | { "4ByteLiterals" , 0x03 }, |
| 78 | { "8ByteLiterals" , 0x04 }, |
| 79 | { "LiteralPointers" , 0x05 }, |
| 80 | { "NonLazySymbolPointers" , 0x06 }, |
| 81 | { "LazySymbolPointers" , 0x07 }, |
| 82 | { "SymbolStubs" , 0x08 }, |
| 83 | { "ModInitFuncs" , 0x09 }, |
| 84 | { "ModTermFuncs" , 0x0A }, |
| 85 | { "Coalesced" , 0x0B }, |
| 86 | { "GBZeroFill" , 0x0C }, |
| 87 | { "Interposing" , 0x0D }, |
| 88 | { "16ByteLiterals" , 0x0E }, |
| 89 | { "DTraceDOF" , 0x0F }, |
| 90 | { "LazyDylibSymbolPoints" , 0x10 }, |
| 91 | { "ThreadLocalRegular" , 0x11 }, |
| 92 | { "ThreadLocalZerofill" , 0x12 }, |
| 93 | { "ThreadLocalVariables" , 0x13 }, |
| 94 | { "ThreadLocalVariablePointers" , 0x14 }, |
| 95 | { "ThreadLocalInitFunctionPointers", 0x15 } |
| 96 | }; |
| 97 | |
| 98 | static const EnumEntry<unsigned> MachOSectionAttributes[] = { |
| 99 | { "LocReloc" , 1 << 0 /*S_ATTR_LOC_RELOC */ }, |
| 100 | { "ExtReloc" , 1 << 1 /*S_ATTR_EXT_RELOC */ }, |
| 101 | { "SomeInstructions" , 1 << 2 /*S_ATTR_SOME_INSTRUCTIONS */ }, |
| 102 | { "Debug" , 1 << 17 /*S_ATTR_DEBUG */ }, |
| 103 | { "SelfModifyingCode", 1 << 18 /*S_ATTR_SELF_MODIFYING_CODE*/ }, |
| 104 | { "LiveSupport" , 1 << 19 /*S_ATTR_LIVE_SUPPORT */ }, |
| 105 | { "NoDeadStrip" , 1 << 20 /*S_ATTR_NO_DEAD_STRIP */ }, |
| 106 | { "StripStaticSyms" , 1 << 21 /*S_ATTR_STRIP_STATIC_SYMS */ }, |
| 107 | { "NoTOC" , 1 << 22 /*S_ATTR_NO_TOC */ }, |
| 108 | { "PureInstructions" , 1 << 23 /*S_ATTR_PURE_INSTRUCTIONS */ }, |
| 109 | }; |
| 110 | |
| 111 | static const EnumEntry<unsigned> MachOSymbolRefTypes[] = { |
| 112 | { "UndefinedNonLazy", 0 }, |
| 113 | { "ReferenceFlagUndefinedLazy", 1 }, |
| 114 | { "ReferenceFlagDefined", 2 }, |
| 115 | { "ReferenceFlagPrivateDefined", 3 }, |
| 116 | { "ReferenceFlagPrivateUndefinedNonLazy", 4 }, |
| 117 | { "ReferenceFlagPrivateUndefinedLazy", 5 } |
| 118 | }; |
| 119 | |
| 120 | static const EnumEntry<unsigned> MachOSymbolFlags[] = { |
| 121 | { "ReferencedDynamically", 0x10 }, |
| 122 | { "NoDeadStrip", 0x20 }, |
| 123 | { "WeakRef", 0x40 }, |
| 124 | { "WeakDef", 0x80 } |
| 125 | }; |
| 126 | |
| 127 | static const EnumEntry<unsigned> MachOSymbolTypes[] = { |
| 128 | { "Undef", 0x0 }, |
| 129 | { "External", 0x1 }, |
| 130 | { "Abs", 0x2 }, |
| 131 | { "Indirect", 0xA }, |
| 132 | { "PreboundUndef", 0xC }, |
| 133 | { "Section", 0xE }, |
| 134 | { "PrivateExternal", 0x10 } |
| 135 | }; |
| 136 | |
| 137 | namespace { |
| 138 | enum { |
| 139 | N_STAB = 0xE0 |
| 140 | }; |
| 141 | |
| 142 | struct MachOSection { |
| 143 | ArrayRef<char> Name; |
| 144 | ArrayRef<char> SegmentName; |
| 145 | uint64_t Address; |
| 146 | uint64_t Size; |
| 147 | uint32_t Offset; |
| 148 | uint32_t Alignment; |
| 149 | uint32_t RelocationTableOffset; |
| 150 | uint32_t NumRelocationTableEntries; |
| 151 | uint32_t Flags; |
| 152 | uint32_t Reserved1; |
| 153 | uint32_t Reserved2; |
| 154 | }; |
| 155 | |
| 156 | struct MachOSymbol { |
| 157 | uint32_t StringIndex; |
| 158 | uint8_t Type; |
| 159 | uint8_t SectionIndex; |
| 160 | uint16_t Flags; |
| 161 | uint64_t Value; |
| 162 | }; |
| 163 | } |
| 164 | |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 165 | static void getSection(const MachOObjectFile *Obj, |
| 166 | DataRefImpl Sec, |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 167 | MachOSection &Section) { |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 168 | if (!Obj->is64Bit()) { |
| 169 | macho::Section Sect = Obj->getSection(Sec); |
| 170 | Section.Address = Sect.Address; |
| 171 | Section.Size = Sect.Size; |
| 172 | Section.Offset = Sect.Offset; |
| 173 | Section.Alignment = Sect.Align; |
| 174 | Section.RelocationTableOffset = Sect.RelocationTableOffset; |
| 175 | Section.NumRelocationTableEntries = Sect.NumRelocationTableEntries; |
| 176 | Section.Flags = Sect.Flags; |
| 177 | Section.Reserved1 = Sect.Reserved1; |
| 178 | Section.Reserved2 = Sect.Reserved2; |
| 179 | return; |
| 180 | } |
| 181 | macho::Section64 Sect = Obj->getSection64(Sec); |
| 182 | Section.Address = Sect.Address; |
| 183 | Section.Size = Sect.Size; |
| 184 | Section.Offset = Sect.Offset; |
| 185 | Section.Alignment = Sect.Align; |
| 186 | Section.RelocationTableOffset = Sect.RelocationTableOffset; |
| 187 | Section.NumRelocationTableEntries = Sect.NumRelocationTableEntries; |
| 188 | Section.Flags = Sect.Flags; |
| 189 | Section.Reserved1 = Sect.Reserved1; |
| 190 | Section.Reserved2 = Sect.Reserved2; |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 193 | |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 194 | static void getSymbol(const MachOObjectFile *Obj, |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 195 | DataRefImpl DRI, |
| 196 | MachOSymbol &Symbol) { |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 197 | if (!Obj->is64Bit()) { |
| 198 | macho::SymbolTableEntry Entry = Obj->getSymbolTableEntry(DRI); |
| 199 | Symbol.StringIndex = Entry.StringIndex; |
| 200 | Symbol.Type = Entry.Type; |
| 201 | Symbol.SectionIndex = Entry.SectionIndex; |
| 202 | Symbol.Flags = Entry.Flags; |
| 203 | Symbol.Value = Entry.Value; |
| 204 | return; |
| 205 | } |
| 206 | macho::Symbol64TableEntry Entry = Obj->getSymbol64TableEntry(DRI); |
| 207 | Symbol.StringIndex = Entry.StringIndex; |
| 208 | Symbol.Type = Entry.Type; |
| 209 | Symbol.SectionIndex = Entry.SectionIndex; |
| 210 | Symbol.Flags = Entry.Flags; |
| 211 | Symbol.Value = Entry.Value; |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void MachODumper::printFileHeaders() { |
| 215 | W.startLine() << "FileHeaders not implemented.\n"; |
| 216 | } |
| 217 | |
| 218 | void MachODumper::printSections() { |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 219 | return printSections(Obj); |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 222 | void MachODumper::printSections(const MachOObjectFile *Obj) { |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 223 | ListScope Group(W, "Sections"); |
| 224 | |
| 225 | int SectionIndex = -1; |
| 226 | error_code EC; |
| 227 | for (section_iterator SecI = Obj->begin_sections(), |
| 228 | SecE = Obj->end_sections(); |
| 229 | SecI != SecE; SecI.increment(EC)) { |
| 230 | if (error(EC)) break; |
| 231 | |
| 232 | ++SectionIndex; |
| 233 | |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 234 | MachOSection Section; |
Rafael Espindola | 7ea2e48 | 2013-04-07 15:05:12 +0000 | [diff] [blame] | 235 | getSection(Obj, SecI->getRawDataRefImpl(), Section); |
Rafael Espindola | f16c2bb | 2013-04-05 15:15:22 +0000 | [diff] [blame] | 236 | DataRefImpl DR = SecI->getRawDataRefImpl(); |
| 237 | |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 238 | StringRef Name; |
| 239 | if (error(SecI->getName(Name))) |
| 240 | Name = ""; |
| 241 | |
Rafael Espindola | f16c2bb | 2013-04-05 15:15:22 +0000 | [diff] [blame] | 242 | ArrayRef<char> RawName = Obj->getSectionRawName(DR); |
| 243 | StringRef SegmentName = Obj->getSectionFinalSegmentName(DR); |
| 244 | ArrayRef<char> RawSegmentName = Obj->getSectionRawFinalSegmentName(DR); |
| 245 | |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 246 | DictScope SectionD(W, "Section"); |
| 247 | W.printNumber("Index", SectionIndex); |
Rafael Espindola | f16c2bb | 2013-04-05 15:15:22 +0000 | [diff] [blame] | 248 | W.printBinary("Name", Name, RawName); |
| 249 | W.printBinary("Segment", SegmentName, RawSegmentName); |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 250 | W.printHex ("Address", Section.Address); |
| 251 | W.printHex ("Size", Section.Size); |
| 252 | W.printNumber("Offset", Section.Offset); |
| 253 | W.printNumber("Alignment", Section.Alignment); |
| 254 | W.printHex ("RelocationOffset", Section.RelocationTableOffset); |
| 255 | W.printNumber("RelocationCount", Section.NumRelocationTableEntries); |
| 256 | W.printEnum ("Type", Section.Flags & 0xFF, |
| 257 | makeArrayRef(MachOSectionAttributes)); |
| 258 | W.printFlags ("Attributes", Section.Flags >> 8, |
| 259 | makeArrayRef(MachOSectionAttributes)); |
| 260 | W.printHex ("Reserved1", Section.Reserved1); |
| 261 | W.printHex ("Reserved2", Section.Reserved2); |
| 262 | |
| 263 | if (opts::SectionRelocations) { |
| 264 | ListScope D(W, "Relocations"); |
| 265 | for (relocation_iterator RelI = SecI->begin_relocations(), |
| 266 | RelE = SecI->end_relocations(); |
| 267 | RelI != RelE; RelI.increment(EC)) { |
| 268 | if (error(EC)) break; |
| 269 | |
| 270 | printRelocation(SecI, RelI); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | if (opts::SectionSymbols) { |
| 275 | ListScope D(W, "Symbols"); |
| 276 | for (symbol_iterator SymI = Obj->begin_symbols(), |
| 277 | SymE = Obj->end_symbols(); |
| 278 | SymI != SymE; SymI.increment(EC)) { |
| 279 | if (error(EC)) break; |
| 280 | |
| 281 | bool Contained = false; |
| 282 | if (SecI->containsSymbol(*SymI, Contained) || !Contained) |
| 283 | continue; |
| 284 | |
| 285 | printSymbol(SymI); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (opts::SectionData) { |
| 290 | StringRef Data; |
| 291 | if (error(SecI->getContents(Data))) break; |
| 292 | |
| 293 | W.printBinaryBlock("SectionData", Data); |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | void MachODumper::printRelocations() { |
| 299 | ListScope D(W, "Relocations"); |
| 300 | |
| 301 | error_code EC; |
| 302 | for (section_iterator SecI = Obj->begin_sections(), |
| 303 | SecE = Obj->end_sections(); |
| 304 | SecI != SecE; SecI.increment(EC)) { |
| 305 | if (error(EC)) break; |
| 306 | |
| 307 | StringRef Name; |
| 308 | if (error(SecI->getName(Name))) |
| 309 | continue; |
| 310 | |
| 311 | bool PrintedGroup = false; |
| 312 | for (relocation_iterator RelI = SecI->begin_relocations(), |
| 313 | RelE = SecI->end_relocations(); |
| 314 | RelI != RelE; RelI.increment(EC)) { |
| 315 | if (error(EC)) break; |
| 316 | |
| 317 | if (!PrintedGroup) { |
| 318 | W.startLine() << "Section " << Name << " {\n"; |
| 319 | W.indent(); |
| 320 | PrintedGroup = true; |
| 321 | } |
| 322 | |
| 323 | printRelocation(SecI, RelI); |
| 324 | } |
| 325 | |
| 326 | if (PrintedGroup) { |
| 327 | W.unindent(); |
| 328 | W.startLine() << "}\n"; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | void MachODumper::printRelocation(section_iterator SecI, |
| 334 | relocation_iterator RelI) { |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 335 | return printRelocation(Obj, SecI, RelI); |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 338 | void MachODumper::printRelocation(const MachOObjectFile *Obj, |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 339 | section_iterator SecI, |
| 340 | relocation_iterator RelI) { |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 341 | uint64_t Offset; |
| 342 | SmallString<32> RelocName; |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 343 | StringRef SymbolName; |
| 344 | SymbolRef Symbol; |
| 345 | if (error(RelI->getOffset(Offset))) return; |
| 346 | if (error(RelI->getTypeName(RelocName))) return; |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 347 | if (error(RelI->getSymbol(Symbol))) return; |
| 348 | if (error(Symbol.getName(SymbolName))) return; |
| 349 | |
Rafael Espindola | e292347 | 2013-04-12 00:17:33 +0000 | [diff] [blame] | 350 | DataRefImpl DR = RelI->getRawDataRefImpl(); |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 351 | macho::RelocationEntry RE = Obj->getRelocation(DR); |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 352 | bool IsScattered = Obj->isRelocationScattered(RE); |
Rafael Espindola | e292347 | 2013-04-12 00:17:33 +0000 | [diff] [blame] | 353 | |
Nico Rieck | 1c8dfa5 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 354 | if (opts::ExpandRelocs) { |
| 355 | DictScope Group(W, "Relocation"); |
| 356 | W.printHex("Offset", Offset); |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 357 | W.printNumber("PCRel", Obj->getAnyRelocationPCRel(RE)); |
| 358 | W.printNumber("Length", Obj->getAnyRelocationLength(RE)); |
Nico Rieck | 1c8dfa5 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 359 | if (IsScattered) |
| 360 | W.printString("Extern", StringRef("N/A")); |
| 361 | else |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 362 | W.printNumber("Extern", Obj->getPlainRelocationExternal(RE)); |
| 363 | W.printNumber("Type", RelocName, Obj->getAnyRelocationType(RE)); |
Nico Rieck | 1c8dfa5 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 364 | W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-"); |
| 365 | W.printNumber("Scattered", IsScattered); |
| 366 | } else { |
| 367 | raw_ostream& OS = W.startLine(); |
| 368 | OS << W.hex(Offset) |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 369 | << " " << Obj->getAnyRelocationPCRel(RE) |
| 370 | << " " << Obj->getAnyRelocationLength(RE); |
Nico Rieck | 1c8dfa5 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 371 | if (IsScattered) |
| 372 | OS << " n/a"; |
| 373 | else |
Rafael Espindola | fd7aa38 | 2013-04-18 18:08:55 +0000 | [diff] [blame^] | 374 | OS << " " << Obj->getPlainRelocationExternal(RE); |
Nico Rieck | 1c8dfa5 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 375 | OS << " " << RelocName |
| 376 | << " " << IsScattered |
| 377 | << " " << (SymbolName.size() > 0 ? SymbolName : "-") |
| 378 | << "\n"; |
| 379 | } |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | void MachODumper::printSymbols() { |
| 383 | ListScope Group(W, "Symbols"); |
| 384 | |
| 385 | error_code EC; |
| 386 | for (symbol_iterator SymI = Obj->begin_symbols(), |
| 387 | SymE = Obj->end_symbols(); |
| 388 | SymI != SymE; SymI.increment(EC)) { |
| 389 | if (error(EC)) break; |
| 390 | |
| 391 | printSymbol(SymI); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | void MachODumper::printDynamicSymbols() { |
| 396 | ListScope Group(W, "DynamicSymbols"); |
| 397 | } |
| 398 | |
| 399 | void MachODumper::printSymbol(symbol_iterator SymI) { |
| 400 | error_code EC; |
| 401 | |
| 402 | StringRef SymbolName; |
| 403 | if (SymI->getName(SymbolName)) |
| 404 | SymbolName = ""; |
| 405 | |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 406 | MachOSymbol Symbol; |
Rafael Espindola | 1efa604 | 2013-04-07 15:35:18 +0000 | [diff] [blame] | 407 | getSymbol(Obj, SymI->getRawDataRefImpl(), Symbol); |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 408 | |
| 409 | StringRef SectionName; |
| 410 | section_iterator SecI(Obj->end_sections()); |
| 411 | if (error(SymI->getSection(SecI)) || |
Rafael Espindola | da2a237 | 2013-04-13 01:45:40 +0000 | [diff] [blame] | 412 | SecI == Obj->end_sections() || |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 413 | error(SecI->getName(SectionName))) |
| 414 | SectionName = ""; |
| 415 | |
| 416 | DictScope D(W, "Symbol"); |
| 417 | W.printNumber("Name", SymbolName, Symbol.StringIndex); |
| 418 | if (Symbol.Type & N_STAB) { |
| 419 | W.printHex ("Type", "SymDebugTable", Symbol.Type); |
| 420 | } else { |
| 421 | W.printEnum("Type", Symbol.Type, makeArrayRef(MachOSymbolTypes)); |
| 422 | } |
| 423 | W.printHex ("Section", SectionName, Symbol.SectionIndex); |
| 424 | W.printEnum ("RefType", static_cast<uint16_t>(Symbol.Flags & 0xF), |
| 425 | makeArrayRef(MachOSymbolRefTypes)); |
| 426 | W.printFlags ("Flags", static_cast<uint16_t>(Symbol.Flags & ~0xF), |
| 427 | makeArrayRef(MachOSymbolFlags)); |
| 428 | W.printHex ("Value", Symbol.Value); |
| 429 | } |
| 430 | |
| 431 | void MachODumper::printUnwindInfo() { |
| 432 | W.startLine() << "UnwindInfo not implemented.\n"; |
| 433 | } |