From: Petr Machata Date: Fri, 1 Oct 2010 14:51:48 +0000 (+0200) Subject: dwarflint: Use wrapper to print check descriptions X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ea0dc974162987dc18ee05f51baf3a2ce6598a18;p=thirdparty%2Felfutils.git dwarflint: Use wrapper to print check descriptions - this should make it easier to write them - also use argp to print out properly formatted help for each check. Drop a bunch of code that was necessary to do things the old way --- diff --git a/dwarflint/check_debug_abbrev.cc b/dwarflint/check_debug_abbrev.cc index ed19b134f..e62445d23 100644 --- a/dwarflint/check_debug_abbrev.cc +++ b/dwarflint/check_debug_abbrev.cc @@ -50,29 +50,29 @@ check_debug_abbrev::descriptor () .prereq () .prereq () .description ( -"Checks for low-level structure of .debug_abbrev. In addition it\n" +"Checks for low-level structure of .debug_abbrev. In addition it " "checks:\n" " - that all abbreviation tables are non-empty\n" -" - that certain attribute forms match expectations (mainly those that\n" -" we have to work with in subsequent check passes. For example we\n" -" check that DW_AT_low_pc has a form of DW_FORM_{,ref_}addr)\n" -" - that all CUs that share an abbrev table are of the same DWARF\n" -" version\n" +" - that certain attribute forms match expectations (mainly those that " +"we have to work with in subsequent check passes. For example we " +"check that DW_AT_low_pc has a form of DW_FORM_{,ref_}addr)\n" +" - that all CUs that share an abbrev table are of the same DWARF " +"version\n" " - that each abbrev table is used\n" " - that abbrevs don't share abbrev codes\n" -" - that abbrev tags, attribute names and attribute forms are all known\n" -" (note that this assumes that elfutils know about all tags used in\n" -" practice. Be sure to build against recent-enough version)\n" +" - that abbrev tags, attribute names and attribute forms are all known " +"(note that this assumes that elfutils know about all tags used in " +"practice. Be sure to build against recent-enough version)\n" " - that the value of has_children is either 0 or 1\n" -" - that DW_AT_sibling isn't formed as DW_FORM_ref_addr, and that it\n" -" isn't present at childless abbrevs\n" +" - that DW_AT_sibling isn't formed as DW_FORM_ref_addr, and that it " +"isn't present at childless abbrevs\n" " - that attributes are not duplicated at abbrev\n" -" - that DW_AT_high_pc is never used without DW_AT_low_pc. If both are\n" -" used, that DW_AT_ranges isn't also used\n" -"This check generally requires CU headers to be readable, i.e. that the\n" -".debug_info section is roughly well-defined. If that isn't the case,\n" -"many checks will still be done, operating under assumption that what\n" -"we see is the latest DWARF format. This may render some checks\n" +" - that DW_AT_high_pc is never used without DW_AT_low_pc. If both are " +"used, that DW_AT_ranges isn't also used\n" +"This check generally requires CU headers to be readable, i.e. that the " +".debug_info section is roughly well-defined. If that isn't the case, " +"many checks will still be done, operating under assumption that what " +"we see is the latest DWARF format. This may render some checks " "inaccurate.\n")); return &cd; } diff --git a/dwarflint/check_debug_aranges.cc b/dwarflint/check_debug_aranges.cc index 99f8669b2..87f96832a 100644 --- a/dwarflint/check_debug_aranges.cc +++ b/dwarflint/check_debug_aranges.cc @@ -52,10 +52,10 @@ check_debug_aranges::descriptor () .prereq () .prereq () .description ( -"Checks for low-level structure of .debug_aranges. In addition it\n" +"Checks for low-level structure of .debug_aranges. In addition it " "checks:\n" -" - that relocations are valid. In ET_REL files that certain fields\n" -" are relocated\n" +" - that relocations are valid. In ET_REL files that certain fields " +"are relocated\n" " - for dangling and duplicate CU references\n" " - for garbage inside padding\n" " - for zero-length ranges\n" diff --git a/dwarflint/check_debug_info.cc b/dwarflint/check_debug_info.cc index 3b4942a65..87b81c885 100644 --- a/dwarflint/check_debug_info.cc +++ b/dwarflint/check_debug_info.cc @@ -65,34 +65,34 @@ check_debug_info::descriptor () .prereq () .prereq () .description ( -"Checks for low-level structure of .debug_info. In addition it\n" +"Checks for low-level structure of .debug_info. In addition it " "checks:\n" " - for dangling reference to .debug_abbrev section\n" " - that reported CU address sizes are consistent\n" " - that rangeptr values are aligned to CU address size\n" -" - it is checked that DW_AT_low_pc and DW_AT_high_pc are relocated\n" -" consistently\n" -" - that DIE references are well formed (both intra-CU and inter-CU)\n" -" and that local reference isn't needlessly formed as global\n" -" - that .debug_string references are well formed and referred strings\n" -" are properly NUL-terminated\n" +" - it is checked that DW_AT_low_pc and DW_AT_high_pc are relocated " +"consistently\n" +" - that DIE references are well formed (both intra-CU and inter-CU) " +"and that local reference isn't needlessly formed as global\n" +" - that .debug_string references are well formed and referred strings " +"are properly NUL-terminated\n" " - that referenced abbreviations actually exist\n" -" - that DIEs with children have the DW_AT_sibling attribute and that\n" -" the sibling actually is at the address reported at that attribute\n" +" - that DIEs with children have the DW_AT_sibling attribute and that " +"the sibling actually is at the address reported at that attribute\n" " - that the DIE chain is terminated\n" " - that the last sibling in chain has no DW_AT_sibling attribute\n" -" - that the DIE with children actually has children (i.e. that the\n" -" chain is not empty)\n" -" - for format constraints (such as that there are no 64-bit CUs inside\n" -" DWARF 2 file)\n" -" - in 32-bit CUs, that location attributes are not formed with\n" -" DW_FORM_data8\n" -" - all the attribute checks done by check_debug_abbrev are done here\n" -" for attributes with DW_FORM_indirect. Indirect form is forbidden\n" -" to be again indirect\n" +" - that the DIE with children actually has children (i.e. that the " +"chain is not empty)\n" +" - for format constraints (such as that there are no 64-bit CUs inside " +"DWARF 2 file)\n" +" - in 32-bit CUs, that location attributes are not formed with " +"DW_FORM_data8\n" +" - all the attribute checks done by check_debug_abbrev are done here " +"for attributes with DW_FORM_indirect. Indirect form is forbidden " +"to be again indirect\n" " - that all abbreviations are used\n" -" - that relocations are valid. In ET_REL files that certain fields\n" -" are relocated\n" +" - that relocations are valid. In ET_REL files that certain fields " +"are relocated\n" )); return &cd; } @@ -1303,8 +1303,8 @@ check_debug_info_refs::descriptor () .description ( "This pass checks:\n" " - for outstanding unresolved references from .debug_info to .debug_line\n" -" - that each CU has an associated aranges entry (that even if there is\n" -" no .debug_aranges to begin with).\n")); +" - that each CU has an associated aranges entry (that even if there is " +"no .debug_aranges to begin with).\n")); return &cd; } diff --git a/dwarflint/check_debug_line.cc b/dwarflint/check_debug_line.cc index fe44618a4..d4675babb 100644 --- a/dwarflint/check_debug_line.cc +++ b/dwarflint/check_debug_line.cc @@ -47,29 +47,29 @@ check_debug_line::descriptor () .description ( "Checks for low-level structure of .debug_line. In addition it\n" "checks:\n" -" - for normalized values of certain attributes (such as that\n" -" default_is_stmt is 0 or 1, even though technically any non-zero\n" -" value is allowed).\n" -" - for valid setting of opcode base (i.e. non-zero) and any file\n" -" indices\n" +" - for normalized values of certain attributes (such as that " +"default_is_stmt is 0 or 1, even though technically any non-zero " +"value is allowed).\n" +" - for valid setting of opcode base (i.e. non-zero) and any file" +"indices\n" " - that all include directories and all files are used\n" -" - that files with absolute paths don't refer to include directories,\n" -" and otherwise that the directory reference is valid\n" -" - that each used standard or extended opcode is known (note that this\n" -" assumes that elfutils know about all opcodes used in practice. Be\n" -" sure to build against recent-enough version).\n" -" - that the line number program is properly terminated with the\n" -" DW_LNE_end_sequence instruction and that it contains at least one\n" -" other instruction\n" -" - that relocations are valid. In ET_REL files that certain fields\n" -" are relocated\n" -"Furthermore, if .debug_info is valid, it is checked that each line\n" +" - that files with absolute paths don't refer to include directories," +"and otherwise that the directory reference is valid\n" +" - that each used standard or extended opcode is known (note that this " +"assumes that elfutils know about all opcodes used in practice. Be " +"sure to build against recent-enough version).\n" +" - that the line number program is properly terminated with the " +"DW_LNE_end_sequence instruction and that it contains at least one " +"other instruction\n" +" - that relocations are valid. In ET_REL files that certain fields " +"are relocated\n" +"Furthermore, if .debug_info is valid, it is checked that each line " "table is used by some CU.\n" "TODOs:\n" -" - overlaps in defined addresses are probably OK, one instruction can\n" -" be derived from several statements. But certain flags in table\n" -" should be consistent in that case, namely is_stmt, basic_block,\n" -" end_sequence, prologue_end, epilogue_begin, isa.\n" +" - overlaps in defined addresses are probably OK, one instruction can " +"be derived from several statements. But certain flags in table " +"should be consistent in that case, namely is_stmt, basic_block, " +"end_sequence, prologue_end, epilogue_begin, isa.\n" )); return &cd; } diff --git a/dwarflint/check_debug_loc_range.cc b/dwarflint/check_debug_loc_range.cc index b8456b919..7bbca1d6f 100644 --- a/dwarflint/check_debug_loc_range.cc +++ b/dwarflint/check_debug_loc_range.cc @@ -57,17 +57,17 @@ check_debug_ranges::descriptor () .prereq () .prereq () .description ( -"Checks for low-level structure of .debug_ranges. In addition it\n" +"Checks for low-level structure of .debug_ranges. In addition it " "checks:\n" " - for overlapping and dangling references from .debug_info\n" " - that base address is set and that it actually changes the address\n" " - that ranges have a positive size\n" " - that there are no unreferenced holes in the section\n" -" - that relocations are valid. In ET_REL files that certain fields\n" -" are relocated\n" -" - neither or both of range start and range end are expected to be\n" -" relocated. It's expected that they are both relocated against the\n" -" same section.\n")); +" - that relocations are valid. In ET_REL files that certain fields " +"are relocated\n" +" - neither or both of range start and range end are expected to be " +"relocated. It's expected that they are both relocated against the " +"same section.\n")); return &cd; } @@ -80,17 +80,17 @@ check_debug_loc::descriptor () .prereq () .prereq () .description ( -"Checks for low-level structure of .debug_loc. In addition it\n" -"makes the same checks as .debug_ranges. For location expressions\n" +"Checks for low-level structure of .debug_loc. In addition it " +"makes the same checks as .debug_ranges. For location expressions " "it further checks:\n" -" - that DW_OP_bra and DW_OP_skip argument is non-zero and doesn't\n" -" escape the expression. In addition it is required that the jump\n" -" ends on another instruction, not arbitrarily in the middle of the\n" -" byte stream, even if that position happened to be interpretable as\n" -" another well-defined instruction stream.\n" +" - that DW_OP_bra and DW_OP_skip argument is non-zero and doesn't " +"escape the expression. In addition it is required that the jump " +"ends on another instruction, not arbitrarily in the middle of the " +"byte stream, even if that position happened to be interpretable as " +"another well-defined instruction stream.\n" " - on 32-bit machines it rejects DW_OP_const8u and DW_OP_const8s\n" -" - on 32-bit machines it checks that ULEB128-encoded arguments aren't\n" -" quantities that don't fit into 32 bits\n")); +" - on 32-bit machines it checks that ULEB128-encoded arguments aren't " +"quantities that don't fit into 32 bits\n")); return &cd; } diff --git a/dwarflint/check_debug_pub.cc b/dwarflint/check_debug_pub.cc index 008355863..568db4329 100644 --- a/dwarflint/check_debug_pub.cc +++ b/dwarflint/check_debug_pub.cc @@ -50,11 +50,11 @@ check_debug_pubnames::descriptor () .prereq () .prereq () .description ( -"Checks for low-level structure of .debug_pubnames. In addition it\n" +"Checks for low-level structure of .debug_pubnames. In addition it " "checks:\n" " - for garbage inside padding\n" -" - that relocations are valid. In ET_REL files that certain fields\n" -" are relocated\n" +" - that relocations are valid. In ET_REL files that certain fields " +"are relocated\n" "Furthermore, if .debug_info is valid, it is checked:\n" " - that references point to actual CUs and DIEs\n" " - that there's only one pub section per CU\n")); @@ -72,7 +72,7 @@ check_debug_pubtypes::descriptor () .prereq () .prereq () .description ( -"Checks for low-level structure of .debug_pubtypes. In addition it\n" +"Checks for low-level structure of .debug_pubtypes. In addition it " "makes the same checks as check_debug_pubnames.\n")); return &cd; } diff --git a/dwarflint/check_duplicate_DW_tag_variable.cc b/dwarflint/check_duplicate_DW_tag_variable.cc index 3fb11632a..80f966326 100644 --- a/dwarflint/check_duplicate_DW_tag_variable.cc +++ b/dwarflint/check_duplicate_DW_tag_variable.cc @@ -57,8 +57,8 @@ namespace (checkdescriptor::create ("check_duplicate_DW_tag_variable") .inherit > () .description ( -"Implements a check for two full DW_TAG_variable DIEs with the same\n" -"DW_AT_name value. This covers duplicate declaration, duplicate\n" +"Implements a check for two full DW_TAG_variable DIEs with the same " +"DW_AT_name value. This covers duplicate declaration, duplicate " "definition and declaration with definition.\n" " https://fedorahosted.org/pipermail/elfutils-devel/2010-July/001497.html\n" " http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39524\n")); diff --git a/dwarflint/check_dups_abstract_origin.cc b/dwarflint/check_dups_abstract_origin.cc index ec786561f..b746bba31 100644 --- a/dwarflint/check_dups_abstract_origin.cc +++ b/dwarflint/check_dups_abstract_origin.cc @@ -48,8 +48,8 @@ namespace (checkdescriptor::create ("check_dups_abstract_origin") .inherit > () .description ( -"If a given attribute name is present on a DIE, it is\n" -"suspicious if that attribute name appears on the DIE that's the\n" +"If a given attribute name is present on a DIE, it is " +"suspicious if that attribute name appears on the DIE that's the " "first DIE's DW_AT_abstract_origin or DW_AT_specification.\n" " https://bugzilla.redhat.com/show_bug.cgi?id=527430\n")); return &cd; diff --git a/dwarflint/check_nodebug.cc b/dwarflint/check_nodebug.cc index f658c615e..a5ed1c19a 100644 --- a/dwarflint/check_nodebug.cc +++ b/dwarflint/check_nodebug.cc @@ -43,7 +43,7 @@ public: .groups ("@low") .option (ignore_missing) .description ( -"Checks that there are at least essential debuginfo sections present\n" +"Checks that there are at least essential debuginfo sections present " "in the ELF file.\n")); return &cd; } diff --git a/dwarflint/dwarflint.cc b/dwarflint/dwarflint.cc index 6d01f7e02..f00c1c175 100644 --- a/dwarflint/dwarflint.cc +++ b/dwarflint/dwarflint.cc @@ -27,6 +27,7 @@ #include "messages.hh" #include "checks.hh" #include "main.hh" +#include "wrap.hh" #include #include @@ -134,6 +135,7 @@ dwarflint::check_registrar::list_checks () const { bool be_verbose = opt_list_checks.value () == "full"; checkdescriptors_t descriptors = get_descriptors (); + const size_t columns = 70; for (checkdescriptors_t::const_iterator it = descriptors.begin (); it != descriptors.end (); ++it) @@ -160,17 +162,17 @@ dwarflint::check_registrar::list_checks () const prereqs const &prereq = cd.prereq (); if (!prereq.empty ()) std::cout << "prerequisites: " << prereq << std::endl; + char const *desc = cd.description (); if (desc != NULL) - std::cout << desc; + std::cout << wrap_str (desc, columns).join (); options const &opts = cd.opts (); if (!opts.empty ()) { std::cout << "recognized options:" << std::endl; - for (options::const_iterator ot = opts.begin (); - ot != opts.end (); ++ot) - std::cout << " " << ot->second->format () << std::endl; + argp a = opts.build_argp (); + argp_help (&a, stdout, ARGP_HELP_LONG, NULL); } std::cout << std::endl; diff --git a/dwarflint/locstats.cc b/dwarflint/locstats.cc index 0fb40282a..7f7571d29 100644 --- a/dwarflint/locstats.cc +++ b/dwarflint/locstats.cc @@ -67,13 +67,13 @@ or special value 0.0 indicating cases with no coverage whatsoever \ .option (opt_dump) .option (opt_tabulation_rule) .description ( -"Computes a location info coverage statistics. Goes through the whole\n" -"DIE graph, looking at each variable and formal parameter, and\n" -"determining scope coverage of its location information. In other\n" -"words for how big a part of scope we know, where the variable\n" +"Computes a location info coverage statistics. Goes through the whole " +"DIE graph, looking at each variable and formal parameter, and " +"determining scope coverage of its location information. In other " +"words for how big a part of scope we know, where the variable " "\"lives\".\n" -" https://fedorahosted.org/pipermail/elfutils-devel/2010-July/001498.html\n" -" https://fedorahosted.org/pipermail/elfutils-devel/2010-September/001602.html\n")); +" - https://fedorahosted.org/pipermail/elfutils-devel/2010-July/001498.html\n" +" - https://fedorahosted.org/pipermail/elfutils-devel/2010-September/001602.html\n")); return &cd; } diff --git a/dwarflint/option.cc b/dwarflint/option.cc index 99cfd0f24..99277270e 100644 --- a/dwarflint/option.cc +++ b/dwarflint/option.cc @@ -209,44 +209,4 @@ option_common::option_common (char const *description, , _m_seen (false) {} -std::string -option_common::format () const -{ - std::string ret; - bool has_short = _m_opt.key < 127; - if (has_short) - { - char buf[3] = {}; - std::sprintf (buf, "-%c", _m_opt.key); - ret += buf; - } - - if (_m_opt.name != NULL) - { - if (has_short) - ret += ", "; - ret += "--"; - ret += _m_opt.name; - } - - if (_m_opt.arg != NULL) - { - bool optional = !!(_m_opt.flags & OPTION_ARG_OPTIONAL); - if (optional) - ret += '['; - ret += '='; - ret += _m_opt.arg; - if (optional) - ret += ']'; - } - - if (_m_opt.doc != NULL) - { - ret += "\t"; - ret += _m_opt.doc; - } - - return ret; -} - options global_opts; diff --git a/dwarflint/option.hh b/dwarflint/option.hh index 15a9bf463..45109a992 100644 --- a/dwarflint/option.hh +++ b/dwarflint/option.hh @@ -93,12 +93,12 @@ protected: static int get_short_option (char opt_short); public: + virtual ~option_i () {} + virtual bool seen () const = 0; virtual argp_option const &build_option () const = 0; virtual error_t parse_opt (char *arg, argp_state *state) = 0; virtual int key () const = 0; - virtual std::string format () const = 0; - virtual ~option_i () {} }; class option_common @@ -132,8 +132,6 @@ public: { return _m_opt.key; } - - std::string format () const; }; template