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 1/3] gdb/block: make find_iterator_compunit_symtab a method of block_iterator
Date: Thu, 29 Jan 2026 21:55:26 -0500	[thread overview]
Message-ID: <20260130025546.322629-1-simon.marchi@polymtl.ca> (raw)

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

I noticed some code in bkscm_print_block_syms_progress_smob peeking a
bit in the implementation details of block_iterator, and doing
essentially the same thing as the existing static function
find_iterator_compunit_symtab.

Change find_iterator_compunit_symtab to become
block_iterator::compunit_symtab, and use it in
bkscm_print_block_syms_progress_smob.

Change-Id: I344a2155a2edb5d278e98684c71f1ee161e8d1d4
---
 gdb/block.c           | 19 ++++++++-----------
 gdb/block.h           |  4 ++++
 gdb/guile/scm-block.c |  7 ++-----
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index 0ee29d9e3f26..fa2246383d1e 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -440,15 +440,14 @@ initialize_block_iterator (const struct block *block,
     }
 }
 
-/* A helper function that finds the current compunit over whose static
-   or global block we should iterate.  */
+/* See block.h.  */
 
-static struct compunit_symtab *
-find_iterator_compunit_symtab (struct block_iterator *iterator)
+compunit_symtab *
+block_iterator::compunit_symtab () const
 {
-  if (iterator->idx == -1)
-    return iterator->d.compunit_symtab;
-  return iterator->d.compunit_symtab->includes[iterator->idx];
+  if (this->idx == -1)
+    return this->d.compunit_symtab;
+  return this->d.compunit_symtab->includes[this->idx];
 }
 
 /* Perform a single step for a plain block iterator, iterating across
@@ -466,8 +465,7 @@ block_iterator_step (struct block_iterator *iterator, int first)
     {
       if (first)
 	{
-	  struct compunit_symtab *cust
-	    = find_iterator_compunit_symtab (iterator);
+	  compunit_symtab *cust = iterator->compunit_symtab ();
 	  const struct block *block;
 
 	  /* Iteration is complete.  */
@@ -508,8 +506,7 @@ block_iter_match_step (struct block_iterator *iterator,
     {
       if (first)
 	{
-	  struct compunit_symtab *cust
-	    = find_iterator_compunit_symtab (iterator);
+	  compunit_symtab *cust = iterator->compunit_symtab ();
 	  const struct block *block;
 
 	  /* Iteration is complete.  */
diff --git a/gdb/block.h b/gdb/block.h
index c3d060af92fb..535db5ced51d 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -553,6 +553,10 @@ extern const struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *);
 
 struct block_iterator
 {
+/* Return the compunit over whose static or global block the iterator currently
+   iterates.  Return nullptr is the iteration is finished.  */
+  struct compunit_symtab *compunit_symtab () const;
+
   /* If we're iterating over a single block, this holds the block.
      Otherwise, it holds the canonical compunit.  */
 
diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index c1edd2b5782a..5db73ec917e1 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -535,16 +535,13 @@ bkscm_print_block_syms_progress_smob (SCM self, SCM port,
 	case GLOBAL_BLOCK:
 	case STATIC_BLOCK:
 	  {
-	    struct compunit_symtab *cust;
-
 	    gdbscm_printf (port, " %s",
 			   i_smob->iter.which == GLOBAL_BLOCK
 			   ? "global" : "static");
 	    if (i_smob->iter.idx != -1)
 	      gdbscm_printf (port, " @%d", i_smob->iter.idx);
-	    cust = (i_smob->iter.idx == -1
-		    ? i_smob->iter.d.compunit_symtab
-		    : i_smob->iter.d.compunit_symtab->includes[i_smob->iter.idx]);
+
+	    compunit_symtab *cust = i_smob->iter.compunit_symtab ();
 	    gdbscm_printf (port, " %s",
 			   symtab_to_filename_for_display
 			     (cust->primary_filetab ()));

base-commit: be3c73b4610a7ccf915daca693565bc895f3584e
-- 
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 simon.marchi [this message]
2026-01-30  2:55 ` [PATCH 2/3] gdb/symtab: make compunit_symtab::includes a std::vector simon.marchi
2026-02-05 18:38   ` 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-1-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