]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Merge roland/dwarf-collector, fiddle constructors more. roland/dwarf_edit
authorRoland McGrath <roland@redhat.com>
Thu, 2 Jul 2009 07:57:27 +0000 (00:57 -0700)
committerRoland McGrath <roland@redhat.com>
Thu, 2 Jul 2009 07:57:27 +0000 (00:57 -0700)
1  2 
libdw/c++/dwarf_data
libdw/c++/dwarf_edit
libdw/c++/dwarf_output
tests/dwarf_edit.cc

index 1f92fddf81f62f0b620d501ded3eac155a299622,423028f2c6e16bdd241c19a01d80dd959aaeaa6f..6d039009e0bdbb55b78db6aa5386df167c3719f8
@@@ -673,11 -651,12 +673,11 @@@ namespace elfutil
    public:
      struct nothing {};
  
-     template<typename impl, typename constructor_arg_type>
+     template<typename impl>
      struct value
      {
 -      class value_dispatch
 +      struct value_dispatch
        {
 -      public:
        virtual ~value_dispatch () {}
        };
  
  
        struct value_string : public value_dispatch, public std::string
        {
-       template<typename string>
-       inline value_string (const string &s, const constructor_arg_type &arg)
 +      inline value_string () {}
 +
+       template<typename string, typename arg_type>
+       inline value_string (const string &s, const arg_type &arg)
          : std::string (s)
        {}
  
        {
        bool flag;
  
-       inline value_flag (bool t, const constructor_arg_type &arg)
 +      inline value_flag ()
 +        : flag (true)
 +      {}
 +
+       template<typename arg_type>
+       inline value_flag (bool t, const arg_type &arg)
          : flag (t)
        {}
        };
        // XXX dwfl, reloc
        ::Dwarf_Addr addr;
  
-       inline value_address (::Dwarf_Addr a, const constructor_arg_type &arg)
-         : addr (a)
 +      inline value_address ()
 +        : addr (0)
 +      {}
 +
+       template<typename arg_type>
+       inline value_address (::Dwarf_Addr x, const arg_type &arg)
+         : addr (x)
        {}
        };
  
        struct value_rangelistptr : public value_dispatch, public range_list
        {
-       inline value_rangelistptr ()
-       {}
++      inline value_rangelistptr () {}
 +
-       template<typename list>
-       inline value_rangelistptr (const list &other,
-                                  const constructor_arg_type &arg)
+       template<typename list, typename arg_type>
+       inline value_rangelistptr (const list &other, const arg_type &arg)
          : range_list (other)
        {}
        };
  
        struct value_lineptr : public value_dispatch, public impl::line_info_table
        {
-       inline value_lineptr ()
-       {}
++      inline value_lineptr () {}
 +
-       template<typename table>
-       inline value_lineptr (const table &other,
-                             const constructor_arg_type &arg)
+       template<typename table, typename arg_type>
+       inline value_lineptr (const table &other, const arg_type &arg)
          : impl::line_info_table (other)
        {}
        };
          ::Dwarf_Sword sword;
        };
  
-       inline value_constant (::Dwarf_Word x, const constructor_arg_type &arg)
 +      inline value_constant ()
 +        : word (0)
 +      {}
 +
+       template<typename arg_type>
+       inline value_constant (::Dwarf_Word x, const arg_type &arg)
          : word (x)
        {}
        };
        struct value_constant_block : public value_dispatch,
                                    public std::vector<uint8_t>
        {
-       template<typename block>
-       inline value_constant_block (const block &b,
-                                    const constructor_arg_type &arg)
 +      inline value_constant_block () {}
 +
+       template<typename block, typename arg_type>
+       inline value_constant_block (const block &b, const arg_type &arg)
          : std::vector<uint8_t> (b.begin (), b.end ())
        {}
        };
  
        struct value_dwarf_constant : public value_dispatch, public dwarf_enum
        {
-       template<typename constant>
-       inline value_dwarf_constant (const constant &other,
-                                    const constructor_arg_type &arg)
-         : dwarf_enum (other) {}
 +      inline value_dwarf_constant () {}
 +
+       template<typename constant, typename arg_type>
+       inline value_dwarf_constant (const constant &other, const arg_type &arg)
+         : dwarf_enum (other)
+       {}
        };
  
        struct value_source_file : public value_dispatch, public source_file
        {
-       inline value_source_file ()
-       {}
++      inline value_source_file () {}
 +
-       template<typename file>
-       inline value_source_file (const file &other,
-                                 const constructor_arg_type &arg)
-         : source_file (other) {}
+       template<typename file, typename arg_type>
+       inline value_source_file (const file &other, const arg_type &arg)
+         : source_file (other)
+       {}
        };
  
        struct value_source_line : public value_dispatch
        {
        unsigned int n;
  
-       inline value_source_line (unsigned int m,
-                                 const constructor_arg_type &arg)
 +      inline value_source_line ()
 +        : n (0)
 +      {}
 +
+       template<typename arg_type>
+       inline value_source_line (unsigned int m, const arg_type &arg)
          : n (m)
        {}
        };
  
        struct value_location : public value_dispatch, public location_attr
        {
-       inline value_location ()
-       {}
++      inline value_location () {}
 +
-       template<typename loc>
-       inline value_location (const loc &other,
-                              const constructor_arg_type &arg)
+       template<typename loc, typename arg_type>
+       inline value_location (const loc &other, const arg_type &arg)
          : location_attr (other)
        {}
        };
      private:
        typename vw::value_dispatch *_m_value;
  
-       template<typename value>
-       inline void init (const value &other,
-                       const constructor_arg_type &arg
-                       = constructor_arg_type ())
 -      template<typename value, typename arg_type>
 -      inline void init (const value &other, const arg_type &arg)
++      template<typename value, typename arg_type = nothing>
++      struct init
        {
--      switch (other.what_space ())
--        {
--#define _DWARF_DATA_AV_MAKE(flavor, fetch)                                  \
--        case dwarf::VS_##flavor:                                            \
--          {                                                                 \
--            typename vw::value_##flavor *p;                                 \
--            _m_value = vw::make (p, other.fetch (), arg);                   \
--          }                                                                 \
--          break
--
--        _DWARF_DATA_AV_MAKE (identifier, identifier);
--        _DWARF_DATA_AV_MAKE (string, string);
--        _DWARF_DATA_AV_MAKE (flag, flag);
--        _DWARF_DATA_AV_MAKE (rangelistptr, ranges);
--        _DWARF_DATA_AV_MAKE (lineptr, line_info);
--        _DWARF_DATA_AV_MAKE (address, address);
--        _DWARF_DATA_AV_MAKE (source_line, source_line);
--        _DWARF_DATA_AV_MAKE (source_file, source_file);
--        _DWARF_DATA_AV_MAKE (dwarf_constant, dwarf_constant);
--        _DWARF_DATA_AV_MAKE (reference, reference);
--        _DWARF_DATA_AV_MAKE (unit_reference, unit_reference);
--        _DWARF_DATA_AV_MAKE (location, location);
--        //_DWARF_DATA_AV_MAKE (macptr, macros);       XXX
--
--        case dwarf::VS_constant:
--          if (other.constant_is_integer ())
--            {
--              typename vw::value_constant *p;
--              _m_value = vw::make (p, other.constant (), arg);
--            }
--          else
--            {
--              typename vw::value_constant_block *p;
--              _m_value = vw::make (p, other.constant_block (), arg);
--            }
--          break;
--
--        default:
--        case dwarf::VS_discr_list:
--          throw std::runtime_error ("XXX unimplemented");
++      inline init (attr_value *av,
++                   const value &other, const arg_type &arg = arg_type ())
++      {
++        switch (other.what_space ())
++          {
++#define _DWARF_DATA_AV_MAKE(flavor, fetch)                            \
++            case dwarf::VS_##flavor:                                  \
++              {                                                       \
++                typename vw::value_##flavor *p;                       \
++                av->_m_value = vw::make (p, other.fetch (), arg);     \
++              }                                                       \
++            break
++
++            _DWARF_DATA_AV_MAKE (identifier, identifier);
++            _DWARF_DATA_AV_MAKE (string, string);
++            _DWARF_DATA_AV_MAKE (flag, flag);
++            _DWARF_DATA_AV_MAKE (rangelistptr, ranges);
++            _DWARF_DATA_AV_MAKE (lineptr, line_info);
++            _DWARF_DATA_AV_MAKE (address, address);
++            _DWARF_DATA_AV_MAKE (source_line, source_line);
++            _DWARF_DATA_AV_MAKE (source_file, source_file);
++            _DWARF_DATA_AV_MAKE (dwarf_constant, dwarf_constant);
++            _DWARF_DATA_AV_MAKE (reference, reference);
++            _DWARF_DATA_AV_MAKE (unit_reference, unit_reference);
++            _DWARF_DATA_AV_MAKE (location, location);
++            //_DWARF_DATA_AV_MAKE (macptr, macros);   XXX
++
++          case dwarf::VS_constant:
++            if (other.constant_is_integer ())
++              {
++                typename vw::value_constant *p;
++                av->_m_value = vw::make (p, other.constant (), arg);
++              }
++            else
++              {
++                typename vw::value_constant_block *p;
++                av->_m_value = vw::make (p, other.constant_block (), arg);
++              }
++            break;
++
++          default:
++          case dwarf::VS_discr_list:
++            throw std::runtime_error ("XXX unimplemented");
  
  #undef _DWARF_DATA_AV_MAKE
--        }
--      }
++          }
++      }
++      };
  
        template<typename flavor>
 -      inline flavor &variant () const
 +      inline flavor &const_variant () const
        {
        flavor *p = dynamic_cast<flavor *> (_m_value);
        if (p == NULL)
        attr_value (const attr_value &other)
        : _m_value (NULL)
        {
 -      init (other);
 +      if (other._m_value != NULL)
-         init (other);
++        init<attr_value> me (this, other);
        }
 -      */
  
-       template<typename value>
-       attr_value (const value &other, const constructor_arg_type &arg)
+       template<typename value, typename arg_type>
+       attr_value (const value &other, const arg_type &arg)
        : _m_value (NULL)
        {
--      init (other, arg);
++      init<value, arg_type> me (this, other, arg);
        }
  
        inline attr_value ()
            delete _m_value;
            _m_value = NULL;
          }
--      init (other);
++      init<attr_value> me (this, other);
        return *this;
        }
        template<typename value>
            delete _m_value;
            _m_value = NULL;
          }
--      init (other);
++      init<value> me (this, other);
        return *this;
        }
  
Simple merge
index 65bff72f7e42e340b735e3cc914e72fd6a62da12,255afa27c06c32a3dacb7cb7ce1d2dd3ec2ec995..ff2621ba5ef6db7bc428f1a12c417b48aac48a8f
@@@ -327,6 -328,6 +328,28 @@@ namespace elfutil
          return result;
        }
        };
++
++      template<typename flavor, typename input>
++      static inline value_dispatch *
++      make (flavor *&result, const input &x, const dwarf_data::nothing &)
++      {
++      throw std::logic_error ("dwarf_output cannot be default-constructed");
++      }
++
++      template<typename flavor, typename input, typename arg_type>
++      static inline value_dispatch *
++      make (flavor *&result, const input &x, const arg_type &arg)
++      {
++      return result = new flavor (x, arg);
++      }
++
++      template<typename input>
++      static inline value_dispatch *
++      make (value_string *&result, const input &x, dwarf_output_collector *c)
++      {
++      return result = new value_string (x, c);
++      }
++
      };
  
    public:
index 7c4b3ecf75a03f7f8e2f31baac422eed537f2818,0000000000000000000000000000000000000000..35e6b1c205d86c99c7d143333424749a33fcaf0e
mode 100644,000000..100644
--- /dev/null
@@@ -1,65 -1,0 +1,68 @@@
-   cu.add_entry (DW_TAG_subprogram)
-     .attributes ()[DW_AT_name].identifier () = "foo";
 +/* Test program for elfutils::dwarf_edit basics.
 +   Copyright (C) 2009 Red Hat, Inc.
 +   This file is part of Red Hat elfutils.
 +
 +   Red Hat elfutils is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by the
 +   Free Software Foundation; version 2 of the License.
 +
 +   Red Hat elfutils is distributed in the hope that it will be useful, but
 +   WITHOUT ANY WARRANTY; without even the implied warranty of
 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 +   General Public License for more details.
 +
 +   You should have received a copy of the GNU General Public License along
 +   with Red Hat elfutils; if not, write to the Free Software Foundation,
 +   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
 +
 +   Red Hat elfutils is an included package of the Open Invention Network.
 +   An included package of the Open Invention Network is a package for which
 +   Open Invention Network licensees cross-license their patents.  No patent
 +   license is granted, either expressly or impliedly, by designation as an
 +   included package.  Should you wish to participate in the Open Invention
 +   Network licensing program, please visit www.openinventionnetwork.com
 +   <http://www.openinventionnetwork.com>.  */
 +
 +#ifdef HAVE_CONFIG_H
 +# include <config.h>
 +#endif
 +
 +#include <errno.h>
 +#include <error.h>
 +#include <fcntl.h>
 +#include <clocale>
 +#include <cstdio>
 +#include <libintl.h>
 +#include <ostream>
 +#include <iomanip>
 +
 +#include "c++/dwarf_edit"
 +
 +using namespace elfutils;
 +using namespace std;
 +
 +#include "print-die.hh"
 +
 +
 +int
 +main (int argc, char **argv)
 +{
 +  unsigned int depth;
 +  print_die_main (argc, argv, depth);
 +
 +  dwarf_edit f;
 +
 +  dwarf_edit::compile_unit &cu = f.add_unit ();
 +
 +  cu.attributes ()[DW_AT_name].source_file () = "source-file.c";
 +
++  dwarf_edit::debug_info_entry &ent = cu.add_entry (DW_TAG_subprogram);
++
++  ent.attributes ()[DW_AT_name].identifier () = "foo";
++
++  ent.attributes ()[DW_AT_description] = ent.attributes ()[DW_AT_name];
 +
 +  print_file ("consed", f, depth);
 +
 +  return 0;
 +}