[2/3,gdb/symtab] Make cooked_index_entry::parent_entry private

Message ID 20240104141911.7596-3-tdevries@suse.de
State Superseded
Headers
Series Eliminate deferred_entry |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Tom de Vries Jan. 4, 2024, 2:19 p.m. UTC
  Make cooked_index_entry::parent_entry private, and add member functions to
access it.

Tested on x86_64-linux.
---
 gdb/dwarf2/cooked-index.c | 14 +++++++-------
 gdb/dwarf2/cooked-index.h | 25 +++++++++++++++++++------
 gdb/dwarf2/read.c         |  6 +++---
 3 files changed, 29 insertions(+), 16 deletions(-)
  

Comments

Alexandra Petlanova Hajkova Jan. 9, 2024, 11:49 a.m. UTC | #1
On Thu, Jan 4, 2024 at 3:19 PM Tom de Vries <tdevries@suse.de> wrote:

> Make cooked_index_entry::parent_entry private, and add member functions to
> access it.
>
> Tested on x86_64-linux.
> ---
>
>   I can confirm this change does not introduce any regressions on Fedora
> Rawhide, ppc64le.
  

Patch

diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index f9850d39bd0..307cfe74a87 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -186,7 +186,7 @@  cooked_index_entry::full_name (struct obstack *storage, bool for_main) const
 {
   const char *local_name = for_main ? name : canonical;
 
-  if ((flags & IS_LINKAGE) != 0 || parent_entry == nullptr)
+  if ((flags & IS_LINKAGE) != 0 || get_parent () == nullptr)
     return local_name;
 
   const char *sep = nullptr;
@@ -207,7 +207,7 @@  cooked_index_entry::full_name (struct obstack *storage, bool for_main) const
       return local_name;
     }
 
-  parent_entry->write_scope (storage, sep, for_main);
+  get_parent ()->write_scope (storage, sep, for_main);
   obstack_grow0 (storage, local_name, strlen (local_name));
   return (const char *) obstack_finish (storage);
 }
@@ -219,8 +219,8 @@  cooked_index_entry::write_scope (struct obstack *storage,
 				 const char *sep,
 				 bool for_main) const
 {
-  if (parent_entry != nullptr)
-    parent_entry->write_scope (storage, sep, for_main);
+  if (get_parent () != nullptr)
+    get_parent ()->write_scope (storage, sep, for_main);
   const char *local_name = for_main ? name : canonical;
   obstack_grow (storage, local_name, strlen (local_name));
   obstack_grow (storage, sep, strlen (sep));
@@ -299,7 +299,7 @@  cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
       parent = last;
     }
 
-  entry->parent_entry = parent;
+  entry->set_parent (parent);
   return make_unique_xstrndup (tail.data (), tail.length ());
 }
 
@@ -585,9 +585,9 @@  cooked_index::dump (gdbarch *arch) const
       gdb_printf ("    flags:      %s\n", to_string (entry->flags).c_str ());
       gdb_printf ("    DIE offset: %s\n", sect_offset_str (entry->die_offset));
 
-      if (entry->parent_entry != nullptr)
+      if (entry->get_parent () != nullptr)
 	gdb_printf ("    parent:     ((cooked_index_entry *) %p) [%s]\n",
-		    entry->parent_entry, entry->parent_entry->name);
+		    entry->get_parent (), entry->get_parent ()->name);
       else
 	gdb_printf ("    parent:     ((cooked_index_entry *) 0)\n");
 
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 452a07ffb80..2b2f2f79bab 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -84,8 +84,8 @@  struct cooked_index_entry : public allocate_on_obstack
       tag (tag_),
       flags (flags_),
       die_offset (die_offset_),
-      parent_entry (parent_entry_),
-      per_cu (per_cu_)
+      per_cu (per_cu_),
+      m_parent_entry (parent_entry_)
   {
   }
 
@@ -210,6 +210,18 @@  struct cooked_index_entry : public allocate_on_obstack
     return compare (canonical, other.canonical, SORT) < 0;
   }
 
+  /* Set parent entry to PARENT.  */
+  void set_parent (const cooked_index_entry *parent)
+  {
+    m_parent_entry = parent;
+  }
+
+  /* Return parent entry.  */
+  const cooked_index_entry *get_parent () const
+  {
+    return m_parent_entry;
+  }
+
   /* The name as it appears in DWARF.  This always points into one of
      the mapped DWARF sections.  Note that this may be the name or the
      linkage name -- two entries are created for DIEs which have both
@@ -224,10 +236,6 @@  struct cooked_index_entry : public allocate_on_obstack
   cooked_index_flag flags;
   /* The offset of this DIE.  */
   sect_offset die_offset;
-  /* The parent entry.  This is NULL for top-level entries.
-     Otherwise, it points to the parent entry, such as a namespace or
-     class.  */
-  const cooked_index_entry *parent_entry;
   /* The CU from which this entry originates.  */
   dwarf2_per_cu_data *per_cu;
 
@@ -238,6 +246,11 @@  struct cooked_index_entry : public allocate_on_obstack
      a parent, its write_scope method is called first.  */
   void write_scope (struct obstack *storage, const char *sep,
 		    bool for_name) const;
+
+  /* The parent entry.  This is NULL for top-level entries.
+     Otherwise, it points to the parent entry, such as a namespace or
+     class.  */
+  const cooked_index_entry *m_parent_entry;
 };
 
 class cooked_index;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 61646a5fba0..841746b7473 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16421,7 +16421,7 @@  cooked_indexer::index_dies (cutu_reader *reader,
       /* The scope of a DW_TAG_entry_point cooked_index_entry is the one of
 	 its surrounding subroutine.  */
       if (abbrev->tag == DW_TAG_entry_point)
-	this_parent_entry = parent_entry->parent_entry;
+	this_parent_entry = parent_entry->get_parent ();
       info_ptr = scan_attributes (reader->cu->per_cu, reader, info_ptr,
 				  info_ptr, abbrev, &name, &linkage_name,
 				  &flags, &sibling, &this_parent_entry,
@@ -16764,7 +16764,7 @@  cooked_index_functions::expand_symtabs_matching
 	     matches.  */
 	  bool found = true;
 
-	  const cooked_index_entry *parent = entry->parent_entry;
+	  const cooked_index_entry *parent = entry->get_parent ();
 	  for (int i = name_vec.size () - 1; i > 0; --i)
 	    {
 	      /* If we ran out of entries, or if this segment doesn't
@@ -16777,7 +16777,7 @@  cooked_index_functions::expand_symtabs_matching
 		  break;
 		}
 
-	      parent = parent->parent_entry;
+	      parent = parent->get_parent ();
 	    }
 
 	  if (!found)