]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Use pri::hex where possible
authorPetr Machata <pmachata@redhat.com>
Wed, 4 Nov 2009 14:11:18 +0000 (15:11 +0100)
committerPetr Machata <pmachata@redhat.com>
Wed, 18 Aug 2010 12:55:12 +0000 (14:55 +0200)
* Change pri::addr to be trivial subclass of pri::hex

src/dwarflint/check_debug_abbrev.cc
src/dwarflint/check_debug_line.cc
src/dwarflint/pri.cc
src/dwarflint/pri.hh

index 46e8751e90c2f3d6d45481674a0f54c2f78a8042..3aadd1d37d93c419fbdc8121bc0e5f2800aafe49 100644 (file)
@@ -28,7 +28,7 @@
 #endif
 
 #include "checks-low.hh"
-#include "dwarfstrings.h"
+#include "pri.hh"
 
 #include <dwarf.h>
 #include <sstream>
@@ -119,6 +119,16 @@ namespace
       return a.code < b.code;
     }
   };
+
+  void
+  complain_invalid_form (where const &where, int name, int form,
+                        std::string const &specification = "")
+  {
+    wr_error (where)
+      << specification << (" "[specification == ""])
+      << pri::attr (name) << " with invalid form "
+      << pri::form (form) << '.' << std::endl;
+  }
 }
 
 check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
@@ -243,9 +253,9 @@ check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
 
       if (abbr_tag > DW_TAG_hi_user)
        {
-         std::stringstream ss;
-         ss << ": invalid abbrev tag 0x" << std::hex << abbr_tag << '.';
-         wr_error (&where, "%s\n", ss.str ().c_str ());
+         wr_error (where)
+           << "invalid abbrev tag " << pri::hex (abbr_tag)
+           << '.' << std::endl;
          throw check_base::failed ();
        }
       cur->tag = (typeof (cur->tag))abbr_tag;
@@ -261,8 +271,9 @@ check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
       if (has_children != DW_CHILDREN_no
          && has_children != DW_CHILDREN_yes)
        {
-         wr_error (&where,
-                   ": invalid has_children value 0x%x.\n", cur->has_children);
+         wr_error (where)
+           << "invalid has_children value " << pri::hex (cur->has_children)
+           << '.' << std::endl;
          throw check_base::failed ();
        }
       cur->has_children = has_children == DW_CHILDREN_yes;
@@ -298,17 +309,17 @@ check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
              /* Otherwise validate name and form.  */
              if (attrib_name > DW_AT_hi_user)
                {
-                 std::stringstream ss;
-                 ss << ": invalid name 0x" << std::hex << attrib_name << '.';
-                 wr_error (&where, "%s\n", ss.str ().c_str ());
+                 wr_error (where)
+                   << "invalid name " << pri::hex (attrib_name)
+                   << '.' << std::endl;
                  throw check_base::failed ();
                }
 
              if (!attrib_form_valid (attrib_form))
                {
-                 std::stringstream ss;
-                 ss << ": invalid form 0x" << std::hex << attrib_form << '.';
-                 wr_error (&where, "%s\n", ss.str ().c_str ());
+                 wr_error (where)
+                   << "invalid form " << pri::hex (attrib_form)
+                   << '.' << std::endl;
                  throw check_base::failed ();
                }
            }
@@ -326,44 +337,42 @@ check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
          if (attrib_name == DW_AT_sibling)
            {
              if (sibling_attr != 0)
-               {
-                 std::stringstream ss;
-                 ss << ": Another DW_AT_sibling attribute in one abbreviation. "
-                    << "(First was 0x" << std::hex << sibling_attr << ".)";
-                 wr_error (&where, "%s\n", ss.str ().c_str ());
-               }
+               wr_error (where)
+                 << "another DW_AT_sibling attribute in one abbreviation "
+                 << "(first was " << pri::hex (sibling_attr) << ")."
+                 << std::endl;
              else
                {
                  assert (attr_off > 0);
                  sibling_attr = attr_off;
 
                  if (!cur->has_children)
-                   wr_message (mc_die_rel | mc_acc_bloat | mc_impact_1,
-                               &where,
-                               ": Excessive DW_AT_sibling attribute at childless abbrev.\n");
+                   wr_message (where,
+                               cat (mc_die_rel, mc_acc_bloat, mc_impact_1))
+                     << "excessive DW_AT_sibling attribute at childless abbrev."
+                     << std::endl;
                }
 
              switch (check_sibling_form (attrib_form))
                {
                case -1:
-                 wr_message (mc_die_rel | mc_impact_2, &where,
-                             ": DW_AT_sibling attribute with form DW_FORM_ref_addr.\n");
+                 wr_message (where, cat (mc_die_rel, mc_impact_2))
+                   << "DW_AT_sibling attribute with form DW_FORM_ref_addr."
+                   << std::endl;
                  break;
 
                case -2:
-                 wr_error (&where,
-                           ": DW_AT_sibling attribute with non-reference form \"%s\".\n",
-                           dwarf_form_string (attrib_form));
+                 wr_error (where)
+                   << "DW_AT_sibling attribute with non-reference form "
+                   << pri::form (attrib_form) << '.' << std::endl;
                };
            }
          /* Similar for DW_AT_location and friends.  */
          else if (is_location_attrib (attrib_name))
            {
              if (!check_abbrev_location_form (attrib_form))
-               wr_error (&where,
-                         ": location attribute %s with invalid form \"%s\".\n",
-                         dwarf_attr_string (attrib_name),
-                         dwarf_form_string (attrib_form));
+               complain_invalid_form (where, attrib_name, attrib_form,
+                                      "location attribute");
            }
          /* Similar for DW_AT_ranges.  */
          else if (attrib_name == DW_AT_ranges
@@ -373,10 +382,7 @@ check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
                  && attrib_form != DW_FORM_data8
                  && attrib_form != DW_FORM_sec_offset
                  && attrib_form != DW_FORM_indirect)
-               wr_error (&where,
-                         ": %s with invalid form \"%s\".\n",
-                         dwarf_attr_string (attrib_name),
-                         dwarf_form_string (attrib_form));
+               complain_invalid_form (where, attrib_name, attrib_form);
              if (attrib_name == DW_AT_ranges)
                ranges = true;
            }
@@ -387,10 +393,7 @@ check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
            {
              if (attrib_form != DW_FORM_addr
                  && attrib_form != DW_FORM_ref_addr)
-               wr_error (&where,
-                         ": %s with invalid form \"%s\".\n",
-                         dwarf_attr_string (attrib_name),
-                         dwarf_form_string (attrib_form));
+               complain_invalid_form (where, attrib_name, attrib_form);
 
              if (attrib_name == DW_AT_low_pc)
                low_pc = true;
@@ -406,13 +409,13 @@ check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
 
       where_reset_2 (&where, where.addr2); // drop addr 3
       if (high_pc && !low_pc)
-       wr_error (&where,
-                 ": the abbrev has DW_AT_high_pc"
-                 " without also having DW_AT_low_pc.\n");
+       wr_error (where)
+         << "the abbrev has DW_AT_high_pc without also having DW_AT_low_pc."
+         << std::endl;
       else if (high_pc && ranges)
-       wr_error (&where,
-                 ": the abbrev has DW_AT_high_pc & DW_AT_low_pc,"
-                 " but also has DW_AT_ranges.\n");
+       wr_error (where)
+         << "the abbrev has DW_AT_high_pc & DW_AT_low_pc, "
+         << "but also has DW_AT_ranges." << std::endl;
     }
 
   abbrev_table *last = NULL;
index 838bf11cb9f3933596f58482f8359ec858e203fa..b976a6cea2f5b669d108bc5f3db196bfd71d937a 100644 (file)
@@ -52,8 +52,8 @@ namespace
              struct ref *ref = it->line_refs.refs + i;
              if (!addr_record_has_addr (&line_tables, ref->addr))
                wr_error (ref->who)
-                 << "unresolved reference to .debug_line table "
-                 << "0x" << std::hex << ref->addr << "." << std::endl;
+                 << "unresolved reference to .debug_line table "
+                 << pri::hex (ref->addr) << '.' << std::endl;
            }
       addr_record_free (&line_tables);
     }
index cd39829110ad0d6b402251d59353440a58fd1ebd..f69307b9a655de2529d9ad4720e215cf9485265a 100644 (file)
@@ -6,6 +6,10 @@ pri::attr::attr (int attr_name)
   : pribase (dwarf_attr_string (attr_name))
 {}
 
+pri::form::form (int attr_form)
+  : pribase (dwarf_form_string (attr_form))
+{}
+
 std::ostream &
 pri::operator << (std::ostream &os, pri::pribase const &obj)
 {
@@ -21,10 +25,10 @@ pri::operator << (std::ostream &os, pri::ref const &obj)
 }
 
 std::ostream &
-pri::operator << (std::ostream &os, pri::addr const &obj)
+pri::operator << (std::ostream &os, pri::hex const &obj)
 {
   std::stringstream ss;
-  ss << std::hex << "0x" << obj.off;
+  ss << std::hex << "0x" << obj.value;
   return os << ss.str ();
 }
 
index 5914db4d1be41d9ac7c7a6c6b3f32899d182a5f5..b4ef54df1e7fda7277648dc9b3a93c38521b5ac2 100644 (file)
@@ -44,6 +44,12 @@ namespace pri
     attr (int attr_name);
   };
 
+  struct form
+    : public pribase
+  {
+    form (int attr_form);
+  };
+
   class ref
   {
     Dwarf_Off off;
@@ -56,16 +62,20 @@ namespace pri
   };
   std::ostream &operator << (std::ostream &os, ref const &obj);
 
-  class addr
+  class hex
   {
-    Dwarf_Off off;
+    Dwarf_Off value;
   public:
-    addr (Dwarf_Off a_off)
-      : off (a_off)
+    hex (Dwarf_Off a_value)
+      : value (a_value)
     {}
-    friend std::ostream &operator << (std::ostream &os, addr const &obj);
+    friend std::ostream &operator << (std::ostream &os, hex const &obj);
+  };
+  std::ostream &operator << (std::ostream &os, hex const &obj);
+
+  struct addr : public hex {
+    addr (Dwarf_Off off) : hex (off) {}
   };
-  std::ostream &operator << (std::ostream &os, addr const &obj);
 
   class range
   {