aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2025-03-14 00:32:49 -0400
committerSimon Marchi <simon.marchi@efficios.com>2025-03-14 12:23:40 -0400
commit8c6d5bcf9b83b2d8347238c456a9fef8fdd6bab8 (patch)
tree070dd702f852cacb65466cbd57424ccaf1414dfe
parent4fca47b93866f96db4723cc5f8570a66df9a7127 (diff)
downloadbinutils-8c6d5bcf9b83b2d8347238c456a9fef8fdd6bab8.zip
binutils-8c6d5bcf9b83b2d8347238c456a9fef8fdd6bab8.tar.gz
binutils-8c6d5bcf9b83b2d8347238c456a9fef8fdd6bab8.tar.bz2
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 <tom@tromey.com>
-rw-r--r--gdb/dwarf2/read.c32
-rw-r--r--gdb/dwarf2/read.h5
2 files changed, 22 insertions, 15 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index d656fbd..46114f0 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 29dcf18..2c88c0c 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. */