This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] Adjust spacing and field width for --section-headers
ClosedPublic

Authored by rupprecht on Oct 9 2019, 2:17 PM.

Details

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

Diff Detail

Event Timeline

rupprecht created this revision.Oct 9 2019, 2:17 PM
Herald added a project: Restricted Project. · View Herald Transcript
grimar added inline comments.Oct 10 2019, 2:32 AM
llvm/test/tools/llvm-objdump/section-headers-address-width.test
10 ↗(On Diff #224163)

I wonder, should we be able to shrink it too?

Something like:
Len = max length among all sections.

Instead of a current (if I understand it right)
Len = max(max length ..., 13)

37 ↗(On Diff #224163)

nit: We are often reducing the identation to a single space after the longest tag. Just like you have for FileHeader
(here and everywhere below)

38 ↗(On Diff #224163)

nit: you can remove '...'
(here and everywhere below)

llvm/test/tools/llvm-objdump/section-headers-name-width.test
2 ↗(On Diff #224163)

nit: missing empty line after comment.

4 ↗(On Diff #224163)

You are not using --show-lma it seems? I.e. I am not sure why do you need this test.

16 ↗(On Diff #224163)

nit: We often add a short comment for each test in addition to a file comment.
I.e. you could say something like "here we test that name with the length 14 expands ..."

llvm/test/tools/llvm-objdump/section-headers-spacing.test
1 ↗(On Diff #224163)

What do you think about combining these tests you have here into one that
could use yaml2obj --docnum=X and check spacing, formatting etc in one place?
(I am not sure it if it is usefull to have 3 different test files?)

llvm/tools/llvm-objdump/llvm-objdump.cpp
1653

getMaxSectionNameWidth?

1694

May be I'd try to avoid using an additional vector and algorithm here and just:

std::string Type = Section.isText() ? "TEXT" : "";
if (Section.isData())
  Type += Type.empty() ? "DATA" : " DATA";
if (Section.isBSS())
  Type += Type.empty() ? "BSS" : " BSS";
rupprecht marked 9 inline comments as done.Oct 10 2019, 11:51 AM
rupprecht added inline comments.
llvm/test/tools/llvm-objdump/section-headers-address-width.test
10 ↗(On Diff #224163)

13 is chosen to make the output match GNU objdump. Having a cutoff (not necessarily 13, but any number around there) also makes the formatting stable for objects with regular-length section names.

llvm/test/tools/llvm-objdump/section-headers-name-width.test
4 ↗(On Diff #224163)

Added a comment -- the reason is just that it goes down a different code path, e.g. would catch a bad implementation like:

if (ShowLMA)
  outs() << "Name    " << ... // Oops, didn't use left_justify
else
  outs() << left_justify("Name", NameWidth) << ...
llvm/test/tools/llvm-objdump/section-headers-spacing.test
1 ↗(On Diff #224163)

I started out with one test file, but found it to be a collection of somewhat unrelated things -- e.g. name column width and 32 vs 64 bit column widths are different features. So I think it's better to have more focused test files. It's a slightly personal preference though.

llvm/tools/llvm-objdump/llvm-objdump.cpp
1694

I think the lack of using an algorithm is why there was odd trailing whitespace before, although I agree it would be great if this could be more succinct...

rupprecht marked an inline comment as done.
  • Remove yaml ... separators
  • Whitespace changes
  • Add more test comments
  • Rename to getMaxSectionNameWidth
  • Fix yaml spacing
  • Remove some unnecessary yaml fields
grimar added inline comments.Oct 11 2019, 3:45 AM
llvm/test/tools/llvm-objdump/section-headers-spacing.test
1 ↗(On Diff #224163)

We often combine tests by a feature. I.e. test that checks the "-h" output might contain everything related to "-h" at once. Sometimes we do a split to make a test that contain only a error/warnings checks (if there are too many of them) or a particular set of tests that are very different.

It is not a huge problem, but might be interesting what others think about this too though.
(to summarize my position: I'd prefer to combine them to reduce the number of tests, but it is not critical and is OK as is probably).

llvm/tools/llvm-objdump/llvm-objdump.cpp
1694

But does my version has a trailing whitespace issue? I think no.

rupprecht marked 5 inline comments as done.
  • Merge tests
  • Avoid llvm::join() call
llvm/test/tools/llvm-objdump/section-headers-spacing.test
1 ↗(On Diff #224163)

I don't have that strong of preference either, so merged. My only concern is now it's on the larger end of test sizes (7th of all objdump tests per find llvm/test/tools/llvm-objdump/ -name '*.test' | xargs wc -l | sort -nr | tail +2 | head -10), but it's still not excessively long.

grimar accepted this revision.Oct 12 2019, 4:25 AM

LGTM

This revision is now accepted and ready to land.Oct 12 2019, 4:25 AM
This revision was automatically updated to reflect the committed changes.
jhenderson added inline comments.Oct 29 2019, 3:50 AM
llvm/test/tools/llvm-objdump/section-headers.test
7

No need to change this, but rather than using {{^}} and {{$}} you could have used --match-full-lines instead. Combined with --strict-whitespace, this will ensure that the line checked matches exactly the specified string. The downside is the lack of a space after the FileCheck pattern name, but you can solve that with additional spacing:

#      WHITESPACE:Sections:
# WHITESPACE-NEXT:Idx Name

or (I think, though not tested):

# WHITESPACE     :Sections:
# WHITESPACE-NEXT:Idx Name