Convert MachOObjectFile to a template.
[oota-llvm.git] / tools / llvm-objdump / MachODump.cpp
1 //===-- MachODump.cpp - Object file dumping utility for llvm --------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the MachO-specific dumper for llvm-objdump.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm-objdump.h"
15 #include "MCFunction.h"
16 #include "llvm/ADT/OwningPtr.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/DebugInfo/DIContext.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCDisassembler.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCInstPrinter.h"
24 #include "llvm/MC/MCInstrAnalysis.h"
25 #include "llvm/MC/MCInstrDesc.h"
26 #include "llvm/MC/MCInstrInfo.h"
27 #include "llvm/MC/MCRegisterInfo.h"
28 #include "llvm/MC/MCSubtargetInfo.h"
29 #include "llvm/Object/MachO.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/Debug.h"
32 #include "llvm/Support/Format.h"
33 #include "llvm/Support/GraphWriter.h"
34 #include "llvm/Support/MachO.h"
35 #include "llvm/Support/MemoryBuffer.h"
36 #include "llvm/Support/TargetRegistry.h"
37 #include "llvm/Support/TargetSelect.h"
38 #include "llvm/Support/raw_ostream.h"
39 #include "llvm/Support/system_error.h"
40 #include <algorithm>
41 #include <cstring>
42 using namespace llvm;
43 using namespace object;
44
45 static cl::opt<bool>
46   CFG("cfg", cl::desc("Create a CFG for every symbol in the object file and"
47                       " write it to a graphviz file (MachO-only)"));
48
49 static cl::opt<bool>
50   UseDbg("g", cl::desc("Print line information from debug info if available"));
51
52 static cl::opt<std::string>
53   DSYMFile("dsym", cl::desc("Use .dSYM file for debug info"));
54
55 static const Target *GetTarget(const MachOObjectFileBase *MachOObj) {
56   // Figure out the target triple.
57   if (TripleName.empty()) {
58     llvm::Triple TT("unknown-unknown-unknown");
59     switch (MachOObj->getHeader()->CPUType) {
60     case llvm::MachO::CPUTypeI386:
61       TT.setArch(Triple::ArchType(Triple::x86));
62       break;
63     case llvm::MachO::CPUTypeX86_64:
64       TT.setArch(Triple::ArchType(Triple::x86_64));
65       break;
66     case llvm::MachO::CPUTypeARM:
67       TT.setArch(Triple::ArchType(Triple::arm));
68       break;
69     case llvm::MachO::CPUTypePowerPC:
70       TT.setArch(Triple::ArchType(Triple::ppc));
71       break;
72     case llvm::MachO::CPUTypePowerPC64:
73       TT.setArch(Triple::ArchType(Triple::ppc64));
74       break;
75     }
76     TripleName = TT.str();
77   }
78
79   // Get the target specific parser.
80   std::string Error;
81   const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
82   if (TheTarget)
83     return TheTarget;
84
85   errs() << "llvm-objdump: error: unable to get target for '" << TripleName
86          << "', see --version and --triple.\n";
87   return 0;
88 }
89
90 struct SymbolSorter {
91   bool operator()(const SymbolRef &A, const SymbolRef &B) {
92     SymbolRef::Type AType, BType;
93     A.getType(AType);
94     B.getType(BType);
95
96     uint64_t AAddr, BAddr;
97     if (AType != SymbolRef::ST_Function)
98       AAddr = 0;
99     else
100       A.getAddress(AAddr);
101     if (BType != SymbolRef::ST_Function)
102       BAddr = 0;
103     else
104       B.getAddress(BAddr);
105     return AAddr < BAddr;
106   }
107 };
108
109 // Print additional information about an address, if available.
110 static void DumpAddress(uint64_t Address, ArrayRef<SectionRef> Sections,
111                         const MachOObjectFileBase *MachOObj, raw_ostream &OS) {
112   for (unsigned i = 0; i != Sections.size(); ++i) {
113     uint64_t SectAddr = 0, SectSize = 0;
114     Sections[i].getAddress(SectAddr);
115     Sections[i].getSize(SectSize);
116     uint64_t addr = SectAddr;
117     if (SectAddr <= Address &&
118         SectAddr + SectSize > Address) {
119       StringRef bytes, name;
120       Sections[i].getContents(bytes);
121       Sections[i].getName(name);
122       // Print constant strings.
123       if (!name.compare("__cstring"))
124         OS << '"' << bytes.substr(addr, bytes.find('\0', addr)) << '"';
125       // Print constant CFStrings.
126       if (!name.compare("__cfstring"))
127         OS << "@\"" << bytes.substr(addr, bytes.find('\0', addr)) << '"';
128     }
129   }
130 }
131
132 typedef std::map<uint64_t, MCFunction*> FunctionMapTy;
133 typedef SmallVector<MCFunction, 16> FunctionListTy;
134 static void createMCFunctionAndSaveCalls(StringRef Name,
135                                          const MCDisassembler *DisAsm,
136                                          MemoryObject &Object, uint64_t Start,
137                                          uint64_t End,
138                                          MCInstrAnalysis *InstrAnalysis,
139                                          uint64_t Address,
140                                          raw_ostream &DebugOut,
141                                          FunctionMapTy &FunctionMap,
142                                          FunctionListTy &Functions) {
143   SmallVector<uint64_t, 16> Calls;
144   MCFunction f =
145     MCFunction::createFunctionFromMC(Name, DisAsm, Object, Start, End,
146                                      InstrAnalysis, DebugOut, Calls);
147   Functions.push_back(f);
148   FunctionMap[Address] = &Functions.back();
149
150   // Add the gathered callees to the map.
151   for (unsigned i = 0, e = Calls.size(); i != e; ++i)
152     FunctionMap.insert(std::make_pair(Calls[i], (MCFunction*)0));
153 }
154
155 // Write a graphviz file for the CFG inside an MCFunction.
156 static void emitDOTFile(const char *FileName, const MCFunction &f,
157                         MCInstPrinter *IP) {
158   // Start a new dot file.
159   std::string Error;
160   raw_fd_ostream Out(FileName, Error);
161   if (!Error.empty()) {
162     errs() << "llvm-objdump: warning: " << Error << '\n';
163     return;
164   }
165
166   Out << "digraph " << f.getName() << " {\n";
167   Out << "graph [ rankdir = \"LR\" ];\n";
168   for (MCFunction::iterator i = f.begin(), e = f.end(); i != e; ++i) {
169     bool hasPreds = false;
170     // Only print blocks that have predecessors.
171     // FIXME: Slow.
172     for (MCFunction::iterator pi = f.begin(), pe = f.end(); pi != pe;
173         ++pi)
174       if (pi->second.contains(i->first)) {
175         hasPreds = true;
176         break;
177       }
178
179     if (!hasPreds && i != f.begin())
180       continue;
181
182     Out << '"' << i->first << "\" [ label=\"<a>";
183     // Print instructions.
184     for (unsigned ii = 0, ie = i->second.getInsts().size(); ii != ie;
185         ++ii) {
186       // Escape special chars and print the instruction in mnemonic form.
187       std::string Str;
188       raw_string_ostream OS(Str);
189       IP->printInst(&i->second.getInsts()[ii].Inst, OS, "");
190       Out << DOT::EscapeString(OS.str()) << '|';
191     }
192     Out << "<o>\" shape=\"record\" ];\n";
193
194     // Add edges.
195     for (MCBasicBlock::succ_iterator si = i->second.succ_begin(),
196         se = i->second.succ_end(); si != se; ++si)
197       Out << i->first << ":o -> " << *si <<":a\n";
198   }
199   Out << "}\n";
200 }
201
202 static void getSectionsAndSymbols(const MachOFormat::Header *Header,
203                                   MachOObjectFileBase *MachOObj,
204                                   std::vector<SectionRef> &Sections,
205                                   std::vector<SymbolRef> &Symbols,
206                                   SmallVectorImpl<uint64_t> &FoundFns) {
207   error_code ec;
208   for (symbol_iterator SI = MachOObj->begin_symbols(),
209        SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec))
210     Symbols.push_back(*SI);
211
212   for (section_iterator SI = MachOObj->begin_sections(),
213        SE = MachOObj->end_sections(); SI != SE; SI.increment(ec)) {
214     SectionRef SR = *SI;
215     StringRef SectName;
216     SR.getName(SectName);
217     Sections.push_back(*SI);
218   }
219
220   for (unsigned i = 0; i != Header->NumLoadCommands; ++i) {
221     const MachOFormat::LoadCommand *Command = MachOObj->getLoadCommandInfo(i);
222     if (Command->Type == macho::LCT_FunctionStarts) {
223       // We found a function starts segment, parse the addresses for later
224       // consumption.
225       const MachOFormat::LinkeditDataLoadCommand *LLC =
226         reinterpret_cast<const MachOFormat::LinkeditDataLoadCommand*>(Command);
227
228       MachOObj->ReadULEB128s(LLC->DataOffset, FoundFns);
229     }
230   }
231 }
232
233 void llvm::DisassembleInputMachO(StringRef Filename) {
234   OwningPtr<MemoryBuffer> Buff;
235
236   if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
237     errs() << "llvm-objdump: " << Filename << ": " << ec.message() << "\n";
238     return;
239   }
240
241   OwningPtr<MachOObjectFileBase> MachOOF(static_cast<MachOObjectFileBase*>(
242         ObjectFile::createMachOObjectFile(Buff.take())));
243
244   const Target *TheTarget = GetTarget(MachOOF.get());
245   if (!TheTarget) {
246     // GetTarget prints out stuff.
247     return;
248   }
249   OwningPtr<const MCInstrInfo> InstrInfo(TheTarget->createMCInstrInfo());
250   OwningPtr<MCInstrAnalysis>
251     InstrAnalysis(TheTarget->createMCInstrAnalysis(InstrInfo.get()));
252
253   // Set up disassembler.
254   OwningPtr<const MCAsmInfo> AsmInfo(TheTarget->createMCAsmInfo(TripleName));
255   OwningPtr<const MCSubtargetInfo>
256     STI(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
257   OwningPtr<const MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI));
258   OwningPtr<const MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
259   int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
260   OwningPtr<MCInstPrinter>
261     IP(TheTarget->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *InstrInfo,
262                                       *MRI, *STI));
263
264   if (!InstrAnalysis || !AsmInfo || !STI || !DisAsm || !IP) {
265     errs() << "error: couldn't initialize disassembler for target "
266            << TripleName << '\n';
267     return;
268   }
269
270   outs() << '\n' << Filename << ":\n\n";
271
272   const MachOFormat::Header *Header = MachOOF->getHeader();
273
274   std::vector<SectionRef> Sections;
275   std::vector<SymbolRef> Symbols;
276   SmallVector<uint64_t, 8> FoundFns;
277
278   getSectionsAndSymbols(Header, MachOOF.get(), Sections, Symbols, FoundFns);
279
280   // Make a copy of the unsorted symbol list. FIXME: duplication
281   std::vector<SymbolRef> UnsortedSymbols(Symbols);
282   // Sort the symbols by address, just in case they didn't come in that way.
283   std::sort(Symbols.begin(), Symbols.end(), SymbolSorter());
284
285 #ifndef NDEBUG
286   raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls();
287 #else
288   raw_ostream &DebugOut = nulls();
289 #endif
290
291   OwningPtr<DIContext> diContext;
292   ObjectFile *DbgObj = MachOOF.get();
293   // Try to find debug info and set up the DIContext for it.
294   if (UseDbg) {
295     // A separate DSym file path was specified, parse it as a macho file,
296     // get the sections and supply it to the section name parsing machinery.
297     if (!DSYMFile.empty()) {
298       OwningPtr<MemoryBuffer> Buf;
299       if (error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile.c_str(), Buf)) {
300         errs() << "llvm-objdump: " << Filename << ": " << ec.message() << '\n';
301         return;
302       }
303       DbgObj = ObjectFile::createMachOObjectFile(Buf.take());
304     }
305
306     // Setup the DIContext
307     diContext.reset(DIContext::getDWARFContext(DbgObj));
308   }
309
310   FunctionMapTy FunctionMap;
311   FunctionListTy Functions;
312
313   for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
314     StringRef SectName;
315     if (Sections[SectIdx].getName(SectName) ||
316         SectName != "__text")
317       continue; // Skip non-text sections
318
319     DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
320     StringRef SegmentName = MachOOF->getSectionFinalSegmentName(DR);
321     if (SegmentName != "__TEXT")
322       continue;
323
324     // Insert the functions from the function starts segment into our map.
325     uint64_t VMAddr;
326     Sections[SectIdx].getAddress(VMAddr);
327     for (unsigned i = 0, e = FoundFns.size(); i != e; ++i) {
328       StringRef SectBegin;
329       Sections[SectIdx].getContents(SectBegin);
330       uint64_t Offset = (uint64_t)SectBegin.data();
331       FunctionMap.insert(std::make_pair(VMAddr + FoundFns[i]-Offset,
332                                         (MCFunction*)0));
333     }
334
335     StringRef Bytes;
336     Sections[SectIdx].getContents(Bytes);
337     StringRefMemoryObject memoryObject(Bytes);
338     bool symbolTableWorked = false;
339
340     // Parse relocations.
341     std::vector<std::pair<uint64_t, SymbolRef> > Relocs;
342     error_code ec;
343     for (relocation_iterator RI = Sections[SectIdx].begin_relocations(),
344          RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) {
345       uint64_t RelocOffset, SectionAddress;
346       RI->getAddress(RelocOffset);
347       Sections[SectIdx].getAddress(SectionAddress);
348       RelocOffset -= SectionAddress;
349
350       SymbolRef RelocSym;
351       RI->getSymbol(RelocSym);
352
353       Relocs.push_back(std::make_pair(RelocOffset, RelocSym));
354     }
355     array_pod_sort(Relocs.begin(), Relocs.end());
356
357     // Disassemble symbol by symbol.
358     for (unsigned SymIdx = 0; SymIdx != Symbols.size(); SymIdx++) {
359       StringRef SymName;
360       Symbols[SymIdx].getName(SymName);
361
362       SymbolRef::Type ST;
363       Symbols[SymIdx].getType(ST);
364       if (ST != SymbolRef::ST_Function)
365         continue;
366
367       // Make sure the symbol is defined in this section.
368       bool containsSym = false;
369       Sections[SectIdx].containsSymbol(Symbols[SymIdx], containsSym);
370       if (!containsSym)
371         continue;
372
373       // Start at the address of the symbol relative to the section's address.
374       uint64_t SectionAddress = 0;
375       uint64_t Start = 0;
376       Sections[SectIdx].getAddress(SectionAddress);
377       Symbols[SymIdx].getAddress(Start);
378       Start -= SectionAddress;
379
380       // Stop disassembling either at the beginning of the next symbol or at
381       // the end of the section.
382       bool containsNextSym = false;
383       uint64_t NextSym = 0;
384       uint64_t NextSymIdx = SymIdx+1;
385       while (Symbols.size() > NextSymIdx) {
386         SymbolRef::Type NextSymType;
387         Symbols[NextSymIdx].getType(NextSymType);
388         if (NextSymType == SymbolRef::ST_Function) {
389           Sections[SectIdx].containsSymbol(Symbols[NextSymIdx],
390                                            containsNextSym);
391           Symbols[NextSymIdx].getAddress(NextSym);
392           NextSym -= SectionAddress;
393           break;
394         }
395         ++NextSymIdx;
396       }
397
398       uint64_t SectSize;
399       Sections[SectIdx].getSize(SectSize);
400       uint64_t End = containsNextSym ?  NextSym : SectSize;
401       uint64_t Size;
402
403       symbolTableWorked = true;
404
405       if (!CFG) {
406         // Normal disassembly, print addresses, bytes and mnemonic form.
407         StringRef SymName;
408         Symbols[SymIdx].getName(SymName);
409
410         outs() << SymName << ":\n";
411         DILineInfo lastLine;
412         for (uint64_t Index = Start; Index < End; Index += Size) {
413           MCInst Inst;
414
415           if (DisAsm->getInstruction(Inst, Size, memoryObject, Index,
416                                      DebugOut, nulls())) {
417             uint64_t SectAddress = 0;
418             Sections[SectIdx].getAddress(SectAddress);
419             outs() << format("%8" PRIx64 ":\t", SectAddress + Index);
420
421             DumpBytes(StringRef(Bytes.data() + Index, Size));
422             IP->printInst(&Inst, outs(), "");
423
424             // Print debug info.
425             if (diContext) {
426               DILineInfo dli =
427                 diContext->getLineInfoForAddress(SectAddress + Index);
428               // Print valid line info if it changed.
429               if (dli != lastLine && dli.getLine() != 0)
430                 outs() << "\t## " << dli.getFileName() << ':'
431                        << dli.getLine() << ':' << dli.getColumn();
432               lastLine = dli;
433             }
434             outs() << "\n";
435           } else {
436             errs() << "llvm-objdump: warning: invalid instruction encoding\n";
437             if (Size == 0)
438               Size = 1; // skip illegible bytes
439           }
440         }
441       } else {
442         // Create CFG and use it for disassembly.
443         StringRef SymName;
444         Symbols[SymIdx].getName(SymName);
445         createMCFunctionAndSaveCalls(
446             SymName, DisAsm.get(), memoryObject, Start, End,
447             InstrAnalysis.get(), Start, DebugOut, FunctionMap, Functions);
448       }
449     }
450     if (!CFG && !symbolTableWorked) {
451       // Reading the symbol table didn't work, disassemble the whole section. 
452       uint64_t SectAddress;
453       Sections[SectIdx].getAddress(SectAddress);
454       uint64_t SectSize;
455       Sections[SectIdx].getSize(SectSize);
456       uint64_t InstSize;
457       for (uint64_t Index = 0; Index < SectSize; Index += InstSize) {
458         MCInst Inst;
459
460         if (DisAsm->getInstruction(Inst, InstSize, memoryObject, Index,
461                                    DebugOut, nulls())) {
462           outs() << format("%8" PRIx64 ":\t", SectAddress + Index);
463           DumpBytes(StringRef(Bytes.data() + Index, InstSize));
464           IP->printInst(&Inst, outs(), "");
465           outs() << "\n";
466         } else {
467           errs() << "llvm-objdump: warning: invalid instruction encoding\n";
468           if (InstSize == 0)
469             InstSize = 1; // skip illegible bytes
470         }
471       }
472     }
473
474     if (CFG) {
475       if (!symbolTableWorked) {
476         // Reading the symbol table didn't work, create a big __TEXT symbol.
477         uint64_t SectSize = 0, SectAddress = 0;
478         Sections[SectIdx].getSize(SectSize);
479         Sections[SectIdx].getAddress(SectAddress);
480         createMCFunctionAndSaveCalls("__TEXT", DisAsm.get(), memoryObject,
481                                      0, SectSize,
482                                      InstrAnalysis.get(),
483                                      SectAddress, DebugOut,
484                                      FunctionMap, Functions);
485       }
486       for (std::map<uint64_t, MCFunction*>::iterator mi = FunctionMap.begin(),
487            me = FunctionMap.end(); mi != me; ++mi)
488         if (mi->second == 0) {
489           // Create functions for the remaining callees we have gathered,
490           // but we didn't find a name for them.
491           uint64_t SectSize = 0;
492           Sections[SectIdx].getSize(SectSize);
493
494           SmallVector<uint64_t, 16> Calls;
495           MCFunction f =
496             MCFunction::createFunctionFromMC("unknown", DisAsm.get(),
497                                              memoryObject, mi->first,
498                                              SectSize,
499                                              InstrAnalysis.get(), DebugOut,
500                                              Calls);
501           Functions.push_back(f);
502           mi->second = &Functions.back();
503           for (unsigned i = 0, e = Calls.size(); i != e; ++i) {
504             std::pair<uint64_t, MCFunction*> p(Calls[i], (MCFunction*)0);
505             if (FunctionMap.insert(p).second)
506               mi = FunctionMap.begin();
507           }
508         }
509
510       DenseSet<uint64_t> PrintedBlocks;
511       for (unsigned ffi = 0, ffe = Functions.size(); ffi != ffe; ++ffi) {
512         MCFunction &f = Functions[ffi];
513         for (MCFunction::iterator fi = f.begin(), fe = f.end(); fi != fe; ++fi){
514           if (!PrintedBlocks.insert(fi->first).second)
515             continue; // We already printed this block.
516
517           // We assume a block has predecessors when it's the first block after
518           // a symbol.
519           bool hasPreds = FunctionMap.find(fi->first) != FunctionMap.end();
520
521           // See if this block has predecessors.
522           // FIXME: Slow.
523           for (MCFunction::iterator pi = f.begin(), pe = f.end(); pi != pe;
524               ++pi)
525             if (pi->second.contains(fi->first)) {
526               hasPreds = true;
527               break;
528             }
529
530           uint64_t SectSize = 0, SectAddress;
531           Sections[SectIdx].getSize(SectSize);
532           Sections[SectIdx].getAddress(SectAddress);
533
534           // No predecessors, this is a data block. Print as .byte directives.
535           if (!hasPreds) {
536             uint64_t End = llvm::next(fi) == fe ? SectSize :
537                                                   llvm::next(fi)->first;
538             outs() << "# " << End-fi->first << " bytes of data:\n";
539             for (unsigned pos = fi->first; pos != End; ++pos) {
540               outs() << format("%8x:\t", SectAddress + pos);
541               DumpBytes(StringRef(Bytes.data() + pos, 1));
542               outs() << format("\t.byte 0x%02x\n", (uint8_t)Bytes[pos]);
543             }
544             continue;
545           }
546
547           if (fi->second.contains(fi->first)) // Print a header for simple loops
548             outs() << "# Loop begin:\n";
549
550           DILineInfo lastLine;
551           // Walk over the instructions and print them.
552           for (unsigned ii = 0, ie = fi->second.getInsts().size(); ii != ie;
553                ++ii) {
554             const MCDecodedInst &Inst = fi->second.getInsts()[ii];
555
556             // If there's a symbol at this address, print its name.
557             if (FunctionMap.find(SectAddress + Inst.Address) !=
558                 FunctionMap.end())
559               outs() << FunctionMap[SectAddress + Inst.Address]-> getName()
560                      << ":\n";
561
562             outs() << format("%8" PRIx64 ":\t", SectAddress + Inst.Address);
563             DumpBytes(StringRef(Bytes.data() + Inst.Address, Inst.Size));
564
565             if (fi->second.contains(fi->first)) // Indent simple loops.
566               outs() << '\t';
567
568             IP->printInst(&Inst.Inst, outs(), "");
569
570             // Look for relocations inside this instructions, if there is one
571             // print its target and additional information if available.
572             for (unsigned j = 0; j != Relocs.size(); ++j)
573               if (Relocs[j].first >= SectAddress + Inst.Address &&
574                   Relocs[j].first < SectAddress + Inst.Address + Inst.Size) {
575                 StringRef SymName;
576                 uint64_t Addr;
577                 Relocs[j].second.getAddress(Addr);
578                 Relocs[j].second.getName(SymName);
579
580                 outs() << "\t# " << SymName << ' ';
581                 DumpAddress(Addr, Sections, MachOOF.get(), outs());
582               }
583
584             // If this instructions contains an address, see if we can evaluate
585             // it and print additional information.
586             uint64_t targ = InstrAnalysis->evaluateBranch(Inst.Inst,
587                                                           Inst.Address,
588                                                           Inst.Size);
589             if (targ != -1ULL)
590               DumpAddress(targ, Sections, MachOOF.get(), outs());
591
592             // Print debug info.
593             if (diContext) {
594               DILineInfo dli =
595                 diContext->getLineInfoForAddress(SectAddress + Inst.Address);
596               // Print valid line info if it changed.
597               if (dli != lastLine && dli.getLine() != 0)
598                 outs() << "\t## " << dli.getFileName() << ':'
599                        << dli.getLine() << ':' << dli.getColumn();
600               lastLine = dli;
601             }
602
603             outs() << '\n';
604           }
605         }
606
607         emitDOTFile((f.getName().str() + ".dot").c_str(), f, IP.get());
608       }
609     }
610   }
611 }