public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 12/13] Use gdb_bfd_sections in build_section_table
Date: Fri, 28 Aug 2020 10:23:48 -0600	[thread overview]
Message-ID: <20200828162349.987-13-tom@tromey.com> (raw)
In-Reply-To: <20200828162349.987-1-tom@tromey.com>

This changes build_section_table to avoid bfd_map_over_sections, in
favor of iteration.  In this situation it seemed simple to just remove
the helper function entirely.

gdb/ChangeLog
2020-08-28  Tom Tromey  <tom@tromey.com>

	* exec.c (add_to_section_table): Remove.
	(build_section_table): Use foreach.
---
 gdb/ChangeLog |  5 +++++
 gdb/exec.c    | 50 ++++++++++++++++++++------------------------------
 2 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index e50f38899d6..14cc6af7de0 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -587,35 +587,6 @@ file_command (const char *arg, int from_tty)
 }
 \f
 
-/* Locate all mappable sections of a BFD file.
-   table_pp_char is a char * to get it through bfd_map_over_sections;
-   we cast it back to its proper type.  */
-
-static void
-add_to_section_table (bfd *abfd, struct bfd_section *asect,
-		      void *table_pp_char)
-{
-  struct target_section **table_pp = (struct target_section **) table_pp_char;
-  flagword aflag;
-
-  gdb_assert (abfd == asect->owner);
-
-  /* Check the section flags, but do not discard zero-length sections, since
-     some symbols may still be attached to this section.  For instance, we
-     encountered on sparc-solaris 2.10 a shared library with an empty .bss
-     section to which a symbol named "_end" was attached.  The address
-     of this symbol still needs to be relocated.  */
-  aflag = bfd_section_flags (asect);
-  if (!(aflag & SEC_ALLOC))
-    return;
-
-  (*table_pp)->owner = NULL;
-  (*table_pp)->the_bfd_section = asect;
-  (*table_pp)->addr = bfd_section_vma (asect);
-  (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (asect);
-  (*table_pp)++;
-}
-
 /* See exec.h.  */
 
 void
@@ -665,7 +636,26 @@ build_section_table (struct bfd *some_bfd, struct target_section **start,
   xfree (*start);
   *start = XNEWVEC (struct target_section, count);
   *end = *start;
-  bfd_map_over_sections (some_bfd, add_to_section_table, (char *) end);
+  for (asection *asect : gdb_bfd_sections (some_bfd))
+    {
+      flagword aflag;
+
+      /* Check the section flags, but do not discard zero-length
+	 sections, since some symbols may still be attached to this
+	 section.  For instance, we encountered on sparc-solaris 2.10
+	 a shared library with an empty .bss section to which a symbol
+	 named "_end" was attached.  The address of this symbol still
+	 needs to be relocated.  */
+      aflag = bfd_section_flags (asect);
+      if (!(aflag & SEC_ALLOC))
+	continue;
+
+      (*end)->owner = NULL;
+      (*end)->the_bfd_section = asect;
+      (*end)->addr = bfd_section_vma (asect);
+      (*end)->endaddr = (*end)->addr + bfd_section_size (asect);
+      (*end)++;
+    }
 
   gdb_assert (*end <= *start + count);
 
-- 
2.17.2


  parent reply	other threads:[~2020-08-28 16:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-28 16:23 [PATCH 00/13] Use gdb_bfd_sections in more places Tom Tromey
2020-08-28 16:23 ` [PATCH 01/13] Add a new overload of gdb_bfd_sections Tom Tromey
2020-08-28 16:34   ` Simon Marchi
2020-08-28 19:25     ` Tom Tromey
2020-08-28 16:23 ` [PATCH 02/13] Use gdb_bfd_sections in core_target_open Tom Tromey
2020-08-28 16:23 ` [PATCH 03/13] Use gdb_bfd_sections in gdb_bfd_close_or_warn Tom Tromey
2020-08-28 16:23 ` [PATCH 04/13] Use gdb_bfd_sections in get_stap_base_address Tom Tromey
2020-08-28 17:06   ` Simon Marchi
2020-08-28 16:23 ` [PATCH 05/13] Use gdb_bfd_sections in build_objfile_section_table Tom Tromey
2020-08-28 16:23 ` [PATCH 06/13] Use gdb_bfd_sections in symfile.c Tom Tromey
2020-08-28 17:00   ` Simon Marchi
2020-08-28 17:06     ` Simon Marchi
2020-08-28 16:23 ` [PATCH 07/13] Use gdb_bfd_sections in dwarf2/read.c Tom Tromey
2020-08-28 16:23 ` [PATCH 08/13] Use gdb_bfd_sections in ELF osabi tag sniffing Tom Tromey
2020-08-28 16:23 ` [PATCH 09/13] Use gdb_bfd_sections in gcore_memory_sections Tom Tromey
2020-08-28 16:23 ` [PATCH 10/13] Use gdb_bfd_sections in restore_command Tom Tromey
2020-08-28 17:12   ` Simon Marchi
2020-08-29 15:47     ` Tom Tromey
2020-08-29 15:49       ` Simon Marchi
2020-08-28 16:23 ` [PATCH 11/13] Use gdb_bfd_sections in elf_symfile_read Tom Tromey
2020-08-28 16:23 ` Tom Tromey [this message]
2020-08-28 16:23 ` [PATCH 13/13] Use gdb_bfd_sections in generic_load Tom Tromey
2020-08-28 17:14 ` [PATCH 00/13] Use gdb_bfd_sections in more places Simon Marchi
2020-08-31 18:19 ` John Baldwin
2020-09-19 18:07 ` 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=20200828162349.987-13-tom@tromey.com \
    --to=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).