diff options
author | Clement Courbet <courbet@google.com> | 2019-01-18 08:59:39 +0000 |
---|---|---|
committer | Clement Courbet <courbet@google.com> | 2019-01-18 08:59:39 +0000 |
commit | cec38094258c69be4421fae42fdecce97fd4c9da (patch) | |
tree | ab7baa77fb6347787b336f7bf51adbe6ba5e9bf4 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | d5dd6a5fdd0998a4b1c4f273bfa5b2936e4ec739 (diff) | |
download | llvm-cec38094258c69be4421fae42fdecce97fd4c9da.zip llvm-cec38094258c69be4421fae42fdecce97fd4c9da.tar.gz llvm-cec38094258c69be4421fae42fdecce97fd4c9da.tar.bz2 |
[llvm-objdump][NFC] Improve readability.
Summary:
Introduce a `struct SectionSymbol` instead of
`tuple<uint64_t, StringRef, uint8>`.
Reviewers: jhenderson, davide
Subscribers: rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D56858
llvm-svn: 351529
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 7d0e7e9..7dc63d7 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -278,9 +278,23 @@ cl::alias DisassembleZeroesShort("z", static StringRef ToolName; -typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy; - namespace { +struct SectionSymbol { + SectionSymbol(uint64_t Address, StringRef Name, uint8_t Type) + : Address(Address), Name(Name), Type(Type) {} + + bool operator<(const SectionSymbol &Other) const { + return std::tie(Address, Name, Type) < + std::tie(Other.Address, Other.Name, Other.Type); + } + + uint64_t Address; + StringRef Name; + uint8_t Type; +}; + +typedef std::vector<SectionSymbol> SectionSymbolsTy; + typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate; class SectionFilterIterator { @@ -1455,8 +1469,8 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { std::vector<uint64_t> TextMappingSymsAddr; if (isArmElf(Obj)) { for (const auto &Symb : Symbols) { - uint64_t Address = std::get<0>(Symb); - StringRef Name = std::get<1>(Symb); + uint64_t Address = Symb.Address; + StringRef Name = Symb.Name; if (Name.startswith("$d")) DataMappingSymsAddr.push_back(Address - SectionAddr); if (Name.startswith("$x")) @@ -1505,11 +1519,11 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { error(Section.getName(SectionName)); // If the section has no symbol at the start, just insert a dummy one. - if (Symbols.empty() || std::get<0>(Symbols[0]) != 0) { + if (Symbols.empty() || Symbols[0].Address != 0) { Symbols.insert( Symbols.begin(), - std::make_tuple(SectionAddr, SectionName, - Section.isText() ? ELF::STT_FUNC : ELF::STT_OBJECT)); + SectionSymbol(SectionAddr, SectionName, + Section.isText() ? ELF::STT_FUNC : ELF::STT_OBJECT)); } SmallString<40> Comments; @@ -1528,12 +1542,12 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { std::vector<RelocationRef>::const_iterator RelEnd = Rels.end(); // Disassemble symbol by symbol. for (unsigned SI = 0, SE = Symbols.size(); SI != SE; ++SI) { - uint64_t Start = std::get<0>(Symbols[SI]) - SectionAddr; + uint64_t Start = Symbols[SI].Address - SectionAddr; // The end is either the section end or the beginning of the next // symbol. uint64_t End = (SI == SE - 1) ? SectSize - : std::get<0>(Symbols[SI + 1]) - SectionAddr; + : Symbols[SI + 1].Address - SectionAddr; // Don't try to disassemble beyond the end of section contents. if (End > SectSize) End = SectSize; @@ -1549,8 +1563,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { } /// Skip if user requested specific symbols and this is not in the list - if (!DisasmFuncsSet.empty() && - !DisasmFuncsSet.count(std::get<1>(Symbols[SI]))) + if (!DisasmFuncsSet.empty() && !DisasmFuncsSet.count(Symbols[SI].Name)) continue; if (!PrintedSection) { @@ -1566,12 +1579,12 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { End = StopAddress - SectionAddr; if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) { - if (std::get<2>(Symbols[SI]) == ELF::STT_AMDGPU_HSA_KERNEL) { + if (Symbols[SI].Type == ELF::STT_AMDGPU_HSA_KERNEL) { // skip amd_kernel_code_t at the begining of kernel symbol (256 bytes) Start += 256; } if (SI == SE - 1 || - std::get<2>(Symbols[SI + 1]) == ELF::STT_AMDGPU_HSA_KERNEL) { + Symbols[SI + 1].Type == ELF::STT_AMDGPU_HSA_KERNEL) { // cut trailing zeroes at the end of kernel // cut up to 256 bytes const uint64_t EndAlign = 256; @@ -1586,7 +1599,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (!NoLeadingAddr) outs() << format("%016" PRIx64 " ", SectionAddr + Start); - StringRef SymbolName = std::get<1>(Symbols[SI]); + StringRef SymbolName = Symbols[SI].Name; if (Demangle) outs() << demangle(SymbolName) << ":\n"; else @@ -1624,7 +1637,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // same section. We rely on the markers introduced to // understand what we need to dump. If the data marker is within a // function, it is denoted as a word/short etc - if (isArmElf(Obj) && std::get<2>(Symbols[SI]) != ELF::STT_OBJECT && + if (isArmElf(Obj) && Symbols[SI].Type != ELF::STT_OBJECT && !DisassembleAll) { uint64_t Stride = 0; @@ -1688,7 +1701,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // disassembling text (applicable all architectures), // we are in a situation where we must print the data and not // disassemble it. - if (Obj->isELF() && std::get<2>(Symbols[SI]) == ELF::STT_OBJECT && + if (Obj->isELF() && Symbols[SI].Type == ELF::STT_OBJECT && !DisassembleAll && Section.isText()) { // print out data up to 8 bytes at a time in hex and ascii uint8_t AsciiData[9] = {'\0'}; @@ -1785,25 +1798,21 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // the target, find the nearest preceding absolute symbol. auto TargetSym = std::upper_bound( TargetSectionSymbols->begin(), TargetSectionSymbols->end(), - Target, [](uint64_t LHS, - const std::tuple<uint64_t, StringRef, uint8_t> &RHS) { - return LHS < std::get<0>(RHS); + Target, [](uint64_t LHS, const SectionSymbol &RHS) { + return LHS < RHS.Address; }); if (TargetSym == TargetSectionSymbols->begin()) { TargetSectionSymbols = &AbsoluteSymbols; TargetSym = std::upper_bound( - AbsoluteSymbols.begin(), AbsoluteSymbols.end(), - Target, [](uint64_t LHS, - const std::tuple<uint64_t, StringRef, uint8_t> &RHS) { - return LHS < std::get<0>(RHS); - }); + AbsoluteSymbols.begin(), AbsoluteSymbols.end(), Target, + [](uint64_t LHS, const SectionSymbol &RHS) { + return LHS < RHS.Address; + }); } if (TargetSym != TargetSectionSymbols->begin()) { --TargetSym; - uint64_t TargetAddress = std::get<0>(*TargetSym); - StringRef TargetName = std::get<1>(*TargetSym); - outs() << " <" << TargetName; - uint64_t Disp = Target - TargetAddress; + outs() << " <" << TargetSym->Name; + uint64_t Disp = Target - TargetSym->Address; if (Disp) outs() << "+0x" << Twine::utohexstr(Disp); outs() << '>'; |