This is an archive of the discontinued LLVM Phabricator instance.

[llvm-dwarfdump] Print =<offset> after --debug-* options in help output.
ClosedPublic

Authored by JDevlieghere on Jun 1 2020, 3:02 PM.

Details

Summary

Some of the --debug-* options can take an optional offset. Although the man page does a good job of making that clear it's less discoverable from the help output. Currently the only reference to this is the following sentence:

Where applicable these parameters take an optional =<offset> argument to dump only the entry at the specified offset.

This patch changes the help output from

--debug-info=              - Dump the .debug_info section

to

--debug-info[=<offset>]    - Dump the .debug_info section

rdar://problem/63150066

Diff Detail

Event Timeline

JDevlieghere created this revision.Jun 1 2020, 3:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2020, 3:02 PM
Herald added a subscriber: cmtice. · View Herald Transcript

Print an error when passing a value to a flag that doesn't take one.

$ ./bin/llvm-dwarfdump --debug-names=0x0
llvm-dwarfdump: for the --debug-names option: this is a flag and does not take a value.
aprantl added inline comments.Jun 1 2020, 4:13 PM
llvm/include/llvm/BinaryFormat/Dwarf.def
927

I'm not feeling very strongly about it, but I wonder if we should burden everyone's Dwarf.def with an implementation detail of llvm-dwarfdump.

MaskRay added inline comments.Jun 1 2020, 5:10 PM
llvm/docs/CommandGuide/llvm-dwarfdump.rst
152

I think there should be no space before [=<offset>], because the user specifies --eh-frame=0, instead of --eh-frame =0

JDevlieghere marked an inline comment as done.Jun 1 2020, 5:49 PM
JDevlieghere added inline comments.
llvm/include/llvm/BinaryFormat/Dwarf.def
927

Yeah, I'm not super happy about it either, but on the other hand we already have the cmdline name and it's easy to ignore.

Unfortunately this is still suboptimal. What I'd like to have is

You can patch lib/Support/CommandLine.cpp:1779:

--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1778,9 +1778,10 @@ void basic_parser_impl::printOptionInfo(const Option &O,
   if (!ValName.empty()) {
     if (O.getMiscFlags() & PositionalEatsArgs) {
       outs() << " <" << getValueStr(O, ValName) << ">...";
-    } else {
+    } else if (O.getValueExpectedFlag() == ValueOptional)
+      outs() << "[=<" << getValueStr(O, ValName) << ">]";
+    else
       outs() << "=<" << getValueStr(O, ValName) << '>';
-    }
   }
 
   Option::printHelpStr(O.HelpStr, GlobalWidth, getOptionWidth(O));
JDevlieghere marked 2 inline comments as done.
JDevlieghere edited the summary of this revision. (Show Details)

Thanks for the suggestion @MaskRay !

Generally looks good, only a couple of nits

llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
117

I think this code path should be impossible.

assert(!Arg.empty() && "this is a flag and does not take a value")

129

Either {} or StringRef() should work.

137

A key function is only useful if the class can be included by multiple files. The whole class is defined in the .cpp file. This should be unnecessary.

JDevlieghere marked 4 inline comments as done.

Address code review feedback.

JDevlieghere added inline comments.Jun 2 2020, 10:58 AM
llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
117

It's not, see the test case for a counter example.

MaskRay accepted this revision.Jun 2 2020, 11:02 AM

LGTM.

This revision is now accepted and ready to land.Jun 2 2020, 11:02 AM
This revision was automatically updated to reflect the committed changes.

Couple of post-commit review comments from me.

llvm/docs/CommandGuide/llvm-dwarfdump.rst
152

Unfortunately, if you take a look at the formatted output, if there is no space, the opening square brackets ends up bolded like the option name (see https://llvm.org/docs/CommandGuide/llvm-dwarfdump.html). I think you need to re-add the space before [=<offset>] to fix it (it was the only solution I found with llvm-symbolizer --functions which has a similar problem). If you can come up with an alternative solution without the space, I'd also be happy!

llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
92

Error messages should not end with a full stop (see recent Coding Standards updates) to be consistent with the majority of diagnostics elsewhere.