diff options
author | Stephen Hines <srhines@google.com> | 2014-04-23 16:57:46 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-04-24 15:53:16 -0700 |
commit | 36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch) | |
tree | e6cfb69fbbd937f450eeb83bfb83b9da3b01275a /tools/llvm-objdump/MachODump.cpp | |
parent | 69a8640022b04415ae9fac62f8ab090601d8f889 (diff) | |
download | external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2 |
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'tools/llvm-objdump/MachODump.cpp')
-rw-r--r-- | tools/llvm-objdump/MachODump.cpp | 80 |
1 files changed, 36 insertions, 44 deletions
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 86923fd..89b038f 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "llvm-objdump.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Triple.h" @@ -147,28 +146,23 @@ static void DumpDataInCode(const char *bytes, uint64_t Size, } } -static void -getSectionsAndSymbols(const MachO::mach_header Header, - MachOObjectFile *MachOObj, - std::vector<SectionRef> &Sections, - std::vector<SymbolRef> &Symbols, - SmallVectorImpl<uint64_t> &FoundFns, - uint64_t &BaseSegmentAddress) { - error_code ec; - for (symbol_iterator SI = MachOObj->begin_symbols(), - SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec)) - Symbols.push_back(*SI); - - for (section_iterator SI = MachOObj->begin_sections(), - SE = MachOObj->end_sections(); SI != SE; SI.increment(ec)) { - SectionRef SR = *SI; +static void getSectionsAndSymbols(const MachO::mach_header Header, + MachOObjectFile *MachOObj, + std::vector<SectionRef> &Sections, + std::vector<SymbolRef> &Symbols, + SmallVectorImpl<uint64_t> &FoundFns, + uint64_t &BaseSegmentAddress) { + for (const SymbolRef &Symbol : MachOObj->symbols()) + Symbols.push_back(Symbol); + + for (const SectionRef &Section : MachOObj->sections()) { StringRef SectName; - SR.getName(SectName); - Sections.push_back(*SI); + Section.getName(SectName); + Sections.push_back(Section); } MachOObjectFile::LoadCommandInfo Command = - MachOObj->getFirstLoadCommandInfo(); + MachOObj->getFirstLoadCommandInfo(); bool BaseSegmentAddressSet = false; for (unsigned i = 0; ; ++i) { if (Command.C.cmd == MachO::LC_FUNCTION_STARTS) { @@ -200,15 +194,15 @@ static void DisassembleInputMachO2(StringRef Filename, MachOObjectFile *MachOOF); void llvm::DisassembleInputMachO(StringRef Filename) { - OwningPtr<MemoryBuffer> Buff; + std::unique_ptr<MemoryBuffer> Buff; if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { errs() << "llvm-objdump: " << Filename << ": " << ec.message() << "\n"; return; } - OwningPtr<MachOObjectFile> MachOOF(static_cast<MachOObjectFile*>( - ObjectFile::createMachOObjectFile(Buff.take()))); + std::unique_ptr<MachOObjectFile> MachOOF(static_cast<MachOObjectFile *>( + ObjectFile::createMachOObjectFile(Buff.release()).get())); DisassembleInputMachO2(Filename, MachOOF.get()); } @@ -220,21 +214,22 @@ static void DisassembleInputMachO2(StringRef Filename, // GetTarget prints out stuff. return; } - OwningPtr<const MCInstrInfo> InstrInfo(TheTarget->createMCInstrInfo()); - OwningPtr<MCInstrAnalysis> - InstrAnalysis(TheTarget->createMCInstrAnalysis(InstrInfo.get())); + std::unique_ptr<const MCInstrInfo> InstrInfo(TheTarget->createMCInstrInfo()); + std::unique_ptr<MCInstrAnalysis> InstrAnalysis( + TheTarget->createMCInstrAnalysis(InstrInfo.get())); // Set up disassembler. - OwningPtr<const MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName)); - OwningPtr<const MCAsmInfo> AsmInfo( + std::unique_ptr<const MCRegisterInfo> MRI( + TheTarget->createMCRegInfo(TripleName)); + std::unique_ptr<const MCAsmInfo> AsmInfo( TheTarget->createMCAsmInfo(*MRI, TripleName)); - OwningPtr<const MCSubtargetInfo> - STI(TheTarget->createMCSubtargetInfo(TripleName, "", "")); - OwningPtr<const MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI)); + std::unique_ptr<const MCSubtargetInfo> STI( + TheTarget->createMCSubtargetInfo(TripleName, "", "")); + std::unique_ptr<const MCDisassembler> DisAsm( + TheTarget->createMCDisassembler(*STI)); int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); - OwningPtr<MCInstPrinter> - IP(TheTarget->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *InstrInfo, - *MRI, *STI)); + std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter( + AsmPrinterVariant, *AsmInfo, *InstrInfo, *MRI, *STI)); if (!InstrAnalysis || !AsmInfo || !STI || !DisAsm || !IP) { errs() << "error: couldn't initialize disassembler for target " @@ -270,9 +265,8 @@ static void DisassembleInputMachO2(StringRef Filename, else BaseAddress = BaseSegmentAddress; DiceTable Dices; - error_code ec; for (dice_iterator DI = MachOOF->begin_dices(), DE = MachOOF->end_dices(); - DI != DE; DI.increment(ec)){ + DI != DE; ++DI) { uint32_t Offset; DI->getOffset(Offset); Dices.push_back(std::make_pair(BaseAddress + Offset, *DI)); @@ -285,19 +279,19 @@ static void DisassembleInputMachO2(StringRef Filename, raw_ostream &DebugOut = nulls(); #endif - OwningPtr<DIContext> diContext; + std::unique_ptr<DIContext> diContext; ObjectFile *DbgObj = MachOOF; // Try to find debug info and set up the DIContext for it. if (UseDbg) { // A separate DSym file path was specified, parse it as a macho file, // get the sections and supply it to the section name parsing machinery. if (!DSYMFile.empty()) { - OwningPtr<MemoryBuffer> Buf; + std::unique_ptr<MemoryBuffer> Buf; if (error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile, Buf)) { errs() << "llvm-objdump: " << Filename << ": " << ec.message() << '\n'; return; } - DbgObj = ObjectFile::createMachOObjectFile(Buf.take()); + DbgObj = ObjectFile::createMachOObjectFile(Buf.release()).get(); } // Setup the DIContext @@ -328,16 +322,14 @@ static void DisassembleInputMachO2(StringRef Filename, bool symbolTableWorked = false; // Parse relocations. - std::vector<std::pair<uint64_t, SymbolRef> > Relocs; - error_code ec; - for (relocation_iterator RI = Sections[SectIdx].begin_relocations(), - RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) { + std::vector<std::pair<uint64_t, SymbolRef>> Relocs; + for (const RelocationRef &Reloc : Sections[SectIdx].relocations()) { uint64_t RelocOffset, SectionAddress; - RI->getOffset(RelocOffset); + Reloc.getOffset(RelocOffset); Sections[SectIdx].getAddress(SectionAddress); RelocOffset -= SectionAddress; - symbol_iterator RelocSym = RI->getSymbol(); + symbol_iterator RelocSym = Reloc.getSymbol(); Relocs.push_back(std::make_pair(RelocOffset, *RelocSym)); } |