Run clang-format on tools/llvm-objdump/MachODump.cpp . No functional change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220875 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kevin Enderby 2014-10-29 21:28:24 +00:00
parent 973a76f9ce
commit be5683a6e0

View File

@ -53,13 +53,13 @@ using namespace llvm;
using namespace object; using namespace object;
static cl::opt<bool> 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> static cl::opt<std::string> DSYMFile("dsym",
DSYMFile("dsym", cl::desc("Use .dSYM file for debug info")); cl::desc("Use .dSYM file for debug info"));
static cl::opt<bool> static cl::opt<bool> FullLeadingAddr("full-leading-addr",
FullLeadingAddr("full-leading-addr",
cl::desc("Print full leading address")); cl::desc("Print full leading address"));
static cl::opt<bool> static cl::opt<bool>
@ -124,8 +124,7 @@ typedef std::pair<uint64_t, DiceRef> DiceTableEntry;
typedef std::vector<DiceTableEntry> DiceTable; typedef std::vector<DiceTableEntry> DiceTable;
typedef DiceTable::iterator dice_table_iterator; typedef DiceTable::iterator dice_table_iterator;
static bool static bool compareDiceTableEntries(const DiceTableEntry i,
compareDiceTableEntries(const DiceTableEntry i,
const DiceTableEntry j) { const DiceTableEntry j) {
return i.first == j.first; return i.first == j.first;
} }
@ -138,15 +137,11 @@ static void DumpDataInCode(const char *bytes, uint64_t Size,
case MachO::DICE_KIND_DATA: case MachO::DICE_KIND_DATA:
switch (Size) { switch (Size) {
case 4: case 4:
Value = bytes[3] << 24 | Value = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
bytes[2] << 16 |
bytes[1] << 8 |
bytes[0];
outs() << "\t.long " << Value; outs() << "\t.long " << Value;
break; break;
case 2: case 2:
Value = bytes[1] << 8 | Value = bytes[1] << 8 | bytes[0];
bytes[0];
outs() << "\t.short " << Value; outs() << "\t.short " << Value;
break; break;
case 1: case 1:
@ -161,15 +156,11 @@ static void DumpDataInCode(const char *bytes, uint64_t Size,
outs() << "\t.byte " << Value << "\t@ KIND_JUMP_TABLE8"; outs() << "\t.byte " << Value << "\t@ KIND_JUMP_TABLE8";
break; break;
case MachO::DICE_KIND_JUMP_TABLE16: case MachO::DICE_KIND_JUMP_TABLE16:
Value = bytes[1] << 8 | Value = bytes[1] << 8 | bytes[0];
bytes[0];
outs() << "\t.short " << Value << "\t@ KIND_JUMP_TABLE16"; outs() << "\t.short " << Value << "\t@ KIND_JUMP_TABLE16";
break; break;
case MachO::DICE_KIND_JUMP_TABLE32: case MachO::DICE_KIND_JUMP_TABLE32:
Value = bytes[3] << 24 | Value = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
bytes[2] << 16 |
bytes[1] << 8 |
bytes[0];
outs() << "\t.long " << Value << "\t@ KIND_JUMP_TABLE32"; outs() << "\t.long " << Value << "\t@ KIND_JUMP_TABLE32";
break; break;
default: default:
@ -204,10 +195,8 @@ static void getSectionsAndSymbols(const MachO::mach_header Header,
MachOObj->getLinkeditDataLoadCommand(Command); MachOObj->getLinkeditDataLoadCommand(Command);
MachOObj->ReadULEB128s(LLC.dataoff, FoundFns); MachOObj->ReadULEB128s(LLC.dataoff, FoundFns);
} } else if (Command.C.cmd == MachO::LC_SEGMENT) {
else if (Command.C.cmd == MachO::LC_SEGMENT) { MachO::segment_command SLC = MachOObj->getSegmentLoadCommand(Command);
MachO::segment_command SLC =
MachOObj->getSegmentLoadCommand(Command);
StringRef SegName = SLC.segname; StringRef SegName = SLC.segname;
if (!BaseSegmentAddressSet && SegName != "__PAGEZERO") { if (!BaseSegmentAddressSet && SegName != "__PAGEZERO") {
BaseSegmentAddressSet = true; BaseSegmentAddressSet = true;
@ -1102,8 +1091,8 @@ const char *SymbolizerSymbolLookUp(void *DisInfo, uint64_t ReferenceValue,
if (info->demangled_name != nullptr) if (info->demangled_name != nullptr)
free(info->demangled_name); free(info->demangled_name);
int status; int status;
info->demangled_name = abi::__cxa_demangle(SymbolName + 1, nullptr, info->demangled_name =
nullptr, &status); abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr, &status);
if (info->demangled_name != nullptr) { if (info->demangled_name != nullptr) {
*ReferenceName = info->demangled_name; *ReferenceName = info->demangled_name;
*ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name; *ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
@ -1125,8 +1114,8 @@ const char *SymbolizerSymbolLookUp(void *DisInfo, uint64_t ReferenceValue,
if (info->demangled_name != nullptr) if (info->demangled_name != nullptr)
free(info->demangled_name); free(info->demangled_name);
int status; int status;
info->demangled_name = abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr, info->demangled_name =
&status); abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr, &status);
if (info->demangled_name != nullptr) { if (info->demangled_name != nullptr) {
*ReferenceName = info->demangled_name; *ReferenceName = info->demangled_name;
*ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name; *ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
@ -1154,6 +1143,7 @@ class DisasmMemoryObject : public MemoryObject {
const uint8_t *Bytes; const uint8_t *Bytes;
uint64_t Size; uint64_t Size;
uint64_t BasePC; uint64_t BasePC;
public: public:
DisasmMemoryObject(const uint8_t *bytes, uint64_t size, uint64_t basePC) DisasmMemoryObject(const uint8_t *bytes, uint64_t size, uint64_t basePC)
: Bytes(bytes), Size(size), BasePC(basePC) {} : Bytes(bytes), Size(size), BasePC(basePC) {}
@ -1369,8 +1359,7 @@ static void DisassembleInputMachO2(StringRef Filename,
continue; continue;
StringRef SectName; StringRef SectName;
if (Sections[SectIdx].getName(SectName) || if (Sections[SectIdx].getName(SectName) || SectName != "__text")
SectName != "__text")
continue; // Skip non-text sections continue; // Skip non-text sections
DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl(); DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
@ -1500,8 +1489,8 @@ static void DisassembleInputMachO2(StringRef Filename,
// instruction to be disassembled. // instruction to be disassembled.
DiceTable Dice; DiceTable Dice;
Dice.push_back(std::make_pair(PC, DiceRef())); Dice.push_back(std::make_pair(PC, DiceRef()));
dice_table_iterator DTI = std::search(Dices.begin(), Dices.end(), dice_table_iterator DTI =
Dice.begin(), Dice.end(), std::search(Dices.begin(), Dices.end(), Dice.begin(), Dice.end(),
compareDiceTableEntries); compareDiceTableEntries);
if (DTI != Dices.end()) { if (DTI != Dices.end()) {
uint16_t Length; uint16_t Length;
@ -1538,8 +1527,7 @@ static void DisassembleInputMachO2(StringRef Filename,
// Print debug info. // Print debug info.
if (diContext) { if (diContext) {
DILineInfo dli = DILineInfo dli = diContext->getLineInfoForAddress(PC);
diContext->getLineInfoForAddress(PC);
// Print valid line info if it changed. // Print valid line info if it changed.
if (dli != lastLine && dli.Line != 0) if (dli != lastLine && dli.Line != 0)
outs() << "\t## " << dli.FileName << ':' << dli.Line << ':' outs() << "\t## " << dli.FileName << ':' << dli.Line << ':'
@ -1609,7 +1597,6 @@ static void DisassembleInputMachO2(StringRef Filename,
} }
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// __compact_unwind section dumping // __compact_unwind section dumping
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -1647,8 +1634,7 @@ struct CompactUnwindEntry {
} }
private: private:
template<typename UIntPtr> template <typename UIntPtr> void read(const char *Buf) {
void read(const char *Buf) {
FunctionAddr = readNext<UIntPtr>(Buf); FunctionAddr = readNext<UIntPtr>(Buf);
Length = readNext<uint32_t>(Buf); Length = readNext<uint32_t>(Buf);
CompactEncoding = readNext<uint32_t>(Buf); CompactEncoding = readNext<uint32_t>(Buf);
@ -1670,8 +1656,7 @@ private:
/// referenced section. /// referenced section.
static void findUnwindRelocNameAddend(const MachOObjectFile *Obj, static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
std::map<uint64_t, SymbolRef> &Symbols, std::map<uint64_t, SymbolRef> &Symbols,
const RelocationRef &Reloc, const RelocationRef &Reloc, uint64_t Addr,
uint64_t Addr,
StringRef &Name, uint64_t &Addend) { StringRef &Name, uint64_t &Addend) {
if (Reloc.getSymbol() != Obj->symbol_end()) { if (Reloc.getSymbol() != Obj->symbol_end()) {
Reloc.getSymbol()->getName(Name); Reloc.getSymbol()->getName(Name);
@ -1713,8 +1698,7 @@ static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
static void printUnwindRelocDest(const MachOObjectFile *Obj, static void printUnwindRelocDest(const MachOObjectFile *Obj,
std::map<uint64_t, SymbolRef> &Symbols, std::map<uint64_t, SymbolRef> &Symbols,
const RelocationRef &Reloc, const RelocationRef &Reloc, uint64_t Addr) {
uint64_t Addr) {
StringRef Name; StringRef Name;
uint64_t Addend; uint64_t Addend;
@ -1778,15 +1762,14 @@ printMachOCompactUnwindSection(const MachOObjectFile *Obj,
<< format("0x%" PRIx32, Entry.OffsetInSection) << ":\n"; << format("0x%" PRIx32, Entry.OffsetInSection) << ":\n";
// 1. Start of the region this entry applies to. // 1. Start of the region this entry applies to.
outs() << " start: " outs() << " start: " << format("0x%" PRIx64,
<< format("0x%" PRIx64, Entry.FunctionAddr) << ' '; Entry.FunctionAddr) << ' ';
printUnwindRelocDest(Obj, Symbols, Entry.FunctionReloc, printUnwindRelocDest(Obj, Symbols, Entry.FunctionReloc, Entry.FunctionAddr);
Entry.FunctionAddr);
outs() << '\n'; outs() << '\n';
// 2. Length of the region this entry applies to. // 2. Length of the region this entry applies to.
outs() << " length: " outs() << " length: " << format("0x%" PRIx32, Entry.Length)
<< format("0x%" PRIx32, Entry.Length) << '\n'; << '\n';
// 3. The 32-bit compact encoding. // 3. The 32-bit compact encoding.
outs() << " compact encoding: " outs() << " compact encoding: "
<< format("0x%08" PRIx32, Entry.CompactEncoding) << '\n'; << format("0x%08" PRIx32, Entry.CompactEncoding) << '\n';
@ -1802,8 +1785,8 @@ printMachOCompactUnwindSection(const MachOObjectFile *Obj,
// 5. This entry's language-specific data area. // 5. This entry's language-specific data area.
if (Entry.LSDAReloc.getObjectFile()) { if (Entry.LSDAReloc.getObjectFile()) {
outs() << " LSDA: " outs() << " LSDA: " << format("0x%" PRIx64,
<< format("0x%" PRIx64, Entry.LSDAAddr) << ' '; Entry.LSDAAddr) << ' ';
printUnwindRelocDest(Obj, Symbols, Entry.LSDAReloc, Entry.LSDAAddr); printUnwindRelocDest(Obj, Symbols, Entry.LSDAReloc, Entry.LSDAAddr);
outs() << '\n'; outs() << '\n';
} }
@ -1829,11 +1812,9 @@ static void printRegularSecondLevelUnwindPage(const char *PageStart) {
uint32_t Encoding = readNext<uint32_t>(Pos); uint32_t Encoding = readNext<uint32_t>(Pos);
outs() << " [" << i << "]: " outs() << " [" << i << "]: "
<< "function offset=" << "function offset=" << format("0x%08" PRIx32, FunctionOffset)
<< format("0x%08" PRIx32, FunctionOffset) << ", " << ", "
<< "encoding=" << "encoding=" << format("0x%08" PRIx32, Encoding) << '\n';
<< format("0x%08" PRIx32, Encoding)
<< '\n';
} }
} }
@ -1866,16 +1847,14 @@ static void printCompressedSecondLevelUnwindPage(
Encoding = PageEncodings[EncodingIdx - CommonEncodings.size()]; Encoding = PageEncodings[EncodingIdx - CommonEncodings.size()];
outs() << " [" << i << "]: " outs() << " [" << i << "]: "
<< "function offset=" << "function offset=" << format("0x%08" PRIx32, FunctionOffset)
<< format("0x%08" PRIx32, FunctionOffset) << ", " << ", "
<< "encoding[" << EncodingIdx << "]=" << "encoding[" << EncodingIdx
<< format("0x%08" PRIx32, Encoding) << "]=" << format("0x%08" PRIx32, Encoding) << '\n';
<< '\n';
} }
} }
static void static void printMachOUnwindInfoSection(const MachOObjectFile *Obj,
printMachOUnwindInfoSection(const MachOObjectFile *Obj,
std::map<uint64_t, SymbolRef> &Symbols, std::map<uint64_t, SymbolRef> &Symbols,
const SectionRef &UnwindInfo) { const SectionRef &UnwindInfo) {
@ -1938,7 +1917,6 @@ printMachOUnwindInfoSection(const MachOObjectFile *Obj,
<< '\n'; << '\n';
} }
//===---------------------------------- //===----------------------------------
// Personality functions used in this executable // Personality functions used in this executable
//===---------------------------------- //===----------------------------------
@ -1980,15 +1958,13 @@ printMachOUnwindInfoSection(const MachOObjectFile *Obj,
IndexEntries.push_back(Entry); IndexEntries.push_back(Entry);
outs() << " [" << i << "]: " outs() << " [" << i << "]: "
<< "function offset=" << "function offset=" << format("0x%08" PRIx32, Entry.FunctionOffset)
<< format("0x%08" PRIx32, Entry.FunctionOffset) << ", " << ", "
<< "2nd level page offset=" << "2nd level page offset="
<< format("0x%08" PRIx32, Entry.SecondLevelPageStart) << ", " << format("0x%08" PRIx32, Entry.SecondLevelPageStart) << ", "
<< "LSDA offset=" << "LSDA offset=" << format("0x%08" PRIx32, Entry.LSDAStart) << '\n';
<< format("0x%08" PRIx32, Entry.LSDAStart) << '\n';
} }
//===---------------------------------- //===----------------------------------
// Next come the LSDA tables // Next come the LSDA tables
//===---------------------------------- //===----------------------------------
@ -2004,10 +1980,9 @@ printMachOUnwindInfoSection(const MachOObjectFile *Obj,
uint32_t FunctionOffset = readNext<uint32_t>(Pos); uint32_t FunctionOffset = readNext<uint32_t>(Pos);
uint32_t LSDAOffset = readNext<uint32_t>(Pos); uint32_t LSDAOffset = readNext<uint32_t>(Pos);
outs() << " [" << i << "]: " outs() << " [" << i << "]: "
<< "function offset=" << "function offset=" << format("0x%08" PRIx32, FunctionOffset)
<< format("0x%08" PRIx32, FunctionOffset) << ", " << ", "
<< "LSDA offset=" << "LSDA offset=" << format("0x%08" PRIx32, LSDAOffset) << '\n';
<< format("0x%08" PRIx32, LSDAOffset) << '\n';
} }
//===---------------------------------- //===----------------------------------
@ -2040,7 +2015,6 @@ printMachOUnwindInfoSection(const MachOObjectFile *Obj,
CommonEncodings); CommonEncodings);
else else
llvm_unreachable("Do not know how to print this kind of 2nd level page"); llvm_unreachable("Do not know how to print this kind of 2nd level page");
} }
} }
@ -2068,7 +2042,6 @@ void llvm::printMachOUnwindInfo(const MachOObjectFile *Obj) {
printMachOUnwindInfoSection(Obj, Symbols, Section); printMachOUnwindInfoSection(Obj, Symbols, Section);
else if (SectName == "__eh_frame") else if (SectName == "__eh_frame")
outs() << "llvm-objdump: warning: unhandled __eh_frame section\n"; outs() << "llvm-objdump: warning: unhandled __eh_frame section\n";
} }
} }
@ -3177,8 +3150,8 @@ void llvm::printMachOExportsTrie(const object::MachOObjectFile *Obj) {
if (ReExport) if (ReExport)
outs() << "[re-export] "; outs() << "[re-export] ";
else else
outs() outs() << format("0x%08llX ",
<< format("0x%08llX ", Entry.address()); // FIXME:add in base address Entry.address()); // FIXME:add in base address
outs() << Entry.name(); outs() << Entry.name();
if (WeakDef || ThreadLocal || Resolver || Abs) { if (WeakDef || ThreadLocal || Resolver || Abs) {
bool NeedsComma = false; bool NeedsComma = false;
@ -3220,7 +3193,6 @@ void llvm::printMachOExportsTrie(const object::MachOObjectFile *Obj) {
} }
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// rebase table dumping // rebase table dumping
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -3319,9 +3291,8 @@ void llvm::printMachORebaseTable(const object::MachOObjectFile *Obj) {
// Table lines look like: __DATA __nl_symbol_ptr 0x0000F00C pointer // Table lines look like: __DATA __nl_symbol_ptr 0x0000F00C pointer
outs() << format("%-8s %-18s 0x%08" PRIX64 " %s\n", outs() << format("%-8s %-18s 0x%08" PRIX64 " %s\n",
SegmentName.str().c_str(), SegmentName.str().c_str(), SectionName.str().c_str(),
SectionName.str().c_str(), Address, Address, Entry.typeName().str().c_str());
Entry.typeName().str().c_str());
} }
} }
@ -3336,8 +3307,8 @@ static StringRef ordinalName(const object::MachOObjectFile *Obj, int Ordinal) {
return "flat-namespace"; return "flat-namespace";
default: default:
if (Ordinal > 0) { if (Ordinal > 0) {
std::error_code EC = Obj->getLibraryShortNameByIndex(Ordinal-1, std::error_code EC =
DylibName); Obj->getLibraryShortNameByIndex(Ordinal - 1, DylibName);
if (EC) if (EC)
return "<<bad library ordinal>>"; return "<<bad library ordinal>>";
return DylibName; return DylibName;
@ -3374,8 +3345,7 @@ void llvm::printMachOBindTable(const object::MachOObjectFile *Obj) {
<< left_justify(Entry.typeName(), 8) << " " << left_justify(Entry.typeName(), 8) << " "
<< format_decimal(Entry.addend(), 8) << " " << format_decimal(Entry.addend(), 8) << " "
<< left_justify(ordinalName(Obj, Entry.ordinal()), 16) << " " << left_justify(ordinalName(Obj, Entry.ordinal()), 16) << " "
<< Entry.symbolName() << Entry.symbolName() << Attr << "\n";
<< Attr << "\n";
} }
} }
@ -3406,7 +3376,6 @@ void llvm::printMachOLazyBindTable(const object::MachOObjectFile *Obj) {
} }
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// weak bind table dumping // weak bind table dumping
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -3436,8 +3405,8 @@ void llvm::printMachOWeakBindTable(const object::MachOObjectFile *Obj) {
<< left_justify(SectionName, 18) << " " << left_justify(SectionName, 18) << " "
<< format_hex(Address, 10, true) << " " << format_hex(Address, 10, true) << " "
<< left_justify(Entry.typeName(), 8) << " " << left_justify(Entry.typeName(), 8) << " "
<< format_decimal(Entry.addend(), 8) << " " << format_decimal(Entry.addend(), 8) << " " << Entry.symbolName()
<< Entry.symbolName() << "\n"; << "\n";
} }
} }