aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
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";
}