Index: llvm/docs/CommandGuide/llvm-dwarfdump.rst =================================================================== --- llvm/docs/CommandGuide/llvm-dwarfdump.rst +++ llvm/docs/CommandGuide/llvm-dwarfdump.rst @@ -149,7 +149,7 @@ Display the version of the tool. -.. option:: --debug-abbrev, --debug-addr, --debug-aranges, --debug-cu-index, --debug-frame [=], --debug-gnu-pubnames, --debug-gnu-pubtypes, --debug-info [=], --debug-line [=], --debug-line-str, --debug-loc [=], --debug-loclists [=], --debug-macro, --debug-names, --debug-pubnames, --debug-pubtypes, --debug-ranges, --debug-rnglists, --debug-str, --debug-str-offsets, --debug-tu-index, --debug-types, --eh-frame [=], --gdb-index, --apple-names, --apple-types, --apple-namespaces, --apple-objc +.. option:: --debug-abbrev, --debug-addr, --debug-aranges, --debug-cu-index, --debug-frame [=], --debug-gnu-pubnames, --debug-gnu-pubtypes, --debug-info [=], --debug-line [=], --debug-line-str, --debug-loc [=], --debug-loclists [=], --debug-macro, --debug-names, --debug-pubnames, --debug-pubtypes, --debug-ranges, --debug-rnglists, --debug-str, --debug-str-offsets, --debug-tu-index, --debug-types [=], --eh-frame [=], --gdb-index, --apple-names, --apple-types, --apple-namespaces, --apple-objc Dump the specified DWARF section by name. Only the `.debug_info` section is shown by default. Some entries Index: llvm/include/llvm/BinaryFormat/Dwarf.def =================================================================== --- llvm/include/llvm/BinaryFormat/Dwarf.def +++ llvm/include/llvm/BinaryFormat/Dwarf.def @@ -117,7 +117,7 @@ #endif #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 #ifndef HANDLE_DW_IDX @@ -924,38 +924,38 @@ HANDLE_DW_UT(0x05, split_compile) 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. // TODO: Add Mach-O and COFF names. // Official DWARF sections. -HANDLE_DWARF_SECTION(DebugAbbrev, ".debug_abbrev", "debug-abbrev") -HANDLE_DWARF_SECTION(DebugAddr, ".debug_addr", "debug-addr") -HANDLE_DWARF_SECTION(DebugAranges, ".debug_aranges", "debug-aranges") -HANDLE_DWARF_SECTION(DebugInfo, ".debug_info", "debug-info") -HANDLE_DWARF_SECTION(DebugTypes, ".debug_types", "debug-types") -HANDLE_DWARF_SECTION(DebugLine, ".debug_line", "debug-line") -HANDLE_DWARF_SECTION(DebugLineStr, ".debug_line_str", "debug-line-str") -HANDLE_DWARF_SECTION(DebugLoc, ".debug_loc", "debug-loc") -HANDLE_DWARF_SECTION(DebugLoclists, ".debug_loclists", "debug-loclists") -HANDLE_DWARF_SECTION(DebugFrame, ".debug_frame", "debug-frame") -HANDLE_DWARF_SECTION(DebugMacro, ".debug_macro", "debug-macro") -HANDLE_DWARF_SECTION(DebugNames, ".debug_names", "debug-names") -HANDLE_DWARF_SECTION(DebugPubnames, ".debug_pubnames", "debug-pubnames") -HANDLE_DWARF_SECTION(DebugPubtypes, ".debug_pubtypes", "debug-pubtypes") -HANDLE_DWARF_SECTION(DebugGnuPubnames, ".debug_gnu_pubnames", "debug-gnu-pubnames") -HANDLE_DWARF_SECTION(DebugGnuPubtypes, ".debug_gnu_pubtypes", "debug-gnu-pubtypes") -HANDLE_DWARF_SECTION(DebugRanges, ".debug_ranges", "debug-ranges") -HANDLE_DWARF_SECTION(DebugRnglists, ".debug_rnglists", "debug-rnglists") -HANDLE_DWARF_SECTION(DebugStr, ".debug_str", "debug-str") -HANDLE_DWARF_SECTION(DebugStrOffsets, ".debug_str_offsets", "debug-str-offsets") -HANDLE_DWARF_SECTION(DebugCUIndex, ".debug_cu_index", "debug-cu-index") -HANDLE_DWARF_SECTION(DebugTUIndex, ".debug_tu_index", "debug-tu-index") +HANDLE_DWARF_SECTION(DebugAbbrev, ".debug_abbrev", "debug-abbrev", BoolOption) +HANDLE_DWARF_SECTION(DebugAddr, ".debug_addr", "debug-addr", BoolOption) +HANDLE_DWARF_SECTION(DebugAranges, ".debug_aranges", "debug-aranges", BoolOption) +HANDLE_DWARF_SECTION(DebugInfo, ".debug_info", "debug-info", OffsetOption) +HANDLE_DWARF_SECTION(DebugTypes, ".debug_types", "debug-types", OffsetOption) +HANDLE_DWARF_SECTION(DebugLine, ".debug_line", "debug-line", OffsetOption) +HANDLE_DWARF_SECTION(DebugLineStr, ".debug_line_str", "debug-line-str", BoolOption) +HANDLE_DWARF_SECTION(DebugLoc, ".debug_loc", "debug-loc", OffsetOption) +HANDLE_DWARF_SECTION(DebugLoclists, ".debug_loclists", "debug-loclists", OffsetOption) +HANDLE_DWARF_SECTION(DebugFrame, ".debug_frame", "debug-frame", OffsetOption) +HANDLE_DWARF_SECTION(DebugMacro, ".debug_macro", "debug-macro", BoolOption) +HANDLE_DWARF_SECTION(DebugNames, ".debug_names", "debug-names", BoolOption) +HANDLE_DWARF_SECTION(DebugPubnames, ".debug_pubnames", "debug-pubnames", BoolOption) +HANDLE_DWARF_SECTION(DebugPubtypes, ".debug_pubtypes", "debug-pubtypes", BoolOption) +HANDLE_DWARF_SECTION(DebugGnuPubnames, ".debug_gnu_pubnames", "debug-gnu-pubnames", BoolOption) +HANDLE_DWARF_SECTION(DebugGnuPubtypes, ".debug_gnu_pubtypes", "debug-gnu-pubtypes", BoolOption) +HANDLE_DWARF_SECTION(DebugRanges, ".debug_ranges", "debug-ranges", BoolOption) +HANDLE_DWARF_SECTION(DebugRnglists, ".debug_rnglists", "debug-rnglists", BoolOption) +HANDLE_DWARF_SECTION(DebugStr, ".debug_str", "debug-str", BoolOption) +HANDLE_DWARF_SECTION(DebugStrOffsets, ".debug_str_offsets", "debug-str-offsets", BoolOption) +HANDLE_DWARF_SECTION(DebugCUIndex, ".debug_cu_index", "debug-cu-index", BoolOption) +HANDLE_DWARF_SECTION(DebugTUIndex, ".debug_tu_index", "debug-tu-index", BoolOption) // Vendor extensions. -HANDLE_DWARF_SECTION(AppleNames, ".apple_names", "apple-names") -HANDLE_DWARF_SECTION(AppleTypes, ".apple_types", "apple-types") -HANDLE_DWARF_SECTION(AppleNamespaces, ".apple_namespaces", "apple-namespaces") -HANDLE_DWARF_SECTION(AppleObjC, ".apple_objc", "apple-objc") -HANDLE_DWARF_SECTION(GdbIndex, ".gdb_index", "gdb-index") +HANDLE_DWARF_SECTION(AppleNames, ".apple_names", "apple-names", BoolOption) +HANDLE_DWARF_SECTION(AppleTypes, ".apple_types", "apple-types", BoolOption) +HANDLE_DWARF_SECTION(AppleNamespaces, ".apple_namespaces", "apple-namespaces", BoolOption) +HANDLE_DWARF_SECTION(AppleObjC, ".apple_objc", "apple-objc", BoolOption) +HANDLE_DWARF_SECTION(GdbIndex, ".gdb_index", "gdb-index", BoolOption) HANDLE_DW_IDX(0x01, compile_unit) HANDLE_DW_IDX(0x02, type_unit) Index: llvm/include/llvm/DebugInfo/DIContext.h =================================================================== --- llvm/include/llvm/DebugInfo/DIContext.h +++ llvm/include/llvm/DebugInfo/DIContext.h @@ -156,7 +156,7 @@ /// This is just a helper to programmatically construct DIDumpType. 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, #include "llvm/BinaryFormat/Dwarf.def" #undef HANDLE_DWARF_SECTION @@ -169,7 +169,7 @@ enum DIDumpType : unsigned { DIDT_Null, 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, #include "llvm/BinaryFormat/Dwarf.def" #undef HANDLE_DWARF_SECTION Index: llvm/test/tools/llvm-dwarfdump/cmdline.test =================================================================== --- llvm/test/tools/llvm-dwarfdump/cmdline.test +++ llvm/test/tools/llvm-dwarfdump/cmdline.test @@ -8,8 +8,9 @@ HELP: --help-list HELP: --version HELP: Section-specific Dump Options -HELP: --debug-info - Dump the .debug_info section -HELP: --eh-frame +HELP: --debug-info= - Dump the .debug_info section +HELP: --debug-names - Dump the .debug_names section +HELP: --eh-frame - Alias for -debug-frame HELP: Specific Options HELP: --diff HELP: --find @@ -32,3 +33,6 @@ 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 + +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. Index: llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp =================================================================== --- llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -44,6 +44,7 @@ bool HasValue = false; bool IsRequested = false; }; +struct BoolOption : public OffsetOption {}; } // namespace namespace llvm { @@ -72,7 +73,7 @@ return ValueOptional; } - StringRef getValueName() const override { return StringRef(); } + StringRef getValueName() const override { return StringRef("offset"); } void printOptionDiff(const Option &O, OffsetOption V, OptVal Default, size_t GlobalWidth) const { @@ -83,6 +84,35 @@ // An out-of-line virtual method to provide a 'home' for this class. void anchor() override {}; }; + +template <> class parser final : public basic_parser { +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); + } + + // An out-of-line virtual method to provide a 'home' for this class. + void anchor() override{}; +}; } // namespace cl } // namespace llvm @@ -112,10 +142,10 @@ static unsigned DumpType = DIDT_Null; static std::array, (unsigned)DIDT_ID_Count> DumpOffsets; -#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \ - static opt Dump##ENUM_NAME( \ - CMDLINE_NAME, desc("Dump the " ELF_NAME " section"), \ - cat(SectionCategory)); +#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \ + static opt