Remove unused argument.
[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 MachOObject *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                         MachOObject *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 macho::Header &Header,
203                                   MachOObjectFile *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 MachOObject::LoadCommandInfo &LCI =
222        MachOObj->getObject()->getLoadCommandInfo(i);
223     if (LCI.Command.Type == macho::LCT_FunctionStarts) {
224       // We found a function starts segment, parse the addresses for later
225       // consumption.
226       InMemoryStruct<macho::LinkeditDataLoadCommand> LLC;
227       MachOObj->getObject()->ReadLinkeditDataLoadCommand(LCI, LLC);
228
229       MachOObj->getObject()->ReadULEB128s(LLC->DataOffset, FoundFns);
230     }
231   }
232 }
233
234 void llvm::DisassembleInputMachO(StringRef Filename) {
235   OwningPtr<MemoryBuffer> Buff;
236
237   if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
238     errs() << "llvm-objdump: " << Filename << ": " << ec.message() << "\n";
239     return;
240   }
241
242   OwningPtr<MachOObjectFile> MachOOF(static_cast<MachOObjectFile*>(
243         ObjectFile::createMachOObjectFile(Buff.take())));
244   MachOObject *MachOObj = MachOOF->getObject();
245
246   const Target *TheTarget = GetTarget(MachOObj);
247   if (!TheTarget) {
248     // GetTarget prints out stuff.
249     return;
250   }
251   OwningPtr<const MCInstrInfo> InstrInfo(TheTarget->createMCInstrInfo());
252   OwningPtr<MCInstrAnalysis>
253     InstrAnalysis(TheTarget->createMCInstrAnalysis(InstrInfo.get()));
254
255   // Set up disassembler.
256   OwningPtr<const MCAsmInfo> AsmInfo(TheTarget->createMCAsmInfo(TripleName));
257   OwningPtr<const MCSubtargetInfo>
258     STI(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
259   OwningPtr<const MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI));
260   OwningPtr<const MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
261   int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
262   OwningPtr<MCInstPrinter>
263     IP(TheTarget->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *InstrInfo,
264                                       *MRI, *STI));
265
266   if (!InstrAnalysis || !AsmInfo || !STI || !DisAsm || !IP) {
267     errs() << "error: couldn't initialize disassembler for target "
268            << TripleName << '\n';
269     return;
270   }
271
272   outs() << '\n' << Filename << ":\n\n";
273
274   const macho::Header &Header = MachOObj->getHeader();
275
276   const MachOObject::LoadCommandInfo *SymtabLCI = 0;
277   // First, find the symbol table segment.
278   for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
279     const MachOObject::LoadCommandInfo &LCI = MachOObj->getLoadCommandInfo(i);
280     if (LCI.Command.Type == macho::LCT_Symtab) {
281       SymtabLCI = &LCI;
282       break;
283     }
284   }
285
286   // Read and register the symbol table data.
287   InMemoryStruct<macho::SymtabLoadCommand> SymtabLC;
288   if (SymtabLCI) {
289     MachOObj->ReadSymtabLoadCommand(*SymtabLCI, SymtabLC);
290     MachOObj->RegisterStringTable(*SymtabLC);
291   }
292
293   std::vector<SectionRef> Sections;
294   std::vector<SymbolRef> Symbols;
295   SmallVector<uint64_t, 8> FoundFns;
296
297   getSectionsAndSymbols(Header, MachOOF.get(), Sections, Symbols, FoundFns);
298
299   // Make a copy of the unsorted symbol list. FIXME: duplication
300   std::vector<SymbolRef> UnsortedSymbols(Symbols);
301   // Sort the symbols by address, just in case they didn't come in that way.
302   std::sort(Symbols.begin(), Symbols.end(), SymbolSorter());
303
304 #ifndef NDEBUG
305   raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls();
306 #else
307   raw_ostream &DebugOut = nulls();
308 #endif
309
310   OwningPtr<DIContext> diContext;
311   ObjectFile *DbgObj = MachOOF.get();
312   // Try to find debug info and set up the DIContext for it.
313   if (UseDbg) {
314     // A separate DSym file path was specified, parse it as a macho file,
315     // get the sections and supply it to the section name parsing machinery.
316     if (!DSYMFile.empty()) {
317       OwningPtr<MemoryBuffer> Buf;
318       if (error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile.c_str(), Buf)) {
319         errs() << "llvm-objdump: " << Filename << ": " << ec.message() << '\n';
320         return;
321       }
322       DbgObj = ObjectFile::createMachOObjectFile(Buf.take());
323     }
324
325     // Setup the DIContext
326     diContext.reset(DIContext::getDWARFContext(DbgObj));
327   }
328
329   FunctionMapTy FunctionMap;
330   FunctionListTy Functions;
331
332   for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
333     StringRef SectName;
334     if (Sections[SectIdx].getName(SectName) ||
335         SectName != "__text")
336       continue; // Skip non-text sections
337
338     DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
339     StringRef SegmentName = MachOOF->getSectionFinalSegmentName(DR);
340     if (SegmentName != "__TEXT")
341       continue;
342
343     // Insert the functions from the function starts segment into our map.
344     uint64_t VMAddr;
345     Sections[SectIdx].getAddress(VMAddr);
346     for (unsigned i = 0, e = FoundFns.size(); i != e; ++i) {
347       StringRef SectBegin;
348       Sections[SectIdx].getContents(SectBegin);
349       uint64_t Offset = (uint64_t)SectBegin.data();
350       FunctionMap.insert(std::make_pair(VMAddr + FoundFns[i]-Offset,
351                                         (MCFunction*)0));
352     }
353
354     StringRef Bytes;
355     Sections[SectIdx].getContents(Bytes);
356     StringRefMemoryObject memoryObject(Bytes);
357     bool symbolTableWorked = false;
358
359     // Parse relocations.
360     std::vector<std::pair<uint64_t, SymbolRef> > Relocs;
361     error_code ec;
362     for (relocation_iterator RI = Sections[SectIdx].begin_relocations(),
363          RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) {
364       uint64_t RelocOffset, SectionAddress;
365       RI->getAddress(RelocOffset);
366       Sections[SectIdx].getAddress(SectionAddress);
367       RelocOffset -= SectionAddress;
368
369       SymbolRef RelocSym;
370       RI->getSymbol(RelocSym);
371
372       Relocs.push_back(std::make_pair(RelocOffset, RelocSym));
373     }
374     array_pod_sort(Relocs.begin(), Relocs.end());
375
376     // Disassemble symbol by symbol.
377     for (unsigned SymIdx = 0; SymIdx != Symbols.size(); SymIdx++) {
378       StringRef SymName;
379       Symbols[SymIdx].getName(SymName);
380
381       SymbolRef::Type ST;
382       Symbols[SymIdx].getType(ST);
383       if (ST != SymbolRef::ST_Function)
384         continue;
385
386       // Make sure the symbol is defined in this section.
387       bool containsSym = false;
388       Sections[SectIdx].containsSymbol(Symbols[SymIdx], containsSym);
389       if (!containsSym)
390         continue;
391
392       // Start at the address of the symbol relative to the section's address.
393       uint64_t SectionAddress = 0;
394       uint64_t Start = 0;
395       Sections[SectIdx].getAddress(SectionAddress);
396       Symbols[SymIdx].getAddress(Start);
397       Start -= SectionAddress;
398
399       // Stop disassembling either at the beginning of the next symbol or at
400       // the end of the section.
401       bool containsNextSym = false;
402       uint64_t NextSym = 0;
403       uint64_t NextSymIdx = SymIdx+1;
404       while (Symbols.size() > NextSymIdx) {
405         SymbolRef::Type NextSymType;
406         Symbols[NextSymIdx].getType(NextSymType);
407         if (NextSymType == SymbolRef::ST_Function) {
408           Sections[SectIdx].containsSymbol(Symbols[NextSymIdx],
409                                            containsNextSym);
410           Symbols[NextSymIdx].getAddress(NextSym);
411           NextSym -= SectionAddress;
412           break;
413         }
414         ++NextSymIdx;
415       }
416
417       uint64_t SectSize;
418       Sections[SectIdx].getSize(SectSize);
419       uint64_t End = containsNextSym ?  NextSym : SectSize;
420       uint64_t Size;
421
422       symbolTableWorked = true;
423
424       if (!CFG) {
425         // Normal disassembly, print addresses, bytes and mnemonic form.
426         StringRef SymName;
427         Symbols[SymIdx].getName(SymName);
428
429         outs() << SymName << ":\n";
430         DILineInfo lastLine;
431         for (uint64_t Index = Start; Index < End; Index += Size) {
432           MCInst Inst;
433
434           if (DisAsm->getInstruction(Inst, Size, memoryObject, Index,
435                                      DebugOut, nulls())) {
436             uint64_t SectAddress = 0;
437             Sections[SectIdx].getAddress(SectAddress);
438             outs() << format("%8" PRIx64 ":\t", SectAddress + Index);
439
440             DumpBytes(StringRef(Bytes.data() + Index, Size));
441             IP->printInst(&Inst, outs(), "");
442
443             // Print debug info.
444             if (diContext) {
445               DILineInfo dli =
446                 diContext->getLineInfoForAddress(SectAddress + Index);
447               // Print valid line info if it changed.
448               if (dli != lastLine && dli.getLine() != 0)
449                 outs() << "\t## " << dli.getFileName() << ':'
450                        << dli.getLine() << ':' << dli.getColumn();
451               lastLine = dli;
452             }
453             outs() << "\n";
454           } else {
455             errs() << "llvm-objdump: warning: invalid instruction encoding\n";
456             if (Size == 0)
457               Size = 1; // skip illegible bytes
458           }
459         }
460       } else {
461         // Create CFG and use it for disassembly.
462         StringRef SymName;
463         Symbols[SymIdx].getName(SymName);
464         createMCFunctionAndSaveCalls(
465             SymName, DisAsm.get(), memoryObject, Start, End,
466             InstrAnalysis.get(), Start, DebugOut, FunctionMap, Functions);
467       }
468     }
469     if (!CFG && !symbolTableWorked) {
470       // Reading the symbol table didn't work, disassemble the whole section. 
471       uint64_t SectAddress;
472       Sections[SectIdx].getAddress(SectAddress);
473       uint64_t SectSize;
474       Sections[SectIdx].getSize(SectSize);
475       uint64_t InstSize;
476       for (uint64_t Index = 0; Index < SectSize; Index += InstSize) {
477         MCInst Inst;
478
479         if (DisAsm->getInstruction(Inst, InstSize, memoryObject, Index,
480                                    DebugOut, nulls())) {
481           outs() << format("%8" PRIx64 ":\t", SectAddress + Index);
482           DumpBytes(StringRef(Bytes.data() + Index, InstSize));
483           IP->printInst(&Inst, outs(), "");
484           outs() << "\n";
485         } else {
486           errs() << "llvm-objdump: warning: invalid instruction encoding\n";
487           if (InstSize == 0)
488             InstSize = 1; // skip illegible bytes
489         }
490       }
491     }
492
493     if (CFG) {
494       if (!symbolTableWorked) {
495         // Reading the symbol table didn't work, create a big __TEXT symbol.
496         uint64_t SectSize = 0, SectAddress = 0;
497         Sections[SectIdx].getSize(SectSize);
498         Sections[SectIdx].getAddress(SectAddress);
499         createMCFunctionAndSaveCalls("__TEXT", DisAsm.get(), memoryObject,
500                                      0, SectSize,
501                                      InstrAnalysis.get(),
502                                      SectAddress, DebugOut,
503                                      FunctionMap, Functions);
504       }
505       for (std::map<uint64_t, MCFunction*>::iterator mi = FunctionMap.begin(),
506            me = FunctionMap.end(); mi != me; ++mi)
507         if (mi->second == 0) {
508           // Create functions for the remaining callees we have gathered,
509           // but we didn't find a name for them.
510           uint64_t SectSize = 0;
511           Sections[SectIdx].getSize(SectSize);
512
513           SmallVector<uint64_t, 16> Calls;
514           MCFunction f =
515             MCFunction::createFunctionFromMC("unknown", DisAsm.get(),
516                                              memoryObject, mi->first,
517                                              SectSize,
518                                              InstrAnalysis.get(), DebugOut,
519                                              Calls);
520           Functions.push_back(f);
521           mi->second = &Functions.back();
522           for (unsigned i = 0, e = Calls.size(); i != e; ++i) {
523             std::pair<uint64_t, MCFunction*> p(Calls[i], (MCFunction*)0);
524             if (FunctionMap.insert(p).second)
525               mi = FunctionMap.begin();
526           }
527         }
528
529       DenseSet<uint64_t> PrintedBlocks;
530       for (unsigned ffi = 0, ffe = Functions.size(); ffi != ffe; ++ffi) {
531         MCFunction &f = Functions[ffi];
532         for (MCFunction::iterator fi = f.begin(), fe = f.end(); fi != fe; ++fi){
533           if (!PrintedBlocks.insert(fi->first).second)
534             continue; // We already printed this block.
535
536           // We assume a block has predecessors when it's the first block after
537           // a symbol.
538           bool hasPreds = FunctionMap.find(fi->first) != FunctionMap.end();
539
540           // See if this block has predecessors.
541           // FIXME: Slow.
542           for (MCFunction::iterator pi = f.begin(), pe = f.end(); pi != pe;
543               ++pi)
544             if (pi->second.contains(fi->first)) {
545               hasPreds = true;
546               break;
547             }
548
549           uint64_t SectSize = 0, SectAddress;
550           Sections[SectIdx].getSize(SectSize);
551           Sections[SectIdx].getAddress(SectAddress);
552
553           // No predecessors, this is a data block. Print as .byte directives.
554           if (!hasPreds) {
555             uint64_t End = llvm::next(fi) == fe ? SectSize :
556                                                   llvm::next(fi)->first;
557             outs() << "# " << End-fi->first << " bytes of data:\n";
558             for (unsigned pos = fi->first; pos != End; ++pos) {
559               outs() << format("%8x:\t", SectAddress + pos);
560               DumpBytes(StringRef(Bytes.data() + pos, 1));
561               outs() << format("\t.byte 0x%02x\n", (uint8_t)Bytes[pos]);
562             }
563             continue;
564           }
565
566           if (fi->second.contains(fi->first)) // Print a header for simple loops
567             outs() << "# Loop begin:\n";
568
569           DILineInfo lastLine;
570           // Walk over the instructions and print them.
571           for (unsigned ii = 0, ie = fi->second.getInsts().size(); ii != ie;
572                ++ii) {
573             const MCDecodedInst &Inst = fi->second.getInsts()[ii];
574
575             // If there's a symbol at this address, print its name.
576             if (FunctionMap.find(SectAddress + Inst.Address) !=
577                 FunctionMap.end())
578               outs() << FunctionMap[SectAddress + Inst.Address]-> getName()
579                      << ":\n";
580
581             outs() << format("%8" PRIx64 ":\t", SectAddress + Inst.Address);
582             DumpBytes(StringRef(Bytes.data() + Inst.Address, Inst.Size));
583
584             if (fi->second.contains(fi->first)) // Indent simple loops.
585               outs() << '\t';
586
587             IP->printInst(&Inst.Inst, outs(), "");
588
589             // Look for relocations inside this instructions, if there is one
590             // print its target and additional information if available.
591             for (unsigned j = 0; j != Relocs.size(); ++j)
592               if (Relocs[j].first >= SectAddress + Inst.Address &&
593                   Relocs[j].first < SectAddress + Inst.Address + Inst.Size) {
594                 StringRef SymName;
595                 uint64_t Addr;
596                 Relocs[j].second.getAddress(Addr);
597                 Relocs[j].second.getName(SymName);
598
599                 outs() << "\t# " << SymName << ' ';
600                 DumpAddress(Addr, Sections, MachOObj, outs());
601               }
602
603             // If this instructions contains an address, see if we can evaluate
604             // it and print additional information.
605             uint64_t targ = InstrAnalysis->evaluateBranch(Inst.Inst,
606                                                           Inst.Address,
607                                                           Inst.Size);
608             if (targ != -1ULL)
609               DumpAddress(targ, Sections, MachOObj, outs());
610
611             // Print debug info.
612             if (diContext) {
613               DILineInfo dli =
614                 diContext->getLineInfoForAddress(SectAddress + Inst.Address);
615               // Print valid line info if it changed.
616               if (dli != lastLine && dli.getLine() != 0)
617                 outs() << "\t## " << dli.getFileName() << ':'
618                        << dli.getLine() << ':' << dli.getColumn();
619               lastLine = dli;
620             }
621
622             outs() << '\n';
623           }
624         }
625
626         emitDOTFile((f.getName().str() + ".dot").c_str(), f, IP.get());
627       }
628     }
629   }
630 }