- if (CFG) {
- if (!symbolTableWorked) {
- // Create CFG and use it for disassembly.
- SmallVector<uint64_t, 16> Calls;
- MCFunction f =
- MCFunction::createFunctionFromMC("__TEXT", DisAsm.get(),
- memoryObject, 0, Sections[SectIdx].Size,
- InstrAnalysis.get(), DebugOut,
- Calls);
-
- Functions.push_back(f);
- FunctionMap[Sections[SectIdx].Offset] = &Functions.back();
-
- for (unsigned i = 0, e = Calls.size(); i != e; ++i)
- FunctionMap.insert(std::make_pair(Calls[i], (MCFunction*)0));
- }
- for (std::map<uint64_t, MCFunction*>::iterator mi = FunctionMap.begin(),
- me = FunctionMap.end(); mi != me; ++mi)
- if (mi->second == 0) {
- SmallVector<uint64_t, 16> Calls;
- MCFunction f =
- MCFunction::createFunctionFromMC("unknown", DisAsm.get(),
- memoryObject, mi->first,
- Sections[SectIdx].Size,
- InstrAnalysis.get(), DebugOut,
- Calls);
- Functions.push_back(f);
- mi->second = &Functions.back();
- for (unsigned i = 0, e = Calls.size(); i != e; ++i)
- if (FunctionMap.insert(std::pair<uint64_t, MCFunction*>(Calls[i],0))
- .second)
- mi = FunctionMap.begin();
- }
-
- DenseSet<uint64_t> PrintedBlocks;
- for (unsigned ffi = 0, ffe = Functions.size(); ffi != ffe; ++ffi) {
- MCFunction &f = Functions[ffi];
- for (MCFunction::iterator fi = f.begin(), fe = f.end(); fi != fe; ++fi){
- if (!PrintedBlocks.insert(fi->first).second)
- continue;
- bool hasPreds = FunctionMap.find(fi->first) != FunctionMap.end();
-
- // Only print blocks that have predecessors.
- // FIXME: Slow.
- for (MCFunction::iterator pi = f.begin(), pe = f.end(); pi != pe;
- ++pi)
- if (pi->second.contains(fi->first)) {
- hasPreds = true;
- break;
- }
-
- // Data block.
- if (!hasPreds && fi != f.begin()) {
- uint64_t End = llvm::next(fi) == fe ? Sections[SectIdx].Size :
- llvm::next(fi)->first;
- outs() << "# " << End-fi->first << " bytes of data:\n";
- for (unsigned pos = fi->first; pos != End; ++pos) {
- outs() << format("%8x:\t", Sections[SectIdx].Address + pos);
- DumpBytes(StringRef(Bytes.data() + pos, 1));
- outs() << format("\t.byte 0x%02x\n", (uint8_t)Bytes[pos]);
- }
- continue;
- }