aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2019-10-14 17:47:17 +0000
committerJordan Rupprecht <rupprecht@google.com>2019-10-14 17:47:17 +0000
commitc526ff8a629e73978a8cf94dba08202d28c296d7 (patch)
tree7841f9dc77c5e6b2ddf9c4703cfd4e8afe160162 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent5af0201c2a08370fd3782b445cd96603d7988fd4 (diff)
downloadllvm-c526ff8a629e73978a8cf94dba08202d28c296d7.zip
llvm-c526ff8a629e73978a8cf94dba08202d28c296d7.tar.gz
llvm-c526ff8a629e73978a8cf94dba08202d28c296d7.tar.bz2
[llvm-objdump] Adjust spacing and field width for --section-headers
Summary: - Expand the "Name" column past 13 characters when any of the section names are longer. Current behavior is a staggard output instead of a nice table if a single name is longer. - Only print the required number of hex chars for addresses (i.e. 8 characters for 32-bit, 16 characters for 64-bit) - Fix trailing spaces Reviewers: grimar, jhenderson, espindola Reviewed By: grimar Subscribers: emaste, sbc100, arichardson, aheejin, seiya, llvm-commits, MaskRay Tags: #llvm Differential Revision: https://reviews.llvm.org/D68730 llvm-svn: 374795
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp48
1 files changed, 33 insertions, 15 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 8b0a04c..83344e7 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1650,15 +1650,31 @@ static bool shouldDisplayLMA(const ObjectFile *Obj) {
return ShowLMA;
}
+static size_t getMaxSectionNameWidth(const ObjectFile *Obj) {
+ // Default column width for names is 13 even if no names are that long.
+ size_t MaxWidth = 13;
+ for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
+ StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
+ MaxWidth = std::max(MaxWidth, Name.size());
+ }
+ return MaxWidth;
+}
+
void printSectionHeaders(const ObjectFile *Obj) {
+ size_t NameWidth = getMaxSectionNameWidth(Obj);
+ size_t AddressWidth = 2 * Obj->getBytesInAddress();
bool HasLMAColumn = shouldDisplayLMA(Obj);
if (HasLMAColumn)
outs() << "Sections:\n"
- "Idx Name Size VMA LMA "
- "Type\n";
+ "Idx "
+ << left_justify("Name", NameWidth) << " Size "
+ << left_justify("VMA", AddressWidth) << " "
+ << left_justify("LMA", AddressWidth) << " Type\n";
else
outs() << "Sections:\n"
- "Idx Name Size VMA Type\n";
+ "Idx "
+ << left_justify("Name", NameWidth) << " Size "
+ << left_justify("VMA", AddressWidth) << " Type\n";
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
@@ -1667,21 +1683,23 @@ void printSectionHeaders(const ObjectFile *Obj) {
VMA += AdjustVMA;
uint64_t Size = Section.getSize();
- bool Text = Section.isText();
- bool Data = Section.isData();
- bool BSS = Section.isBSS();
- std::string Type = (std::string(Text ? "TEXT " : "") +
- (Data ? "DATA " : "") + (BSS ? "BSS" : ""));
+
+ std::string Type = Section.isText() ? "TEXT" : "";
+ if (Section.isData())
+ Type += Type.empty() ? "DATA" : " DATA";
+ if (Section.isBSS())
+ Type += Type.empty() ? "BSS" : " BSS";
if (HasLMAColumn)
- outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %016" PRIx64
- " %s\n",
- (unsigned)Section.getIndex(), Name.str().c_str(), Size,
- VMA, getELFSectionLMA(Section), Type.c_str());
+ outs() << format("%3d %-*s %08" PRIx64 " ", (unsigned)Section.getIndex(),
+ NameWidth, Name.str().c_str(), Size)
+ << format_hex_no_prefix(VMA, AddressWidth) << " "
+ << format_hex_no_prefix(getELFSectionLMA(Section), AddressWidth)
+ << " " << Type << "\n";
else
- outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n",
- (unsigned)Section.getIndex(), Name.str().c_str(), Size,
- VMA, Type.c_str());
+ outs() << format("%3d %-*s %08" PRIx64 " ", (unsigned)Section.getIndex(),
+ NameWidth, Name.str().c_str(), Size)
+ << format_hex_no_prefix(VMA, AddressWidth) << " " << Type << "\n";
}
outs() << "\n";
}