1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

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

Some of the --debug-* options can take an optional offset. Although the
man page does a good job of making that clear, it's much harder to
discover 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 to print [=<offset>] after the
options that take an offset.

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

rdar://problem/63150066

Differential revision: https://reviews.llvm.org/D80959
This commit is contained in:
Jonas Devlieghere 2020-06-02 11:03:21 -07:00
parent f2733aab9a
commit 2b24554801
6 changed files with 74 additions and 45 deletions

View File

@ -149,7 +149,7 @@ OPTIONS
Display the version of the tool. Display the version of the tool.
.. option:: --debug-abbrev, --debug-addr, --debug-aranges, --debug-cu-index, --debug-frame [=<offset>], --debug-gnu-pubnames, --debug-gnu-pubtypes, --debug-info [=<offset>], --debug-line [=<offset>], --debug-line-str, --debug-loc [=<offset>], --debug-loclists [=<offset>], --debug-macro, --debug-names, --debug-pubnames, --debug-pubtypes, --debug-ranges, --debug-rnglists, --debug-str, --debug-str-offsets, --debug-tu-index, --debug-types, --eh-frame [=<offset>], --gdb-index, --apple-names, --apple-types, --apple-namespaces, --apple-objc .. option:: --debug-abbrev, --debug-addr, --debug-aranges, --debug-cu-index, --debug-frame[=<offset>], --debug-gnu-pubnames, --debug-gnu-pubtypes, --debug-info[=<offset>], --debug-line[=<offset>], --debug-line-str, --debug-loc[=<offset>], --debug-loclists[=<offset>], --debug-macro, --debug-names, --debug-pubnames, --debug-pubtypes, --debug-ranges, --debug-rnglists, --debug-str, --debug-str-offsets, --debug-tu-index, --debug-types[=<offset>], --eh-frame[=<offset>], --gdb-index, --apple-names, --apple-types, --apple-namespaces, --apple-objc
Dump the specified DWARF section by name. Only the Dump the specified DWARF section by name. Only the
`.debug_info` section is shown by default. Some entries `.debug_info` section is shown by default. Some entries

View File

@ -117,7 +117,7 @@
#endif #endif
#ifndef HANDLE_DWARF_SECTION #ifndef HANDLE_DWARF_SECTION
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION)
#endif #endif
#ifndef HANDLE_DW_IDX #ifndef HANDLE_DW_IDX
@ -924,38 +924,38 @@ HANDLE_DW_UT(0x04, skeleton)
HANDLE_DW_UT(0x05, split_compile) HANDLE_DW_UT(0x05, split_compile)
HANDLE_DW_UT(0x06, split_type) HANDLE_DW_UT(0x06, split_type)
// DWARF section types. (enum name, ELF name, ELF DWO name, cmdline name) // DWARF section types. (enum name, ELF name, ELF DWO name, cmdline name, option)
// Note that these IDs don't mean anything. // Note that these IDs don't mean anything.
// TODO: Add Mach-O and COFF names. // TODO: Add Mach-O and COFF names.
// Official DWARF sections. // Official DWARF sections.
HANDLE_DWARF_SECTION(DebugAbbrev, ".debug_abbrev", "debug-abbrev") HANDLE_DWARF_SECTION(DebugAbbrev, ".debug_abbrev", "debug-abbrev", BoolOption)
HANDLE_DWARF_SECTION(DebugAddr, ".debug_addr", "debug-addr") HANDLE_DWARF_SECTION(DebugAddr, ".debug_addr", "debug-addr", BoolOption)
HANDLE_DWARF_SECTION(DebugAranges, ".debug_aranges", "debug-aranges") HANDLE_DWARF_SECTION(DebugAranges, ".debug_aranges", "debug-aranges", BoolOption)
HANDLE_DWARF_SECTION(DebugInfo, ".debug_info", "debug-info") HANDLE_DWARF_SECTION(DebugInfo, ".debug_info", "debug-info", OffsetOption)
HANDLE_DWARF_SECTION(DebugTypes, ".debug_types", "debug-types") HANDLE_DWARF_SECTION(DebugTypes, ".debug_types", "debug-types", OffsetOption)
HANDLE_DWARF_SECTION(DebugLine, ".debug_line", "debug-line") HANDLE_DWARF_SECTION(DebugLine, ".debug_line", "debug-line", OffsetOption)
HANDLE_DWARF_SECTION(DebugLineStr, ".debug_line_str", "debug-line-str") HANDLE_DWARF_SECTION(DebugLineStr, ".debug_line_str", "debug-line-str", BoolOption)
HANDLE_DWARF_SECTION(DebugLoc, ".debug_loc", "debug-loc") HANDLE_DWARF_SECTION(DebugLoc, ".debug_loc", "debug-loc", OffsetOption)
HANDLE_DWARF_SECTION(DebugLoclists, ".debug_loclists", "debug-loclists") HANDLE_DWARF_SECTION(DebugLoclists, ".debug_loclists", "debug-loclists", OffsetOption)
HANDLE_DWARF_SECTION(DebugFrame, ".debug_frame", "debug-frame") HANDLE_DWARF_SECTION(DebugFrame, ".debug_frame", "debug-frame", OffsetOption)
HANDLE_DWARF_SECTION(DebugMacro, ".debug_macro", "debug-macro") HANDLE_DWARF_SECTION(DebugMacro, ".debug_macro", "debug-macro", BoolOption)
HANDLE_DWARF_SECTION(DebugNames, ".debug_names", "debug-names") HANDLE_DWARF_SECTION(DebugNames, ".debug_names", "debug-names", BoolOption)
HANDLE_DWARF_SECTION(DebugPubnames, ".debug_pubnames", "debug-pubnames") HANDLE_DWARF_SECTION(DebugPubnames, ".debug_pubnames", "debug-pubnames", BoolOption)
HANDLE_DWARF_SECTION(DebugPubtypes, ".debug_pubtypes", "debug-pubtypes") HANDLE_DWARF_SECTION(DebugPubtypes, ".debug_pubtypes", "debug-pubtypes", BoolOption)
HANDLE_DWARF_SECTION(DebugGnuPubnames, ".debug_gnu_pubnames", "debug-gnu-pubnames") HANDLE_DWARF_SECTION(DebugGnuPubnames, ".debug_gnu_pubnames", "debug-gnu-pubnames", BoolOption)
HANDLE_DWARF_SECTION(DebugGnuPubtypes, ".debug_gnu_pubtypes", "debug-gnu-pubtypes") HANDLE_DWARF_SECTION(DebugGnuPubtypes, ".debug_gnu_pubtypes", "debug-gnu-pubtypes", BoolOption)
HANDLE_DWARF_SECTION(DebugRanges, ".debug_ranges", "debug-ranges") HANDLE_DWARF_SECTION(DebugRanges, ".debug_ranges", "debug-ranges", BoolOption)
HANDLE_DWARF_SECTION(DebugRnglists, ".debug_rnglists", "debug-rnglists") HANDLE_DWARF_SECTION(DebugRnglists, ".debug_rnglists", "debug-rnglists", BoolOption)
HANDLE_DWARF_SECTION(DebugStr, ".debug_str", "debug-str") HANDLE_DWARF_SECTION(DebugStr, ".debug_str", "debug-str", BoolOption)
HANDLE_DWARF_SECTION(DebugStrOffsets, ".debug_str_offsets", "debug-str-offsets") HANDLE_DWARF_SECTION(DebugStrOffsets, ".debug_str_offsets", "debug-str-offsets", BoolOption)
HANDLE_DWARF_SECTION(DebugCUIndex, ".debug_cu_index", "debug-cu-index") HANDLE_DWARF_SECTION(DebugCUIndex, ".debug_cu_index", "debug-cu-index", BoolOption)
HANDLE_DWARF_SECTION(DebugTUIndex, ".debug_tu_index", "debug-tu-index") HANDLE_DWARF_SECTION(DebugTUIndex, ".debug_tu_index", "debug-tu-index", BoolOption)
// Vendor extensions. // Vendor extensions.
HANDLE_DWARF_SECTION(AppleNames, ".apple_names", "apple-names") HANDLE_DWARF_SECTION(AppleNames, ".apple_names", "apple-names", BoolOption)
HANDLE_DWARF_SECTION(AppleTypes, ".apple_types", "apple-types") HANDLE_DWARF_SECTION(AppleTypes, ".apple_types", "apple-types", BoolOption)
HANDLE_DWARF_SECTION(AppleNamespaces, ".apple_namespaces", "apple-namespaces") HANDLE_DWARF_SECTION(AppleNamespaces, ".apple_namespaces", "apple-namespaces", BoolOption)
HANDLE_DWARF_SECTION(AppleObjC, ".apple_objc", "apple-objc") HANDLE_DWARF_SECTION(AppleObjC, ".apple_objc", "apple-objc", BoolOption)
HANDLE_DWARF_SECTION(GdbIndex, ".gdb_index", "gdb-index") HANDLE_DWARF_SECTION(GdbIndex, ".gdb_index", "gdb-index", BoolOption)
HANDLE_DW_IDX(0x01, compile_unit) HANDLE_DW_IDX(0x01, compile_unit)
HANDLE_DW_IDX(0x02, type_unit) HANDLE_DW_IDX(0x02, type_unit)

View File

@ -156,7 +156,7 @@ struct DILineInfoSpecifier {
/// This is just a helper to programmatically construct DIDumpType. /// This is just a helper to programmatically construct DIDumpType.
enum DIDumpTypeCounter { enum DIDumpTypeCounter {
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \ #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
DIDT_ID_##ENUM_NAME, DIDT_ID_##ENUM_NAME,
#include "llvm/BinaryFormat/Dwarf.def" #include "llvm/BinaryFormat/Dwarf.def"
#undef HANDLE_DWARF_SECTION #undef HANDLE_DWARF_SECTION
@ -169,7 +169,7 @@ static_assert(DIDT_ID_Count <= 32, "section types overflow storage");
enum DIDumpType : unsigned { enum DIDumpType : unsigned {
DIDT_Null, DIDT_Null,
DIDT_All = ~0U, DIDT_All = ~0U,
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \ #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
DIDT_##ENUM_NAME = 1U << DIDT_ID_##ENUM_NAME, DIDT_##ENUM_NAME = 1U << DIDT_ID_##ENUM_NAME,
#include "llvm/BinaryFormat/Dwarf.def" #include "llvm/BinaryFormat/Dwarf.def"
#undef HANDLE_DWARF_SECTION #undef HANDLE_DWARF_SECTION

View File

@ -1778,10 +1778,11 @@ void basic_parser_impl::printOptionInfo(const Option &O,
if (!ValName.empty()) { if (!ValName.empty()) {
if (O.getMiscFlags() & PositionalEatsArgs) { if (O.getMiscFlags() & PositionalEatsArgs) {
outs() << " <" << getValueStr(O, ValName) << ">..."; outs() << " <" << getValueStr(O, ValName) << ">...";
} else { } else if (O.getValueExpectedFlag() == ValueOptional)
outs() << "[=<" << getValueStr(O, ValName) << ">]";
else
outs() << "=<" << getValueStr(O, ValName) << '>'; outs() << "=<" << getValueStr(O, ValName) << '>';
} }
}
Option::printHelpStr(O.HelpStr, GlobalWidth, getOptionWidth(O)); Option::printHelpStr(O.HelpStr, GlobalWidth, getOptionWidth(O));
} }

View File

@ -8,8 +8,9 @@ HELP: --help
HELP: --help-list HELP: --help-list
HELP: --version HELP: --version
HELP: Section-specific Dump Options HELP: Section-specific Dump Options
HELP: --debug-info - Dump the .debug_info section HELP: --debug-info[=<offset>] - Dump the .debug_info section
HELP: --eh-frame HELP: --debug-names - Dump the .debug_names section
HELP: --eh-frame - Alias for -debug-frame
HELP: Specific Options HELP: Specific Options
HELP: --diff HELP: --diff
HELP: --find HELP: --find
@ -32,3 +33,6 @@ VERSION: {{ version }}
RUN: llvm-dwarfdump -diff -verbose 2>&1 | FileCheck --check-prefix=INCOMPATIBLE %s RUN: llvm-dwarfdump -diff -verbose 2>&1 | FileCheck --check-prefix=INCOMPATIBLE %s
INCOMPATIBLE: error: incompatible arguments: specifying both -diff and -verbose is currently not supported INCOMPATIBLE: error: incompatible arguments: specifying both -diff and -verbose is currently not supported
RUN: not llvm-dwarfdump --debug-names=0x0 2>&1 | FileCheck --check-prefix=FLAG %s
FLAG: for the --debug-names option: this is a flag and does not take a value.

View File

@ -44,6 +44,7 @@ struct OffsetOption {
bool HasValue = false; bool HasValue = false;
bool IsRequested = false; bool IsRequested = false;
}; };
struct BoolOption : public OffsetOption {};
} // namespace } // namespace
namespace llvm { namespace llvm {
@ -72,16 +73,39 @@ public:
return ValueOptional; return ValueOptional;
} }
StringRef getValueName() const override { return StringRef(); } StringRef getValueName() const override { return StringRef("offset"); }
void printOptionDiff(const Option &O, OffsetOption V, OptVal Default, void printOptionDiff(const Option &O, OffsetOption V, OptVal Default,
size_t GlobalWidth) const { size_t GlobalWidth) const {
printOptionName(O, GlobalWidth); printOptionName(O, GlobalWidth);
outs() << "[=offset]"; outs() << "[=offset]";
} }
};
// An out-of-line virtual method to provide a 'home' for this class. template <> class parser<BoolOption> final : public basic_parser<BoolOption> {
void anchor() override {}; public:
parser(Option &O) : basic_parser(O) {}
/// Return true on error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, BoolOption &Val) {
if (Arg != "")
return O.error("this is a flag and does not take a value.");
Val.Val = 0;
Val.HasValue = false;
Val.IsRequested = true;
return false;
}
enum ValueExpected getValueExpectedFlagDefault() const {
return ValueOptional;
}
StringRef getValueName() const override { return StringRef(); }
void printOptionDiff(const Option &O, OffsetOption V, OptVal Default,
size_t GlobalWidth) const {
printOptionName(O, GlobalWidth);
}
}; };
} // namespace cl } // namespace cl
} // namespace llvm } // namespace llvm
@ -112,9 +136,9 @@ static alias DumpAllAlias("a", desc("Alias for -all"), aliasopt(DumpAll));
static unsigned DumpType = DIDT_Null; static unsigned DumpType = DIDT_Null;
static std::array<llvm::Optional<uint64_t>, (unsigned)DIDT_ID_Count> static std::array<llvm::Optional<uint64_t>, (unsigned)DIDT_ID_Count>
DumpOffsets; DumpOffsets;
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \ #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
static opt<OffsetOption> Dump##ENUM_NAME( \ static opt<OPTION> Dump##ENUM_NAME(CMDLINE_NAME, \
CMDLINE_NAME, desc("Dump the " ELF_NAME " section"), \ desc("Dump the " ELF_NAME " section"), \
cat(SectionCategory)); cat(SectionCategory));
#include "llvm/BinaryFormat/Dwarf.def" #include "llvm/BinaryFormat/Dwarf.def"
#undef HANDLE_DWARF_SECTION #undef HANDLE_DWARF_SECTION
@ -240,7 +264,7 @@ static void error(StringRef Prefix, std::error_code EC) {
exit(1); exit(1);
} }
static DIDumpOptions getDumpOpts(DWARFContext& C) { static DIDumpOptions getDumpOpts(DWARFContext &C) {
DIDumpOptions DumpOpts; DIDumpOptions DumpOpts;
DumpOpts.DumpType = DumpType; DumpOpts.DumpType = DumpType;
DumpOpts.ChildRecurseDepth = ChildRecurseDepth; DumpOpts.ChildRecurseDepth = ChildRecurseDepth;
@ -609,7 +633,7 @@ int main(int argc, char **argv) {
// Defaults to dumping all sections, unless brief mode is specified in which // Defaults to dumping all sections, unless brief mode is specified in which
// case only the .debug_info section in dumped. // case only the .debug_info section in dumped.
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \ #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
if (Dump##ENUM_NAME.IsRequested) { \ if (Dump##ENUM_NAME.IsRequested) { \
DumpType |= DIDT_##ENUM_NAME; \ DumpType |= DIDT_##ENUM_NAME; \
if (Dump##ENUM_NAME.HasValue) { \ if (Dump##ENUM_NAME.HasValue) { \