: Obj(Obj), Dis(Dis), MIA(MIA), MOS(0) {}
uint64_t MCObjectDisassembler::getEntrypoint() {
- error_code ec;
- for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
- SI != SE; SI.increment(ec)) {
- if (ec)
- break;
+ for (const SymbolRef &Symbol : Obj.symbols()) {
StringRef Name;
- SI->getName(Name);
+ Symbol.getName(Name);
if (Name == "main" || Name == "_main") {
uint64_t Entrypoint;
- SI->getAddress(Entrypoint);
+ Symbol.getAddress(Entrypoint);
return getEffectiveLoadAddr(Entrypoint);
}
}
}
void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
- error_code ec;
- for (section_iterator SI = Obj.begin_sections(),
- SE = Obj.end_sections();
- SI != SE;
- SI.increment(ec)) {
- if (ec) break;
-
- bool isText; SI->isText(isText);
- bool isData; SI->isData(isData);
+ for (const SectionRef &Section : Obj.sections()) {
+ bool isText;
+ Section.isText(isText);
+ bool isData;
+ Section.isData(isData);
if (!isData && !isText)
continue;
- uint64_t StartAddr; SI->getAddress(StartAddr);
- uint64_t SecSize; SI->getSize(SecSize);
+ uint64_t StartAddr;
+ Section.getAddress(StartAddr);
+ uint64_t SecSize;
+ Section.getSize(SecSize);
if (StartAddr == UnknownAddressOrSize || SecSize == UnknownAddressOrSize)
continue;
StartAddr = getEffectiveLoadAddr(StartAddr);
- StringRef Contents; SI->getContents(Contents);
+ StringRef Contents;
+ Section.getContents(Contents);
StringRefMemoryObject memoryObject(Contents, StartAddr);
// We don't care about things like non-file-backed sections yet.
continue;
uint64_t EndAddr = StartAddr + SecSize - 1;
- StringRef SecName; SI->getName(SecName);
+ StringRef SecName;
+ Section.getName(SecName);
if (isText) {
MCTextAtom *Text = 0;
Text->addInst(Inst, InstSize);
InvalidData = 0;
} else {
+ assert(InstSize && "getInstruction() consumed no bytes");
if (!InvalidData) {
Text = 0;
- InvalidData = Module->createDataAtom(CurAddr, EndAddr);
+ InvalidData = Module->createDataAtom(CurAddr, CurAddr+InstSize - 1);
}
- InvalidData->addData(Contents[Index]);
+ for (uint64_t I = 0; I < InstSize; ++I)
+ InvalidData->addData(Contents[Index+I]);
}
}
} else {
AddressSetTy Splits;
AddressSetTy Calls;
- error_code ec;
- for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
- SI != SE; SI.increment(ec)) {
- if (ec)
- break;
+ for (const SymbolRef &Symbol : Obj.symbols()) {
SymbolRef::Type SymType;
- SI->getType(SymType);
+ Symbol.getType(SymType);
if (SymType == SymbolRef::ST_Function) {
uint64_t SymAddr;
- SI->getAddress(SymAddr);
+ Symbol.getAddress(SymAddr);
SymAddr = getEffectiveLoadAddr(SymAddr);
Calls.push_back(SymAddr);
Splits.push_back(SymAddr);
: MCObjectDisassembler(MOOF, Dis, MIA), MOOF(MOOF),
VMAddrSlide(VMAddrSlide), HeaderLoadAddress(HeaderLoadAddress) {
- error_code ec;
- for (section_iterator SI = MOOF.begin_sections(), SE = MOOF.end_sections();
- SI != SE; SI.increment(ec)) {
- if (ec)
- break;
+ for (const SectionRef &Section : MOOF.sections()) {
StringRef Name;
- SI->getName(Name);
+ Section.getName(Name);
// FIXME: We should use the S_ section type instead of the name.
if (Name == "__mod_init_func") {
DEBUG(dbgs() << "Found __mod_init_func section!\n");
- SI->getContents(ModInitContents);
+ Section.getContents(ModInitContents);
} else if (Name == "__mod_exit_func") {
DEBUG(dbgs() << "Found __mod_exit_func section!\n");
- SI->getContents(ModExitContents);
+ Section.getContents(ModExitContents);
}
}
}
// Look for LC_MAIN.
{
- uint32_t LoadCommandCount = MOOF.getHeader().NumLoadCommands;
+ uint32_t LoadCommandCount = MOOF.getHeader().ncmds;
MachOObjectFile::LoadCommandInfo Load = MOOF.getFirstLoadCommandInfo();
for (unsigned I = 0;; ++I) {
- if (Load.C.Type == MachO::LC_MAIN) {
+ if (Load.C.cmd == MachO::LC_MAIN) {
EntryFileOffset =
((const MachO::entry_point_command *)Load.Ptr)->entryoff;
break;