This is an archive of the discontinued LLVM Phabricator instance.

[llvm-dwarfdump] Make commandline arguments consistent.
ClosedPublic

Authored by Higuoxing on May 8 2020, 1:07 AM.

Details

Summary

Currently, llvm-dwarfdump's help message has two issues.

  1. Most long options are printed in --long-option, except for some section dumping options, e.g., -apple-names, -debug-addr.
  1. Most options are printed with consistent indention, except for some section dumping options.

This patch helps resolve these two issues.

Diff Detail

Event Timeline

Higuoxing created this revision.May 8 2020, 1:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2020, 1:07 AM

Most options are printed with consistent indention, except for some "debug" options.

Could you elaborate on this point, and how this helps fix it? Could you also please paste before/after examples of the help output?

llvm/test/tools/llvm-dwarfdump/cmdline.test
10–11

Why have you singled out the -debug-info option for this extra testing? What about the other options?

Most options are printed with consistent indention, except for some "debug" options.

Could you elaborate on this point, and how this helps fix it? Could you also please paste before/after examples of the help output?

Sure, let me explain this.

llvm-dwarfdump offers some options called OffsetOption. These options take an optional argument called offset, which directs llvm-dwarfdump to dump only the entry at the specified offset, e.g., llvm-dwarfdump --debug-info=0x0b some_object will dump the .debug_info entry at offset 0x0b of the object file some_object.

Help messages are printed via printOptionInfo(). If we use the default printOptionInfo() method, these options will be printed as --debug-info=<value>. I guess the original author wants to discard the optional value string =<value>, so he implements a customed one. However, this will cause the command line arguments parser to calculate the wrong numbers of indent whitespaces. As you cant see the examples below, all the "debug" options are lacking some indent whitespaces between argument and help message, and the number of missing whitespaces is as many as characters in =<value>.

Actually, we can simply override the getValueName() method to tell the commandline parser not to print =<value>.


Below are the output examples of llvm-dwarfdump --help

Before,

$ llvm-dwarfdump --help
OVERVIEW: pretty-print DWARF debug information in object files and debug info archives.

USAGE: llvm-dwarfdump [options] <input object files or .dSYM bundles>

OPTIONS:

Color Options:

  --color                      - Use colors in output (default=autodetect)

Generic Options:

  --help                       - Display available options (--help-hidden for more)
  --help-list                  - Display list of available options (--help-list-hidden for more)
  --version                    - Display the version of this program

Section-specific Dump Options:
These control which sections are dumped. Where applicable these parameters take an optional =<offset> argument to dump only the entry at the specified offset.

  --all                        - Dump all debug info sections
  -apple-names        - Dump the .apple_names section
  -apple-namespaces   - Dump the .apple_namespaces section
  -apple-objc         - Dump the .apple_objc section
  -apple-types        - Dump the .apple_types section
  -debug-abbrev       - Dump the .debug_abbrev section
  -debug-addr         - Dump the .debug_addr section
  -debug-aranges      - Dump the .debug_aranges section
  -debug-cu-index     - Dump the .debug_cu_index section
  -debug-frame        - Dump the .debug_frame section
  -debug-gnu-pubnames - Dump the .debug_gnu_pubnames section
  -debug-gnu-pubtypes - Dump the .debug_gnu_pubtypes section
  -debug-info         - Dump the .debug_info section
  -debug-line         - Dump the .debug_line section
  -debug-line-str     - Dump the .debug_line_str section
  -debug-loc          - Dump the .debug_loc section
  -debug-loclists     - Dump the .debug_loclists section
  -debug-macro        - Dump the .debug_macro section
  -debug-names        - Dump the .debug_names section
  -debug-pubnames     - Dump the .debug_pubnames section
  -debug-pubtypes     - Dump the .debug_pubtypes section
  -debug-ranges       - Dump the .debug_ranges section
  -debug-rnglists     - Dump the .debug_rnglists section
  -debug-str          - Dump the .debug_str section
  -debug-str-offsets  - Dump the .debug_str_offsets section
  -debug-tu-index     - Dump the .debug_tu_index section
  -debug-types        - Dump the .debug_types section
  --eh-frame                   - Alias for -debug-frame
  -gdb-index          - Dump the .gdb_index section

Specific Options:

  --arch=<string>              - Dump debug information for the specified CPU architecture only. Architectures may be specified by name or by number. This option can be specified multiple times, once for each desired architecture.
  --diff                       - Emit diff-friendly output by omitting offsets and addresses.
  --find=<name>                - Search for the exact match for <name> in the accelerator tables and print the matching debug information entries. When no accelerator tables are available, the slower but more complete -name option can be used instead.
  --ignore-case                - Ignore case distinctions when searching.
  --lookup=<address>           - Lookup <address> in the debug information and print out any available file, function, block and line table details.
  --name=<pattern>             - Find and print all debug info entries whose name (DW_AT_name attribute) matches the exact text in <pattern>.  When used with the the -regex option <pattern> is interpreted as a regular expression.
  -o=<filename>                - Redirect output to the specified file.
  --parent-recurse-depth=<N>   - Only recurse to a depth of N when displaying parents of debug info entries.
  --quiet                      - Use with -verify to not emit to STDOUT.
  --recurse-depth=<N>          - Only recurse to a depth of N when displaying children of debug info entries.
  --regex                      - Treat any <pattern> strings as regular expressions when searching instead of just as an exact string match.
  --show-children              - Show a debug info entry's children when selectively printing entries.
  --show-form                  - Show DWARF form types after the DWARF attribute types.
  --show-parents               - Show a debug info entry's parents when selectively printing entries.
  --show-section-sizes         - Show the sizes of all debug sections, expressed in bytes.
  --statistics                 - Emit JSON-formatted debug info quality metrics.
  --summarize-types            - Abbreviate the description of type unit entries.
  --uuid                       - Show the UUID for each architecture.
  --verbose                    - Print more low-level encoding details.
  --verify                     - Verify the DWARF debug info.

Pass @FILE as argument to read options from FILE.

After,

$ llvm-dwarfdump --help                                  
OVERVIEW: pretty-print DWARF debug information in object files and debug info archives.

USAGE: llvm-dwarfdump [options] <input object files or .dSYM bundles>

OPTIONS:

Color Options:

  --color                    - Use colors in output (default=autodetect)

Generic Options:

  --help                     - Display available options (--help-hidden for more)
  --help-list                - Display list of available options (--help-list-hidden for more)
  --version                  - Display the version of this program

Section-specific Dump Options:
These control which sections are dumped. Where applicable these parameters take an optional =<offset> argument to dump only the entry at the specified offset.

  --all                      - Dump all debug info sections
  --apple-names              - Dump the .apple_names section
  --apple-namespaces         - Dump the .apple_namespaces section
  --apple-objc               - Dump the .apple_objc section
  --apple-types              - Dump the .apple_types section
  --debug-abbrev             - Dump the .debug_abbrev section
  --debug-addr               - Dump the .debug_addr section
  --debug-aranges            - Dump the .debug_aranges section
  --debug-cu-index           - Dump the .debug_cu_index section
  --debug-frame              - Dump the .debug_frame section
  --debug-gnu-pubnames       - Dump the .debug_gnu_pubnames section
  --debug-gnu-pubtypes       - Dump the .debug_gnu_pubtypes section
  --debug-info               - Dump the .debug_info section
  --debug-line               - Dump the .debug_line section
  --debug-line-str           - Dump the .debug_line_str section
  --debug-loc                - Dump the .debug_loc section
  --debug-loclists           - Dump the .debug_loclists section
  --debug-macro              - Dump the .debug_macro section
  --debug-names              - Dump the .debug_names section
  --debug-pubnames           - Dump the .debug_pubnames section
  --debug-pubtypes           - Dump the .debug_pubtypes section
  --debug-ranges             - Dump the .debug_ranges section
  --debug-rnglists           - Dump the .debug_rnglists section
  --debug-str                - Dump the .debug_str section
  --debug-str-offsets        - Dump the .debug_str_offsets section
  --debug-tu-index           - Dump the .debug_tu_index section
  --debug-types              - Dump the .debug_types section
  --eh-frame                 - Alias for -debug-frame
  --gdb-index                - Dump the .gdb_index section

Specific Options:

  --arch=<string>            - Dump debug information for the specified CPU architecture only. Architectures may be specified by name or by number. This option can be specified multiple times, once for each desired architecture.
  --diff                     - Emit diff-friendly output by omitting offsets and addresses.
  --find=<name>              - Search for the exact match for <name> in the accelerator tables and print the matching debug information entries. When no accelerator tables are available, the slower but more complete -name option can be used instead.
  --ignore-case              - Ignore case distinctions when searching.
  --lookup=<address>         - Lookup <address> in the debug information and print out any available file, function, block and line table details.
  --name=<pattern>           - Find and print all debug info entries whose name (DW_AT_name attribute) matches the exact text in <pattern>.  When used with the the -regex option <pattern> is interpreted as a regular expression.
  -o=<filename>              - Redirect output to the specified file.
  --parent-recurse-depth=<N> - Only recurse to a depth of N when displaying parents of debug info entries.
  --quiet                    - Use with -verify to not emit to STDOUT.
  --recurse-depth=<N>        - Only recurse to a depth of N when displaying children of debug info entries.
  --regex                    - Treat any <pattern> strings as regular expressions when searching instead of just as an exact string match.
  --show-children            - Show a debug info entry's children when selectively printing entries.
  --show-form                - Show DWARF form types after the DWARF attribute types.
  --show-parents             - Show a debug info entry's parents when selectively printing entries.
  --show-section-sizes       - Show the sizes of all debug sections, expressed in bytes.
  --statistics               - Emit JSON-formatted debug info quality metrics.
  --summarize-types          - Abbreviate the description of type unit entries.
  --uuid                     - Show the UUID for each architecture.
  --verbose                  - Print more low-level encoding details.
  --verify                   - Verify the DWARF debug info.

Pass @FILE as argument to read options from FILE.
Higuoxing marked an inline comment as done.May 11 2020, 2:45 AM
Higuoxing added inline comments.
llvm/test/tools/llvm-dwarfdump/cmdline.test
10–11

Because there's only one test case for --debug-* options. Should I add more tests for this?

If you are planning on using the description as your commit message, please rephrase the second point "some section dumping options have inconsistent indentation". Also change the first one saying "debug" options to "section dumping options", as the phrasing you use suggests to me that they are for debugging the tool, rather than provide useful output!

If you could fix that, and also add the double-dashes to the rest of the test, I think that would be sufficient for this.

llvm/test/tools/llvm-dwarfdump/cmdline.test
10–11

I was thinking more why do -color/-help etc not use double dashes.

I'm not sure that we need extra testing beyond that point, as I don't think it will provide much use.

Higuoxing updated this revision to Diff 263909.May 13 2020, 7:13 PM

Address comments.

  • Add double-dashes to the rest of test.
Higuoxing edited the summary of this revision. (Show Details)May 13 2020, 7:14 PM
This revision is now accepted and ready to land.May 14 2020, 1:33 AM
This revision was automatically updated to reflect the committed changes.