From: Simon Marchi Date: Fri, 14 Mar 2025 04:32:49 +0000 (-0400) Subject: gdb/dwarf: remove cutu_reader::keep, add cutu_reader::release_cu X-Git-Tag: binutils-2_45~1180 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8c6d5bcf9b83b2d8347238c456a9fef8fdd6bab8;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: remove cutu_reader::keep, add cutu_reader::release_cu This is a bit subjective, but I often struggle to understand what cutu_reader::keep is meant to do (keep what, where). Perhaps it's just a question of bad naming, but I think it's a bit confusing for cutu_reader to transfer the ownership of the dwarf2_cu to the per_objfile directly. Add the cutu::release_cu method and make the caller of cutu_reader transfer the ownership to the per_objfile object. Right now, it is theoretically possible for release_cu to return nullptr, so I made callers check the return value. A patch later in this series will change release_cu to ensure it always return non-nullptr, so those callers will get simplified. Change-Id: I3103ff894d1654a95c9d69001073c218501c988a Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index d656fbd3fd3..46114f06aee 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3246,18 +3246,14 @@ cutu_reader::cutu_reader (dwarf2_per_cu *this_cu, prepare_one_comp_unit (cu, pretend_language); } -void -cutu_reader::keep () +/* See read.h. */ + +dwarf2_cu_up +cutu_reader::release_cu () { - /* Done, clean up. */ gdb_assert (!m_dummy_p); - if (m_new_cu != NULL) - { - /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it - now. */ - dwarf2_per_objfile *per_objfile = m_new_cu->per_objfile; - per_objfile->set_cu (m_this_cu, std::move (m_new_cu)); - } + + return std::move (m_new_cu); } /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name) @@ -4401,7 +4397,14 @@ load_full_comp_unit (dwarf2_per_cu *this_cu, return; reader.read_all_dies (); - reader.keep (); + + if (auto new_cu = reader.release_cu (); + new_cu != nullptr) + { + /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it + now. */ + per_objfile->set_cu (this_cu, std::move (new_cu)); + } } /* Add a DIE to the delayed physname list. */ @@ -19102,7 +19105,12 @@ read_signatured_type (signatured_type *sig_type, if (!reader.is_dummy ()) { reader.read_all_dies (); - reader.keep (); + + /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it + now. */ + dwarf2_cu_up new_cu = reader.release_cu (); + gdb_assert (new_cu != nullptr); + per_objfile->set_cu (sig_type, std::move (new_cu)); } sig_type->tu_read = 1; diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 29dcf182691..2c88c0c9788 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -941,9 +941,8 @@ public: const dwarf2_section_info *section () const { return m_die_section; } - /* Release the new CU, putting it on the chain. This cannot be done - for dummy CUs. */ - void keep (); + /* Release the CU created by this cutu_reader. */ + dwarf2_cu_up release_cu (); /* Release the abbrev table, transferring ownership to the caller. */