From: Roland McGrath Date: Thu, 2 Jul 2009 07:57:27 +0000 (-0700) Subject: Merge roland/dwarf-collector, fiddle constructors more. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f3eb01147ecd46d5519ba4a49d1d085468372dc;p=thirdparty%2Felfutils.git Merge roland/dwarf-collector, fiddle constructors more. --- 6f3eb01147ecd46d5519ba4a49d1d085468372dc diff --cc libdw/c++/dwarf_data index 1f92fddf8,423028f2c..6d039009e --- a/libdw/c++/dwarf_data +++ b/libdw/c++/dwarf_data @@@ -673,11 -651,12 +673,11 @@@ namespace elfutil public: struct nothing {}; - template + template struct value { - class value_dispatch + struct value_dispatch { - public: virtual ~value_dispatch () {} }; @@@ -690,10 -669,8 +690,10 @@@ struct value_string : public value_dispatch, public std::string { + inline value_string () {} + - template - inline value_string (const string &s, const constructor_arg_type &arg) + template + inline value_string (const string &s, const arg_type &arg) : std::string (s) {} @@@ -748,11 -728,8 +751,12 @@@ { bool flag; + inline value_flag () + : flag (true) + {} + - inline value_flag (bool t, const constructor_arg_type &arg) + template + inline value_flag (bool t, const arg_type &arg) : flag (t) {} }; @@@ -762,35 -739,24 +766,32 @@@ // XXX dwfl, reloc ::Dwarf_Addr addr; + inline value_address () + : addr (0) + {} + - inline value_address (::Dwarf_Addr a, const constructor_arg_type &arg) - : addr (a) + template + 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 - inline value_rangelistptr (const list &other, - const constructor_arg_type &arg) + template + 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 - inline value_lineptr (const table &other, - const constructor_arg_type &arg) + template + inline value_lineptr (const table &other, const arg_type &arg) : impl::line_info_table (other) {} }; @@@ -803,11 -769,8 +804,12 @@@ ::Dwarf_Sword sword; }; + inline value_constant () + : word (0) + {} + - inline value_constant (::Dwarf_Word x, const constructor_arg_type &arg) + template + inline value_constant (::Dwarf_Word x, const arg_type &arg) : word (x) {} }; @@@ -815,46 -778,34 +817,44 @@@ struct value_constant_block : public value_dispatch, public std::vector { + inline value_constant_block () {} + - template - inline value_constant_block (const block &b, - const constructor_arg_type &arg) + template + inline value_constant_block (const block &b, const arg_type &arg) : std::vector (b.begin (), b.end ()) {} }; struct value_dwarf_constant : public value_dispatch, public dwarf_enum { + inline value_dwarf_constant () {} + - template - inline value_dwarf_constant (const constant &other, - const constructor_arg_type &arg) - : dwarf_enum (other) {} + template + 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 - inline value_source_file (const file &other, - const constructor_arg_type &arg) - : source_file (other) {} + template + 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 () + : n (0) + {} + - inline value_source_line (unsigned int m, - const constructor_arg_type &arg) + template + inline value_source_line (unsigned int m, const arg_type &arg) : n (m) {} }; @@@ -864,12 -815,8 +864,10 @@@ struct value_location : public value_dispatch, public location_attr { - inline value_location () - {} ++ inline value_location () {} + - template - inline value_location (const loc &other, - const constructor_arg_type &arg) + template + inline value_location (const loc &other, const arg_type &arg) : location_attr (other) {} }; @@@ -884,58 -828,56 +879,60 @@@ private: typename vw::value_dispatch *_m_value; - template - inline void init (const value &other, - const constructor_arg_type &arg - = constructor_arg_type ()) - template - inline void init (const value &other, const arg_type &arg) ++ template ++ 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 - inline flavor &variant () const + inline flavor &const_variant () const { flavor *p = dynamic_cast (_m_value); if (p == NULL) @@@ -961,15 -889,16 +958,15 @@@ attr_value (const attr_value &other) : _m_value (NULL) { - init (other); + if (other._m_value != NULL) - init (other); ++ init me (this, other); } - */ - template - attr_value (const value &other, const constructor_arg_type &arg) + template + attr_value (const value &other, const arg_type &arg) : _m_value (NULL) { -- init (other, arg); ++ init me (this, other, arg); } inline attr_value () @@@ -989,7 -918,7 +986,7 @@@ delete _m_value; _m_value = NULL; } -- init (other); ++ init me (this, other); return *this; } template @@@ -1000,7 -929,7 +997,7 @@@ delete _m_value; _m_value = NULL; } -- init (other); ++ init me (this, other); return *this; } diff --cc libdw/c++/dwarf_output index 65bff72f7,255afa27c..ff2621ba5 --- a/libdw/c++/dwarf_output +++ b/libdw/c++/dwarf_output @@@ -327,6 -328,6 +328,28 @@@ namespace elfutil return result; } }; ++ ++ template ++ 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 ++ static inline value_dispatch * ++ make (flavor *&result, const input &x, const arg_type &arg) ++ { ++ return result = new flavor (x, arg); ++ } ++ ++ template ++ static inline value_dispatch * ++ make (value_string *&result, const input &x, dwarf_output_collector *c) ++ { ++ return result = new value_string (x, c); ++ } ++ }; public: diff --cc tests/dwarf_edit.cc index 7c4b3ecf7,000000000..35e6b1c20 mode 100644,000000..100644 --- a/tests/dwarf_edit.cc +++ b/tests/dwarf_edit.cc @@@ -1,65 -1,0 +1,68 @@@ +/* 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 + . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#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"; + - cu.add_entry (DW_TAG_subprogram) - .attributes ()[DW_AT_name].identifier () = "foo"; ++ 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; +}