From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id AED5D386CE43; Wed, 8 Jun 2022 17:11:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AED5D386CE43 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Change allocation of m_dwarf2_cus X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 2c3b9a91303097446d36107153ef1e588ec4f5ba X-Git-Newrev: d09ee622ee7fb4f64e9456c600874070ca21debf Message-Id: <20220608171138.AED5D386CE43@sourceware.org> Date: Wed, 8 Jun 2022 17:11:38 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 17:11:38 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd09ee622ee7f= b4f64e9456c600874070ca21debf commit d09ee622ee7fb4f64e9456c600874070ca21debf Author: Tom Tromey Date: Tue Jun 7 18:00:59 2022 -0600 Change allocation of m_dwarf2_cus =20 m_dwarf2_cus manually manages the 'dwarf2_cu' pointers it owns. This patch simplifies the code by changing it to use unique_ptr. Diff: --- gdb/dwarf2/read.c | 23 +++++++++-------------- gdb/dwarf2/read.h | 6 ++++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 848fd5627b8..d279e729db9 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1476,9 +1476,6 @@ dwarf2_per_objfile::remove_all_cus () { gdb_assert (!this->per_bfd->queue.has_value ()); =20 - for (auto pair : m_dwarf2_cus) - delete pair.second; - m_dwarf2_cus.clear (); } =20 @@ -6350,7 +6347,7 @@ cutu_reader::keep () /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it now. */ dwarf2_per_objfile *per_objfile =3D m_new_cu->per_objfile; - per_objfile->set_cu (m_this_cu, m_new_cu.release ()); + per_objfile->set_cu (m_this_cu, std::move (m_new_cu)); } } =20 @@ -23535,17 +23532,18 @@ dwarf2_per_objfile::get_cu (dwarf2_per_cu_data *p= er_cu) if (it =3D=3D m_dwarf2_cus.end ()) return nullptr; =20 - return it->second; + return it->second.get (); } =20 /* See read.h. */ =20 void -dwarf2_per_objfile::set_cu (dwarf2_per_cu_data *per_cu, dwarf2_cu *cu) +dwarf2_per_objfile::set_cu (dwarf2_per_cu_data *per_cu, + std::unique_ptr cu) { gdb_assert (this->get_cu (per_cu) =3D=3D nullptr); =20 - m_dwarf2_cus[per_cu] =3D cu; + m_dwarf2_cus[per_cu] =3D std::move (cu); } =20 /* See read.h. */ @@ -23563,14 +23561,14 @@ dwarf2_per_objfile::age_comp_units () gdb_assert (!this->per_bfd->queue.has_value ()); =20 /* Start by clearing all marks. */ - for (auto pair : m_dwarf2_cus) + for (const auto &pair : m_dwarf2_cus) pair.second->clear_mark (); =20 /* Traverse all CUs, mark them and their dependencies if used recently enough. */ - for (auto pair : m_dwarf2_cus) + for (const auto &pair : m_dwarf2_cus) { - dwarf2_cu *cu =3D pair.second; + dwarf2_cu *cu =3D pair.second.get (); =20 cu->last_used++; if (cu->last_used <=3D dwarf_max_cache_age) @@ -23580,13 +23578,12 @@ dwarf2_per_objfile::age_comp_units () /* Delete all CUs still not marked. */ for (auto it =3D m_dwarf2_cus.begin (); it !=3D m_dwarf2_cus.end ();) { - dwarf2_cu *cu =3D it->second; + dwarf2_cu *cu =3D it->second.get (); =20 if (!cu->is_marked ()) { dwarf_read_debug_printf_v ("deleting old CU %s", sect_offset_str (cu->per_cu->sect_off)); - delete cu; it =3D m_dwarf2_cus.erase (it); } else @@ -23603,8 +23600,6 @@ dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data *= per_cu) if (it =3D=3D m_dwarf2_cus.end ()) return; =20 - delete it->second; - m_dwarf2_cus.erase (it); } =20 diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index b58c574c2be..75dd38c0b73 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -28,6 +28,7 @@ #include "dwarf2/index-cache.h" #include "dwarf2/mapped-index.h" #include "dwarf2/section.h" +#include "dwarf2/cu.h" #include "filename-seen-cache.h" #include "gdbsupport/gdb_obstack.h" #include "gdbsupport/hash_enum.h" @@ -547,7 +548,7 @@ struct dwarf2_per_objfile dwarf2_cu *get_cu (dwarf2_per_cu_data *per_cu); =20 /* Set the dwarf2_cu matching PER_CU for this objfile. */ - void set_cu (dwarf2_per_cu_data *per_cu, dwarf2_cu *cu); + void set_cu (dwarf2_per_cu_data *per_cu, std::unique_ptr cu); =20 /* Remove/free the dwarf2_cu matching PER_CU for this objfile. */ void remove_cu (dwarf2_per_cu_data *per_cu); @@ -596,7 +597,8 @@ private: =20 /* Map from the objfile-independent dwarf2_per_cu_data instances to the corresponding objfile-dependent dwarf2_cu instances. */ - std::unordered_map m_dwarf2_cus; + std::unordered_map> m_dwarf2_cus; }; =20 /* Get the dwarf2_per_objfile associated to OBJFILE. */