]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Report summary for sub-category of variables
authorDjordje Todorovic <djordje.todorovic@rt-rk.com>
Tue, 26 Sep 2017 13:33:13 +0000 (15:33 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 6 Oct 2017 19:38:48 +0000 (21:38 +0200)
Add new option --sub-category of locstats that reports
summary for either for local variables or formal parameters.

* dwarflint/locstats.cc: Handle the option.

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
dwarflint/locstats.cc

index 8a7802b69dc7e693f65ffb94502819107d22f3fa..411e06cd1d08375a8559914564c85bc2070addd6 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <sstream>
 #include <bitset>
+#include <string>
 #include <unistd.h>
 
 using elfutils::dwarf;
@@ -51,6 +52,11 @@ or special value 0.0 indicating cases with no coverage whatsoever \
 (i.e. not those that happen to round to 0%).",
    "start[:step][,...]", "tabulate");
 
+global_opt<string_option> opt_var_group
+  ("Report the summary for specific sub-category of variables, \
+group may be formal_parameters (function arguments) or variables (local variables).",
+ "group", "sub-category");
+
 // where.c needs to know how to format certain wheres.  The module
 // doesn't know that we don't use these :)
 extern "C"
@@ -295,6 +301,13 @@ is_inlined (dwarf::debug_info_entry const &die)
   return false;
 }
 
+typedef struct var_category
+{
+  std::string name;
+  bool local_var_in;
+  bool func_args_in;
+}Var_category;
+
 void
 process(Dwarf *c_dw, dwarf const &dw)
 {
@@ -309,6 +322,24 @@ process(Dwarf *c_dw, dwarf const &dw)
                       ? opt_tabulation_rule.value () : "10:10");
   die_type_matcher ignore (opt_ignore.seen () ? opt_ignore.value () : "");
   die_type_matcher dump (opt_dump.seen () ? opt_dump.value () : "");
+
+  Var_category vars;
+  vars.local_var_in = false;
+  vars.func_args_in = false;
+  vars.name = std::string (opt_var_group.seen() ?  opt_var_group.value() : "");
+
+  if (vars.name.compare("") != 0)
+  {
+       if (vars.name.compare("formal_parameters") == 0)
+                // We are interested only in formal parameters
+                vars.func_args_in = true;
+       else if (vars.name.compare("variables") == 0)
+                // We are interested only in variables
+                vars.local_var_in = true;
+       else
+                std::cerr << "Ignore unknown variables category" << std::endl;
+  }
+
   std::bitset<dt__count> interested = ignore | dump;
   bool interested_mutability
     = interested.test (dt_mutable) || interested.test (dt_immutable);
@@ -319,10 +350,24 @@ process(Dwarf *c_dw, dwarf const &dw)
       std::bitset<dt__count> die_type;
       dwarf::debug_info_entry const &die = *it;
 
-      // We are interested in variables and formal parameters
       bool is_formal_parameter = die.tag () == DW_TAG_formal_parameter;
-      if (!is_formal_parameter && die.tag () != DW_TAG_variable)
-       continue;
+      bool is_local_var = die.tag () == DW_TAG_variable;
+
+      // We are interested in variables and formal parameters,
+      // but if --sub-category option is set we choose one
+      // of these.
+      if (vars.func_args_in || vars.local_var_in)
+      {
+                if (vars.func_args_in && !is_formal_parameter)
+                       continue;
+                else if (vars.local_var_in && !is_local_var)
+                       continue;
+      }
+      else
+      {
+                if (!is_formal_parameter && !is_local_var)
+                       continue;
+      }
 
       dwarf::debug_info_entry::attributes_type const &attrs
        = die.attributes ();