1 //===- llvm-cxxdump.cpp - Dump C++ data in an Object File -------*- 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 // Dumps C++ data resident in object files and archives. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm-cxxdump.h" 15 #include "Error.h" 16 #include "llvm/ADT/ArrayRef.h" 17 #include "llvm/Object/Archive.h" 18 #include "llvm/Object/ObjectFile.h" 19 #include "llvm/Object/SymbolSize.h" 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" 28 #include "llvm/Support/raw_ostream.h" 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 43 namespace llvm { 44 45 static void error(std::error_code EC) { 46 if (!EC) 47 return; 48 outs() << "\nError reading file: " << EC.message() << ".\n"; 49 outs().flush(); 50 exit(1); 51 } 52 53 } // namespace llvm 54 55 static void reportError(StringRef Input, StringRef Message) { 56 if (Input == "-") 57 Input = "<stdin>"; 58 errs() << Input << ": " << Message << "\n"; 59 errs().flush(); 60 exit(1); 61 } 62 63 static void reportError(StringRef Input, std::error_code EC) { 64 reportError(Input, EC.message()); 65 } 66 67 static std::map<SectionRef, SmallVector<SectionRef, 1>> SectionRelocMap; 68 69 static void collectRelocatedSymbols(const ObjectFile *Obj, 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; 75 for (const SectionRef &SR : SectionRelocMap[Sec]) { 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; 82 ErrorOr<StringRef> RelocSymName = RelocSymI->getName(); 83 error(RelocSymName.getError()); 84 uint64_t Offset = Reloc.getOffset(); 85 if (Offset >= SymOffset && Offset < SymEnd) { 86 *I = *RelocSymName; 87 ++I; 88 } 89 } 90 } 91 } 92 93 static void collectRelocationOffsets( 94 const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress, 95 uint64_t SymAddress, uint64_t SymSize, StringRef SymName, 96 std::map<std::pair<StringRef, uint64_t>, StringRef> &Collection) { 97 uint64_t SymOffset = SymAddress - SecAddress; 98 uint64_t SymEnd = SymOffset + SymSize; 99 for (const SectionRef &SR : SectionRelocMap[Sec]) { 100 for (const object::RelocationRef &Reloc : SR.relocations()) { 101 const object::symbol_iterator RelocSymI = Reloc.getSymbol(); 102 if (RelocSymI == Obj->symbol_end()) 103 continue; 104 ErrorOr<StringRef> RelocSymName = RelocSymI->getName(); 105 error(RelocSymName.getError()); 106 uint64_t Offset = Reloc.getOffset(); 107 if (Offset >= SymOffset && Offset < SymEnd) 108 Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName; 109 } 110 } 111 } 112 113 static void dumpCXXData(const ObjectFile *Obj) { 114 struct CompleteObjectLocator { 115 StringRef Symbols[2]; 116 ArrayRef<little32_t> Data; 117 }; 118 struct ClassHierarchyDescriptor { 119 StringRef Symbols[1]; 120 ArrayRef<little32_t> Data; 121 }; 122 struct BaseClassDescriptor { 123 StringRef Symbols[2]; 124 ArrayRef<little32_t> Data; 125 }; 126 struct TypeDescriptor { 127 StringRef Symbols[1]; 128 uint64_t AlwaysZero; 129 StringRef MangledName; 130 }; 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; 142 uint32_t Size; 143 StringRef Symbols[2]; 144 }; 145 std::map<std::pair<StringRef, uint64_t>, StringRef> VFTableEntries; 146 std::map<std::pair<StringRef, uint64_t>, StringRef> TIEntries; 147 std::map<std::pair<StringRef, uint64_t>, StringRef> CTAEntries; 148 std::map<StringRef, ArrayRef<little32_t>> VBTables; 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; 154 std::map<StringRef, ThrowInfo> TIs; 155 std::map<StringRef, CatchableTypeArray> CTAs; 156 std::map<StringRef, CatchableType> CTs; 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 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 170 uint8_t BytesInAddress = Obj->getBytesInAddress(); 171 172 std::vector<std::pair<SymbolRef, uint64_t>> SymAddr = 173 object::computeSymbolSizes(*Obj); 174 175 for (auto &P : SymAddr) { 176 object::SymbolRef Sym = P.first; 177 uint64_t SymSize = P.second; 178 ErrorOr<StringRef> SymNameOrErr = Sym.getName(); 179 error(SymNameOrErr.getError()); 180 StringRef SymName = *SymNameOrErr; 181 ErrorOr<object::section_iterator> SecIOrErr = Sym.getSection(); 182 error(SecIOrErr.getError()); 183 object::section_iterator SecI = *SecIOrErr; 184 // Skip external symbols. 185 if (SecI == Obj->section_end()) 186 continue; 187 const SectionRef &Sec = *SecI; 188 // Skip virtual or BSS sections. 189 if (Sec.isBSS() || Sec.isVirtual()) 190 continue; 191 StringRef SecContents; 192 error(Sec.getContents(SecContents)); 193 ErrorOr<uint64_t> SymAddressOrErr = Sym.getAddress(); 194 error(SymAddressOrErr.getError()); 195 uint64_t SymAddress = *SymAddressOrErr; 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 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")) { 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. 207 collectRelocationOffsets(Obj, Sec, SecAddress, SecAddress, SecSize, 208 SymName, VFTableEntries); 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")) { 213 ArrayRef<little32_t> VBTableData( 214 reinterpret_cast<const little32_t *>(SymContents.data()), 215 SymContents.size() / sizeof(little32_t)); 216 VBTables[SymName] = VBTableData; 217 } 218 // Complete object locators in the MS-ABI start with '??_R4' 219 else if (SymName.startswith("??_R4")) { 220 CompleteObjectLocator COL; 221 COL.Data = makeArrayRef( 222 reinterpret_cast<const little32_t *>(SymContents.data()), 3); 223 StringRef *I = std::begin(COL.Symbols), *E = std::end(COL.Symbols); 224 collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); 225 COLs[SymName] = COL; 226 } 227 // Class hierarchy descriptors in the MS-ABI start with '??_R3' 228 else if (SymName.startswith("??_R3")) { 229 ClassHierarchyDescriptor CHD; 230 CHD.Data = makeArrayRef( 231 reinterpret_cast<const little32_t *>(SymContents.data()), 3); 232 StringRef *I = std::begin(CHD.Symbols), *E = std::end(CHD.Symbols); 233 collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); 234 CHDs[SymName] = CHD; 235 } 236 // Class hierarchy descriptors in the MS-ABI start with '??_R2' 237 else if (SymName.startswith("??_R2")) { 238 // Each relocation names a base class descriptor. We note the offset into 239 // the section and the symbol used for the relocation. 240 collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize, 241 SymName, BCAEntries); 242 } 243 // Base class descriptors in the MS-ABI start with '??_R1' 244 else if (SymName.startswith("??_R1")) { 245 BaseClassDescriptor BCD; 246 BCD.Data = makeArrayRef( 247 reinterpret_cast<const little32_t *>(SymContents.data()) + 1, 5); 248 StringRef *I = std::begin(BCD.Symbols), *E = std::end(BCD.Symbols); 249 collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); 250 BCDs[SymName] = BCD; 251 } 252 // Type descriptors in the MS-ABI start with '??_R0' 253 else if (SymName.startswith("??_R0")) { 254 const char *DataPtr = SymContents.drop_front(BytesInAddress).data(); 255 TypeDescriptor TD; 256 if (BytesInAddress == 8) 257 TD.AlwaysZero = *reinterpret_cast<const little64_t *>(DataPtr); 258 else 259 TD.AlwaysZero = *reinterpret_cast<const little32_t *>(DataPtr); 260 TD.MangledName = SymContents.drop_front(BytesInAddress * 2); 261 StringRef *I = std::begin(TD.Symbols), *E = std::end(TD.Symbols); 262 collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); 263 TDs[SymName] = TD; 264 } 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]; 291 CT.Size = DataPtr[5]; 292 StringRef *I = std::begin(CT.Symbols), *E = std::end(CT.Symbols); 293 collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E); 294 CTs[SymName] = CT; 295 } 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; 313 const char *DataPtr = 314 SymContents.substr(SymOffI, BytesInAddress).data(); 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 } 327 } 328 for (const auto &VFTableEntry : VFTableEntries) { 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 } 334 for (const auto &VBTable : VBTables) { 335 StringRef VBTableName = VBTable.first; 336 uint32_t Idx = 0; 337 for (little32_t Offset : VBTable.second) { 338 outs() << VBTableName << '[' << Idx << "]: " << Offset << '\n'; 339 Idx += sizeof(Offset); 340 } 341 } 342 for (const auto &COLPair : COLs) { 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'; 349 outs() << COLName << "[ClassHierarchyDescriptor]: " << COL.Symbols[1] 350 << '\n'; 351 } 352 for (const auto &CHDPair : CHDs) { 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 } 360 for (const auto &BCAEntry : BCAEntries) { 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 } 366 for (const auto &BCDPair : BCDs) { 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'; 375 outs() << BCDName << "[ClassHierarchyDescriptor]: " << BCD.Symbols[1] 376 << '\n'; 377 } 378 for (const auto &TDPair : TDs) { 379 StringRef TDName = TDPair.first; 380 const TypeDescriptor &TD = TDPair.second; 381 outs() << TDName << "[VFPtr]: " << TD.Symbols[0] << '\n'; 382 outs() << TDName << "[AlwaysZero]: " << TD.AlwaysZero << '\n'; 383 outs() << TDName << "[MangledName]: "; 384 outs().write_escaped(TD.MangledName.rtrim(StringRef("\0", 1)), 385 /*UseHexEscapes=*/true) 386 << '\n'; 387 } 388 for (const auto &TIPair : TIs) { 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 } 407 for (const auto &CTAPair : CTAs) { 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 } 419 for (const auto &CTPair : CTs) { 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'; 437 outs() << CTName << "[Size]: " << CT.Size << '\n'; 438 outs() << CTName 439 << "[CopyCtor]: " << (CT.Symbols[1].empty() ? "null" : CT.Symbols[1]) 440 << '\n'; 441 } 442 for (const auto &VTTPair : VTTEntries) { 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 } 448 for (const auto &TIPair : TINames) { 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 } 482 } 483 484 static void dumpArchive(const Archive *Arc) { 485 for (auto &ErrorOrChild : Arc->children()) { 486 error(ErrorOrChild.getError()); 487 const Archive::Child &ArcC = *ErrorOrChild; 488 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = ArcC.getAsBinary(); 489 if (std::error_code EC = ChildOrErr.getError()) { 490 // Ignore non-object files. 491 if (EC != object_error::invalid_file_type) 492 reportError(Arc->getFileName(), EC.message()); 493 continue; 494 } 495 496 if (ObjectFile *Obj = dyn_cast<ObjectFile>(&*ChildOrErr.get())) 497 dumpCXXData(Obj); 498 else 499 reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format); 500 } 501 } 502 503 static void dumpInput(StringRef File) { 504 // Attempt to open the binary. 505 ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(File); 506 if (std::error_code EC = BinaryOrErr.getError()) { 507 reportError(File, EC); 508 return; 509 } 510 Binary &Binary = *BinaryOrErr.get().getBinary(); 511 512 if (Archive *Arc = dyn_cast<Archive>(&Binary)) 513 dumpArchive(Arc); 514 else if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary)) 515 dumpCXXData(Obj); 516 else 517 reportError(File, cxxdump_error::unrecognized_file_format); 518 } 519 520 int main(int argc, const char *argv[]) { 521 sys::PrintStackTraceOnErrorSignal(); 522 PrettyStackTraceProgram X(argc, argv); 523 llvm_shutdown_obj Y; 524 525 // Initialize targets. 526 llvm::InitializeAllTargetInfos(); 527 528 // Register the target printer for --version. 529 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); 530 531 cl::ParseCommandLineOptions(argc, argv, "LLVM C++ ABI Data Dumper\n"); 532 533 // Default to stdin if no filename is specified. 534 if (opts::InputFilenames.size() == 0) 535 opts::InputFilenames.push_back("-"); 536 537 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(), 538 dumpInput); 539 540 return EXIT_SUCCESS; 541 } 542