[2/3] gdb/dwarf: move cooked_index_storage method implementations to cooked-index.c

Message ID 20250306174143.53657-2-simon.marchi@polymtl.ca
State New
Headers
Series [1/3] gdb/dwarf: move cutu_reader to read.h |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Simon Marchi March 6, 2025, 5:41 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

Since the cooked_index_storage class is declared in cooked-index.h, move
its method implementations to cooked-index.c.

Change-Id: I2a07eb446d8a07b15c5664dfe01e3a820cdd45be
---
 gdb/dwarf2/cooked-index.c | 56 +++++++++++++++++++++++++++++++++++++++
 gdb/dwarf2/read.c         | 49 ----------------------------------
 2 files changed, 56 insertions(+), 49 deletions(-)
  

Comments

Tom Tromey March 6, 2025, 8:14 p.m. UTC | #1
>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes:

Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
Simon> Since the cooked_index_storage class is declared in cooked-index.h, move
Simon> its method implementations to cooked-index.c.

This looks good.  I'd even support new separate .[ch] files for this
class and I suppose various others.

Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Simon Marchi March 6, 2025, 8:18 p.m. UTC | #2
On 2025-03-06 15:14, Tom Tromey wrote:
>>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes:
> 
> Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
> Simon> Since the cooked_index_storage class is declared in cooked-index.h, move
> Simon> its method implementations to cooked-index.c.
> 
> This looks good.  I'd even support new separate .[ch] files for this
> class and I suppose various others.

I can do that.  I would split cooked-index.c, but I think you are
working on that file at the moment, so I'll wait.

Simon
  
Tom Tromey March 6, 2025, 9:14 p.m. UTC | #3
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> I can do that.  I would split cooked-index.c, but I think you are
Simon> working on that file at the moment, so I'll wait.

Yeah.  And maybe some stuff there should logically be clumped together.
I see the shards as kind of a detail of the index data structure as a
whole.

Tom
  

Patch

diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index bbe14adcd56e..b88bba7d820b 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -500,6 +500,62 @@  cooked_index_shard::find (const std::string &name, bool completing) const
 
 /* See cooked-index.h.  */
 
+cooked_index_storage::cooked_index_storage ()
+  : m_reader_hash (htab_create_alloc (10, hash_cutu_reader,
+				      eq_cutu_reader,
+				      htab_delete_entry<cutu_reader>,
+				      xcalloc, xfree)),
+    m_shard (new cooked_index_shard)
+{
+}
+
+/* See cooked-index.h.  */
+
+cutu_reader *
+cooked_index_storage::get_reader (dwarf2_per_cu *per_cu)
+{
+  int index = per_cu->index;
+  return (cutu_reader *) htab_find_with_hash (m_reader_hash.get (),
+					      &index, index);
+}
+
+/* See cooked-index.h.  */
+
+cutu_reader *
+cooked_index_storage::preserve (cutu_reader_up reader)
+{
+  m_abbrev_table_cache.add (reader->release_abbrev_table ());
+
+  int index = reader->cu ()->per_cu->index;
+  void **slot = htab_find_slot_with_hash (m_reader_hash.get (), &index,
+					  index, INSERT);
+  gdb_assert (*slot == nullptr);
+  cutu_reader *result = reader.get ();
+  *slot = reader.release ();
+  return result;
+}
+
+/* See cooked-index.h.  */
+
+hashval_t
+cooked_index_storage::hash_cutu_reader (const void *a)
+{
+  const cutu_reader *reader = (const cutu_reader *) a;
+  return reader->cu ()->per_cu->index;
+}
+
+/* See cooked-index.h.  */
+
+int
+cooked_index_storage::eq_cutu_reader (const void *a, const void *b)
+{
+  const cutu_reader *ra = (const cutu_reader *) a;
+  const int *rb = (const int *) b;
+  return ra->cu ()->per_cu->index == *rb;
+}
+
+/* See cooked-index.h.  */
+
 void
 cooked_index_worker::start ()
 {
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ccf532009686..cb805c1c5dc4 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -3501,55 +3501,6 @@  get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list)
   gdb_assert (tu_group != nullptr);
   return tu_group;
 }
-
-
-cooked_index_storage::cooked_index_storage ()
-  : m_reader_hash (htab_create_alloc (10, hash_cutu_reader,
-				      eq_cutu_reader,
-				      htab_delete_entry<cutu_reader>,
-				      xcalloc, xfree)),
-    m_shard (new cooked_index_shard)
-{
-}
-
-cutu_reader *
-cooked_index_storage::get_reader (dwarf2_per_cu *per_cu)
-{
-  int index = per_cu->index;
-  return (cutu_reader *) htab_find_with_hash (m_reader_hash.get (),
-					      &index, index);
-}
-
-cutu_reader *
-cooked_index_storage::preserve (cutu_reader_up reader)
-{
-  m_abbrev_table_cache.add (reader->release_abbrev_table ());
-
-  int index = reader->cu ()->per_cu->index;
-  void **slot = htab_find_slot_with_hash (m_reader_hash.get (), &index,
-					  index, INSERT);
-  gdb_assert (*slot == nullptr);
-  cutu_reader *result = reader.get ();
-  *slot = reader.release ();
-  return result;
-}
-
-/* Hash function for a cutu_reader.  */
-hashval_t
-cooked_index_storage::hash_cutu_reader (const void *a)
-{
-  const cutu_reader *reader = (const cutu_reader *) a;
-  return reader->cu ()->per_cu->index;
-}
-
-/* Equality function for cutu_reader.  */
-int
-cooked_index_storage::eq_cutu_reader (const void *a, const void *b)
-{
-  const cutu_reader *ra = (const cutu_reader *) a;
-  const int *rb = (const int *) b;
-  return ra->cu ()->per_cu->index == *rb;
-}
 
 /* An instance of this is created to index a CU.  */