Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/3] gdb/symtab: make compunit_symtab::includes a std::vector
Date: Thu, 29 Jan 2026 21:55:27 -0500	[thread overview]
Message-ID: <20260130025546.322629-2-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260130025546.322629-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@efficios.com>

Since compunit_symtab is now a properly constructed and destructed
object, we can use fancy C++ things in it.  Change the includes field to
be an std::vector.

Previously, the includes list was NULL-terminated.  I went through all
users and I'm pretty sure that none of them rely on it being
NULL-terminated anymore.

Change-Id: Ie68a8dc0f227fd49c291d85c3e8e020463e9d0d4
---
 gdb/block.c       | 11 +++++++++--
 gdb/dwarf2/read.c | 37 +++++++++----------------------------
 gdb/symmisc.c     | 42 ++++++++++++++----------------------------
 gdb/symtab.h      |  5 ++---
 4 files changed, 34 insertions(+), 61 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index fa2246383d1e..e61122410650 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -426,7 +426,7 @@ initialize_block_iterator (const struct block *block,
      functions.  If there are no included symtabs, we only need to
      search a single block, so we might as well just do that
      directly.  */
-  if (cu->includes == NULL)
+  if (cu->includes.empty ())
     {
       iter->d.block = block;
       /* A signal value meaning that we're iterating over a single
@@ -447,7 +447,14 @@ block_iterator::compunit_symtab () const
 {
   if (this->idx == -1)
     return this->d.compunit_symtab;
-  return this->d.compunit_symtab->includes[this->idx];
+
+  auto &includes = this->d.compunit_symtab->includes;
+
+  if (this->idx < includes.size ())
+    return includes[this->idx];
+
+  /* Iteration is complete.  */
+  return nullptr;
 }
 
 /* Perform a single step for a plain block iterator, iterating across
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 036ec7e6337f..94fa3919b885 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2117,24 +2117,16 @@ static struct compunit_symtab *
 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust,
 					  CORE_ADDR pc)
 {
-  int i;
-
   if (cust->blockvector () != nullptr && cust->blockvector ()->contains (pc))
     return cust;
 
-  if (cust->includes == NULL)
-    return NULL;
-
-  for (i = 0; cust->includes[i]; ++i)
-    {
-      struct compunit_symtab *s = cust->includes[i];
-
-      s = recursively_find_pc_sect_compunit_symtab (s, pc);
-      if (s != NULL)
-	return s;
-    }
+  for (compunit_symtab *include : cust->includes)
+    if (compunit_symtab *found
+	  = recursively_find_pc_sect_compunit_symtab (include, pc);
+	found != nullptr)
+      return found;
 
-  return NULL;
+  return nullptr;
 }
 
 struct compunit_symtab *
@@ -4744,8 +4736,8 @@ recursively_compute_inclusions
 				    cust);
 }
 
-/* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
-   PER_CU.  */
+/* Compute compunit_symtab::includes for the compunit_symtab of PER_CU.  This
+   is the transitive closure of all the included compunit_symtabs.  */
 
 static void
 compute_compunit_symtab_includes (dwarf2_per_cu *per_cu,
@@ -4755,8 +4747,6 @@ compute_compunit_symtab_includes (dwarf2_per_cu *per_cu,
 
   if (!per_cu->imported_symtabs.empty ())
     {
-      int len;
-      std::vector<compunit_symtab *> result_symtabs;
       compunit_symtab *cust = per_objfile->get_symtab (per_cu);
 
       /* If we don't have a symtab, we can just skip this case.  */
@@ -4767,18 +4757,9 @@ compute_compunit_symtab_includes (dwarf2_per_cu *per_cu,
       gdb::unordered_set<compunit_symtab *> all_type_symtabs;
 
       for (dwarf2_per_cu *ptr : per_cu->imported_symtabs)
-	recursively_compute_inclusions (&result_symtabs, all_children,
+	recursively_compute_inclusions (&cust->includes, all_children,
 					all_type_symtabs, ptr,
 					per_objfile, cust);
-
-      /* Now we have a transitive closure of all the included symtabs.  */
-      len = result_symtabs.size ();
-      cust->includes
-	= XOBNEWVEC (&per_objfile->objfile->objfile_obstack,
-		     struct compunit_symtab *, len + 1);
-      memcpy (cust->includes, result_symtabs.data (),
-	      len * sizeof (compunit_symtab *));
-      cust->includes[len] = NULL;
     }
 }
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 838c2a002e15..258489fe8f07 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -362,21 +362,13 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
       struct compunit_symtab *cust = symtab->compunit ();
 
       if (cust->user != nullptr)
-	{
-	  const char *addr
-	    = host_address_to_string (cust->user->primary_filetab ());
-	  gdb_printf (outfile, _("Compunit user: %s\n"), addr);
-	}
-      if (cust->includes != nullptr)
-	for (int i = 0; ; ++i)
-	  {
-	    struct compunit_symtab *include = cust->includes[i];
-	    if (include == nullptr)
-	      break;
-	    const char *addr
-	      = host_address_to_string (include->primary_filetab ());
-	    gdb_printf (outfile, _("Compunit include: %s\n"), addr);
-	  }
+	gdb_printf (outfile, _("Compunit user: %s\n"),
+		    host_address_to_string (cust->user->primary_filetab ()));
+
+
+      for (compunit_symtab *include : cust->includes)
+	gdb_printf (outfile, _("Compunit include: %s\n"),
+		    host_address_to_string (include->primary_filetab ()));
     }
 }
 
@@ -816,21 +808,15 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
 				    cust.user != nullptr
 				    ? host_address_to_string (cust.user)
 				    : "(null)");
-			if (cust.includes != nullptr)
+			if (!cust.includes.empty ())
 			  {
 			    gdb_printf (_("    ( includes\n"));
-			    for (int i = 0; ; ++i)
-			      {
-				struct compunit_symtab *include
-				  = cust.includes[i];
-				if (include == nullptr)
-				  break;
-				const char *addr
-				  = host_address_to_string (include);
-				gdb_printf ("      (%s %s)\n",
-					    "(struct compunit_symtab *)",
-					    addr);
-			      }
+
+			    for (compunit_symtab *include : cust.includes)
+			      gdb_printf ("      (%s %s)\n",
+					  "(struct compunit_symtab *)",
+					  host_address_to_string (include));
+
 			    gdb_printf ("    )\n");
 			  }
 			printed_compunit_symtab_start = 1;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 6a1320aabad8..8f0cc728410d 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2008,14 +2008,13 @@ struct compunit_symtab : intrusive_list_node<compunit_symtab>
      the given compilation unit, but it currently is.  */
   struct macro_table *m_macro_table = nullptr;
 
-  /* If non-NULL, then this points to a NULL-terminated vector of
-     included compunits.  When searching the static or global
+  /* Vector of included compunit symtabs.  When searching the static or global
      block of this compunit, the corresponding block of all
      included compunits will also be searched.  Note that this
      list must be flattened -- the symbol reader is responsible for
      ensuring that this vector contains the transitive closure of all
      included compunits.  */
-  struct compunit_symtab **includes = nullptr;
+  std::vector<compunit_symtab *> includes;
 
   /* If this is an included compunit, this points to one includer
      of the table.  This user is considered the canonical compunit
-- 
2.52.0


  reply	other threads:[~2026-01-30  2:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30  2:55 [PATCH 1/3] gdb/block: make find_iterator_compunit_symtab a method of block_iterator simon.marchi
2026-01-30  2:55 ` simon.marchi [this message]
2026-02-05 18:38   ` [PATCH 2/3] gdb/symtab: make compunit_symtab::includes a std::vector Tom Tromey
2026-01-30  2:55 ` [PATCH 3/3] gdb/block: bool-ify some parameters simon.marchi
2026-02-03 17:36   ` [PATCH] gdb/dwarf2: don't search included symtabs recursively Simon Marchi
2026-02-05 18:53     ` Tom Tromey
2026-02-05 19:36       ` Simon Marchi
2026-02-05 18:38   ` [PATCH 3/3] gdb/block: bool-ify some parameters Tom Tromey
2026-02-05 17:41 ` [PATCH 1/3] gdb/block: make find_iterator_compunit_symtab a method of block_iterator Tom Tromey
2026-02-05 19:33   ` Simon Marchi
2026-02-05 18:46 ` Tom Tromey
2026-02-05 19:17   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260130025546.322629-2-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox