[3/3] Change dwarf2_cu marking to use methods

Message ID 20210327195604.3371214-4-tom@tromey.com
State New
Headers show
Series
  • Move dwarf2_cu to its own file
Related show

Commit Message

Tom Tromey March 27, 2021, 7:56 p.m.
This changes the dwarf2_cu marking functions to be methods on
dwarf2_cu.

gdb/ChangeLog
2021-03-27  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (maybe_queue_comp_unit)
	(dwarf2_per_objfile::age_comp_units): Update.
	(dwarf2_add_dependence, dwarf2_mark_helper, dwarf2_mark): Move to
	dwarf2_cu methods.
	* dwarf2/cu.h (struct dwarf2_cu) <mark, clear_mark, is_marked,
	add_dependence>: New methods.
	<m_dependencies, m_mark>: Rename, adding "m_" prefix.
	* dwarf2/cu.c (dwarf2_cu::dwarf2_cu): Update.
	(dwarf2_mark_helper): New function.
	(dwarf2_cu::mark, dwarf2_cu::add_dependence): New methods.
---
 gdb/ChangeLog     | 13 ++++++++
 gdb/dwarf2/cu.c   | 52 ++++++++++++++++++++++++++++++-
 gdb/dwarf2/cu.h   | 22 +++++++++++--
 gdb/dwarf2/read.c | 78 +++--------------------------------------------
 4 files changed, 88 insertions(+), 77 deletions(-)

-- 
2.26.2

Comments

Mike Frysinger via Gdb-patches March 28, 2021, 3:24 p.m. | #1
> @@ -134,7 +152,7 @@ struct dwarf2_cu

>    /* A set of pointers to dwarf2_per_cu_data objects for compilation

>       units referenced by this one.  Only set during full symbol processing;

>       partial symbol tables do not have dependencies.  */

> -  htab_t dependencies = nullptr;

> +  htab_t m_dependencies = nullptr;


That can probably be moved to "private:".

The series LGTM, other than the concern I raised on patch 1, which is
really minor (and could be dealt with later).

Simon
Tom Tromey March 28, 2021, 5:47 p.m. | #2
>> @@ -134,7 +152,7 @@ struct dwarf2_cu

>> /* A set of pointers to dwarf2_per_cu_data objects for compilation

>> units referenced by this one.  Only set during full symbol processing;

>> partial symbol tables do not have dependencies.  */

>> -  htab_t dependencies = nullptr;

>> +  htab_t m_dependencies = nullptr;


Simon> That can probably be moved to "private:".

I made this change.

Simon> The series LGTM, other than the concern I raised on patch 1, which is
Simon> really minor (and could be dealt with later).

If we can think of a better name, it's simpler to do it now.
I will probably forget about it if we leave it.

Tom

Patch

diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index 4f13f4f9677..2451df4f5b6 100644
--- a/gdb/dwarf2/cu.c
+++ b/gdb/dwarf2/cu.c
@@ -27,7 +27,7 @@  dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu,
 		      dwarf2_per_objfile *per_objfile)
   : per_cu (per_cu),
     per_objfile (per_objfile),
-    mark (false),
+    m_mark (false),
     has_loclist (false),
     checked_producer (false),
     producer_is_gxx_lt_4_6 (false),
@@ -87,3 +87,53 @@  dwarf2_cu::addr_type () const
   addr_type = addr_sized_int_type (addr_type->is_unsigned ());
   return addr_type;
 }
+
+/* A hashtab traversal function that marks the dependent CUs.  */
+
+static int
+dwarf2_mark_helper (void **slot, void *data)
+{
+  dwarf2_per_cu_data *per_cu = (dwarf2_per_cu_data *) *slot;
+  dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) data;
+  dwarf2_cu *cu = per_objfile->get_cu (per_cu);
+
+  /* cu->m_dependencies references may not yet have been ever read if
+     QUIT aborts reading of the chain.  As such dependencies remain
+     valid it is not much useful to track and undo them during QUIT
+     cleanups.  */
+  if (cu != nullptr)
+    cu->mark ();
+  return 1;
+}
+
+/* See dwarf2/cu.h.  */
+
+void
+dwarf2_cu::mark ()
+{
+  if (!m_mark)
+    {
+      m_mark = true;
+      if (m_dependencies != nullptr)
+	htab_traverse (m_dependencies, dwarf2_mark_helper, per_objfile);
+    }
+}
+
+/* See dwarf2/cu.h.  */
+
+void
+dwarf2_cu::add_dependence (struct dwarf2_per_cu_data *ref_per_cu)
+{
+  void **slot;
+
+  if (m_dependencies == nullptr)
+    m_dependencies
+      = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
+			      NULL, &comp_unit_obstack,
+			      hashtab_obstack_allocate,
+			      dummy_obstack_deallocate);
+
+  slot = htab_find_slot (m_dependencies, ref_per_cu, INSERT);
+  if (*slot == nullptr)
+    *slot = ref_per_cu;
+}
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index 9fb2d61163a..e469c5881c3 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -78,6 +78,24 @@  struct dwarf2_cu
      the integer is unsigned or not.  */
   struct type *addr_sized_int_type (bool unsigned_p) const;
 
+  /* Mark this CU as used.  */
+  void mark ();
+
+  /* Clear the mark on this CU.  */
+  void clear_mark ()
+  {
+    m_mark = false;
+  }
+
+  /* True if this CU has been marked.  */
+  bool is_marked () const
+  {
+    return m_mark;
+  }
+
+  /* Add a dependence relationship from this cu to REF_PER_CU.  */
+  void add_dependence (struct dwarf2_per_cu_data *ref_per_cu);
+
   /* The header of the compilation unit.  */
   struct comp_unit_head header {};
 
@@ -134,7 +152,7 @@  struct dwarf2_cu
   /* A set of pointers to dwarf2_per_cu_data objects for compilation
      units referenced by this one.  Only set during full symbol processing;
      partial symbol tables do not have dependencies.  */
-  htab_t dependencies = nullptr;
+  htab_t m_dependencies = nullptr;
 
   /* Header data from the line table, during full symbol processing.  */
   struct line_header *line_header = nullptr;
@@ -221,7 +239,7 @@  struct dwarf2_cu
   gdb::optional<ULONGEST> str_offsets_base;
 
   /* Mark used when releasing cached dies.  */
-  bool mark : 1;
+  bool m_mark : 1;
 
   /* This CU references .debug_loc.  See the symtab->locations_valid field.
      This test is imperfect as there may exist optimized debug code not using
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index adb5442c9ab..f5a5db86b01 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1415,11 +1415,6 @@  static void process_full_comp_unit (dwarf2_cu *cu,
 static void process_full_type_unit (dwarf2_cu *cu,
 				    enum language pretend_language);
 
-static void dwarf2_add_dependence (struct dwarf2_cu *,
-				   struct dwarf2_per_cu_data *);
-
-static void dwarf2_mark (struct dwarf2_cu *);
-
 static struct type *get_die_type_at_offset (sect_offset,
 					    dwarf2_per_cu_data *per_cu,
 					    dwarf2_per_objfile *per_objfile);
@@ -8891,7 +8886,7 @@  maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu,
   /* Mark the dependence relation so that we don't flush PER_CU
      too early.  */
   if (dependent_cu != NULL)
-    dwarf2_add_dependence (dependent_cu, per_cu);
+    dependent_cu->add_dependence (per_cu);
 
   /* If it's already on the queue, we have nothing to do.  */
   if (per_cu->queued)
@@ -24852,7 +24847,7 @@  dwarf2_per_objfile::age_comp_units ()
 
   /* Start by clearing all marks.  */
   for (auto pair : m_dwarf2_cus)
-    pair.second->mark = false;
+    pair.second->clear_mark ();
 
   /* Traverse all CUs, mark them and their dependencies if used recently
      enough.  */
@@ -24862,7 +24857,7 @@  dwarf2_per_objfile::age_comp_units ()
 
       cu->last_used++;
       if (cu->last_used <= dwarf_max_cache_age)
-	dwarf2_mark (cu);
+	cu->mark ();
     }
 
   /* Delete all CUs still not marked.  */
@@ -24870,7 +24865,7 @@  dwarf2_per_objfile::age_comp_units ()
     {
       dwarf2_cu *cu = it->second;
 
-      if (!cu->mark)
+      if (!cu->is_marked ())
 	{
 	  dwarf_read_debug_printf_v ("deleting old CU %s",
 				     sect_offset_str (cu->per_cu->sect_off));
@@ -25071,71 +25066,6 @@  get_die_type (struct die_info *die, struct dwarf2_cu *cu)
   return get_die_type_at_offset (die->sect_off, cu->per_cu, cu->per_objfile);
 }
 
-/* Add a dependence relationship from CU to REF_PER_CU.  */
-
-static void
-dwarf2_add_dependence (struct dwarf2_cu *cu,
-		       struct dwarf2_per_cu_data *ref_per_cu)
-{
-  void **slot;
-
-  if (cu->dependencies == NULL)
-    cu->dependencies
-      = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
-			      NULL, &cu->comp_unit_obstack,
-			      hashtab_obstack_allocate,
-			      dummy_obstack_deallocate);
-
-  slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
-  if (*slot == NULL)
-    *slot = ref_per_cu;
-}
-
-/* Subroutine of dwarf2_mark to pass to htab_traverse.
-   Set the mark field in every compilation unit in the
-   cache that we must keep because we are keeping CU.
-
-   DATA is the dwarf2_per_objfile object in which to look up CUs.  */
-
-static int
-dwarf2_mark_helper (void **slot, void *data)
-{
-  dwarf2_per_cu_data *per_cu = (dwarf2_per_cu_data *) *slot;
-  dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) data;
-  dwarf2_cu *cu = per_objfile->get_cu (per_cu);
-
-  /* cu->dependencies references may not yet have been ever read if QUIT aborts
-     reading of the chain.  As such dependencies remain valid it is not much
-     useful to track and undo them during QUIT cleanups.  */
-  if (cu == nullptr)
-    return 1;
-
-  if (cu->mark)
-    return 1;
-
-  cu->mark = true;
-
-  if (cu->dependencies != nullptr)
-    htab_traverse (cu->dependencies, dwarf2_mark_helper, per_objfile);
-
-  return 1;
-}
-
-/* Set the mark field in CU and in every other compilation unit in the
-   cache that we must keep because we are keeping CU.  */
-
-static void
-dwarf2_mark (struct dwarf2_cu *cu)
-{
-  if (cu->mark)
-    return;
-
-  cu->mark = true;
-
-  if (cu->dependencies != nullptr)
-    htab_traverse (cu->dependencies, dwarf2_mark_helper, cu->per_objfile);
-}
-
 /* Trivial hash function for partial_die_info: the hash value of a DIE
    is its offset in .debug_info for this objfile.  */