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