]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Drop WIPE, add more ctors throughout
authorPetr Machata <pmachata@redhat.com>
Wed, 13 Apr 2011 10:44:09 +0000 (12:44 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 13 Apr 2011 10:44:09 +0000 (12:44 +0200)
15 files changed:
dwarflint/addr-record.cc
dwarflint/addr-record.hh
dwarflint/check_debug_abbrev.cc
dwarflint/check_debug_abbrev.hh
dwarflint/check_debug_info.cc
dwarflint/check_debug_info.hh
dwarflint/check_debug_loc_range.cc
dwarflint/check_range_out_of_scope.cc
dwarflint/coverage.cc
dwarflint/elf_file.hh
dwarflint/messages.cc
dwarflint/misc.hh
dwarflint/reloc.cc
dwarflint/reloc.hh
dwarflint/sections.cc

index c2f68be1cb4a7b78e482edbe8f2e8568a0394693..2be2880346c2ec73d5bdb77832d174265d779cc8 100644 (file)
    <http://www.openinventionnetwork.com>.  */
 
 #include "addr-record.hh"
-#include "misc.hh"
 
 size_t
 addr_record_find_addr (struct addr_record *ar, uint64_t addr)
 {
   size_t a = 0;
-  size_t b = ar->size;
+  size_t b = ar->size ();
 
   while (a < b)
     {
       size_t i = (a + b) / 2;
-      uint64_t v = ar->addrs[i];
+      uint64_t v = (*ar)[i];
 
       if (v > addr)
        b = i;
@@ -51,33 +50,19 @@ addr_record_find_addr (struct addr_record *ar, uint64_t addr)
 bool
 addr_record_has_addr (struct addr_record *ar, uint64_t addr)
 {
-  if (ar->size == 0
-      || addr < ar->addrs[0]
-      || addr > ar->addrs[ar->size - 1])
+  if (ar->size () == 0
+      || addr < (*ar)[0]
+      || addr > (*ar)[ar->size () - 1])
     return false;
 
   size_t a = addr_record_find_addr (ar, addr);
-  return a < ar->size && ar->addrs[a] == addr;
+  return a < ar->size () && (*ar)[a] == addr;
 }
 
 void
 addr_record_add (struct addr_record *ar, uint64_t addr)
 {
   size_t a = addr_record_find_addr (ar, addr);
-  if (a >= ar->size || ar->addrs[a] != addr)
-    {
-      REALLOC (ar, addrs);
-      size_t len = ar->size - a;
-      memmove (ar->addrs + a + 1, ar->addrs + a, len * sizeof (*ar->addrs));
-
-      ar->addrs[a] = addr;
-      ar->size++;
-    }
-}
-
-void
-addr_record_free (struct addr_record *ar)
-{
-  if (ar != NULL)
-    free (ar->addrs);
+  if (a >= ar->size () || (*ar)[a] != addr)
+    ar->insert (ar->begin () + a, addr);
 }
index e22ae6500e01d41d79d57f10f8888d3d3f85b54f..b0be7a965aa92dd0c96c7973ce90c64ddaf77f02 100644 (file)
    interpretable as a DIE.  */
 
 struct addr_record
+  : std::vector<uint64_t>
 {
-  size_t size;
-  size_t alloc;
-  uint64_t *addrs;
+  typedef std::vector<uint64_t> _super_t;
+public:
+  using _super_t::const_iterator;
+  using _super_t::begin;
+  using _super_t::end;
+  using _super_t::push_back;
+  using _super_t::operator[];
+  using _super_t::size;
+  using _super_t::insert;
 };
 
 size_t addr_record_find_addr (struct addr_record *ar, uint64_t addr);
 bool addr_record_has_addr (struct addr_record *ar, uint64_t addr);
 void addr_record_add (struct addr_record *ar, uint64_t addr);
-void addr_record_free (struct addr_record *ar);
 
 /* Functions and data structures for reference handling.  Just like
    the above, we use this to check validity of DIE references.
index f7ae7d2ae1cdae09ec37a774aba136fa81c14cd1..a543e13299063aefdd5a513fbc58f27a9eba5828 100644 (file)
@@ -236,7 +236,6 @@ namespace
        if (section == NULL)
          {
            abbrev_table t;
-           WIPE (t);
            section = &abbrevs.insert (std::make_pair (abbr_off, t)).first->second;
            section->offset = abbr_off;
 
index c1cbc9359dd2fff7cb9b42005c7444a88f0f8382..6b25535c605184ea7015558b6652afb659e49f2b 100644 (file)
@@ -85,6 +85,15 @@ struct abbrev_table
   bool used;           /* There are CUs using this table.  */
 
   abbrev *find_abbrev (uint64_t abbrev_code) const;
+
+  abbrev_table ()
+    : next (NULL)
+    , abbr (NULL)
+    , offset (0)
+    , size (0)
+    , alloc (0)
+    , used (false)
+  {}
 };
 
 class check_debug_abbrev
index 2ee494c31c76f8db11d0e2928a31dfd1f1f3435c..04344851241458c2b27e7bc9a428498c43a1248d 100644 (file)
@@ -43,7 +43,6 @@
 #include "check_debug_info.hh"
 #include "check_debug_line.hh"
 #include "check_debug_aranges.hh"
-#include "misc.hh"
 
 checkdescriptor const *
 read_cu_headers::descriptor ()
@@ -895,7 +894,7 @@ namespace
            else
              {
                if (symbolp != NULL)
-                 WIPE (*symbolp);
+                 memset (*symbolp, 0, sizeof (**symbolp));
                if (type_is_rel
                    && (relocate == rel_require
                        || (relocate == rel_nonzero
@@ -1217,9 +1216,6 @@ check_debug_info::check_debug_info (checkstack &stack, dwarflint &lint)
 
 check_debug_info::~check_debug_info ()
 {
-  for (std::vector<cu>::iterator it = cus.begin ();
-       it != cus.end (); ++it)
-    addr_record_free (&it->die_addrs);
 }
 
 cu *
index d71f1a2a134edb501d886b9cb3c80f4a2934d998..b82b18f6c92dcc76bd3287e6108f1bf7754176db 100644 (file)
@@ -78,6 +78,16 @@ struct cu
   bool has_arange;              // Whether we saw arange section pointing at this CU.
   bool has_pubnames;            // Likewise for pubnames.
   bool has_pubtypes;            // Likewise for pubtypes.
+
+  cu ()
+    : next (NULL)
+    , head (NULL)
+    , cudie_offset (0)
+    , low_pc (0)
+    , has_arange (false)
+    , has_pubnames (false)
+    , has_pubtypes (false)
+  {}
 };
 
 /** The pass for reading basic .debug_info data -- the layout of
index 6719c3087da19dd97287054690dc907822791e41..153f427b1e38711e4758127dc94e9349b12d1690 100644 (file)
@@ -850,9 +850,7 @@ check_location_expression (dwarf_version const *ver,
     }
 
   ref_record oprefs;
-
-  struct addr_record opaddrs;
-  WIPE (opaddrs);
+  addr_record opaddrs;
 
   while (!read_ctx_eof (&ctx))
     {
@@ -940,13 +938,9 @@ check_location_expression (dwarf_version const *ver,
  out:
   for (ref_record::const_iterator it = oprefs.begin ();
        it != oprefs.end (); ++it)
-    {
-      if (!addr_record_has_addr (&opaddrs, it->addr))
-       wr_error (it->who) << "unresolved reference to opcode at "
-                          << pri::hex (it->addr) << ".\n";
-    }
-
-  addr_record_free (&opaddrs);
+    if (!addr_record_has_addr (&opaddrs, it->addr))
+      wr_error (it->who) << "unresolved reference to opcode at "
+                        << pri::hex (it->addr) << ".\n";
 
   return true;
 }
index c0312917af2d32d6a0ac4c7fe16fecae952f5260..57b96baf54b55c5993c546afecf378e6d20e4171 100644 (file)
@@ -31,7 +31,6 @@
 #include "coverage.hh"
 #include "pri.hh"
 #include "check_debug_loc_range.hh"
-#include "misc.hh"
 
 using elfutils::dwarf;
 
index 6d4109b963a4481bc9336fb91ce997866c4b5334..f9194057a7bb21c771665a256e89a457700063df 100644 (file)
@@ -29,7 +29,6 @@
 #endif
 
 #include "coverage.hh"
-#include "misc.hh"
 #include "pri.hh"
 
 #include <stdbool.h>
index d283e7877b764426edf7f3d8e72afa0581eb4593..e315247ec1cb7ed8eb1524918a7b262052f1f9fe 100644 (file)
@@ -1,5 +1,5 @@
 /* Pedantic checking of DWARF files.
-   Copyright (C) 2008, 2009, 2010 Red Hat, Inc.
+   Copyright (C) 2008, 2009, 2010, 2011 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -40,6 +40,13 @@ struct sec
   Elf_Data *data;      /* May be NULL if data in this section are
                           missing or not substantial.  */
   enum section_id id;
+
+  sec ()
+    : scn (NULL)
+    , name (NULL)
+    , data (NULL)
+    , id (sec_invalid)
+  {}
 };
 
 struct elf_file
index 7ea65d280e71198939db58b076f3bc0c9895c1e5..e7ea4a495e66fa930a4366db6dda6cc5689fc3ce 100644 (file)
@@ -24,7 +24,6 @@
    <http://www.openinventionnetwork.com>.  */
 
 #include "messages.hh"
-#include "misc.hh"
 #include "coverage.hh"
 #include "option.hh"
 
@@ -217,9 +216,7 @@ operator<< (std::ostream &o, __attribute__ ((unused)) message_criteria const &cr
 void
 message_criteria::operator *= (message_criteria const &rhs)
 {
-  struct message_criteria ret;
-  WIPE (ret);
-
+  message_criteria ret;
   for (size_t i = 0; i < size (); ++i)
     for (size_t j = 0; j < rhs.size (); ++j)
       {
index fac9526d260f074a8074bd1a757c9cae22bf8e98..c75ecde2424eeab5fb6e36596bb5bee40aa4c82e 100644 (file)
@@ -49,8 +49,6 @@ extern "C"
       }                                                        \
   } while (0)
 
-#define WIPE(OBJ) memset (&OBJ, 0, sizeof (OBJ))
-
 bool address_aligned (uint64_t addr, uint64_t align);
 bool necessary_alignment (uint64_t start, uint64_t length,
                          uint64_t align);
index e4a702254b38b80f235c28168ac26284ad76add1..602a6aa3f666c93a2787b04c707e465f74c4de94 100644 (file)
@@ -419,7 +419,7 @@ read_rel (struct elf_file *file,
 
       REALLOC (&sec->rel, rel);
       struct relocation *cur = sec->rel.rel + sec->rel.size++;
-      WIPE (*cur);
+      new (cur) relocation ();
 
       GElf_Rela rela_mem, *rela
        = get_rel_or_rela (reldata, i, &rela_mem, sec->rel.type);
index d7685c6fe67754c54120faf755dc67d8dc4c0d39..137642e53bfba98a8ffc10e52e59b8d2fcbcbdd1 100644 (file)
@@ -1,5 +1,5 @@
 /* Pedantic checking of DWARF files.
-   Copyright (C) 2008, 2009, 2010 Red Hat, Inc.
+   Copyright (C) 2008, 2009, 2010, 2011 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -40,6 +40,14 @@ struct relocation
   bool invalid;        /* Whether this one relocation should be
                   ignored.  Necessary so that we don't report
                   invalid & missing relocation twice.  */
+
+  relocation ()
+    : offset (0)
+    , addend (0)
+    , symndx (0)
+    , type (0)
+    , invalid (false)
+  {}
 };
 
 struct relocation_data
@@ -54,6 +62,15 @@ struct relocation_data
   size_t size;
   size_t alloc;
   size_t index;            /* Current index. */
+
+  relocation_data ()
+    : symdata (NULL)
+    , type (SHT_NULL)
+    , rel (NULL)
+    , size (0)
+    , alloc (0)
+    , index (0)
+  {}
 };
 
 enum skip_type
index 6f9f2546146c0f7e2977dde61b60a11aba867c07..7fd888dce45546c108cbd2f8c4871ad766b3c37d 100644 (file)
@@ -246,7 +246,7 @@ namespace
 
     /* Section 0 is special, skip it.  */
     REALLOC (file, sec);
-    file->sec[file->size++].id = sec_invalid;
+    new (file->sec + file->size++) sec ();
 
     if (false)
       {
@@ -266,6 +266,7 @@ namespace
        REALLOC (file, sec);
        size_t curndx = file->size++;
        struct sec *cursec = file->sec + curndx;
+       new (cursec) sec ();
 
        GElf_Shdr *shdr = gelf_getshdr (scn, &cursec->shdr);
        if (shdr == NULL)
@@ -285,9 +286,9 @@ namespace
 
        secentry *entry = secinfo.get (scnname);
        cursec->scn = scn;
-       cursec->id = entry != NULL ? entry->id : sec_invalid;
+       if (entry != NULL)
+         cursec->id = entry->id;
        cursec->name = scnname;
-       cursec->rel = (struct relocation_data){NULL, SHT_NULL, NULL, 0, 0, 0};
 
        /* Dwarf section.  */
        if (entry != NULL)