//===----------------------------------------------------------------------===//
#include "llvm-objdump.h"
-#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Triple.h"
}
}
-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 (symbol_iterator SI = MachOObj->symbol_begin(),
- SE = MachOObj->symbol_end();
- SI != SE; ++SI)
- Symbols.push_back(*SI);
-
- for (section_iterator SI = MachOObj->section_begin(),
- SE = MachOObj->section_end();
- SI != SE; ++SI) {
- 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) {
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()).get()));
+ std::unique_ptr<MachOObjectFile> MachOOF(static_cast<MachOObjectFile *>(
+ ObjectFile::createMachOObjectFile(Buff.release()).get()));
DisassembleInputMachO2(Filename, MachOOF.get());
}
// 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 "
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()).get();
+ DbgObj = ObjectFile::createMachOObjectFile(Buf.release()).get();
}
// Setup the DIContext
bool symbolTableWorked = false;
// Parse relocations.
- std::vector<std::pair<uint64_t, SymbolRef> > Relocs;
- for (relocation_iterator RI = Sections[SectIdx].relocation_begin(),
- RE = Sections[SectIdx].relocation_end();
- RI != RE; ++RI) {
+ 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));
}