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;
}
--- /dev/null
- 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;
+}