using namespace object;
static cl::opt<bool>
- UseDbg("g", cl::desc("Print line information from debug info if available"));
+ UseDbg("g",
+ cl::desc("Print line information from debug info if available"));
-static cl::opt<std::string>
- DSYMFile("dsym", cl::desc("Use .dSYM file for debug info"));
+static cl::opt<std::string> DSYMFile("dsym",
+ cl::desc("Use .dSYM file for debug info"));
-static cl::opt<bool>
- FullLeadingAddr("full-leading-addr",
- cl::desc("Print full leading address"));
+static cl::opt<bool> FullLeadingAddr("full-leading-addr",
+ cl::desc("Print full leading address"));
static cl::opt<bool>
PrintImmHex("print-imm-hex",
typedef std::vector<DiceTableEntry> DiceTable;
typedef DiceTable::iterator dice_table_iterator;
-static bool
-compareDiceTableEntries(const DiceTableEntry i,
- const DiceTableEntry j) {
+static bool compareDiceTableEntries(const DiceTableEntry i,
+ const DiceTableEntry j) {
return i.first == j.first;
}
case MachO::DICE_KIND_DATA:
switch (Size) {
case 4:
- Value = bytes[3] << 24 |
- bytes[2] << 16 |
- bytes[1] << 8 |
- bytes[0];
+ Value = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
outs() << "\t.long " << Value;
break;
case 2:
- Value = bytes[1] << 8 |
- bytes[0];
+ Value = bytes[1] << 8 | bytes[0];
outs() << "\t.short " << Value;
break;
case 1:
outs() << "\t.byte " << Value << "\t@ KIND_JUMP_TABLE8";
break;
case MachO::DICE_KIND_JUMP_TABLE16:
- Value = bytes[1] << 8 |
- bytes[0];
+ Value = bytes[1] << 8 | bytes[0];
outs() << "\t.short " << Value << "\t@ KIND_JUMP_TABLE16";
break;
case MachO::DICE_KIND_JUMP_TABLE32:
- Value = bytes[3] << 24 |
- bytes[2] << 16 |
- bytes[1] << 8 |
- bytes[0];
+ Value = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
outs() << "\t.long " << Value << "\t@ KIND_JUMP_TABLE32";
break;
default:
MachOObjectFile::LoadCommandInfo Command =
MachOObj->getFirstLoadCommandInfo();
bool BaseSegmentAddressSet = false;
- for (unsigned i = 0; ; ++i) {
+ for (unsigned i = 0;; ++i) {
if (Command.C.cmd == MachO::LC_FUNCTION_STARTS) {
// We found a function starts segment, parse the addresses for later
// consumption.
MachO::linkedit_data_command LLC =
- MachOObj->getLinkeditDataLoadCommand(Command);
+ MachOObj->getLinkeditDataLoadCommand(Command);
MachOObj->ReadULEB128s(LLC.dataoff, FoundFns);
- }
- else if (Command.C.cmd == MachO::LC_SEGMENT) {
- MachO::segment_command SLC =
- MachOObj->getSegmentLoadCommand(Command);
+ } else if (Command.C.cmd == MachO::LC_SEGMENT) {
+ MachO::segment_command SLC = MachOObj->getSegmentLoadCommand(Command);
StringRef SegName = SLC.segname;
- if(!BaseSegmentAddressSet && SegName != "__PAGEZERO") {
+ if (!BaseSegmentAddressSet && SegName != "__PAGEZERO") {
BaseSegmentAddressSet = true;
BaseSegmentAddress = SLC.vmaddr;
}
*ReferenceType = LLVMDisassembler_ReferenceType_Out_SymbolStub;
} else
#if HAVE_CXXABI_H
- if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
+ if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
if (info->demangled_name != nullptr)
free(info->demangled_name);
int status;
- info->demangled_name = abi::__cxa_demangle(SymbolName + 1, nullptr,
- nullptr, &status);
+ info->demangled_name =
+ abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr, &status);
if (info->demangled_name != nullptr) {
*ReferenceName = info->demangled_name;
*ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
if (info->demangled_name != nullptr)
free(info->demangled_name);
int status;
- info->demangled_name = abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr,
- &status);
+ info->demangled_name =
+ abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr, &status);
if (info->demangled_name != nullptr) {
*ReferenceName = info->demangled_name;
*ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
const uint8_t *Bytes;
uint64_t Size;
uint64_t BasePC;
+
public:
DisasmMemoryObject(const uint8_t *bytes, uint64_t size, uint64_t basePC)
: Bytes(bytes), Size(size), BasePC(basePC) {}
continue;
StringRef SectName;
- if (Sections[SectIdx].getName(SectName) ||
- SectName != "__text")
+ if (Sections[SectIdx].getName(SectName) || SectName != "__text")
continue; // Skip non-text sections
DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
// the end of the section.
bool containsNextSym = false;
uint64_t NextSym = 0;
- uint64_t NextSymIdx = SymIdx+1;
+ uint64_t NextSymIdx = SymIdx + 1;
while (Symbols.size() > NextSymIdx) {
SymbolRef::Type NextSymType;
Symbols[NextSymIdx].getType(NextSymType);
}
uint64_t SectSize = Sections[SectIdx].getSize();
- uint64_t End = containsNextSym ? NextSym : SectSize;
+ uint64_t End = containsNextSym ? NextSym : SectSize;
uint64_t Size;
symbolTableWorked = true;
// instruction to be disassembled.
DiceTable Dice;
Dice.push_back(std::make_pair(PC, DiceRef()));
- dice_table_iterator DTI = std::search(Dices.begin(), Dices.end(),
- Dice.begin(), Dice.end(),
- compareDiceTableEntries);
- if (DTI != Dices.end()){
+ dice_table_iterator DTI =
+ std::search(Dices.begin(), Dices.end(), Dice.begin(), Dice.end(),
+ compareDiceTableEntries);
+ if (DTI != Dices.end()) {
uint16_t Length;
DTI->second.getLength(Length);
DumpBytes(StringRef(Bytes.data() + Index, Length));
// Print debug info.
if (diContext) {
- DILineInfo dli =
- diContext->getLineInfoForAddress(PC);
+ DILineInfo dli = diContext->getLineInfoForAddress(PC);
// Print valid line info if it changed.
if (dli != lastLine && dli.Line != 0)
outs() << "\t## " << dli.FileName << ':' << dli.Line << ':'
outs() << "\n";
} else {
unsigned int Arch = MachOOF->getArch();
- if (Arch == Triple::x86_64 || Arch == Triple::x86){
+ if (Arch == Triple::x86_64 || Arch == Triple::x86) {
outs() << format("\t.byte 0x%02x #bad opcode\n",
*(Bytes.data() + Index) & 0xff);
Size = 1; // skip exactly one illegible byte and move on.
outs() << "\n";
} else {
unsigned int Arch = MachOOF->getArch();
- if (Arch == Triple::x86_64 || Arch == Triple::x86){
+ if (Arch == Triple::x86_64 || Arch == Triple::x86) {
outs() << format("\t.byte 0x%02x #bad opcode\n",
*(Bytes.data() + Index) & 0xff);
InstSize = 1; // skip exactly one illegible byte and move on.
}
}
-
//===----------------------------------------------------------------------===//
// __compact_unwind section dumping
//===----------------------------------------------------------------------===//
namespace {
template <typename T> static uint64_t readNext(const char *&Buf) {
- using llvm::support::little;
- using llvm::support::unaligned;
+ using llvm::support::little;
+ using llvm::support::unaligned;
- uint64_t Val = support::endian::read<T, little, unaligned>(Buf);
- Buf += sizeof(T);
- return Val;
- }
+ uint64_t Val = support::endian::read<T, little, unaligned>(Buf);
+ Buf += sizeof(T);
+ return Val;
+}
struct CompactUnwindEntry {
uint32_t OffsetInSection;
RelocationRef LSDAReloc;
CompactUnwindEntry(StringRef Contents, unsigned Offset, bool Is64)
- : OffsetInSection(Offset) {
+ : OffsetInSection(Offset) {
if (Is64)
read<uint64_t>(Contents.data() + Offset);
else
}
private:
- template<typename UIntPtr>
- void read(const char *Buf) {
+ template <typename UIntPtr> void read(const char *Buf) {
FunctionAddr = readNext<UIntPtr>(Buf);
Length = readNext<uint32_t>(Buf);
CompactEncoding = readNext<uint32_t>(Buf);
/// referenced section.
static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
std::map<uint64_t, SymbolRef> &Symbols,
- const RelocationRef &Reloc,
- uint64_t Addr,
+ const RelocationRef &Reloc, uint64_t Addr,
StringRef &Name, uint64_t &Addend) {
if (Reloc.getSymbol() != Obj->symbol_end()) {
Reloc.getSymbol()->getName(Name);
static void printUnwindRelocDest(const MachOObjectFile *Obj,
std::map<uint64_t, SymbolRef> &Symbols,
- const RelocationRef &Reloc,
- uint64_t Addr) {
+ const RelocationRef &Reloc, uint64_t Addr) {
StringRef Name;
uint64_t Addend;
<< format("0x%" PRIx32, Entry.OffsetInSection) << ":\n";
// 1. Start of the region this entry applies to.
- outs() << " start: "
- << format("0x%" PRIx64, Entry.FunctionAddr) << ' ';
- printUnwindRelocDest(Obj, Symbols, Entry.FunctionReloc,
- Entry.FunctionAddr);
+ outs() << " start: " << format("0x%" PRIx64,
+ Entry.FunctionAddr) << ' ';
+ printUnwindRelocDest(Obj, Symbols, Entry.FunctionReloc, Entry.FunctionAddr);
outs() << '\n';
// 2. Length of the region this entry applies to.
- outs() << " length: "
- << format("0x%" PRIx32, Entry.Length) << '\n';
+ outs() << " length: " << format("0x%" PRIx32, Entry.Length)
+ << '\n';
// 3. The 32-bit compact encoding.
outs() << " compact encoding: "
<< format("0x%08" PRIx32, Entry.CompactEncoding) << '\n';
// 5. This entry's language-specific data area.
if (Entry.LSDAReloc.getObjectFile()) {
- outs() << " LSDA: "
- << format("0x%" PRIx64, Entry.LSDAAddr) << ' ';
+ outs() << " LSDA: " << format("0x%" PRIx64,
+ Entry.LSDAAddr) << ' ';
printUnwindRelocDest(Obj, Symbols, Entry.LSDAReloc, Entry.LSDAAddr);
outs() << '\n';
}
uint32_t Encoding = readNext<uint32_t>(Pos);
outs() << " [" << i << "]: "
- << "function offset="
- << format("0x%08" PRIx32, FunctionOffset) << ", "
- << "encoding="
- << format("0x%08" PRIx32, Encoding)
- << '\n';
+ << "function offset=" << format("0x%08" PRIx32, FunctionOffset)
+ << ", "
+ << "encoding=" << format("0x%08" PRIx32, Encoding) << '\n';
}
}
Encoding = PageEncodings[EncodingIdx - CommonEncodings.size()];
outs() << " [" << i << "]: "
- << "function offset="
- << format("0x%08" PRIx32, FunctionOffset) << ", "
- << "encoding[" << EncodingIdx << "]="
- << format("0x%08" PRIx32, Encoding)
- << '\n';
+ << "function offset=" << format("0x%08" PRIx32, FunctionOffset)
+ << ", "
+ << "encoding[" << EncodingIdx
+ << "]=" << format("0x%08" PRIx32, Encoding) << '\n';
}
}
-static void
-printMachOUnwindInfoSection(const MachOObjectFile *Obj,
- std::map<uint64_t, SymbolRef> &Symbols,
- const SectionRef &UnwindInfo) {
+static void printMachOUnwindInfoSection(const MachOObjectFile *Obj,
+ std::map<uint64_t, SymbolRef> &Symbols,
+ const SectionRef &UnwindInfo) {
assert(Obj->isLittleEndian() &&
"There should not be a big-endian .o with __unwind_info");
<< '\n';
}
-
//===----------------------------------
// Personality functions used in this executable
//===----------------------------------
IndexEntries.push_back(Entry);
outs() << " [" << i << "]: "
- << "function offset="
- << format("0x%08" PRIx32, Entry.FunctionOffset) << ", "
+ << "function offset=" << format("0x%08" PRIx32, Entry.FunctionOffset)
+ << ", "
<< "2nd level page offset="
<< format("0x%08" PRIx32, Entry.SecondLevelPageStart) << ", "
- << "LSDA offset="
- << format("0x%08" PRIx32, Entry.LSDAStart) << '\n';
+ << "LSDA offset=" << format("0x%08" PRIx32, Entry.LSDAStart) << '\n';
}
-
//===----------------------------------
// Next come the LSDA tables
//===----------------------------------
uint32_t FunctionOffset = readNext<uint32_t>(Pos);
uint32_t LSDAOffset = readNext<uint32_t>(Pos);
outs() << " [" << i << "]: "
- << "function offset="
- << format("0x%08" PRIx32, FunctionOffset) << ", "
- << "LSDA offset="
- << format("0x%08" PRIx32, LSDAOffset) << '\n';
+ << "function offset=" << format("0x%08" PRIx32, FunctionOffset)
+ << ", "
+ << "LSDA offset=" << format("0x%08" PRIx32, LSDAOffset) << '\n';
}
//===----------------------------------
CommonEncodings);
else
llvm_unreachable("Do not know how to print this kind of 2nd level page");
-
}
}
printMachOUnwindInfoSection(Obj, Symbols, Section);
else if (SectName == "__eh_frame")
outs() << "llvm-objdump: warning: unhandled __eh_frame section\n";
-
}
}
if (dyld.name >= dyld.cmdsize)
outs() << " name ?(bad offset " << dyld.name << ")\n";
else {
- const char *P = (const char *)(Ptr)+dyld.name;
+ const char *P = (const char *)(Ptr) + dyld.name;
outs() << " name " << P << " (offset " << dyld.name << ")\n";
}
}
else
outs() << "\n";
if (dl.dylib.name < dl.cmdsize) {
- const char *P = (const char *)(Ptr)+dl.dylib.name;
+ const char *P = (const char *)(Ptr) + dl.dylib.name;
outs() << " name " << P << " (offset " << dl.dylib.name << ")\n";
} else {
outs() << " name ?(bad offset " << dl.dylib.name << ")\n";
if (ReExport)
outs() << "[re-export] ";
else
- outs()
- << format("0x%08llX ", Entry.address()); // FIXME:add in base address
+ outs() << format("0x%08llX ",
+ Entry.address()); // FIXME:add in base address
outs() << Entry.name();
if (WeakDef || ThreadLocal || Resolver || Abs) {
bool NeedsComma = false;
}
}
-
//===----------------------------------------------------------------------===//
// rebase table dumping
//===----------------------------------------------------------------------===//
uint64_t Address = sectionTable.address(SegIndex, OffsetInSeg);
// Table lines look like: __DATA __nl_symbol_ptr 0x0000F00C pointer
- outs() << format("%-8s %-18s 0x%08" PRIX64 " %s\n",
- SegmentName.str().c_str(),
- SectionName.str().c_str(), Address,
- Entry.typeName().str().c_str());
+ outs() << format("%-8s %-18s 0x%08" PRIX64 " %s\n",
+ SegmentName.str().c_str(), SectionName.str().c_str(),
+ Address, Entry.typeName().str().c_str());
}
}
return "flat-namespace";
default:
if (Ordinal > 0) {
- std::error_code EC = Obj->getLibraryShortNameByIndex(Ordinal-1,
- DylibName);
+ std::error_code EC =
+ Obj->getLibraryShortNameByIndex(Ordinal - 1, DylibName);
if (EC)
return "<<bad library ordinal>>";
return DylibName;
StringRef Attr;
if (Entry.flags() & MachO::BIND_SYMBOL_FLAGS_WEAK_IMPORT)
Attr = " (weak_import)";
- outs() << left_justify(SegmentName, 8) << " "
+ outs() << left_justify(SegmentName, 8) << " "
<< left_justify(SectionName, 18) << " "
<< format_hex(Address, 10, true) << " "
<< left_justify(Entry.typeName(), 8) << " "
- << format_decimal(Entry.addend(), 8) << " "
+ << format_decimal(Entry.addend(), 8) << " "
<< left_justify(ordinalName(Obj, Entry.ordinal()), 16) << " "
- << Entry.symbolName()
- << Attr << "\n";
+ << Entry.symbolName() << Attr << "\n";
}
}
// Table lines look like:
// __DATA __got 0x00012010 libSystem ___stack_chk_guard
- outs() << left_justify(SegmentName, 8) << " "
+ outs() << left_justify(SegmentName, 8) << " "
<< left_justify(SectionName, 18) << " "
<< format_hex(Address, 10, true) << " "
<< left_justify(ordinalName(Obj, Entry.ordinal()), 16) << " "
}
}
-
//===----------------------------------------------------------------------===//
// weak bind table dumping
//===----------------------------------------------------------------------===//
// Table lines look like:
// __DATA __data 0x00001000 pointer 0 _foo
- outs() << left_justify(SegmentName, 8) << " "
+ outs() << left_justify(SegmentName, 8) << " "
<< left_justify(SectionName, 18) << " "
<< format_hex(Address, 10, true) << " "
<< left_justify(Entry.typeName(), 8) << " "
- << format_decimal(Entry.addend(), 8) << " "
- << Entry.symbolName() << "\n";
+ << format_decimal(Entry.addend(), 8) << " " << Entry.symbolName()
+ << "\n";
}
}