From: Roland McGrath Date: Tue, 27 Jan 2009 03:14:25 +0000 (-0800) Subject: Move class dwarf_output to new file, rename it dwarf_edit. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6355c5c2c166f80d7154b68708f607a221b0dded;p=thirdparty%2Felfutils.git Move class dwarf_output to new file, rename it dwarf_edit. --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 5fdf33f3a..a1f776a1f 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,9 @@ +2009-01-26 Roland McGrath + + * c++/dwarf (dwarf_output): Renamed to dwarf_edit and moved to ... + * c++/dwarf_edit: ... here. New file. + * Makefile.am (pkginclude_HEADERS): Add it. + 2009-01-10 Roland McGrath * c++/dwarf: New file. diff --git a/libdw/Makefile.am b/libdw/Makefile.am index 965ac22eb..daeeead1e 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -48,7 +48,7 @@ endif include_HEADERS = dwarf.h pkginclude_HEADERS = libdw.h \ - c++/dwarf + c++/dwarf c++/dwarf_edit libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \ dwarf_getpubnames.c dwarf_getabbrev.c dwarf_tag.c \ diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index 92fe17248..e7b36ad2e 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -138,6 +138,24 @@ The elfutils::dwarf_output containers are mutable, unlike the input classes. + ------ XXX to be done: more file-level containers + + input side only (?): + + aranges_by_unit : map + can compare range_list == cu.ranges () + only used for dwarflint, can be slow/copying + + units_by_addr : map, CU> and map + use dwarf_getarange_addr + + pub{names,types}_by_unit + + output too: + + pub{names,types}_by_name + too much lang knowledge to autogenerate for now, + output will do it explicitly */ // DWARF reader interfaces: front end to routines @@ -1560,22 +1578,6 @@ namespace elfutils return compile_units::compile_units (raw_compile_units ()); } - /* - raw CU: compile_unit or partial_unit, raw DIE children - logical CU: compile_unit, DIE children with imported_unit replaced - - containers/iterators: - raw CU in file order - XXX pubnames: list of (CU, DIE, FQ name string) - XXX aranges: list of (start, len, CU file offset) - XXX or aranges: list of (CU, range_list) - raw CU by addr (getarange_addr) - - logical CU in file order - logical CU by addr - - */ - private: ::Dwarf *_m_dw; @@ -1636,206 +1638,4 @@ namespace elfutils } }; -// DWARF writer interfaces (pure object construction) -// XXX probably move to separate file -namespace elfutils -{ - class dwarf_output - { - public: - class compile_units; - - // XXX later - class attr_value : public dwarf::attr_value - { - public: - attr_value (const dwarf::attr_value &v) : dwarf::attr_value (v) {} - }; - - class debug_info_entry - { - public: - - class children : public std::list - { - friend class debug_info_entry; - private: - children () {} - - template - children (const childrens &other) - : std::list (other.begin (), other.end ()) {} - }; - - class attributes : public std::map - { - friend class debug_info_entry; - private: - attributes () {} - - template - attributes (const attrs &other) - : std::map (other.begin (), other.end ()) {} - - public: - template - inline operator attrs () const - { - return attrs (begin (), end ()); - } - }; - - private: - const int _m_tag; - attributes _m_attributes; - children _m_children; - - public: - debug_info_entry (int t) : _m_tag (t) - { - if (unlikely (t <= 0)) - throw std::invalid_argument ("invalid tag"); - } - - /* The template constructor lets us copy in from any class that has - compatibly iterable containers for attributes and children. */ - template - debug_info_entry (const die &die) - : _m_tag (die.tag ()), - _m_attributes (die.attributes ()), - _m_children (die.children ()) - {} - - inline int tag () const - { - return _m_tag; - } - - inline bool has_children () const - { - return !_m_children.empty (); - } - - inline class children &children () - { - return _m_children; - } - inline const class children &children () const - { - return _m_children; - } - - inline class attributes &attributes () - { - return _m_attributes; - } - inline const class attributes &attributes () const - { - return _m_attributes; - } - - template - bool operator== (const die &other) const - { - return (other.attributes () == attributes () - && other.children () == children ()); - } - template - bool operator!= (const die &other) const - { - return !(*this == other);; - } - }; - - typedef debug_info_entry::attributes::value_type attribute; - - class compile_unit : public debug_info_entry - { - friend class compile_units; - private: - inline compile_unit () : debug_info_entry (::DW_TAG_compile_unit) {} - - // XXX should be private - public: - template - compile_unit (const die &die) : debug_info_entry (die) - { - if (die.tag () != ::DW_TAG_compile_unit) - throw std::invalid_argument ("not a compile_unit entry"); - } - - /* XXX doesn't help - public: - compile_unit (const compile_unit &u) : debug_info_entry (u) {} - */ - }; - - // Main container anchoring all the output. - class compile_units : public std::list - { - friend class dwarf_output; - private: - // Default constructor: an empty container, no CUs. - inline compile_units () {} - - // Constructor copying CUs from input container. - template - compile_units(const input &units) - : std::list (units.begin (), units.end ()) - {} - - public: - inline compile_unit &new_unit () - { - compile_unit nu; - push_back (nu); - return back (); - } - - template - bool operator== (const other_children &other) const - { - return std::equal (begin (), end (), other.begin ()); - } - template - bool operator!= (const other_children &other) const - { - return !(*this == other); - } - }; - - private: - compile_units _m_units; - - public: - class compile_units &compile_units () - { - return _m_units; - } - const class compile_units &compile_units () const - { - return _m_units; - } - - public: - // Default constructor: an empty container, no CUs. - inline dwarf_output () {} - - // Constructor copying CUs from an input file (dwarf or dwarf_output). - template - dwarf_output (const input &dw) : _m_units (dw.compile_units ()) {} - - template - inline bool operator== (const file &other) const - { - return compile_units () == other.compile_units (); - } - template - inline bool operator!= (const file &other) const - { - return !(*this == other); - } - }; -}; - #endif // diff --git a/libdw/c++/dwarf_edit b/libdw/c++/dwarf_edit new file mode 100644 index 000000000..3c8daf15c --- /dev/null +++ b/libdw/c++/dwarf_edit @@ -0,0 +1,256 @@ +/* -*- C++ -*- interfaces for libdw. + 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. + + In addition, as a special exception, Red Hat, Inc. gives You the + additional right to link the code of Red Hat elfutils with code licensed + under any Open Source Initiative certified open source license + (http://www.opensource.org/licenses/index.php) which requires the + distribution of source code with any binary distribution and to + distribute linked combinations of the two. Non-GPL Code permitted under + this exception must only link to the code of Red Hat elfutils through + those well defined interfaces identified in the file named EXCEPTION + found in the source code files (the "Approved Interfaces"). The files + of Non-GPL Code may instantiate templates or use macros or inline + functions from the Approved Interfaces without causing the resulting + work to be covered by the GNU General Public License. Only Red Hat, + Inc. may make changes or additions to the list of Approved Interfaces. + Red Hat's grant of this exception is conditioned upon your not adding + any new exceptions. If you wish to add a new Approved Interface or + exception, please contact Red Hat. You must obey the GNU General Public + License in all respects for all of the Red Hat elfutils code and other + code used in conjunction with Red Hat elfutils except the Non-GPL Code + covered by this exception. If you modify this file, you may extend this + exception to your version of the file, but you are not obligated to do + so. If you do not wish to provide this exception without modification, + you must delete this exception statement from your version and license + this file solely under the GPL without exception. + + 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 + . */ + +#ifndef _ELFUTILS_DWARF_EDIT +#define _ELFUTILS_DWARF_EDIT 1 + +#include "dwarf" + +// DWARF writer interfaces (pure object construction) +namespace elfutils +{ + class dwarf_edit + { + public: + class compile_units; + + // XXX later + class attr_value : public dwarf::attr_value + { + public: + attr_value (const dwarf::attr_value &v) : dwarf::attr_value (v) {} + }; + + class debug_info_entry + { + public: + + class children : public std::list + { + friend class debug_info_entry; + private: + children () {} + + template + children (const childrens &other) + : std::list (other.begin (), other.end ()) {} + }; + + class attributes : public std::map + { + friend class debug_info_entry; + private: + attributes () {} + + template + attributes (const attrs &other) + : std::map (other.begin (), other.end ()) {} + + public: + template + inline operator attrs () const + { + return attrs (begin (), end ()); + } + }; + + private: + const int _m_tag; + attributes _m_attributes; + children _m_children; + + public: + debug_info_entry (int t) : _m_tag (t) + { + if (unlikely (t <= 0)) + throw std::invalid_argument ("invalid tag"); + } + + /* The template constructor lets us copy in from any class that has + compatibly iterable containers for attributes and children. */ + template + debug_info_entry (const die &die) + : _m_tag (die.tag ()), + _m_attributes (die.attributes ()), + _m_children (die.children ()) + {} + + inline int tag () const + { + return _m_tag; + } + + inline bool has_children () const + { + return !_m_children.empty (); + } + + inline class children &children () + { + return _m_children; + } + inline const class children &children () const + { + return _m_children; + } + + inline class attributes &attributes () + { + return _m_attributes; + } + inline const class attributes &attributes () const + { + return _m_attributes; + } + + template + bool operator== (const die &other) const + { + return (other.attributes () == attributes () + && other.children () == children ()); + } + template + bool operator!= (const die &other) const + { + return !(*this == other);; + } + }; + + typedef debug_info_entry::attributes::value_type attribute; + + class compile_unit : public debug_info_entry + { + friend class compile_units; + private: + inline compile_unit () : debug_info_entry (::DW_TAG_compile_unit) {} + + // XXX should be private + public: + template + compile_unit (const die &die) : debug_info_entry (die) + { + if (die.tag () != ::DW_TAG_compile_unit) + throw std::invalid_argument ("not a compile_unit entry"); + } + + /* XXX doesn't help + public: + compile_unit (const compile_unit &u) : debug_info_entry (u) {} + */ + }; + + // Main container anchoring all the output. + class compile_units : public std::list + { + friend class dwarf_edit; + private: + // Default constructor: an empty container, no CUs. + inline compile_units () {} + + // Constructor copying CUs from input container. + template + compile_units(const input &units) + : std::list (units.begin (), units.end ()) + {} + + public: + inline compile_unit &new_unit () + { + compile_unit nu; + push_back (nu); + return back (); + } + + template + bool operator== (const other_children &other) const + { + return std::equal (begin (), end (), other.begin ()); + } + template + bool operator!= (const other_children &other) const + { + return !(*this == other); + } + }; + + private: + compile_units _m_units; + + public: + class compile_units &compile_units () + { + return _m_units; + } + const class compile_units &compile_units () const + { + return _m_units; + } + + public: + // Default constructor: an empty container, no CUs. + inline dwarf_edit () {} + + // Constructor copying CUs from an input file (dwarf or dwarf_edit). + template + dwarf_edit (const input &dw) : _m_units (dw.compile_units ()) {} + + template + inline bool operator== (const file &other) const + { + return compile_units () == other.compile_units (); + } + template + inline bool operator!= (const file &other) const + { + return !(*this == other); + } + }; +}; + +#endif // diff --git a/src/dwarfcmp.cc b/src/dwarfcmp.cc index 1bf342a90..522b719e2 100644 --- a/src/dwarfcmp.cc +++ b/src/dwarfcmp.cc @@ -44,6 +44,7 @@ #include "../libdw/libdwP.h" // XXX #include "c++/dwarf" +#include "c++/dwarf_edit" using namespace elfutils; using namespace std; @@ -312,8 +313,8 @@ main (int argc, char *argv[]) if (test_writer) { - dwarf_output out1 (file1); - dwarf_output out2 (file2); + dwarf_edit out1 (file1); + dwarf_edit out2 (file2); # define compare_self(x, y) \ assert (x == y); \