From 882eda7c40ffcfbc9c15943f2aea09543dd2fe55 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sun, 16 Aug 2009 19:05:25 -0700 Subject: Fix copying vs destruction regression. --- libdw/c++/dwarf_data | 51 +++++++++++++++++++++++++++++--------------------- libdw/c++/dwarf_output | 18 ++++++++++++------ 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/libdw/c++/dwarf_data b/libdw/c++/dwarf_data index 2a2dead8..005fc5dc 100644 --- a/libdw/c++/dwarf_data +++ b/libdw/c++/dwarf_data @@ -141,6 +141,15 @@ namespace elfutils require_cu (cu), arg) {} + /* Assignment details are up to the base class. + We just ensure it's really a compile_unit. */ + inline compile_unit & + operator= (const typename impl::debug_info_entry &other) + { + impl::debug_info_entry::operator= (require_cu (other)); + return *this; + } + // Fetch the CU's DW_AT_stmt_list. inline const typename impl::line_info_table &line_info () const { @@ -1200,15 +1209,25 @@ namespace elfutils return vw::variant (p, _m_value); } + template + inline attr_value © (const value &other) + { + if (_m_value != NULL) + { + delete _m_value; + _m_value = NULL; + } + init me (this, 0, other); + return *this; + } + public: -#if 0 // XXX attr_value (const attr_value &other) : _m_value (NULL) { if (other._m_value != NULL) init me (this, 0, other); } -#endif inline attr_value () : _m_value (NULL) @@ -1220,29 +1239,19 @@ namespace elfutils delete _m_value; } -#if 0 // XXX - inline attr_value &operator= (const attr_value &other) - { - if (_m_value != NULL) - { - delete _m_value; - _m_value = NULL; - } - init me (this, 0, other); - return *this; - } template inline attr_value &operator= (const value &other) { - if (_m_value != NULL) - { - delete _m_value; - _m_value = NULL; - } - init me (this, 0, other); - return *this; + return copy (other); + } + + /* This is the same as the generic template one, + but we have to define it explicitly to override + the default assignment operator. */ + inline attr_value &operator= (const attr_value &other) + { + return copy (other); } -#endif dwarf::value_space what_space () const; inline std::string to_string () const; diff --git a/libdw/c++/dwarf_output b/libdw/c++/dwarf_output index db4587d1..b03dbd48 100644 --- a/libdw/c++/dwarf_output +++ b/libdw/c++/dwarf_output @@ -1877,7 +1877,7 @@ namespace elfutils /* Complain if we still have dangling references. If not, it should be impossible to have pending entries left. */ - inline void demand_complete () const + inline die_info_pair *final () const { assert (_m_out == NULL); if (unlikely (_m_in->_m_final == NULL)) @@ -1888,6 +1888,7 @@ namespace elfutils ("compile_unit contains dangling reference attributes"); } assert (_m_copier->_m_defined == _m_copier->_m_seen.size ()); + return _m_in->_m_final; } // We're adding a reference attribute inside populate, above. @@ -1945,6 +1946,15 @@ namespace elfutils } }; + struct unit_copier : public entry_copier + { + inline unit_copier (copier *c, const typename dw::compile_unit &in) + : entry_copier (c, 0, c->enter_seen (in), in) + { + populate (in); + } + }; + /* Create a whole CU in the output. */ inline void @@ -1953,11 +1963,7 @@ namespace elfutils { typename tracker::walk into (_m_tracker, in, out); - entry_copier maker (this, 0, enter_seen (*in), *in); - maker.populate (*in); - - dump_seen (); - maker.demand_complete (); + *out = unit_copier (this, *in).final ()->first; } typedef std::tr1::unordered_map< ::Dwarf_Off, seen> seen_map; -- cgit v1.2.1