Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 6/8] gdb/xcoffread: simplify xcoff_secnum_to_sections
Date: Thu,  8 Jan 2026 14:33:24 -0500	[thread overview]
Message-ID: <20260108193507.553779-7-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260108193507.553779-1-simon.marchi@efficios.com>

The only remaining caller of xcoff_secnum_to_sections doesn't care about
the section index in the objfile, so remove that part.

Return the BFD section as the return value of the function, instead of
an output parameter.  Remove the unnecessary default in the switch, to
avoid a "jump to label over variable initialization" warning.

Rename to xcoff_secnum_to_section (singular).

Change-Id: I464d8b0e1425ea2732b0d61355c5b0c66218122e
---
 gdb/xcoffread.c | 41 ++++++++++-------------------------------
 1 file changed, 10 insertions(+), 31 deletions(-)

diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 7dd0f29cb107..5494bb0debbb 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -81,34 +81,18 @@ static void scan_xcoff_symtab (struct objfile *);
 static void xcoff_symfile_init (struct objfile *);
 
 /* Search all BFD sections for the section whose target_index is
-   equal to N_SCNUM.  Set *BFD_SECT to that section.  The section's
-   associated index in the objfile's section_offset table is also
-   stored in *SECNUM.
+   equal to N_SCNUM.
 
-   If no match is found, *BFD_SECT is set to NULL, and *SECNUM
-   is set to the text section's number.  */
+   If no match is found, return nullptr.  */
 
-static void
-xcoff_secnum_to_sections (int n_scnum, struct objfile *objfile,
-			  asection **bfd_sect, int *secnum)
+static asection *
+xcoff_secnum_to_section (int n_scnum, objfile *objfile)
 {
-  *bfd_sect = NULL;
-  *secnum = SECT_OFF_TEXT (objfile);
-
   for (asection *sec : gdb_bfd_sections (objfile->obfd.get ()))
-    {
-      if (sec->target_index == n_scnum)
-	{
-	  /* This is the section.  Figure out what SECT_OFF_* code it is.  */
-	  if (bfd_section_flags (sec) & SEC_CODE)
-	    *secnum = SECT_OFF_TEXT (objfile);
-	  else if (bfd_section_flags (sec) & SEC_LOAD)
-	    *secnum = SECT_OFF_DATA (objfile);
-	  else
-	    *secnum = gdb_bfd_section_index (objfile->obfd.get (), sec);
-	  *bfd_sect = sec;
-	}
-    }
+    if (sec->target_index == n_scnum)
+      return sec;
+
+  return nullptr;
 }
 
 /* Do initialization in preparation for reading symbols from OBJFILE.
@@ -150,8 +134,6 @@ scan_xcoff_symtab (struct objfile *objfile)
 {
   CORE_ADDR toc_offset = 0;	/* toc offset value in data section.  */
 
-  asection *bfd_sect = nullptr;
-  int ignored;
   bfd *abfd = objfile->obfd.get ();
   file_ptr symtab_offset = obj_sym_filepos (abfd);
   struct internal_syment symbol;
@@ -218,14 +200,11 @@ scan_xcoff_symtab (struct objfile *objfile)
 
 		    /* Make TOC offset relative to start address of
 		       section.  */
-		    xcoff_secnum_to_sections (symbol.n_scnum, objfile,
-							 &bfd_sect, &ignored);
+		    asection *bfd_sect
+		      = xcoff_secnum_to_section (symbol.n_scnum, objfile);
 		    if (bfd_sect)
 		      toc_offset -= bfd_section_vma (bfd_sect);
 		    break;
-
-		  default:
-		    break;
 		  }
 		break;
 	      }
-- 
2.52.0


  parent reply	other threads:[~2026-01-08 19:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08 19:33 [PATCH 0/8] More xcoffread cleanups Simon Marchi
2026-01-08 19:33 ` [PATCH 1/8] gdb/xcoffread: remove name computation Simon Marchi
2026-01-08 20:32   ` Tom Tromey
2026-01-08 19:33 ` [PATCH 2/8] gdb/xcoffread: remove read of .debug section Simon Marchi
2026-01-08 20:32   ` Tom Tromey
2026-01-08 19:33 ` [PATCH 3/8] gdb/xcoffread: remove XCOFF_DATA macro Simon Marchi
2026-01-08 20:34   ` Tom Tromey
2026-01-08 19:33 ` [PATCH 4/8] gdb/xcoffread: remove xcoff_symfile_info::{symtbl, symtbl_num_syms} Simon Marchi
2026-01-08 20:36   ` Tom Tromey
2026-01-08 21:24     ` Simon Marchi
2026-01-08 22:17       ` Tom Tromey
2026-01-09  2:05         ` Simon Marchi
2026-01-08 19:33 ` [PATCH 5/8] gdb/xcoffread: allocate symbol table using vector in scan_xcoff_symtab Simon Marchi
2026-01-08 20:37   ` Tom Tromey
2026-01-08 19:33 ` Simon Marchi [this message]
2026-01-08 20:39   ` [PATCH 6/8] gdb/xcoffread: simplify xcoff_secnum_to_sections Tom Tromey
2026-01-08 19:33 ` [PATCH 7/8] gdb/xcoffread: replace 2 switches with if Simon Marchi
2026-01-08 20:40   ` Tom Tromey
2026-01-08 19:33 ` [PATCH 8/8] gdb/xcoffread: stylistic cleanup Simon Marchi
2026-01-08 20:41   ` Tom Tromey

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=20260108193507.553779-7-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /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