From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 06/10] Use symfile_bfd in more places
Date: Fri, 16 Jan 2026 12:11:34 -0700 [thread overview]
Message-ID: <20260116-coffread-cleanups-v1-6-4d46090fad69@adacore.com> (raw)
In-Reply-To: <20260116-coffread-cleanups-v1-0-4d46090fad69@adacore.com>
Since coffread.c is setting symfile_bfd, it might as well use it
everywhere. This changes all other BFD references in coffread.c to
use the global.
---
gdb/coffread.c | 50 +++++++++++++++++++++++---------------------------
1 file changed, 23 insertions(+), 27 deletions(-)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index b75721d2577..5cbbf490937 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -87,7 +87,7 @@ static int symnum;
static const char *getsymname (struct internal_syment *);
-static int init_stringtab (bfd *, file_ptr, gdb::unique_xmalloc_ptr<char> *);
+static int init_stringtab (file_ptr, gdb::unique_xmalloc_ptr<char> *);
static void read_one_sym (struct coff_symbol *);
@@ -97,9 +97,9 @@ static void coff_symtab_read (minimal_symbol_reader &,
/* Return the BFD section that CS points to. */
static asection *
-cs_to_bfd_section (struct coff_symbol *cs, bfd *abfd)
+cs_to_bfd_section (struct coff_symbol *cs)
{
- for (asection *sect : gdb_bfd_sections (abfd))
+ for (asection *sect : gdb_bfd_sections (symfile_bfd))
if (sect->target_index == cs->c_secnum)
return sect;
@@ -110,19 +110,19 @@ cs_to_bfd_section (struct coff_symbol *cs, bfd *abfd)
static int
cs_to_section (struct coff_symbol *cs, struct objfile *objfile)
{
- asection *sect = cs_to_bfd_section (cs, objfile->obfd.get ());
+ asection *sect = cs_to_bfd_section (cs);
if (sect == NULL)
return SECT_OFF_TEXT (objfile);
- return gdb_bfd_section_index (objfile->obfd.get (), sect);
+ return gdb_bfd_section_index (symfile_bfd, sect);
}
/* Return the address of the section of a COFF symbol. */
static CORE_ADDR
-cs_section_address (struct coff_symbol *cs, bfd *abfd)
+cs_section_address (struct coff_symbol *cs)
{
- asection *sect = cs_to_bfd_section (cs, abfd);
+ asection *sect = cs_to_bfd_section (cs);
if (sect == nullptr)
return 0;
@@ -256,8 +256,7 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms,
name1 = name + 6;
if (name1 != NULL)
{
- int lead
- = bfd_get_symbol_leading_char (objfile->obfd.get ());
+ int lead = bfd_get_symbol_leading_char (symfile_bfd);
if (lead != '\0' && *name1 == lead)
name1 += 1;
@@ -283,18 +282,16 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms,
static void
coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{
- bfd *abfd = objfile->obfd.get ();
- coff_data_type *cdata = coff_data (abfd);
- const char *filename = bfd_get_filename (abfd);
+ symfile_bfd = objfile->obfd.get ();
+ coff_data_type *cdata = coff_data (symfile_bfd);
+ const char *filename = bfd_get_filename (symfile_bfd);
int val;
unsigned int num_symbols;
file_ptr symtab_offset;
file_ptr stringtab_offset;
- symfile_bfd = abfd; /* Kludge for swap routines. */
-
/* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
- num_symbols = bfd_get_symcount (abfd); /* How many syms */
+ num_symbols = bfd_get_symcount (symfile_bfd); /* How many syms */
symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
stringtab_offset = symtab_offset + /* String table file offset */
num_symbols * cdata->local_symesz;
@@ -318,8 +315,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
from the section address, rather than as absolute addresses.
FIXME: We should use BFD to read the symbol table, and thus avoid
this problem. */
- pe_file = (startswith (bfd_get_target (objfile->obfd.get ()), "pe")
- || startswith (bfd_get_target (objfile->obfd.get ()), "epoc-pe"));
+ pe_file = (startswith (bfd_get_target (symfile_bfd), "pe")
+ || startswith (bfd_get_target (symfile_bfd), "epoc-pe"));
/* End of warning. */
@@ -327,7 +324,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
scoped_restore restore_stringtab = make_scoped_restore (&stringtab);
gdb::unique_xmalloc_ptr<char> stringtab_storage;
- val = init_stringtab (abfd, stringtab_offset, &stringtab_storage);
+ val = init_stringtab (stringtab_offset, &stringtab_storage);
if (val < 0)
error (_("\"%s\": can't get string table"), filename);
@@ -337,7 +334,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{
bool found_stab_section = false;
- for (asection *sect : gdb_bfd_sections (abfd))
+ for (asection *sect : gdb_bfd_sections (symfile_bfd))
if (startswith (bfd_section_name (sect), ".stab"))
{
found_stab_section = true;
@@ -383,7 +380,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
symnum = 0;
/* Position to read the symbol table. */
- val = bfd_seek (objfile->obfd.get (), symtab_offset, 0);
+ val = bfd_seek (symfile_bfd, symtab_offset, 0);
if (val < 0)
error (_("Error reading symbols from %s: %s"),
objfile_name (objfile), bfd_errmsg (bfd_get_error ()));
@@ -476,8 +473,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
}
else
{
- asection *bfd_section
- = cs_to_bfd_section (cs, objfile->obfd.get ());
+ asection *bfd_section = cs_to_bfd_section (cs);
sec = cs_to_section (cs, objfile);
tmpaddr = cs->c_value;
@@ -579,7 +575,7 @@ read_one_sym (struct coff_symbol *cs)
case C_FCN:
case C_EFCN:
if (cs->c_secnum != 0)
- cs->c_value += cs_section_address (cs, symfile_bfd);
+ cs->c_value += cs_section_address (cs);
break;
}
}
@@ -588,7 +584,7 @@ read_one_sym (struct coff_symbol *cs)
/* Support for string table handling. */
static int
-init_stringtab (bfd *abfd, file_ptr offset, gdb::unique_xmalloc_ptr<char> *storage)
+init_stringtab (file_ptr offset, gdb::unique_xmalloc_ptr<char> *storage)
{
long length;
int val;
@@ -599,10 +595,10 @@ init_stringtab (bfd *abfd, file_ptr offset, gdb::unique_xmalloc_ptr<char> *stora
if (offset == 0)
return 0;
- if (bfd_seek (abfd, offset, 0) < 0)
+ if (bfd_seek (symfile_bfd, offset, 0) < 0)
return -1;
- val = bfd_read (lengthbuf, sizeof lengthbuf, abfd);
+ val = bfd_read (lengthbuf, sizeof lengthbuf, symfile_bfd);
/* If no string table is needed, then the file may end immediately
after the symbols. Just return with `stringtab' set to null. */
if (val != sizeof lengthbuf)
@@ -621,7 +617,7 @@ init_stringtab (bfd *abfd, file_ptr offset, gdb::unique_xmalloc_ptr<char> *stora
return 0;
val = bfd_read (stringtab + sizeof lengthbuf,
- length - sizeof lengthbuf, abfd);
+ length - sizeof lengthbuf, symfile_bfd);
if (val != length - sizeof lengthbuf || stringtab[length - 1] != '\0')
return -1;
--
2.52.0
next prev parent reply other threads:[~2026-01-16 19:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-16 19:11 [PATCH 00/10] More coffread cleanups Tom Tromey
2026-01-16 19:11 ` [PATCH 01/10] Constify coffread.c:getsymname Tom Tromey
2026-01-16 19:11 ` [PATCH 02/10] Clean up a comment in coffread.c Tom Tromey
2026-01-16 19:11 ` [PATCH 03/10] Fix indentation " Tom Tromey
2026-01-17 3:54 ` Simon Marchi
2026-01-20 15:47 ` Tom Tromey
2026-01-16 19:11 ` [PATCH 04/10] Change coffread.c:pe_file to bool Tom Tromey
2026-01-16 19:11 ` [PATCH 05/10] Remove redundant nlist_bfd_global Tom Tromey
2026-01-16 19:11 ` Tom Tromey [this message]
2026-01-17 4:09 ` [PATCH 06/10] Use symfile_bfd in more places Simon Marchi
2026-01-17 4:19 ` Simon Marchi
2026-01-17 4:10 ` Simon Marchi
2026-01-16 19:11 ` [PATCH 07/10] Use coffread_objfile throughout coffread.c Tom Tromey
2026-01-16 19:11 ` [PATCH 08/10] Remove coff_symfile_init Tom Tromey
2026-01-17 4:13 ` Simon Marchi
2026-01-20 15:54 ` Tom Tromey
2026-01-16 19:11 ` [PATCH 09/10] Remove all globals from coffread.c Tom Tromey
2026-01-16 19:11 ` [PATCH 10/10] Change is_import_fixup_symbol to return bool Tom Tromey
2026-01-17 4:20 ` [PATCH 00/10] More coffread cleanups 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=20260116-coffread-cleanups-v1-6-4d46090fad69@adacore.com \
--to=tromey@adacore.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