[Support] Modify LockFileManager::waitForUnlock() to return info about how the lock...
[oota-llvm.git] / lib / MC / MCObjectDisassembler.cpp
index ceebf0f8642dfb937510b3957f41575a383e4b1d..146da6d1ed3f346ae49b33e8b9580f41782d9f0a 100644 (file)
@@ -37,16 +37,12 @@ MCObjectDisassembler::MCObjectDisassembler(const ObjectFile &Obj,
     : 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);
     }
   }
@@ -90,25 +86,24 @@ MCModule *MCObjectDisassembler::buildModule(bool withCFG) {
 }
 
 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.
@@ -116,7 +111,8 @@ void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
       continue;
     uint64_t EndAddr = StartAddr + SecSize - 1;
 
-    StringRef SecName; SI->getName(SecName);
+    StringRef SecName;
+    Section.getName(SecName);
 
     if (isText) {
       MCTextAtom *Text = 0;
@@ -135,11 +131,13 @@ void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
           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 {
@@ -182,16 +180,12 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) {
   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);
@@ -504,20 +498,16 @@ MCMachOObjectDisassembler::MCMachOObjectDisassembler(
     : 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);
     }
   }
 }
@@ -537,10 +527,10 @@ uint64_t MCMachOObjectDisassembler::getEntrypoint() {
 
   // 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;