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 4/8] gdb/xcoffread: remove xcoff_symfile_info::{symtbl, symtbl_num_syms}
Date: Thu,  8 Jan 2026 14:33:22 -0500	[thread overview]
Message-ID: <20260108193507.553779-5-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260108193507.553779-1-simon.marchi@efficios.com>

It is not necessary to save the symbol table content and number of
symbols in xcoff_symfile_info, because they are only needed for the
duration of scan_xcoff_symtab.

Move the reading of the symbol table content to scan_xcoff_symtab, and
keep everything as local variables.

Change-Id: I21e2b95a0b8df2255ba46904083658a4e8cb89f0
---
 gdb/xcoffread.c | 62 ++++++++++++++-----------------------------------
 1 file changed, 18 insertions(+), 44 deletions(-)

diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 052bd6b78b28..0f3470cae45d 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -38,12 +38,6 @@
 \f
 struct xcoff_symfile_info
   {
-    /* Pointer to the a.out symbol table.  */
-    char *symtbl = nullptr;
-
-    /* Number of symbols in symtbl.  */
-    int symtbl_num_syms = 0;
-
     /* Offset in data section to TOC anchor.  */
     CORE_ADDR toc_offset = 0;
   };
@@ -156,22 +150,32 @@ scan_xcoff_symtab (struct objfile *objfile)
 {
   CORE_ADDR toc_offset = 0;	/* toc offset value in data section.  */
 
-  bfd *abfd;
   asection *bfd_sect = nullptr;
   int ignored;
-  unsigned int nsyms;
-
-  char *sraw_symbol;
+  bfd *abfd = objfile->obfd.get ();
+  file_ptr symtab_offset = obj_sym_filepos (abfd);
   struct internal_syment symbol;
   union internal_auxent main_aux[5];
   unsigned int ssymnum;
 
-  abfd = objfile->obfd.get ();
+  /* Seek to symbol table location.  */
+  if (int ret = bfd_seek (abfd, symtab_offset, SEEK_SET);
+      ret < 0)
+    error (_("Error reading symbols from %s: %s"),
+	   objfile_name (objfile), bfd_errmsg (bfd_get_error ()));
 
-  sraw_symbol = xcoff_objfile_data_key.get (objfile)->symtbl;
-  nsyms = xcoff_objfile_data_key.get (objfile)->symtbl_num_syms;
+  unsigned int num_symbols = bfd_get_symcount (abfd);
+  size_t size = coff_data (abfd)->local_symesz * num_symbols;
+  char *symtbl = (char *) obstack_alloc (&objfile->objfile_obstack, size);
+
+  /* Read in symbol table.  */
+  if (int ret = bfd_read (symtbl, size, abfd);
+      ret != size)
+    error (_("reading symbol table: %s"), bfd_errmsg (bfd_get_error ()));
+
+  char *sraw_symbol = symtbl;
   ssymnum = 0;
-  while (ssymnum < nsyms)
+  while (ssymnum < num_symbols)
     {
       int sclass;
 
@@ -277,41 +281,11 @@ xcoff_get_toc_offset (struct objfile *objfile)
 static void
 xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags)
 {
-  bfd *abfd;
-  int val;
-  int num_symbols;		/* # of symbols */
-  file_ptr symtab_offset;	/* symbol table and */
-  struct xcoff_symfile_info *info;
-  const char *name;
-  unsigned int size;
-
-  info = xcoff_objfile_data_key.get (objfile);
-  abfd = objfile->obfd.get ();
-  name = objfile_name (objfile);
-
-  num_symbols = bfd_get_symcount (abfd);	/* # of symbols */
-  symtab_offset = obj_sym_filepos (abfd);	/* symbol table file offset */
-
-  /* Read the symbols.  We keep them in core because we will want to
-     access them randomly in read_symbol*.  */
-  val = bfd_seek (abfd, symtab_offset, SEEK_SET);
-  if (val < 0)
-    error (_("Error reading symbols from %s: %s"),
-	   name, bfd_errmsg (bfd_get_error ()));
-  size = coff_data (abfd)->local_symesz * num_symbols;
-  info->symtbl = (char *) obstack_alloc (&objfile->objfile_obstack, size);
-  info->symtbl_num_syms = num_symbols;
-
-  val = bfd_read (info->symtbl, size, abfd);
-  if (val != size)
-    error (_("reading symbol table: %s"), bfd_errmsg (bfd_get_error ()));
-
   /* We need to do this to get the TOC information only.  STABS
      format is no longer supported.  */
   scan_xcoff_symtab (objfile);
 
   /* DWARF2 sections.  */
-
   dwarf2_initialize_objfile (objfile, &dwarf2_xcoff_names);
 }
 \f
-- 
2.52.0


  parent reply	other threads:[~2026-01-08 19:35 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 ` Simon Marchi [this message]
2026-01-08 20:36   ` [PATCH 4/8] gdb/xcoffread: remove xcoff_symfile_info::{symtbl, symtbl_num_syms} 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 ` [PATCH 6/8] gdb/xcoffread: simplify xcoff_secnum_to_sections Simon Marchi
2026-01-08 20:39   ` 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-5-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