public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Change target section table management
@ 2020-10-03 19:37 Tom Tromey
  2020-10-03 19:37 ` [PATCH 1/6] Introduce target-section.h Tom Tromey
                   ` (6 more replies)
  0 siblings, 7 replies; 24+ messages in thread
From: Tom Tromey @ 2020-10-03 19:37 UTC (permalink / raw)
  To: gdb-patches

I looked into resurrecting my series to remove the macros from
progspace.h and exec.h, but found that this would be improved by first
changing how target section tables are managed.

This series changes target section tables to use a std::vector and
cleans up various related things.

Regression tested on x86-64 Fedora 28.

Tom



^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/6] Introduce target-section.h
  2020-10-03 19:37 [PATCH 0/6] Change target section table management Tom Tromey
@ 2020-10-03 19:37 ` Tom Tromey
  2020-10-04  8:29   ` Andrew Burgess
  2020-10-03 19:37 ` [PATCH 2/6] Use a std::vector in target_section_table Tom Tromey
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-10-03 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This introduces a new target-section.h file.  This makes some of the
later patches in this series a bit cleaner, because new includes of
target.h won't be required.  Also I think it's better to have small
header files for each separate data structure.

gdb/ChangeLog
2020-10-03  Tom Tromey  <tom@tromey.com>

	* target.h (struct target_section, struct target_section_table):
	Move to target-section.h.
	* target-section.h: New file.
---
 gdb/ChangeLog        |  6 ++++++
 gdb/target-section.h | 50 ++++++++++++++++++++++++++++++++++++++++++++
 gdb/target.h         | 28 +------------------------
 3 files changed, 57 insertions(+), 27 deletions(-)
 create mode 100644 gdb/target-section.h

diff --git a/gdb/target-section.h b/gdb/target-section.h
new file mode 100644
index 00000000000..581bc1dbe9f
--- /dev/null
+++ b/gdb/target-section.h
@@ -0,0 +1,50 @@
+/* Target sections.
+
+   Copyright (C) 2020 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_TARGET_SECTION_H
+#define GDB_TARGET_SECTION_H
+
+/* Struct target_section maps address ranges to file sections.  It is
+   mostly used with BFD files, but can be used without (e.g. for handling
+   raw disks, or files not in formats handled by BFD).  */
+
+struct target_section
+  {
+    CORE_ADDR addr;		/* Lowest address in section */
+    CORE_ADDR endaddr;		/* 1+highest address in section */
+
+    struct bfd_section *the_bfd_section;
+
+    /* The "owner" of the section.
+       It can be any unique value.  It is set by add_target_sections
+       and used by remove_target_sections.
+       For example, for executables it is a pointer to exec_bfd and
+       for shlibs it is the so_list pointer.  */
+    void *owner;
+  };
+
+/* Holds an array of target sections.  Defined by [SECTIONS..SECTIONS_END[.  */
+
+struct target_section_table
+{
+  struct target_section *sections;
+  struct target_section *sections_end;
+};
+
+#endif /* GDB_TARGET_SECTION_H */
diff --git a/gdb/target.h b/gdb/target.h
index 695f1b2b7f6..369394aa929 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -44,6 +44,7 @@ struct inferior;
 #include "breakpoint.h" /* For enum bptype.  */
 #include "gdbsupport/scoped_restore.h"
 #include "gdbsupport/refcounted-object.h"
+#include "target-section.h"
 
 /* This include file defines the interface between the main part
    of the debugger, and the part which is target-specific, or
@@ -2413,33 +2414,6 @@ extern bool target_is_pushed (target_ops *t);
 extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
 					       CORE_ADDR offset);
 
-/* Struct target_section maps address ranges to file sections.  It is
-   mostly used with BFD files, but can be used without (e.g. for handling
-   raw disks, or files not in formats handled by BFD).  */
-
-struct target_section
-  {
-    CORE_ADDR addr;		/* Lowest address in section */
-    CORE_ADDR endaddr;		/* 1+highest address in section */
-
-    struct bfd_section *the_bfd_section;
-
-    /* The "owner" of the section.
-       It can be any unique value.  It is set by add_target_sections
-       and used by remove_target_sections.
-       For example, for executables it is a pointer to exec_bfd and
-       for shlibs it is the so_list pointer.  */
-    void *owner;
-  };
-
-/* Holds an array of target sections.  Defined by [SECTIONS..SECTIONS_END[.  */
-
-struct target_section_table
-{
-  struct target_section *sections;
-  struct target_section *sections_end;
-};
-
 /* Return the "section" containing the specified address.  */
 struct target_section *target_section_by_addr (struct target_ops *target,
 					       CORE_ADDR addr);
-- 
2.17.2


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-03 19:37 [PATCH 0/6] Change target section table management Tom Tromey
  2020-10-03 19:37 ` [PATCH 1/6] Introduce target-section.h Tom Tromey
@ 2020-10-03 19:37 ` Tom Tromey
  2020-10-13 16:41   ` Luis Machado
                     ` (2 more replies)
  2020-10-03 19:37 ` [PATCH 3/6] build_section_table cannot fail Tom Tromey
                   ` (4 subsequent siblings)
  6 siblings, 3 replies; 24+ messages in thread
From: Tom Tromey @ 2020-10-03 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes target_section_table to wrap a std::vector.  This
simplifies some code, and also enables the simplifications coming in
the subsequent patches.

Note that for solib, I chose to have it use a pointer to a
target_section_table.  This is more convoluted than would be ideal,
but I didn't want to convert solib to new/delete as a prerequisite for
this series.

gdb/ChangeLog
2020-10-03  Tom Tromey  <tom@tromey.com>

	* target.c (target_section_by_addr, memory_xfer_partial_1):
	Update.
	* target-section.h (struct target_section_table): Use
	std::vector.
	* symfile.h (build_section_addr_info_from_section_table): Take a
	target_section_table.
	* symfile.c (build_section_addr_info_from_section_table): Take a
	target_section_table.
	* solist.h (struct so_list) <sections>: Change type.
	<sections_end>: Remove.
	* solib.c (solib_map_sections, clear_so, solib_read_symbols)
	(solib_contains_address_p): Update.
	* solib-svr4.c (scan_dyntag): Update.
	* solib-dsbt.c (scan_dyntag): Update.
	* remote.c (remote_target::remote_xfer_live_readonly_partial):
	Update.
	* record-full.c (record_full_core_start, record_full_core_end):
	Remove.
	(record_full_core_sections): New global.
	(record_full_core_open_1, record_full_core_target::xfer_partial):
	Update.
	* exec.h (build_section_table, section_table_xfer_memory_partial)
	(add_target_sections): Take a target_section_table.
	* exec.c (exec_file_attach, clear_section_table): Update.
	(resize_section_table): Remove.
	(build_section_table, add_target_sections): Take a
	target_section_table.
	(add_target_sections_of_objfile, remove_target_sections)
	(exec_on_vfork): Update.
	(section_table_available_memory): Take a target_section_table.
	(section_table_read_available_memory): Update.
	(section_table_xfer_memory_partial): Take a target_section_table.
	(print_section_info, set_section_command)
	(exec_set_section_address, exec_target::has_memory): Update.
	* corelow.c (class core_target) <m_core_section_table,
	m_core_file_mappings>: Remove braces.
	<~core_target>: Remove.
	(core_target::core_target): Update.
	(core_target::~core_target): Remove.
	(core_target::build_file_mappings)
	(core_target::xfer_memory_via_mappings)
	(core_target::xfer_partial, core_target::info_proc_mappings):
	Update.
	* bfd-target.c (target_bfd::xfer_partial): Update.
	(target_bfd::target_bfd): Update.
	(target_bfd::~target_bfd): Remove.
---
 gdb/ChangeLog        |  49 +++++++++
 gdb/bfd-target.c     |  13 +--
 gdb/corelow.c        |  58 ++++------
 gdb/exec.c           | 247 +++++++++++++++----------------------------
 gdb/exec.h           |   9 +-
 gdb/record-full.c    |  33 +++---
 gdb/remote.c         |  11 +-
 gdb/solib-dsbt.c     |  18 ++--
 gdb/solib-svr4.c     |  18 ++--
 gdb/solib.c          |  33 +++---
 gdb/solist.h         |   4 +-
 gdb/symfile.c        |  13 +--
 gdb/symfile.h        |   6 +-
 gdb/target-section.h |   5 +-
 gdb/target.c         |  14 +--
 15 files changed, 230 insertions(+), 301 deletions(-)

diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index 3d266951c5a..8a58e92eb1c 100644
--- a/gdb/bfd-target.c
+++ b/gdb/bfd-target.c
@@ -35,7 +35,6 @@ class target_bfd : public target_ops
 {
 public:
   explicit target_bfd (struct bfd *bfd);
-  ~target_bfd () override;
 
   const target_info &info () const override
   { return target_bfd_target_info; }
@@ -76,8 +75,7 @@ target_bfd::xfer_partial (target_object object,
       {
 	return section_table_xfer_memory_partial (readbuf, writebuf,
 						  offset, len, xfered_len,
-						  m_table.sections,
-						  m_table.sections_end);
+						  m_table);
       }
     default:
       return TARGET_XFER_E_IO;
@@ -93,14 +91,7 @@ target_bfd::get_section_table ()
 target_bfd::target_bfd (struct bfd *abfd)
   : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
 {
-  m_table.sections = NULL;
-  m_table.sections_end = NULL;
-  build_section_table (abfd, &m_table.sections, &m_table.sections_end);
-}
-
-target_bfd::~target_bfd ()
-{
-  xfree (m_table.sections);
+  build_section_table (abfd, &m_table);
 }
 
 target_ops *
diff --git a/gdb/corelow.c b/gdb/corelow.c
index e82c183eae5..554561dbb36 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -67,7 +67,6 @@ class core_target final : public process_stratum_target
 {
 public:
   core_target ();
-  ~core_target () override;
 
   const target_info &info () const override
   { return core_target_info; }
@@ -126,11 +125,11 @@ class core_target final : public process_stratum_target
      shared library bfds.  The core bfd sections are an implementation
      detail of the core target, just like ptrace is for unix child
      targets.  */
-  target_section_table m_core_section_table {};
+  target_section_table m_core_section_table;
 
   /* File-backed address space mappings: some core files include
      information about memory mapped files.  */
-  target_section_table m_core_file_mappings {};
+  target_section_table m_core_file_mappings;
 
   /* Unavailable mappings.  These correspond to pathnames which either
      weren't found or could not be opened.  Knowing these addresses can
@@ -162,21 +161,13 @@ core_target::core_target ()
 	   bfd_get_filename (core_bfd));
 
   /* Find the data section */
-  if (build_section_table (core_bfd,
-			   &m_core_section_table.sections,
-			   &m_core_section_table.sections_end))
+  if (build_section_table (core_bfd, &m_core_section_table))
     error (_("\"%s\": Can't find sections: %s"),
 	   bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
 
   build_file_mappings ();
 }
 
-core_target::~core_target ()
-{
-  xfree (m_core_section_table.sections);
-  xfree (m_core_file_mappings.sections);
-}
-
 /* Construct the target_section_table for file-backed mappings if
    they exist.
 
@@ -202,12 +193,9 @@ core_target::build_file_mappings ()
   gdbarch_read_core_file_mappings (m_core_gdbarch, core_bfd,
 
     /* After determining the number of mappings, read_core_file_mappings
-       will invoke this lambda which allocates target_section storage for
-       the mappings.  */
-    [&] (ULONGEST count)
+       will invoke this lambda.  */
+    [&] (ULONGEST)
       {
-	m_core_file_mappings.sections = XNEWVEC (struct target_section, count);
-	m_core_file_mappings.sections_end = m_core_file_mappings.sections;
       },
 
     /* read_core_file_mappings will invoke this lambda for each mapping
@@ -280,11 +268,12 @@ core_target::build_file_mappings ()
 	bfd_set_section_alignment (sec, 2);
 
 	/* Set target_section fields.  */
-	struct target_section *ts = m_core_file_mappings.sections_end++;
-	ts->addr = start;
-	ts->endaddr = end;
-	ts->owner = nullptr;
-	ts->the_bfd_section = sec;
+	m_core_file_mappings.sections.emplace_back ();
+	target_section &ts = m_core_file_mappings.sections.back ();
+	ts.addr = start;
+	ts.endaddr = end;
+	ts.owner = nullptr;
+	ts.the_bfd_section = sec;
       });
 
   normalize_mem_ranges (&m_core_unavailable_mappings);
@@ -759,8 +748,7 @@ core_target::xfer_memory_via_mappings (gdb_byte *readbuf,
   xfer_status = (section_table_xfer_memory_partial
 		   (readbuf, writebuf,
 		    offset, len, xfered_len,
-		    m_core_file_mappings.sections,
-		    m_core_file_mappings.sections_end));
+		    m_core_file_mappings));
 
   if (xfer_status == TARGET_XFER_OK || m_core_unavailable_mappings.empty ())
     return xfer_status;
@@ -818,8 +806,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
 	xfer_status = section_table_xfer_memory_partial
 			(readbuf, writebuf,
 			 offset, len, xfered_len,
-			 m_core_section_table.sections,
-			 m_core_section_table.sections_end,
+			 m_core_section_table,
 			 has_contents_cb);
 	if (xfer_status == TARGET_XFER_OK)
 	  return TARGET_XFER_OK;
@@ -829,7 +816,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
 	   or the like) as this should provide a more accurate
 	   result.  If not, check the stratum beneath us, which should
 	   be the file stratum.  */
-	if (m_core_file_mappings.sections != nullptr)
+	if (!m_core_file_mappings.sections.empty ())
 	  xfer_status = xfer_memory_via_mappings (readbuf, writebuf, offset,
 						  len, xfered_len);
 	else
@@ -848,8 +835,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
 	xfer_status = section_table_xfer_memory_partial
 			(readbuf, writebuf,
 			 offset, len, xfered_len,
-			 m_core_section_table.sections,
-			 m_core_section_table.sections_end,
+			 m_core_section_table,
 			 no_contents_cb);
 
 	return xfer_status;
@@ -1114,7 +1100,7 @@ get_current_core_target ()
 void
 core_target::info_proc_mappings (struct gdbarch *gdbarch)
 {
-  if (m_core_file_mappings.sections != m_core_file_mappings.sections_end)
+  if (!m_core_file_mappings.sections.empty ())
     {
       printf_filtered (_("Mapped address spaces:\n\n"));
       if (gdbarch_addr_bit (gdbarch) == 32)
@@ -1133,14 +1119,12 @@ core_target::info_proc_mappings (struct gdbarch *gdbarch)
 	}
     }
 
-  for (const struct target_section *tsp = m_core_file_mappings.sections;
-       tsp < m_core_file_mappings.sections_end;
-       tsp++)
+  for (const target_section &tsp : m_core_file_mappings.sections)
     {
-      ULONGEST start = tsp->addr;
-      ULONGEST end = tsp->endaddr;
-      ULONGEST file_ofs = tsp->the_bfd_section->filepos;
-      const char *filename = bfd_get_filename (tsp->the_bfd_section->owner);
+      ULONGEST start = tsp.addr;
+      ULONGEST end = tsp.endaddr;
+      ULONGEST file_ofs = tsp.the_bfd_section->filepos;
+      const char *filename = bfd_get_filename (tsp.the_bfd_section->owner);
 
       if (gdbarch_addr_bit (gdbarch) == 32)
 	printf_filtered ("\t%10s %10s %10s %10s %s\n",
diff --git a/gdb/exec.c b/gdb/exec.c
index 251e24dd26b..e3e515fedec 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -413,7 +413,7 @@ exec_file_attach (const char *filename, int from_tty)
       int load_via_target = 0;
       const char *scratch_pathname, *canonical_pathname;
       int scratch_chan;
-      struct target_section *sections = NULL, *sections_end = NULL;
+      target_section_table sections;
       char **matching;
 
       if (is_target_filename (filename))
@@ -503,7 +503,7 @@ exec_file_attach (const char *filename, int from_tty)
 		 gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
 	}
 
-      if (build_section_table (exec_bfd, &sections, &sections_end))
+      if (build_section_table (exec_bfd, &sections))
 	{
 	  /* Make sure to close exec_bfd, or else "run" might try to use
 	     it.  */
@@ -522,8 +522,7 @@ exec_file_attach (const char *filename, int from_tty)
       /* Add the executable's sections to the current address spaces'
 	 list of sections.  This possibly pushes the exec_ops
 	 target.  */
-      add_target_sections (&exec_bfd, sections, sections_end);
-      xfree (sections);
+      add_target_sections (&exec_bfd, sections);
 
       /* Tell display code (if any) about the changed file name.  */
       if (deprecated_exec_file_display_hook)
@@ -592,50 +591,16 @@ file_command (const char *arg, int from_tty)
 void
 clear_section_table (struct target_section_table *table)
 {
-  xfree (table->sections);
-  table->sections = table->sections_end = NULL;
+  table->sections.clear ();
 }
 
-/* Resize section table TABLE by ADJUSTMENT.
-   ADJUSTMENT may be negative, in which case the caller must have already
-   removed the sections being deleted.
-   Returns the old size.  */
-
-static int
-resize_section_table (struct target_section_table *table, int adjustment)
-{
-  int old_count;
-  int new_count;
-
-  old_count = table->sections_end - table->sections;
-
-  new_count = adjustment + old_count;
-
-  if (new_count)
-    {
-      table->sections = XRESIZEVEC (struct target_section, table->sections,
-				    new_count);
-      table->sections_end = table->sections + new_count;
-    }
-  else
-    clear_section_table (table);
-
-  return old_count;
-}
-
-/* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
+/* Builds a section table, given args BFD, TABLE.
    Returns 0 if OK, 1 on error.  */
 
 int
-build_section_table (struct bfd *some_bfd, struct target_section **start,
-		     struct target_section **end)
+build_section_table (struct bfd *some_bfd, target_section_table *table)
 {
-  unsigned count;
-
-  count = bfd_count_sections (some_bfd);
-  xfree (*start);
-  *start = XNEWVEC (struct target_section, count);
-  *end = *start;
+  table->sections.clear ();
   for (asection *asect : gdb_bfd_sections (some_bfd))
     {
       flagword aflag;
@@ -650,15 +615,14 @@ build_section_table (struct bfd *some_bfd, struct target_section **start,
       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)++;
+      table->sections.emplace_back ();
+      target_section &sect = table->sections.back ();
+      sect.owner = NULL;
+      sect.the_bfd_section = asect;
+      sect.addr = bfd_section_vma (asect);
+      sect.endaddr = sect.addr + bfd_section_size (asect);
     }
 
-  gdb_assert (*end <= *start + count);
-
   /* We could realloc the table, but it probably loses for most files.  */
   return 0;
 }
@@ -668,23 +632,16 @@ build_section_table (struct bfd *some_bfd, struct target_section **start,
 
 void
 add_target_sections (void *owner,
-		     struct target_section *sections,
-		     struct target_section *sections_end)
+		     const target_section_table &sections)
 {
-  int count;
   struct target_section_table *table = current_target_sections;
 
-  count = sections_end - sections;
-
-  if (count > 0)
+  if (!sections.sections.empty ())
     {
-      int space = resize_section_table (table, count);
-      int i;
-
-      for (i = 0; i < count; ++i)
+      for (const target_section &s : sections.sections)
 	{
-	  table->sections[space + i] = sections[i];
-	  table->sections[space + i].owner = owner;
+	  table->sections.push_back (s);
+	  table->sections.back ().owner = owner;
 	}
 
       scoped_restore_current_pspace_and_thread restore_pspace_thread;
@@ -714,9 +671,7 @@ add_target_sections_of_objfile (struct objfile *objfile)
 {
   struct target_section_table *table = current_target_sections;
   struct obj_section *osect;
-  int space;
   unsigned count = 0;
-  struct target_section *ts;
 
   if (objfile == NULL)
     return;
@@ -732,23 +687,17 @@ add_target_sections_of_objfile (struct objfile *objfile)
   if (count == 0)
     return;
 
-  space = resize_section_table (table, count);
-
-  ts = table->sections + space;
-
   ALL_OBJFILE_OSECTIONS (objfile, osect)
     {
       if (bfd_section_size (osect->the_bfd_section) == 0)
 	continue;
 
-      gdb_assert (ts < table->sections + space + count);
-
-      ts->addr = obj_section_addr (osect);
-      ts->endaddr = obj_section_endaddr (osect);
-      ts->the_bfd_section = osect->the_bfd_section;
-      ts->owner = (void *) objfile;
-
-      ts++;
+      table->sections.emplace_back ();
+      target_section &ts = table->sections.back ();
+      ts.addr = obj_section_addr (osect);
+      ts.endaddr = obj_section_endaddr (osect);
+      ts.the_bfd_section = osect->the_bfd_section;
+      ts.owner = (void *) objfile;
     }
 }
 
@@ -758,48 +707,36 @@ add_target_sections_of_objfile (struct objfile *objfile)
 void
 remove_target_sections (void *owner)
 {
-  struct target_section *src, *dest;
   struct target_section_table *table = current_target_sections;
 
   gdb_assert (owner != NULL);
 
-  dest = table->sections;
-  for (src = table->sections; src < table->sections_end; src++)
-    if (src->owner != owner)
-      {
-	/* Keep this section.  */
-	if (dest < src)
-	  *dest = *src;
-	dest++;
-      }
-
-  /* If we've dropped any sections, resize the section table.  */
-  if (dest < src)
+  auto it = std::remove_if (table->sections.begin (),
+			    table->sections.end (),
+			    [&] (target_section &sect)
+			    {
+			      return sect.owner == owner;
+			    });
+  table->sections.erase (it, table->sections.end ());
+
+  /* If we don't have any more sections to read memory from,
+     remove the file_stratum target from the stack of each
+     inferior sharing the program space.  */
+  if (table->sections.empty ())
     {
-      int old_count;
-
-      old_count = resize_section_table (table, dest - src);
+      scoped_restore_current_pspace_and_thread restore_pspace_thread;
+      program_space *curr_pspace = current_program_space;
 
-      /* If we don't have any more sections to read memory from,
-	 remove the file_stratum target from the stack of each
-	 inferior sharing the program space.  */
-      if (old_count + (dest - src) == 0)
+      for (inferior *inf : all_inferiors ())
 	{
-	  scoped_restore_current_pspace_and_thread restore_pspace_thread;
-	  program_space *curr_pspace = current_program_space;
-
-	  for (inferior *inf : all_inferiors ())
-	    {
-	      if (inf->pspace != curr_pspace)
-		continue;
+	  if (inf->pspace != curr_pspace)
+	    continue;
 
-	      if (inf->pspace->target_sections.sections
-		  != inf->pspace->target_sections.sections_end)
-		continue;
+	  if (!inf->pspace->target_sections.sections.empty ())
+	    continue;
 
-	      switch_to_inferior_no_thread (inf);
-	      unpush_target (&exec_ops);
-	    }
+	  switch_to_inferior_no_thread (inf);
+	  unpush_target (&exec_ops);
 	}
     }
 }
@@ -809,8 +746,7 @@ remove_target_sections (void *owner)
 void
 exec_on_vfork ()
 {
-  if (current_program_space->target_sections.sections
-      != current_program_space->target_sections.sections_end)
+  if (!current_program_space->target_sections.sections.empty ())
     push_target (&exec_ops);
 }
 
@@ -869,26 +805,25 @@ exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
 
 static std::vector<mem_range>
 section_table_available_memory (CORE_ADDR memaddr, ULONGEST len,
-				struct target_section *sections,
-				struct target_section *sections_end)
+				const target_section_table &sections)
 {
   std::vector<mem_range> memory;
 
-  for (target_section *p = sections; p < sections_end; p++)
+  for (const target_section &p : sections.sections)
     {
-      if ((bfd_section_flags (p->the_bfd_section) & SEC_READONLY) == 0)
+      if ((bfd_section_flags (p.the_bfd_section) & SEC_READONLY) == 0)
 	continue;
 
       /* Copy the meta-data, adjusted.  */
-      if (mem_ranges_overlap (p->addr, p->endaddr - p->addr, memaddr, len))
+      if (mem_ranges_overlap (p.addr, p.endaddr - p.addr, memaddr, len))
 	{
 	  ULONGEST lo1, hi1, lo2, hi2;
 
 	  lo1 = memaddr;
 	  hi1 = memaddr + len;
 
-	  lo2 = p->addr;
-	  hi2 = p->endaddr;
+	  lo2 = p.addr;
+	  hi2 = p.endaddr;
 
 	  CORE_ADDR start = std::max (lo1, lo2);
 	  int length = std::min (hi1, hi2) - start;
@@ -906,8 +841,7 @@ section_table_read_available_memory (gdb_byte *readbuf, ULONGEST offset,
 {
   target_section_table *table = target_get_section_table (&exec_ops);
   std::vector<mem_range> available_memory
-    = section_table_available_memory (offset, len,
-				      table->sections, table->sections_end);
+    = section_table_available_memory (offset, len, *table);
 
   normalize_mem_ranges (&available_memory);
 
@@ -944,37 +878,35 @@ enum target_xfer_status
 section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
 				   ULONGEST offset, ULONGEST len,
 				   ULONGEST *xfered_len,
-				   struct target_section *sections,
-				   struct target_section *sections_end,
+				   const target_section_table &sections,
 				   gdb::function_view<bool
 				     (const struct target_section *)> match_cb)
 {
   int res;
-  struct target_section *p;
   ULONGEST memaddr = offset;
   ULONGEST memend = memaddr + len;
 
   gdb_assert (len != 0);
 
-  for (p = sections; p < sections_end; p++)
+  for (const target_section &p : sections.sections)
     {
-      struct bfd_section *asect = p->the_bfd_section;
+      struct bfd_section *asect = p.the_bfd_section;
       bfd *abfd = asect->owner;
 
-      if (match_cb != nullptr && !match_cb (p))
+      if (match_cb != nullptr && !match_cb (&p))
 	continue;		/* not the section we need.  */
-      if (memaddr >= p->addr)
+      if (memaddr >= p.addr)
         {
-	  if (memend <= p->endaddr)
+	  if (memend <= p.endaddr)
 	    {
 	      /* Entire transfer is within this section.  */
 	      if (writebuf)
 		res = bfd_set_section_contents (abfd, asect,
-						writebuf, memaddr - p->addr,
+						writebuf, memaddr - p.addr,
 						len);
 	      else
 		res = bfd_get_section_contents (abfd, asect,
-						readbuf, memaddr - p->addr,
+						readbuf, memaddr - p.addr,
 						len);
 
 	      if (res != 0)
@@ -985,7 +917,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
 	      else
 		return TARGET_XFER_EOF;
 	    }
-	  else if (memaddr >= p->endaddr)
+	  else if (memaddr >= p.endaddr)
 	    {
 	      /* This section ends before the transfer starts.  */
 	      continue;
@@ -993,14 +925,14 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
 	  else
 	    {
 	      /* This section overlaps the transfer.  Just do half.  */
-	      len = p->endaddr - memaddr;
+	      len = p.endaddr - memaddr;
 	      if (writebuf)
 		res = bfd_set_section_contents (abfd, asect,
-						writebuf, memaddr - p->addr,
+						writebuf, memaddr - p.addr,
 						len);
 	      else
 		res = bfd_get_section_contents (abfd, asect,
-						readbuf, memaddr - p->addr,
+						readbuf, memaddr - p.addr,
 						len);
 	      if (res != 0)
 		{
@@ -1033,8 +965,7 @@ exec_target::xfer_partial (enum target_object object,
   if (object == TARGET_OBJECT_MEMORY)
     return section_table_xfer_memory_partial (readbuf, writebuf,
 					      offset, len, xfered_len,
-					      table->sections,
-					      table->sections_end);
+					      *table);
   else
     return TARGET_XFER_E_IO;
 }
@@ -1044,7 +975,6 @@ void
 print_section_info (struct target_section_table *t, bfd *abfd)
 {
   struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
-  struct target_section *p;
   /* FIXME: 16 is not wide enough when gdbarch_addr_bit > 64.  */
   int wid = gdbarch_addr_bit (gdbarch) <= 32 ? 8 : 16;
 
@@ -1059,10 +989,11 @@ print_section_info (struct target_section_table *t, bfd *abfd)
 	 <p == t->sections_end>.  */
       bfd_vma displacement = 0;
       bfd_vma entry_point;
+      bool found = false;
 
-      for (p = t->sections; p < t->sections_end; p++)
+      for (const target_section &p : t->sections)
 	{
-	  struct bfd_section *psect = p->the_bfd_section;
+	  struct bfd_section *psect = p.the_bfd_section;
 
 	  if ((bfd_section_flags (psect) & (SEC_ALLOC | SEC_LOAD))
 	      != (SEC_ALLOC | SEC_LOAD))
@@ -1072,11 +1003,12 @@ print_section_info (struct target_section_table *t, bfd *abfd)
 	      && abfd->start_address < (bfd_section_vma (psect)
 					+ bfd_section_size (psect)))
 	    {
-	      displacement = p->addr - bfd_section_vma (psect);
+	      displacement = p.addr - bfd_section_vma (psect);
+	      found = true;
 	      break;
 	    }
 	}
-      if (p == t->sections_end)
+      if (!found)
 	warning (_("Cannot find section for the entry point of %ps."),
 		 styled_string (file_name_style.style (),
 				bfd_get_filename (abfd)));
@@ -1087,13 +1019,13 @@ print_section_info (struct target_section_table *t, bfd *abfd)
       printf_filtered (_("\tEntry point: %s\n"),
 		       paddress (gdbarch, entry_point));
     }
-  for (p = t->sections; p < t->sections_end; p++)
+  for (const target_section &p : t->sections)
     {
-      struct bfd_section *psect = p->the_bfd_section;
+      struct bfd_section *psect = p.the_bfd_section;
       bfd *pbfd = psect->owner;
 
-      printf_filtered ("\t%s", hex_string_custom (p->addr, wid));
-      printf_filtered (" - %s", hex_string_custom (p->endaddr, wid));
+      printf_filtered ("\t%s", hex_string_custom (p.addr, wid));
+      printf_filtered (" - %s", hex_string_custom (p.endaddr, wid));
 
       /* FIXME: A format of "08l" is not wide enough for file offsets
 	 larger than 4GB.  OTOH, making it "016l" isn't desirable either
@@ -1125,7 +1057,6 @@ exec_target::files_info ()
 static void
 set_section_command (const char *args, int from_tty)
 {
-  struct target_section *p;
   const char *secname;
   unsigned seclen;
   unsigned long secaddr;
@@ -1144,14 +1075,14 @@ set_section_command (const char *args, int from_tty)
   secaddr = parse_and_eval_address (args);
 
   table = current_target_sections;
-  for (p = table->sections; p < table->sections_end; p++)
+  for (target_section &p : table->sections)
     {
-      if (!strncmp (secname, bfd_section_name (p->the_bfd_section), seclen)
-	  && bfd_section_name (p->the_bfd_section)[seclen] == '\0')
+      if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen)
+	  && bfd_section_name (p.the_bfd_section)[seclen] == '\0')
 	{
-	  offset = secaddr - p->addr;
-	  p->addr += offset;
-	  p->endaddr += offset;
+	  offset = secaddr - p.addr;
+	  p.addr += offset;
+	  p.endaddr += offset;
 	  if (from_tty)
 	    exec_ops.files_info ();
 	  return;
@@ -1170,18 +1101,17 @@ set_section_command (const char *args, int from_tty)
 void
 exec_set_section_address (const char *filename, int index, CORE_ADDR address)
 {
-  struct target_section *p;
   struct target_section_table *table;
 
   table = current_target_sections;
-  for (p = table->sections; p < table->sections_end; p++)
+  for (target_section &p : table->sections)
     {
       if (filename_cmp (filename,
-			bfd_get_filename (p->the_bfd_section->owner)) == 0
-	  && index == p->the_bfd_section->index)
+			bfd_get_filename (p.the_bfd_section->owner)) == 0
+	  && index == p.the_bfd_section->index)
 	{
-	  p->endaddr += address - p->addr;
-	  p->addr = address;
+	  p.endaddr += address - p.addr;
+	  p.addr = address;
 	}
     }
 }
@@ -1191,8 +1121,7 @@ exec_target::has_memory ()
 {
   /* We can provide memory if we have any file/target sections to read
      from.  */
-  return (current_target_sections->sections
-	  != current_target_sections->sections_end);
+  return !current_target_sections->sections.empty ();
 }
 
 char *
diff --git a/gdb/exec.h b/gdb/exec.h
index 82eb39c55d8..d26eba49236 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -37,8 +37,7 @@ struct objfile;
 /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
    Returns 0 if OK, 1 on error.  */
 
-extern int build_section_table (struct bfd *, struct target_section **,
-				struct target_section **);
+extern int build_section_table (struct bfd *, struct target_section_table *);
 
 /* Remove all entries from TABLE.  */
 
@@ -86,8 +85,7 @@ extern enum target_xfer_status
   section_table_xfer_memory_partial (gdb_byte *,
 				     const gdb_byte *,
 				     ULONGEST, ULONGEST, ULONGEST *,
-				     struct target_section *,
-				     struct target_section *,
+				     const target_section_table &,
 				     gdb::function_view<bool
 				       (const struct target_section *)> match_cb
 				         = nullptr);
@@ -111,8 +109,7 @@ extern void remove_target_sections (void *owner);
    current set of target sections.  */
 
 extern void add_target_sections (void *owner,
-				 struct target_section *sections,
-				 struct target_section *sections_end);
+				 const target_section_table &sections);
 
 /* Add the sections of OBJFILE to the current set of target sections.
  * OBJFILE owns the new target sections.  */
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 9a6187e8104..5dcb42d2f4e 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -171,8 +171,7 @@ struct record_full_core_buf_entry
 
 /* Record buf with core target.  */
 static detached_regcache *record_full_core_regbuf = NULL;
-static struct target_section *record_full_core_start;
-static struct target_section *record_full_core_end;
+static target_section_table record_full_core_sections;
 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
 
 /* The following variables are used for managing the linked list that
@@ -924,9 +923,7 @@ record_full_core_open_1 (const char *name, int from_tty)
   for (i = 0; i < regnum; i ++)
     record_full_core_regbuf->raw_supply (i, *regcache);
 
-  /* Get record_full_core_start and record_full_core_end.  */
-  if (build_section_table (core_bfd, &record_full_core_start,
-			   &record_full_core_end))
+  if (build_section_table (core_bfd, &record_full_core_sections))
     {
       delete record_full_core_regbuf;
       record_full_core_regbuf = NULL;
@@ -2147,27 +2144,25 @@ record_full_core_target::xfer_partial (enum target_object object,
     {
       if (record_full_gdb_operation_disable || !writebuf)
 	{
-	  struct target_section *p;
-
-	  for (p = record_full_core_start; p < record_full_core_end; p++)
+	  for (target_section &p : record_full_core_sections.sections)
 	    {
-	      if (offset >= p->addr)
+	      if (offset >= p.addr)
 		{
 		  struct record_full_core_buf_entry *entry;
 		  ULONGEST sec_offset;
 
-		  if (offset >= p->endaddr)
+		  if (offset >= p.endaddr)
 		    continue;
 
-		  if (offset + len > p->endaddr)
-		    len = p->endaddr - offset;
+		  if (offset + len > p.endaddr)
+		    len = p.endaddr - offset;
 
-		  sec_offset = offset - p->addr;
+		  sec_offset = offset - p.addr;
 
 		  /* Read readbuf or write writebuf p, offset, len.  */
 		  /* Check flags.  */
-		  if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
-		      || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
+		  if (p.the_bfd_section->flags & SEC_CONSTRUCTOR
+		      || (p.the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
 		    {
 		      if (readbuf)
 			memset (readbuf, 0, len);
@@ -2178,7 +2173,7 @@ record_full_core_target::xfer_partial (enum target_object object,
 		  /* Get record_full_core_buf_entry.  */
 		  for (entry = record_full_core_buf_list; entry;
 		       entry = entry->prev)
-		    if (entry->p == p)
+		    if (entry->p == &p)
 		      break;
 		  if (writebuf)
 		    {
@@ -2186,10 +2181,10 @@ record_full_core_target::xfer_partial (enum target_object object,
 			{
 			  /* Add a new entry.  */
 			  entry = XNEW (struct record_full_core_buf_entry);
-			  entry->p = p;
+			  entry->p = &p;
 			  if (!bfd_malloc_and_get_section
-			        (p->the_bfd_section->owner,
-				 p->the_bfd_section,
+			        (p.the_bfd_section->owner,
+				 p.the_bfd_section,
 				 &entry->buf))
 			    {
 			      xfree (entry);
diff --git a/gdb/remote.c b/gdb/remote.c
index f95148643f8..c9c5ed03ea2 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -8895,22 +8895,21 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
   if (secp != NULL
       && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
     {
-      struct target_section *p;
       ULONGEST memend = memaddr + len;
 
       table = target_get_section_table (this);
 
-      for (p = table->sections; p < table->sections_end; p++)
+      for (target_section &p : table->sections)
 	{
-	  if (memaddr >= p->addr)
+	  if (memaddr >= p.addr)
 	    {
-	      if (memend <= p->endaddr)
+	      if (memend <= p.endaddr)
 		{
 		  /* Entire transfer is within this section.  */
 		  return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
 					      xfered_len);
 		}
-	      else if (memaddr >= p->endaddr)
+	      else if (memaddr >= p.endaddr)
 		{
 		  /* This section ends before the transfer starts.  */
 		  continue;
@@ -8918,7 +8917,7 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
 	      else
 		{
 		  /* This section overlaps the transfer.  Just do half.  */
-		  len = p->endaddr - memaddr;
+		  len = p.endaddr - memaddr;
 		  return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
 					      xfered_len);
 		}
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 0f146725dba..59089216314 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -407,7 +407,6 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
   Elf32_External_Dyn *x_dynp_32;
   Elf64_External_Dyn *x_dynp_64;
   struct bfd_section *sect;
-  struct target_section *target_section;
 
   if (abfd == NULL)
     return 0;
@@ -424,14 +423,15 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
   if (sect == NULL)
     return 0;
 
-  for (target_section = current_target_sections->sections;
-       target_section < current_target_sections->sections_end;
-       target_section++)
-    if (sect == target_section->the_bfd_section)
-      break;
-  if (target_section < current_target_sections->sections_end)
-    dyn_addr = target_section->addr;
-  else
+  bool found = false;
+  for (target_section &target_section : current_target_sections->sections)
+    if (sect == target_section.the_bfd_section)
+      {
+	dyn_addr = target_section.addr;
+	found = true;
+	break;
+      }
+  if (!found)
     {
       /* ABFD may come from OBJFILE acting only as a symbol file without being
 	 loaded into the target (see add_symbol_file_command).  This case is
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 4ae21d190bf..9bb728ae9b9 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -591,7 +591,6 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
   Elf32_External_Dyn *x_dynp_32;
   Elf64_External_Dyn *x_dynp_64;
   struct bfd_section *sect;
-  struct target_section *target_section;
 
   if (abfd == NULL)
     return 0;
@@ -608,14 +607,15 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
   if (sect == NULL)
     return 0;
 
-  for (target_section = current_target_sections->sections;
-       target_section < current_target_sections->sections_end;
-       target_section++)
-    if (sect == target_section->the_bfd_section)
-      break;
-  if (target_section < current_target_sections->sections_end)
-    dyn_addr = target_section->addr;
-  else
+  bool found = false;
+  for (target_section &target_section : current_target_sections->sections)
+    if (sect == target_section.the_bfd_section)
+      {
+	dyn_addr = target_section.addr;
+	found = true;
+	break;
+      }
+  if (!found)
     {
       /* ABFD may come from OBJFILE acting only as a symbol file without being
 	 loaded into the target (see add_symbol_file_command).  This case is
diff --git a/gdb/solib.c b/gdb/solib.c
index cf5d05e83b2..906e1788c49 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -532,7 +532,6 @@ static int
 solib_map_sections (struct so_list *so)
 {
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
-  struct target_section *p;
 
   gdb::unique_xmalloc_ptr<char> filename (tilde_expand (so->so_name));
   gdb_bfd_ref_ptr abfd (ops->bfd_open (filename.get ()));
@@ -553,27 +552,29 @@ solib_map_sections (struct so_list *so)
     error (_("Shared library file name is too long."));
   strcpy (so->so_name, bfd_get_filename (so->abfd));
 
-  if (build_section_table (so->abfd, &so->sections, &so->sections_end))
+  if (so->sections == nullptr)
+    so->sections = new target_section_table;
+  if (build_section_table (so->abfd, so->sections))
     {
       error (_("Can't find the file sections in `%s': %s"),
 	     bfd_get_filename (so->abfd), bfd_errmsg (bfd_get_error ()));
     }
 
-  for (p = so->sections; p < so->sections_end; p++)
+  for (target_section &p : so->sections->sections)
     {
       /* Relocate the section binding addresses as recorded in the shared
          object's file by the base address to which the object was actually
          mapped.  */
-      ops->relocate_section_addresses (so, p);
+      ops->relocate_section_addresses (so, &p);
 
       /* If the target didn't provide information about the address
 	 range of the shared object, assume we want the location of
 	 the .text section.  */
       if (so->addr_low == 0 && so->addr_high == 0
-	  && strcmp (p->the_bfd_section->name, ".text") == 0)
+	  && strcmp (p.the_bfd_section->name, ".text") == 0)
 	{
-	  so->addr_low = p->addr;
-	  so->addr_high = p->endaddr;
+	  so->addr_low = p.addr;
+	  so->addr_high = p.endaddr;
 	}
     }
 
@@ -581,7 +582,7 @@ solib_map_sections (struct so_list *so)
      section tables.  Do this immediately after mapping the object so
      that later nodes in the list can query this object, as is needed
      in solib-osf.c.  */
-  add_target_sections (so, so->sections, so->sections_end);
+  add_target_sections (so, *so->sections);
 
   return 1;
 }
@@ -600,11 +601,8 @@ clear_so (struct so_list *so)
 {
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
 
-  if (so->sections)
-    {
-      xfree (so->sections);
-      so->sections = so->sections_end = NULL;
-    }
+  delete so->sections;
+  so->sections = NULL;
 
   gdb_bfd_unref (so->abfd);
   so->abfd = NULL;
@@ -683,8 +681,7 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags)
 	  if (so->objfile == NULL)
 	    {
 	      section_addr_info sap
-		= build_section_addr_info_from_section_table (so->sections,
-							      so->sections_end);
+		= build_section_addr_info_from_section_table (*so->sections);
 	      so->objfile = symbol_file_add_from_bfd (so->abfd, so->so_name,
 						      flags, &sap,
 						      OBJF_SHARED, NULL);
@@ -1120,10 +1117,8 @@ bool
 solib_contains_address_p (const struct so_list *const solib,
 			  CORE_ADDR address)
 {
-  struct target_section *p;
-
-  for (p = solib->sections; p < solib->sections_end; p++)
-    if (p->addr <= address && address < p->endaddr)
+  for (target_section &p : solib->sections->sections)
+    if (p.addr <= address && address < p.endaddr)
       return true;
 
   return false;
diff --git a/gdb/solist.h b/gdb/solist.h
index 0360d342ae8..1de797cc14b 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -23,6 +23,7 @@
 /* For domain_enum domain.  */
 #include "symtab.h"
 #include "gdb_bfd.h"
+#include "target-section.h"
 
 /* Base class for target-specific link map information.  */
 
@@ -71,8 +72,7 @@ struct so_list
      the file cannot be found or after the command "nosharedlibrary".  */
   struct objfile *objfile;
 
-  struct target_section *sections;
-  struct target_section *sections_end;
+  target_section_table *sections;
 
   /* Record the range of addresses belonging to this shared library.
      There may not be just one (e.g. if two segments are relocated
diff --git a/gdb/symfile.c b/gdb/symfile.c
index baed72e936e..f4acec50cca 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -212,21 +212,18 @@ find_lowest_section (asection *sect, asection **lowest)
    an existing section table.  */
 
 section_addr_info
-build_section_addr_info_from_section_table (const struct target_section *start,
-                                            const struct target_section *end)
+build_section_addr_info_from_section_table (const target_section_table &table)
 {
-  const struct target_section *stp;
-
   section_addr_info sap;
 
-  for (stp = start; stp != end; stp++)
+  for (const target_section &stp : table.sections)
     {
-      struct bfd_section *asect = stp->the_bfd_section;
+      struct bfd_section *asect = stp.the_bfd_section;
       bfd *abfd = asect->owner;
 
       if (bfd_section_flags (asect) & (SEC_ALLOC | SEC_LOAD)
-	  && sap.size () < end - start)
-	sap.emplace_back (stp->addr,
+	  && sap.size () < table.sections.size ())
+	sap.emplace_back (stp.addr,
 			  bfd_section_name (asect),
 			  gdb_bfd_section_index (abfd, asect));
     }
diff --git a/gdb/symfile.h b/gdb/symfile.h
index ae29451fc6a..df646f0736f 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -27,6 +27,7 @@
 #include "objfile-flags.h"
 #include "gdb_bfd.h"
 #include "gdbsupport/function-view.h"
+#include "target-section.h"
 
 /* Opaque declarations.  */
 struct target_section;
@@ -451,10 +452,7 @@ extern std::string find_separate_debug_file_by_debuglink (struct objfile *);
    existing section table.  */
 
 extern section_addr_info
-   build_section_addr_info_from_section_table (const struct target_section
-					       *start,
-					       const struct target_section
-					       *end);
+    build_section_addr_info_from_section_table (const target_section_table &table);
 
 			/*   Variables   */
 
diff --git a/gdb/target-section.h b/gdb/target-section.h
index 581bc1dbe9f..8c81f3d79ba 100644
--- a/gdb/target-section.h
+++ b/gdb/target-section.h
@@ -39,12 +39,11 @@ struct target_section
     void *owner;
   };
 
-/* Holds an array of target sections.  Defined by [SECTIONS..SECTIONS_END[.  */
+/* Holds an array of target sections.  */
 
 struct target_section_table
 {
-  struct target_section *sections;
-  struct target_section *sections_end;
+  std::vector<struct target_section> sections;
 };
 
 #endif /* GDB_TARGET_SECTION_H */
diff --git a/gdb/target.c b/gdb/target.c
index dd78a848cae..f828d3d6cc3 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -823,15 +823,14 @@ struct target_section *
 target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
 {
   struct target_section_table *table = target_get_section_table (target);
-  struct target_section *secp;
 
   if (table == NULL)
     return NULL;
 
-  for (secp = table->sections; secp < table->sections_end; secp++)
+  for (target_section &secp : table->sections)
     {
-      if (addr >= secp->addr && addr < secp->endaddr)
-	return secp;
+      if (addr >= secp.addr && addr < secp.endaddr)
+	return &secp;
     }
   return NULL;
 }
@@ -978,9 +977,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
 
 	  return section_table_xfer_memory_partial (readbuf, writebuf,
 						    memaddr, len, xfered_len,
-						    table->sections,
-						    table->sections_end,
-						    match_cb);
+						    *table, match_cb);
 	}
     }
 
@@ -997,8 +994,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
 	  table = target_get_section_table (ops);
 	  return section_table_xfer_memory_partial (readbuf, writebuf,
 						    memaddr, len, xfered_len,
-						    table->sections,
-						    table->sections_end);
+						    *table);
 	}
     }
 
-- 
2.17.2


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 3/6] build_section_table cannot fail
  2020-10-03 19:37 [PATCH 0/6] Change target section table management Tom Tromey
  2020-10-03 19:37 ` [PATCH 1/6] Introduce target-section.h Tom Tromey
  2020-10-03 19:37 ` [PATCH 2/6] Use a std::vector in target_section_table Tom Tromey
@ 2020-10-03 19:37 ` Tom Tromey
  2020-10-04  8:38   ` Andrew Burgess
  2020-10-03 19:37 ` [PATCH 4/6] Simplify add_target_sections_of_objfile Tom Tromey
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-10-03 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I noticed that build_section_table cannot fail.  This patch changes it
to return a target_section_table and then removes the dead code.

2020-10-03  Tom Tromey  <tom@tromey.com>

	* solib.c (solib_map_sections): Update.
	* record-full.c (record_full_core_open_1): Update.
	* exec.h (build_section_table): Return a target_section_table.
	* exec.c (exec_file_attach): Update.
	(build_section_table): Return a target_section_table.
	* corelow.c (core_target::core_target): Update.
	* bfd-target.c (target_bfd::target_bfd): Update.
---
 gdb/ChangeLog     | 10 ++++++++++
 gdb/bfd-target.c  |  4 ++--
 gdb/corelow.c     |  4 +---
 gdb/exec.c        | 28 +++++++++-------------------
 gdb/exec.h        |  5 ++---
 gdb/record-full.c |  8 +-------
 gdb/solib.c       |  6 +-----
 7 files changed, 26 insertions(+), 39 deletions(-)

diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index 8a58e92eb1c..d5defab9a80 100644
--- a/gdb/bfd-target.c
+++ b/gdb/bfd-target.c
@@ -89,9 +89,9 @@ target_bfd::get_section_table ()
 }
 
 target_bfd::target_bfd (struct bfd *abfd)
-  : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
+  : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd)),
+    m_table (build_section_table (abfd))
 {
-  build_section_table (abfd, &m_table);
 }
 
 target_ops *
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 554561dbb36..193dccbeeb5 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -161,9 +161,7 @@ core_target::core_target ()
 	   bfd_get_filename (core_bfd));
 
   /* Find the data section */
-  if (build_section_table (core_bfd, &m_core_section_table))
-    error (_("\"%s\": Can't find sections: %s"),
-	   bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
+  m_core_section_table = build_section_table (core_bfd);
 
   build_file_mappings ();
 }
diff --git a/gdb/exec.c b/gdb/exec.c
index e3e515fedec..d4b9b7bcf65 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -413,7 +413,6 @@ exec_file_attach (const char *filename, int from_tty)
       int load_via_target = 0;
       const char *scratch_pathname, *canonical_pathname;
       int scratch_chan;
-      target_section_table sections;
       char **matching;
 
       if (is_target_filename (filename))
@@ -503,15 +502,7 @@ exec_file_attach (const char *filename, int from_tty)
 		 gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
 	}
 
-      if (build_section_table (exec_bfd, &sections))
-	{
-	  /* Make sure to close exec_bfd, or else "run" might try to use
-	     it.  */
-	  exec_close ();
-	  error (_("\"%ps\": can't find the file sections: %s"),
-		 styled_string (file_name_style.style (), scratch_pathname),
-		 bfd_errmsg (bfd_get_error ()));
-	}
+      target_section_table sections = build_section_table (exec_bfd);
 
       exec_bfd_mtime = bfd_get_mtime (exec_bfd);
 
@@ -594,13 +585,13 @@ clear_section_table (struct target_section_table *table)
   table->sections.clear ();
 }
 
-/* Builds a section table, given args BFD, TABLE.
-   Returns 0 if OK, 1 on error.  */
+/* Builds a section table, given args BFD, TABLE.  */
 
-int
-build_section_table (struct bfd *some_bfd, target_section_table *table)
+target_section_table
+build_section_table (struct bfd *some_bfd)
 {
-  table->sections.clear ();
+  target_section_table table;
+
   for (asection *asect : gdb_bfd_sections (some_bfd))
     {
       flagword aflag;
@@ -615,16 +606,15 @@ build_section_table (struct bfd *some_bfd, target_section_table *table)
       if (!(aflag & SEC_ALLOC))
 	continue;
 
-      table->sections.emplace_back ();
-      target_section &sect = table->sections.back ();
+      table.sections.emplace_back ();
+      target_section &sect = table.sections.back ();
       sect.owner = NULL;
       sect.the_bfd_section = asect;
       sect.addr = bfd_section_vma (asect);
       sect.endaddr = sect.addr + bfd_section_size (asect);
     }
 
-  /* We could realloc the table, but it probably loses for most files.  */
-  return 0;
+  return table;
 }
 
 /* Add the sections array defined by [SECTIONS..SECTIONS_END[ to the
diff --git a/gdb/exec.h b/gdb/exec.h
index d26eba49236..75177dda96a 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -34,10 +34,9 @@ struct objfile;
 #define exec_bfd_mtime current_program_space->ebfd_mtime
 #define exec_filename current_program_space->pspace_exec_filename
 
-/* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
-   Returns 0 if OK, 1 on error.  */
+/* Builds a section table, given args BFD.  */
 
-extern int build_section_table (struct bfd *, struct target_section_table *);
+extern target_section_table build_section_table (struct bfd *);
 
 /* Remove all entries from TABLE.  */
 
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 5dcb42d2f4e..40740f216ce 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -923,13 +923,7 @@ record_full_core_open_1 (const char *name, int from_tty)
   for (i = 0; i < regnum; i ++)
     record_full_core_regbuf->raw_supply (i, *regcache);
 
-  if (build_section_table (core_bfd, &record_full_core_sections))
-    {
-      delete record_full_core_regbuf;
-      record_full_core_regbuf = NULL;
-      error (_("\"%s\": Can't find sections: %s"),
-	     bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
-    }
+  record_full_core_sections = build_section_table (core_bfd);
 
   push_target (&record_full_core_ops);
   record_full_restore ();
diff --git a/gdb/solib.c b/gdb/solib.c
index 906e1788c49..bd6a27d8983 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -554,11 +554,7 @@ solib_map_sections (struct so_list *so)
 
   if (so->sections == nullptr)
     so->sections = new target_section_table;
-  if (build_section_table (so->abfd, so->sections))
-    {
-      error (_("Can't find the file sections in `%s': %s"),
-	     bfd_get_filename (so->abfd), bfd_errmsg (bfd_get_error ()));
-    }
+  *so->sections = build_section_table (so->abfd);
 
   for (target_section &p : so->sections->sections)
     {
-- 
2.17.2


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 4/6] Simplify add_target_sections_of_objfile
  2020-10-03 19:37 [PATCH 0/6] Change target section table management Tom Tromey
                   ` (2 preceding siblings ...)
  2020-10-03 19:37 ` [PATCH 3/6] build_section_table cannot fail Tom Tromey
@ 2020-10-03 19:37 ` Tom Tromey
  2020-10-04  8:40   ` Andrew Burgess
  2020-10-03 19:37 ` [PATCH 5/6] Remove clear_section_table Tom Tromey
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-10-03 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Now that target_section_table uses std::vector,
add_target_sections_of_objfile does not need to loop twice.  This
patch simplifies this code to have just a single loop.  Also, the
passed-in objfile can never be NULL, so this changes this function to
assert that.

2020-10-03  Tom Tromey  <tom@tromey.com>

	* exec.c (add_target_sections_of_objfile): Simplify.
---
 gdb/ChangeLog |  4 ++++
 gdb/exec.c    | 14 +-------------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index d4b9b7bcf65..43385fe978f 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -661,22 +661,10 @@ add_target_sections_of_objfile (struct objfile *objfile)
 {
   struct target_section_table *table = current_target_sections;
   struct obj_section *osect;
-  unsigned count = 0;
 
-  if (objfile == NULL)
-    return;
+  gdb_assert (objfile != nullptr);
 
   /* Compute the number of sections to add.  */
-  ALL_OBJFILE_OSECTIONS (objfile, osect)
-    {
-      if (bfd_section_size (osect->the_bfd_section) == 0)
-	continue;
-      count++;
-    }
-
-  if (count == 0)
-    return;
-
   ALL_OBJFILE_OSECTIONS (objfile, osect)
     {
       if (bfd_section_size (osect->the_bfd_section) == 0)
-- 
2.17.2


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 5/6] Remove clear_section_table
  2020-10-03 19:37 [PATCH 0/6] Change target section table management Tom Tromey
                   ` (3 preceding siblings ...)
  2020-10-03 19:37 ` [PATCH 4/6] Simplify add_target_sections_of_objfile Tom Tromey
@ 2020-10-03 19:37 ` Tom Tromey
  2020-10-04  8:44   ` Andrew Burgess
  2020-10-03 19:37 ` [PATCH 6/6] Change target_section_table to std::vector alias Tom Tromey
  2020-10-13  2:19 ` [PATCH 0/6] Change target section table management Tom Tromey
  6 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-10-03 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The call to clear_section_table in ~program_space is now clearly not
needed -- the section table will clear itself.  This patch removes
this call and then inlines the one remaining call to
clear_section_table.

2020-10-03  Tom Tromey  <tom@tromey.com>

	* progspace.c (program_space::~program_space): Don't call
	clear_section_table.
	* exec.h (clear_section_table): Don't declare.
	* exec.c (exec_target::close): Update.
	(clear_section_table): Remove.
---
 gdb/ChangeLog   |  8 ++++++++
 gdb/exec.c      | 10 +---------
 gdb/exec.h      |  4 ----
 gdb/progspace.c |  1 -
 4 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index 43385fe978f..ab47757c2b4 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -183,7 +183,7 @@ exec_target::close ()
   for (struct program_space *ss : program_spaces)
     {
       set_current_program_space (ss);
-      clear_section_table (current_target_sections);
+      current_target_sections->sections.clear ();
       exec_close ();
     }
 }
@@ -577,14 +577,6 @@ file_command (const char *arg, int from_tty)
 }
 \f
 
-/* See exec.h.  */
-
-void
-clear_section_table (struct target_section_table *table)
-{
-  table->sections.clear ();
-}
-
 /* Builds a section table, given args BFD, TABLE.  */
 
 target_section_table
diff --git a/gdb/exec.h b/gdb/exec.h
index 75177dda96a..f28a033428d 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -38,10 +38,6 @@ struct objfile;
 
 extern target_section_table build_section_table (struct bfd *);
 
-/* Remove all entries from TABLE.  */
-
-extern void clear_section_table (struct target_section_table *table);
-
 /* The current inferior is a child vforked and its program space is
    shared with its parent.  This pushes the exec target on the
    current/child inferior's target stack if there are sections in the
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 3f512161215..67ea8bdb9e9 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -154,7 +154,6 @@ program_space::~program_space ()
   clear_symtab_users (SYMFILE_DEFER_BP_RESET);
   if (!gdbarch_has_shared_address_space (target_gdbarch ()))
     free_address_space (this->aspace);
-  clear_section_table (&this->target_sections);
   clear_program_space_solib_cache (this);
     /* Discard any data modules have associated with the PSPACE.  */
   program_space_free_data (this);
-- 
2.17.2


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 6/6] Change target_section_table to std::vector alias
  2020-10-03 19:37 [PATCH 0/6] Change target section table management Tom Tromey
                   ` (4 preceding siblings ...)
  2020-10-03 19:37 ` [PATCH 5/6] Remove clear_section_table Tom Tromey
@ 2020-10-03 19:37 ` Tom Tromey
  2020-10-04  8:46   ` Andrew Burgess
  2020-10-13  2:19 ` [PATCH 0/6] Change target section table management Tom Tromey
  6 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-10-03 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Because target_section_table only holds a vector, and because it is
used in an "open" way, this patch makes it just be an alias for the
std::vector specialization.  This makes the code less wordy.  If we do
ever want to add more specialized behavior to this type, it's simple
enough to convert it back to a struct with the few needed methods
implied by this change.

2020-10-03  Tom Tromey  <tom@tromey.com>

	* target.h (struct target_ops) <get_section_table>: Update.
	(target_get_section_table): Update.
	* target.c (target_get_section_table, target_section_by_addr)
	(memory_xfer_partial_1): Update.
	* target-section.h (target_section_table): Now an alias.
	* target-delegates.c: Rebuild.
	* target-debug.h (target_debug_print_target_section_table_p):
	Rename from target_debug_print_struct_target_section_table_p.
	* symfile.c (build_section_addr_info_from_section_table): Update.
	* solib.c (solib_map_sections, solib_contains_address_p): Update.
	* solib-svr4.c (scan_dyntag): Update.
	* solib-dsbt.c (scan_dyntag): Update.
	* remote.c (remote_target::remote_xfer_live_readonly_partial):
	Update.
	* record-full.c (record_full_core_target::xfer_partial): Update.
	* progspace.h (struct program_space) <target_sections>: Update.
	* exec.h (print_section_info): Update.
	* exec.c (exec_target::close, build_section_table)
	(add_target_sections, add_target_sections_of_objfile)
	(remove_target_sections, exec_on_vfork)
	(section_table_available_memory)
	(section_table_xfer_memory_partial)
	(exec_target::get_section_table, exec_target::xfer_partial)
	(print_section_info, set_section_command)
	(exec_set_section_address, exec_target::has_memory): Update.
	* corelow.c (core_target::build_file_mappings)
	(core_target::xfer_partial, core_target::info_proc_mappings)
	(core_target::info_proc_mappings): Update.
	* bfd-target.c (class target_bfd): Update
---
 gdb/ChangeLog          | 32 +++++++++++++++++++++
 gdb/bfd-target.c       |  2 +-
 gdb/corelow.c          | 10 +++----
 gdb/exec.c             | 63 +++++++++++++++++++-----------------------
 gdb/exec.h             |  2 +-
 gdb/progspace.h        |  2 +-
 gdb/record-full.c      |  2 +-
 gdb/remote.c           |  6 ++--
 gdb/solib-dsbt.c       |  2 +-
 gdb/solib-svr4.c       |  2 +-
 gdb/solib.c            |  4 +--
 gdb/symfile.c          |  4 +--
 gdb/target-debug.h     |  2 +-
 gdb/target-delegates.c | 14 +++++-----
 gdb/target-section.h   |  5 +---
 gdb/target.c           | 12 ++++----
 gdb/target.h           |  5 ++--
 17 files changed, 94 insertions(+), 75 deletions(-)

diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index d5defab9a80..bf4a98594bd 100644
--- a/gdb/bfd-target.c
+++ b/gdb/bfd-target.c
@@ -59,7 +59,7 @@ class target_bfd : public target_ops
   /* The section table build from the ALLOC sections in BFD.  Note
      that we can't rely on extracting the BFD from a random section in
      the table, since the table can be legitimately empty.  */
-  struct target_section_table m_table;
+  target_section_table m_table;
 };
 
 target_xfer_status
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 193dccbeeb5..d557475e06f 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -266,8 +266,8 @@ core_target::build_file_mappings ()
 	bfd_set_section_alignment (sec, 2);
 
 	/* Set target_section fields.  */
-	m_core_file_mappings.sections.emplace_back ();
-	target_section &ts = m_core_file_mappings.sections.back ();
+	m_core_file_mappings.emplace_back ();
+	target_section &ts = m_core_file_mappings.back ();
 	ts.addr = start;
 	ts.endaddr = end;
 	ts.owner = nullptr;
@@ -814,7 +814,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
 	   or the like) as this should provide a more accurate
 	   result.  If not, check the stratum beneath us, which should
 	   be the file stratum.  */
-	if (!m_core_file_mappings.sections.empty ())
+	if (!m_core_file_mappings.empty ())
 	  xfer_status = xfer_memory_via_mappings (readbuf, writebuf, offset,
 						  len, xfered_len);
 	else
@@ -1098,7 +1098,7 @@ get_current_core_target ()
 void
 core_target::info_proc_mappings (struct gdbarch *gdbarch)
 {
-  if (!m_core_file_mappings.sections.empty ())
+  if (!m_core_file_mappings.empty ())
     {
       printf_filtered (_("Mapped address spaces:\n\n"));
       if (gdbarch_addr_bit (gdbarch) == 32)
@@ -1117,7 +1117,7 @@ core_target::info_proc_mappings (struct gdbarch *gdbarch)
 	}
     }
 
-  for (const target_section &tsp : m_core_file_mappings.sections)
+  for (const target_section &tsp : m_core_file_mappings)
     {
       ULONGEST start = tsp.addr;
       ULONGEST end = tsp.endaddr;
diff --git a/gdb/exec.c b/gdb/exec.c
index ab47757c2b4..dd322129139 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -75,7 +75,7 @@ struct exec_target final : public target_ops
 					const gdb_byte *writebuf,
 					ULONGEST offset, ULONGEST len,
 					ULONGEST *xfered_len) override;
-  struct target_section_table *get_section_table () override;
+  target_section_table *get_section_table () override;
   void files_info () override;
 
   bool has_memory () override;
@@ -183,7 +183,7 @@ exec_target::close ()
   for (struct program_space *ss : program_spaces)
     {
       set_current_program_space (ss);
-      current_target_sections->sections.clear ();
+      current_target_sections->clear ();
       exec_close ();
     }
 }
@@ -598,8 +598,8 @@ build_section_table (struct bfd *some_bfd)
       if (!(aflag & SEC_ALLOC))
 	continue;
 
-      table.sections.emplace_back ();
-      target_section &sect = table.sections.back ();
+      table.emplace_back ();
+      target_section &sect = table.back ();
       sect.owner = NULL;
       sect.the_bfd_section = asect;
       sect.addr = bfd_section_vma (asect);
@@ -616,14 +616,14 @@ void
 add_target_sections (void *owner,
 		     const target_section_table &sections)
 {
-  struct target_section_table *table = current_target_sections;
+  target_section_table *table = current_target_sections;
 
-  if (!sections.sections.empty ())
+  if (!sections.empty ())
     {
-      for (const target_section &s : sections.sections)
+      for (const target_section &s : sections)
 	{
-	  table->sections.push_back (s);
-	  table->sections.back ().owner = owner;
+	  table->push_back (s);
+	  table->back ().owner = owner;
 	}
 
       scoped_restore_current_pspace_and_thread restore_pspace_thread;
@@ -651,7 +651,7 @@ add_target_sections (void *owner,
 void
 add_target_sections_of_objfile (struct objfile *objfile)
 {
-  struct target_section_table *table = current_target_sections;
+  target_section_table *table = current_target_sections;
   struct obj_section *osect;
 
   gdb_assert (objfile != nullptr);
@@ -662,8 +662,8 @@ add_target_sections_of_objfile (struct objfile *objfile)
       if (bfd_section_size (osect->the_bfd_section) == 0)
 	continue;
 
-      table->sections.emplace_back ();
-      target_section &ts = table->sections.back ();
+      table->emplace_back ();
+      target_section &ts = table->back ();
       ts.addr = obj_section_addr (osect);
       ts.endaddr = obj_section_endaddr (osect);
       ts.the_bfd_section = osect->the_bfd_section;
@@ -677,22 +677,22 @@ add_target_sections_of_objfile (struct objfile *objfile)
 void
 remove_target_sections (void *owner)
 {
-  struct target_section_table *table = current_target_sections;
+  target_section_table *table = current_target_sections;
 
   gdb_assert (owner != NULL);
 
-  auto it = std::remove_if (table->sections.begin (),
-			    table->sections.end (),
+  auto it = std::remove_if (table->begin (),
+			    table->end (),
 			    [&] (target_section &sect)
 			    {
 			      return sect.owner == owner;
 			    });
-  table->sections.erase (it, table->sections.end ());
+  table->erase (it, table->end ());
 
   /* If we don't have any more sections to read memory from,
      remove the file_stratum target from the stack of each
      inferior sharing the program space.  */
-  if (table->sections.empty ())
+  if (table->empty ())
     {
       scoped_restore_current_pspace_and_thread restore_pspace_thread;
       program_space *curr_pspace = current_program_space;
@@ -702,7 +702,7 @@ remove_target_sections (void *owner)
 	  if (inf->pspace != curr_pspace)
 	    continue;
 
-	  if (!inf->pspace->target_sections.sections.empty ())
+	  if (!inf->pspace->target_sections.empty ())
 	    continue;
 
 	  switch_to_inferior_no_thread (inf);
@@ -716,7 +716,7 @@ remove_target_sections (void *owner)
 void
 exec_on_vfork ()
 {
-  if (!current_program_space->target_sections.sections.empty ())
+  if (!current_program_space->target_sections.empty ())
     push_target (&exec_ops);
 }
 
@@ -779,7 +779,7 @@ section_table_available_memory (CORE_ADDR memaddr, ULONGEST len,
 {
   std::vector<mem_range> memory;
 
-  for (const target_section &p : sections.sections)
+  for (const target_section &p : sections)
     {
       if ((bfd_section_flags (p.the_bfd_section) & SEC_READONLY) == 0)
 	continue;
@@ -858,7 +858,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
 
   gdb_assert (len != 0);
 
-  for (const target_section &p : sections.sections)
+  for (const target_section &p : sections)
     {
       struct bfd_section *asect = p.the_bfd_section;
       bfd *abfd = asect->owner;
@@ -918,7 +918,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
   return TARGET_XFER_EOF;		/* We can't help.  */
 }
 
-struct target_section_table *
+target_section_table *
 exec_target::get_section_table ()
 {
   return current_target_sections;
@@ -930,7 +930,7 @@ exec_target::xfer_partial (enum target_object object,
 			   const gdb_byte *writebuf,
 			   ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
-  struct target_section_table *table = get_section_table ();
+  target_section_table *table = get_section_table ();
 
   if (object == TARGET_OBJECT_MEMORY)
     return section_table_xfer_memory_partial (readbuf, writebuf,
@@ -942,7 +942,7 @@ exec_target::xfer_partial (enum target_object object,
 \f
 
 void
-print_section_info (struct target_section_table *t, bfd *abfd)
+print_section_info (target_section_table *t, bfd *abfd)
 {
   struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
   /* FIXME: 16 is not wide enough when gdbarch_addr_bit > 64.  */
@@ -961,7 +961,7 @@ print_section_info (struct target_section_table *t, bfd *abfd)
       bfd_vma entry_point;
       bool found = false;
 
-      for (const target_section &p : t->sections)
+      for (const target_section &p : *t)
 	{
 	  struct bfd_section *psect = p.the_bfd_section;
 
@@ -989,7 +989,7 @@ print_section_info (struct target_section_table *t, bfd *abfd)
       printf_filtered (_("\tEntry point: %s\n"),
 		       paddress (gdbarch, entry_point));
     }
-  for (const target_section &p : t->sections)
+  for (const target_section &p : *t)
     {
       struct bfd_section *psect = p.the_bfd_section;
       bfd *pbfd = psect->owner;
@@ -1032,7 +1032,6 @@ set_section_command (const char *args, int from_tty)
   unsigned long secaddr;
   char secprint[100];
   long offset;
-  struct target_section_table *table;
 
   if (args == 0)
     error (_("Must specify section name and its virtual address"));
@@ -1044,8 +1043,7 @@ set_section_command (const char *args, int from_tty)
   /* Parse out new virtual address.  */
   secaddr = parse_and_eval_address (args);
 
-  table = current_target_sections;
-  for (target_section &p : table->sections)
+  for (target_section &p : *current_target_sections)
     {
       if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen)
 	  && bfd_section_name (p.the_bfd_section)[seclen] == '\0')
@@ -1071,10 +1069,7 @@ set_section_command (const char *args, int from_tty)
 void
 exec_set_section_address (const char *filename, int index, CORE_ADDR address)
 {
-  struct target_section_table *table;
-
-  table = current_target_sections;
-  for (target_section &p : table->sections)
+  for (target_section &p : *current_target_sections)
     {
       if (filename_cmp (filename,
 			bfd_get_filename (p.the_bfd_section->owner)) == 0
@@ -1091,7 +1086,7 @@ exec_target::has_memory ()
 {
   /* We can provide memory if we have any file/target sections to read
      from.  */
-  return !current_target_sections->sections.empty ();
+  return !current_target_sections->empty ();
 }
 
 char *
diff --git a/gdb/exec.h b/gdb/exec.h
index f28a033428d..24489654ddc 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -115,7 +115,7 @@ extern void add_target_sections_of_objfile (struct objfile *objfile);
    special cased --- it's filename is omitted; if it is the executable
    file, its entry point is printed.  */
 
-extern void print_section_info (struct target_section_table *table,
+extern void print_section_info (target_section_table *table,
 				bfd *abfd);
 
 extern void exec_close (void);
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 099b4dc0b3a..6a0e9036399 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -325,7 +325,7 @@ struct program_space
 
   /* The set of target sections matching the sections mapped into
      this program space.  Managed by both exec_ops and solib.c.  */
-  struct target_section_table target_sections {};
+  target_section_table target_sections;
 
   /* List of shared objects mapped into this space.  Managed by
      solib.c.  */
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 40740f216ce..b5447e5a9a6 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2138,7 +2138,7 @@ record_full_core_target::xfer_partial (enum target_object object,
     {
       if (record_full_gdb_operation_disable || !writebuf)
 	{
-	  for (target_section &p : record_full_core_sections.sections)
+	  for (target_section &p : record_full_core_sections)
 	    {
 	      if (offset >= p.addr)
 		{
diff --git a/gdb/remote.c b/gdb/remote.c
index c9c5ed03ea2..29c7ee64614 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -8889,7 +8889,6 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
 						  ULONGEST *xfered_len)
 {
   struct target_section *secp;
-  struct target_section_table *table;
 
   secp = target_section_by_addr (this, memaddr);
   if (secp != NULL
@@ -8897,9 +8896,8 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
     {
       ULONGEST memend = memaddr + len;
 
-      table = target_get_section_table (this);
-
-      for (target_section &p : table->sections)
+      target_section_table *table = target_get_section_table (this);
+      for (target_section &p : *table)
 	{
 	  if (memaddr >= p.addr)
 	    {
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 59089216314..57c7ab18430 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -424,7 +424,7 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
     return 0;
 
   bool found = false;
-  for (target_section &target_section : current_target_sections->sections)
+  for (target_section &target_section : *current_target_sections)
     if (sect == target_section.the_bfd_section)
       {
 	dyn_addr = target_section.addr;
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 9bb728ae9b9..a780f8d3467 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -608,7 +608,7 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
     return 0;
 
   bool found = false;
-  for (target_section &target_section : current_target_sections->sections)
+  for (target_section &target_section : *current_target_sections)
     if (sect == target_section.the_bfd_section)
       {
 	dyn_addr = target_section.addr;
diff --git a/gdb/solib.c b/gdb/solib.c
index bd6a27d8983..b4864429e9a 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -556,7 +556,7 @@ solib_map_sections (struct so_list *so)
     so->sections = new target_section_table;
   *so->sections = build_section_table (so->abfd);
 
-  for (target_section &p : so->sections->sections)
+  for (target_section &p : *so->sections)
     {
       /* Relocate the section binding addresses as recorded in the shared
          object's file by the base address to which the object was actually
@@ -1113,7 +1113,7 @@ bool
 solib_contains_address_p (const struct so_list *const solib,
 			  CORE_ADDR address)
 {
-  for (target_section &p : solib->sections->sections)
+  for (target_section &p : *solib->sections)
     if (p.addr <= address && address < p.endaddr)
       return true;
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index f4acec50cca..3332e7f69ff 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -216,13 +216,13 @@ build_section_addr_info_from_section_table (const target_section_table &table)
 {
   section_addr_info sap;
 
-  for (const target_section &stp : table.sections)
+  for (const target_section &stp : table)
     {
       struct bfd_section *asect = stp.the_bfd_section;
       bfd *abfd = asect->owner;
 
       if (bfd_section_flags (asect) & (SEC_ALLOC | SEC_LOAD)
-	  && sap.size () < table.sections.size ())
+	  && sap.size () < table.size ())
 	sap.emplace_back (stp.addr,
 			  bfd_section_name (asect),
 			  gdb_bfd_section_index (abfd, asect));
diff --git a/gdb/target-debug.h b/gdb/target-debug.h
index 1b2feb2c7fb..65a14c41787 100644
--- a/gdb/target-debug.h
+++ b/gdb/target-debug.h
@@ -106,7 +106,7 @@
   target_debug_do_print (host_address_to_string (X))
 #define target_debug_print_struct_ui_file_p(X)	\
   target_debug_do_print (host_address_to_string (X))
-#define target_debug_print_struct_target_section_table_p(X)	\
+#define target_debug_print_target_section_table_p(X)	\
   target_debug_do_print (host_address_to_string (X))
 #define target_debug_print_async_callback_ftype_p(X) \
   target_debug_do_print (host_address_to_string (X))
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index c0968e2040e..e9c349fb7ba 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -77,7 +77,7 @@ struct dummy_target : public target_ops
   void rcmd (const char *arg0, struct ui_file *arg1) override;
   char *pid_to_exec_file (int arg0) override;
   void log_command (const char *arg0) override;
-  struct target_section_table *get_section_table () override;
+  target_section_table *get_section_table () override;
   thread_control_capabilities get_thread_control_capabilities () override;
   bool attach_no_wait () override;
   bool can_async_p () override;
@@ -248,7 +248,7 @@ struct debug_target : public target_ops
   void rcmd (const char *arg0, struct ui_file *arg1) override;
   char *pid_to_exec_file (int arg0) override;
   void log_command (const char *arg0) override;
-  struct target_section_table *get_section_table () override;
+  target_section_table *get_section_table () override;
   thread_control_capabilities get_thread_control_capabilities () override;
   bool attach_no_wait () override;
   bool can_async_p () override;
@@ -2021,27 +2021,27 @@ debug_target::log_command (const char *arg0)
   fputs_unfiltered (")\n", gdb_stdlog);
 }
 
-struct target_section_table *
+target_section_table *
 target_ops::get_section_table ()
 {
   return this->beneath ()->get_section_table ();
 }
 
-struct target_section_table *
+target_section_table *
 dummy_target::get_section_table ()
 {
   return NULL;
 }
 
-struct target_section_table *
+target_section_table *
 debug_target::get_section_table ()
 {
-  struct target_section_table * result;
+  target_section_table * result;
   fprintf_unfiltered (gdb_stdlog, "-> %s->get_section_table (...)\n", this->beneath ()->shortname ());
   result = this->beneath ()->get_section_table ();
   fprintf_unfiltered (gdb_stdlog, "<- %s->get_section_table (", this->beneath ()->shortname ());
   fputs_unfiltered (") = ", gdb_stdlog);
-  target_debug_print_struct_target_section_table_p (result);
+  target_debug_print_target_section_table_p (result);
   fputs_unfiltered ("\n", gdb_stdlog);
   return result;
 }
diff --git a/gdb/target-section.h b/gdb/target-section.h
index 8c81f3d79ba..fc4c800158d 100644
--- a/gdb/target-section.h
+++ b/gdb/target-section.h
@@ -41,9 +41,6 @@ struct target_section
 
 /* Holds an array of target sections.  */
 
-struct target_section_table
-{
-  std::vector<struct target_section> sections;
-};
+using target_section_table = std::vector<target_section>;
 
 #endif /* GDB_TARGET_SECTION_H */
diff --git a/gdb/target.c b/gdb/target.c
index f828d3d6cc3..e3b561649ed 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -811,7 +811,7 @@ target_read_string (CORE_ADDR memaddr, int len, int *bytes_read)
   return gdb::unique_xmalloc_ptr<char> ((char *) buffer.release ());
 }
 
-struct target_section_table *
+target_section_table *
 target_get_section_table (struct target_ops *target)
 {
   return target->get_section_table ();
@@ -822,12 +822,12 @@ target_get_section_table (struct target_ops *target)
 struct target_section *
 target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
 {
-  struct target_section_table *table = target_get_section_table (target);
+  target_section_table *table = target_get_section_table (target);
 
   if (table == NULL)
     return NULL;
 
-  for (target_section &secp : table->sections)
+  for (target_section &secp : *table)
     {
       if (addr >= secp.addr && addr < secp.endaddr)
 	return &secp;
@@ -964,8 +964,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
 
       if (pc_in_unmapped_range (memaddr, section))
 	{
-	  struct target_section_table *table
-	    = target_get_section_table (ops);
+	  target_section_table *table = target_get_section_table (ops);
 	  const char *section_name = section->the_bfd_section->name;
 
 	  memaddr = overlay_mapped_address (memaddr, section);
@@ -985,13 +984,12 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
   if (readbuf != NULL && trust_readonly)
     {
       struct target_section *secp;
-      struct target_section_table *table;
 
       secp = target_section_by_addr (ops, memaddr);
       if (secp != NULL
 	  && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
 	{
-	  table = target_get_section_table (ops);
+	  target_section_table *table = target_get_section_table (ops);
 	  return section_table_xfer_memory_partial (readbuf, writebuf,
 						    memaddr, len, xfered_len,
 						    *table);
diff --git a/gdb/target.h b/gdb/target.h
index 369394aa929..5eca0e27ef3 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -29,7 +29,6 @@ struct target_ops;
 struct bp_location;
 struct bp_target_info;
 struct regcache;
-struct target_section_table;
 struct trace_state_variable;
 struct trace_status;
 struct uploaded_tsv;
@@ -681,7 +680,7 @@ struct target_ops
       TARGET_DEFAULT_RETURN (NULL);
     virtual void log_command (const char *)
       TARGET_DEFAULT_IGNORE ();
-    virtual struct target_section_table *get_section_table ()
+    virtual target_section_table *get_section_table ()
       TARGET_DEFAULT_RETURN (NULL);
 
     /* Provide default values for all "must have" methods.  */
@@ -2421,7 +2420,7 @@ struct target_section *target_section_by_addr (struct target_ops *target,
 /* Return the target section table this target (or the targets
    beneath) currently manipulate.  */
 
-extern struct target_section_table *target_get_section_table
+extern target_section_table *target_get_section_table
   (struct target_ops *target);
 
 /* From mem-break.c */
-- 
2.17.2


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/6] Introduce target-section.h
  2020-10-03 19:37 ` [PATCH 1/6] Introduce target-section.h Tom Tromey
@ 2020-10-04  8:29   ` Andrew Burgess
  2020-10-09  1:17     ` Tom Tromey
  0 siblings, 1 reply; 24+ messages in thread
From: Andrew Burgess @ 2020-10-04  8:29 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2020-10-03 13:37:30 -0600]:

> This introduces a new target-section.h file.  This makes some of the
> later patches in this series a bit cleaner, because new includes of
> target.h won't be required.  Also I think it's better to have small
> header files for each separate data structure.
> 
> gdb/ChangeLog
> 2020-10-03  Tom Tromey  <tom@tromey.com>
> 
> 	* target.h (struct target_section, struct target_section_table):
> 	Move to target-section.h.
> 	* target-section.h: New file.
> ---
>  gdb/ChangeLog        |  6 ++++++
>  gdb/target-section.h | 50 ++++++++++++++++++++++++++++++++++++++++++++
>  gdb/target.h         | 28 +------------------------
>  3 files changed, 57 insertions(+), 27 deletions(-)
>  create mode 100644 gdb/target-section.h
> 
> diff --git a/gdb/target-section.h b/gdb/target-section.h
> new file mode 100644
> index 00000000000..581bc1dbe9f
> --- /dev/null
> +++ b/gdb/target-section.h
> @@ -0,0 +1,50 @@
> +/* Target sections.
> +
> +   Copyright (C) 2020 Free Software Foundation, Inc.
> +
> +   This file is part of GDB.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#ifndef GDB_TARGET_SECTION_H
> +#define GDB_TARGET_SECTION_H
> +
> +/* Struct target_section maps address ranges to file sections.  It is
> +   mostly used with BFD files, but can be used without (e.g. for handling
> +   raw disks, or files not in formats handled by BFD).  */
> +
> +struct target_section
> +  {
> +    CORE_ADDR addr;		/* Lowest address in section */
> +    CORE_ADDR endaddr;		/* 1+highest address in section */
> +
> +    struct bfd_section *the_bfd_section;
> +
> +    /* The "owner" of the section.
> +       It can be any unique value.  It is set by add_target_sections
> +       and used by remove_target_sections.
> +       For example, for executables it is a pointer to exec_bfd and
> +       for shlibs it is the so_list pointer.  */
> +    void *owner;
> +  };

I know that this is copy & paste code, but it would be awesome if we
could take this opportunity to fix the whitespace formatting, place
the comments in the correct place, reword them as proper sentences,
and add a comment to the missing field.

Generally bring this code up to our current coding standard :)

Otherwise this looks great.

Thanks,
Andrew


> +
> +/* Holds an array of target sections.  Defined by [SECTIONS..SECTIONS_END[.  */
> +
> +struct target_section_table
> +{
> +  struct target_section *sections;
> +  struct target_section *sections_end;
> +};
> +
> +#endif /* GDB_TARGET_SECTION_H */
> diff --git a/gdb/target.h b/gdb/target.h
> index 695f1b2b7f6..369394aa929 100644
> --- a/gdb/target.h
> +++ b/gdb/target.h
> @@ -44,6 +44,7 @@ struct inferior;
>  #include "breakpoint.h" /* For enum bptype.  */
>  #include "gdbsupport/scoped_restore.h"
>  #include "gdbsupport/refcounted-object.h"
> +#include "target-section.h"
>  
>  /* This include file defines the interface between the main part
>     of the debugger, and the part which is target-specific, or
> @@ -2413,33 +2414,6 @@ extern bool target_is_pushed (target_ops *t);
>  extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
>  					       CORE_ADDR offset);
>  
> -/* Struct target_section maps address ranges to file sections.  It is
> -   mostly used with BFD files, but can be used without (e.g. for handling
> -   raw disks, or files not in formats handled by BFD).  */
> -
> -struct target_section
> -  {
> -    CORE_ADDR addr;		/* Lowest address in section */
> -    CORE_ADDR endaddr;		/* 1+highest address in section */
> -
> -    struct bfd_section *the_bfd_section;
> -
> -    /* The "owner" of the section.
> -       It can be any unique value.  It is set by add_target_sections
> -       and used by remove_target_sections.
> -       For example, for executables it is a pointer to exec_bfd and
> -       for shlibs it is the so_list pointer.  */
> -    void *owner;
> -  };
> -
> -/* Holds an array of target sections.  Defined by [SECTIONS..SECTIONS_END[.  */
> -
> -struct target_section_table
> -{
> -  struct target_section *sections;
> -  struct target_section *sections_end;
> -};
> -
>  /* Return the "section" containing the specified address.  */
>  struct target_section *target_section_by_addr (struct target_ops *target,
>  					       CORE_ADDR addr);
> -- 
> 2.17.2
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/6] build_section_table cannot fail
  2020-10-03 19:37 ` [PATCH 3/6] build_section_table cannot fail Tom Tromey
@ 2020-10-04  8:38   ` Andrew Burgess
  0 siblings, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-04  8:38 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2020-10-03 13:37:32 -0600]:

> I noticed that build_section_table cannot fail.  This patch changes it
> to return a target_section_table and then removes the dead code.
> 
> 2020-10-03  Tom Tromey  <tom@tromey.com>
> 
> 	* solib.c (solib_map_sections): Update.
> 	* record-full.c (record_full_core_open_1): Update.
> 	* exec.h (build_section_table): Return a target_section_table.
> 	* exec.c (exec_file_attach): Update.
> 	(build_section_table): Return a target_section_table.
> 	* corelow.c (core_target::core_target): Update.
> 	* bfd-target.c (target_bfd::target_bfd): Update.

Nice cleanup.  LGTM.

Thanks,
Andrew

> ---
>  gdb/ChangeLog     | 10 ++++++++++
>  gdb/bfd-target.c  |  4 ++--
>  gdb/corelow.c     |  4 +---
>  gdb/exec.c        | 28 +++++++++-------------------
>  gdb/exec.h        |  5 ++---
>  gdb/record-full.c |  8 +-------
>  gdb/solib.c       |  6 +-----
>  7 files changed, 26 insertions(+), 39 deletions(-)
> 
> diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
> index 8a58e92eb1c..d5defab9a80 100644
> --- a/gdb/bfd-target.c
> +++ b/gdb/bfd-target.c
> @@ -89,9 +89,9 @@ target_bfd::get_section_table ()
>  }
>  
>  target_bfd::target_bfd (struct bfd *abfd)
> -  : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
> +  : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd)),
> +    m_table (build_section_table (abfd))
>  {
> -  build_section_table (abfd, &m_table);
>  }
>  
>  target_ops *
> diff --git a/gdb/corelow.c b/gdb/corelow.c
> index 554561dbb36..193dccbeeb5 100644
> --- a/gdb/corelow.c
> +++ b/gdb/corelow.c
> @@ -161,9 +161,7 @@ core_target::core_target ()
>  	   bfd_get_filename (core_bfd));
>  
>    /* Find the data section */
> -  if (build_section_table (core_bfd, &m_core_section_table))
> -    error (_("\"%s\": Can't find sections: %s"),
> -	   bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
> +  m_core_section_table = build_section_table (core_bfd);
>  
>    build_file_mappings ();
>  }
> diff --git a/gdb/exec.c b/gdb/exec.c
> index e3e515fedec..d4b9b7bcf65 100644
> --- a/gdb/exec.c
> +++ b/gdb/exec.c
> @@ -413,7 +413,6 @@ exec_file_attach (const char *filename, int from_tty)
>        int load_via_target = 0;
>        const char *scratch_pathname, *canonical_pathname;
>        int scratch_chan;
> -      target_section_table sections;
>        char **matching;
>  
>        if (is_target_filename (filename))
> @@ -503,15 +502,7 @@ exec_file_attach (const char *filename, int from_tty)
>  		 gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
>  	}
>  
> -      if (build_section_table (exec_bfd, &sections))
> -	{
> -	  /* Make sure to close exec_bfd, or else "run" might try to use
> -	     it.  */
> -	  exec_close ();
> -	  error (_("\"%ps\": can't find the file sections: %s"),
> -		 styled_string (file_name_style.style (), scratch_pathname),
> -		 bfd_errmsg (bfd_get_error ()));
> -	}
> +      target_section_table sections = build_section_table (exec_bfd);
>  
>        exec_bfd_mtime = bfd_get_mtime (exec_bfd);
>  
> @@ -594,13 +585,13 @@ clear_section_table (struct target_section_table *table)
>    table->sections.clear ();
>  }
>  
> -/* Builds a section table, given args BFD, TABLE.
> -   Returns 0 if OK, 1 on error.  */
> +/* Builds a section table, given args BFD, TABLE.  */
>  
> -int
> -build_section_table (struct bfd *some_bfd, target_section_table *table)
> +target_section_table
> +build_section_table (struct bfd *some_bfd)
>  {
> -  table->sections.clear ();
> +  target_section_table table;
> +
>    for (asection *asect : gdb_bfd_sections (some_bfd))
>      {
>        flagword aflag;
> @@ -615,16 +606,15 @@ build_section_table (struct bfd *some_bfd, target_section_table *table)
>        if (!(aflag & SEC_ALLOC))
>  	continue;
>  
> -      table->sections.emplace_back ();
> -      target_section &sect = table->sections.back ();
> +      table.sections.emplace_back ();
> +      target_section &sect = table.sections.back ();
>        sect.owner = NULL;
>        sect.the_bfd_section = asect;
>        sect.addr = bfd_section_vma (asect);
>        sect.endaddr = sect.addr + bfd_section_size (asect);
>      }
>  
> -  /* We could realloc the table, but it probably loses for most files.  */
> -  return 0;
> +  return table;
>  }
>  
>  /* Add the sections array defined by [SECTIONS..SECTIONS_END[ to the
> diff --git a/gdb/exec.h b/gdb/exec.h
> index d26eba49236..75177dda96a 100644
> --- a/gdb/exec.h
> +++ b/gdb/exec.h
> @@ -34,10 +34,9 @@ struct objfile;
>  #define exec_bfd_mtime current_program_space->ebfd_mtime
>  #define exec_filename current_program_space->pspace_exec_filename
>  
> -/* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
> -   Returns 0 if OK, 1 on error.  */
> +/* Builds a section table, given args BFD.  */
>  
> -extern int build_section_table (struct bfd *, struct target_section_table *);
> +extern target_section_table build_section_table (struct bfd *);
>  
>  /* Remove all entries from TABLE.  */
>  
> diff --git a/gdb/record-full.c b/gdb/record-full.c
> index 5dcb42d2f4e..40740f216ce 100644
> --- a/gdb/record-full.c
> +++ b/gdb/record-full.c
> @@ -923,13 +923,7 @@ record_full_core_open_1 (const char *name, int from_tty)
>    for (i = 0; i < regnum; i ++)
>      record_full_core_regbuf->raw_supply (i, *regcache);
>  
> -  if (build_section_table (core_bfd, &record_full_core_sections))
> -    {
> -      delete record_full_core_regbuf;
> -      record_full_core_regbuf = NULL;
> -      error (_("\"%s\": Can't find sections: %s"),
> -	     bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
> -    }
> +  record_full_core_sections = build_section_table (core_bfd);
>  
>    push_target (&record_full_core_ops);
>    record_full_restore ();
> diff --git a/gdb/solib.c b/gdb/solib.c
> index 906e1788c49..bd6a27d8983 100644
> --- a/gdb/solib.c
> +++ b/gdb/solib.c
> @@ -554,11 +554,7 @@ solib_map_sections (struct so_list *so)
>  
>    if (so->sections == nullptr)
>      so->sections = new target_section_table;
> -  if (build_section_table (so->abfd, so->sections))
> -    {
> -      error (_("Can't find the file sections in `%s': %s"),
> -	     bfd_get_filename (so->abfd), bfd_errmsg (bfd_get_error ()));
> -    }
> +  *so->sections = build_section_table (so->abfd);
>  
>    for (target_section &p : so->sections->sections)
>      {
> -- 
> 2.17.2
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/6] Simplify add_target_sections_of_objfile
  2020-10-03 19:37 ` [PATCH 4/6] Simplify add_target_sections_of_objfile Tom Tromey
@ 2020-10-04  8:40   ` Andrew Burgess
  0 siblings, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-04  8:40 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2020-10-03 13:37:33 -0600]:

> Now that target_section_table uses std::vector,
> add_target_sections_of_objfile does not need to loop twice.  This
> patch simplifies this code to have just a single loop.  Also, the
> passed-in objfile can never be NULL, so this changes this function to
> assert that.
> 
> 2020-10-03  Tom Tromey  <tom@tromey.com>
> 
> 	* exec.c (add_target_sections_of_objfile): Simplify.

LGTM.

Thanks,
Andrew

> ---
>  gdb/ChangeLog |  4 ++++
>  gdb/exec.c    | 14 +-------------
>  2 files changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/gdb/exec.c b/gdb/exec.c
> index d4b9b7bcf65..43385fe978f 100644
> --- a/gdb/exec.c
> +++ b/gdb/exec.c
> @@ -661,22 +661,10 @@ add_target_sections_of_objfile (struct objfile *objfile)
>  {
>    struct target_section_table *table = current_target_sections;
>    struct obj_section *osect;
> -  unsigned count = 0;
>  
> -  if (objfile == NULL)
> -    return;
> +  gdb_assert (objfile != nullptr);
>  
>    /* Compute the number of sections to add.  */
> -  ALL_OBJFILE_OSECTIONS (objfile, osect)
> -    {
> -      if (bfd_section_size (osect->the_bfd_section) == 0)
> -	continue;
> -      count++;
> -    }
> -
> -  if (count == 0)
> -    return;
> -
>    ALL_OBJFILE_OSECTIONS (objfile, osect)
>      {
>        if (bfd_section_size (osect->the_bfd_section) == 0)
> -- 
> 2.17.2
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/6] Remove clear_section_table
  2020-10-03 19:37 ` [PATCH 5/6] Remove clear_section_table Tom Tromey
@ 2020-10-04  8:44   ` Andrew Burgess
  0 siblings, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-04  8:44 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2020-10-03 13:37:34 -0600]:

> The call to clear_section_table in ~program_space is now clearly not
> needed -- the section table will clear itself.  This patch removes
> this call and then inlines the one remaining call to
> clear_section_table.
> 
> 2020-10-03  Tom Tromey  <tom@tromey.com>
> 
> 	* progspace.c (program_space::~program_space): Don't call
> 	clear_section_table.
> 	* exec.h (clear_section_table): Don't declare.
> 	* exec.c (exec_target::close): Update.
> 	(clear_section_table): Remove.

LGTM.

Thanks,
Andrew

> ---
>  gdb/ChangeLog   |  8 ++++++++
>  gdb/exec.c      | 10 +---------
>  gdb/exec.h      |  4 ----
>  gdb/progspace.c |  1 -
>  4 files changed, 9 insertions(+), 14 deletions(-)
> 
> diff --git a/gdb/exec.c b/gdb/exec.c
> index 43385fe978f..ab47757c2b4 100644
> --- a/gdb/exec.c
> +++ b/gdb/exec.c
> @@ -183,7 +183,7 @@ exec_target::close ()
>    for (struct program_space *ss : program_spaces)
>      {
>        set_current_program_space (ss);
> -      clear_section_table (current_target_sections);
> +      current_target_sections->sections.clear ();
>        exec_close ();
>      }
>  }
> @@ -577,14 +577,6 @@ file_command (const char *arg, int from_tty)
>  }
>  \f
>  
> -/* See exec.h.  */
> -
> -void
> -clear_section_table (struct target_section_table *table)
> -{
> -  table->sections.clear ();
> -}
> -
>  /* Builds a section table, given args BFD, TABLE.  */
>  
>  target_section_table
> diff --git a/gdb/exec.h b/gdb/exec.h
> index 75177dda96a..f28a033428d 100644
> --- a/gdb/exec.h
> +++ b/gdb/exec.h
> @@ -38,10 +38,6 @@ struct objfile;
>  
>  extern target_section_table build_section_table (struct bfd *);
>  
> -/* Remove all entries from TABLE.  */
> -
> -extern void clear_section_table (struct target_section_table *table);
> -
>  /* The current inferior is a child vforked and its program space is
>     shared with its parent.  This pushes the exec target on the
>     current/child inferior's target stack if there are sections in the
> diff --git a/gdb/progspace.c b/gdb/progspace.c
> index 3f512161215..67ea8bdb9e9 100644
> --- a/gdb/progspace.c
> +++ b/gdb/progspace.c
> @@ -154,7 +154,6 @@ program_space::~program_space ()
>    clear_symtab_users (SYMFILE_DEFER_BP_RESET);
>    if (!gdbarch_has_shared_address_space (target_gdbarch ()))
>      free_address_space (this->aspace);
> -  clear_section_table (&this->target_sections);
>    clear_program_space_solib_cache (this);
>      /* Discard any data modules have associated with the PSPACE.  */
>    program_space_free_data (this);
> -- 
> 2.17.2
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 6/6] Change target_section_table to std::vector alias
  2020-10-03 19:37 ` [PATCH 6/6] Change target_section_table to std::vector alias Tom Tromey
@ 2020-10-04  8:46   ` Andrew Burgess
  0 siblings, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-04  8:46 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2020-10-03 13:37:35 -0600]:

> Because target_section_table only holds a vector, and because it is
> used in an "open" way, this patch makes it just be an alias for the
> std::vector specialization.  This makes the code less wordy.  If we do
> ever want to add more specialized behavior to this type, it's simple
> enough to convert it back to a struct with the few needed methods
> implied by this change.

Sounds good.

Thanks,
Andrew

> 
> 2020-10-03  Tom Tromey  <tom@tromey.com>
> 
> 	* target.h (struct target_ops) <get_section_table>: Update.
> 	(target_get_section_table): Update.
> 	* target.c (target_get_section_table, target_section_by_addr)
> 	(memory_xfer_partial_1): Update.
> 	* target-section.h (target_section_table): Now an alias.
> 	* target-delegates.c: Rebuild.
> 	* target-debug.h (target_debug_print_target_section_table_p):
> 	Rename from target_debug_print_struct_target_section_table_p.
> 	* symfile.c (build_section_addr_info_from_section_table): Update.
> 	* solib.c (solib_map_sections, solib_contains_address_p): Update.
> 	* solib-svr4.c (scan_dyntag): Update.
> 	* solib-dsbt.c (scan_dyntag): Update.
> 	* remote.c (remote_target::remote_xfer_live_readonly_partial):
> 	Update.
> 	* record-full.c (record_full_core_target::xfer_partial): Update.
> 	* progspace.h (struct program_space) <target_sections>: Update.
> 	* exec.h (print_section_info): Update.
> 	* exec.c (exec_target::close, build_section_table)
> 	(add_target_sections, add_target_sections_of_objfile)
> 	(remove_target_sections, exec_on_vfork)
> 	(section_table_available_memory)
> 	(section_table_xfer_memory_partial)
> 	(exec_target::get_section_table, exec_target::xfer_partial)
> 	(print_section_info, set_section_command)
> 	(exec_set_section_address, exec_target::has_memory): Update.
> 	* corelow.c (core_target::build_file_mappings)
> 	(core_target::xfer_partial, core_target::info_proc_mappings)
> 	(core_target::info_proc_mappings): Update.
> 	* bfd-target.c (class target_bfd): Update
> ---
>  gdb/ChangeLog          | 32 +++++++++++++++++++++
>  gdb/bfd-target.c       |  2 +-
>  gdb/corelow.c          | 10 +++----
>  gdb/exec.c             | 63 +++++++++++++++++++-----------------------
>  gdb/exec.h             |  2 +-
>  gdb/progspace.h        |  2 +-
>  gdb/record-full.c      |  2 +-
>  gdb/remote.c           |  6 ++--
>  gdb/solib-dsbt.c       |  2 +-
>  gdb/solib-svr4.c       |  2 +-
>  gdb/solib.c            |  4 +--
>  gdb/symfile.c          |  4 +--
>  gdb/target-debug.h     |  2 +-
>  gdb/target-delegates.c | 14 +++++-----
>  gdb/target-section.h   |  5 +---
>  gdb/target.c           | 12 ++++----
>  gdb/target.h           |  5 ++--
>  17 files changed, 94 insertions(+), 75 deletions(-)
> 
> diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
> index d5defab9a80..bf4a98594bd 100644
> --- a/gdb/bfd-target.c
> +++ b/gdb/bfd-target.c
> @@ -59,7 +59,7 @@ class target_bfd : public target_ops
>    /* The section table build from the ALLOC sections in BFD.  Note
>       that we can't rely on extracting the BFD from a random section in
>       the table, since the table can be legitimately empty.  */
> -  struct target_section_table m_table;
> +  target_section_table m_table;
>  };
>  
>  target_xfer_status
> diff --git a/gdb/corelow.c b/gdb/corelow.c
> index 193dccbeeb5..d557475e06f 100644
> --- a/gdb/corelow.c
> +++ b/gdb/corelow.c
> @@ -266,8 +266,8 @@ core_target::build_file_mappings ()
>  	bfd_set_section_alignment (sec, 2);
>  
>  	/* Set target_section fields.  */
> -	m_core_file_mappings.sections.emplace_back ();
> -	target_section &ts = m_core_file_mappings.sections.back ();
> +	m_core_file_mappings.emplace_back ();
> +	target_section &ts = m_core_file_mappings.back ();
>  	ts.addr = start;
>  	ts.endaddr = end;
>  	ts.owner = nullptr;
> @@ -814,7 +814,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>  	   or the like) as this should provide a more accurate
>  	   result.  If not, check the stratum beneath us, which should
>  	   be the file stratum.  */
> -	if (!m_core_file_mappings.sections.empty ())
> +	if (!m_core_file_mappings.empty ())
>  	  xfer_status = xfer_memory_via_mappings (readbuf, writebuf, offset,
>  						  len, xfered_len);
>  	else
> @@ -1098,7 +1098,7 @@ get_current_core_target ()
>  void
>  core_target::info_proc_mappings (struct gdbarch *gdbarch)
>  {
> -  if (!m_core_file_mappings.sections.empty ())
> +  if (!m_core_file_mappings.empty ())
>      {
>        printf_filtered (_("Mapped address spaces:\n\n"));
>        if (gdbarch_addr_bit (gdbarch) == 32)
> @@ -1117,7 +1117,7 @@ core_target::info_proc_mappings (struct gdbarch *gdbarch)
>  	}
>      }
>  
> -  for (const target_section &tsp : m_core_file_mappings.sections)
> +  for (const target_section &tsp : m_core_file_mappings)
>      {
>        ULONGEST start = tsp.addr;
>        ULONGEST end = tsp.endaddr;
> diff --git a/gdb/exec.c b/gdb/exec.c
> index ab47757c2b4..dd322129139 100644
> --- a/gdb/exec.c
> +++ b/gdb/exec.c
> @@ -75,7 +75,7 @@ struct exec_target final : public target_ops
>  					const gdb_byte *writebuf,
>  					ULONGEST offset, ULONGEST len,
>  					ULONGEST *xfered_len) override;
> -  struct target_section_table *get_section_table () override;
> +  target_section_table *get_section_table () override;
>    void files_info () override;
>  
>    bool has_memory () override;
> @@ -183,7 +183,7 @@ exec_target::close ()
>    for (struct program_space *ss : program_spaces)
>      {
>        set_current_program_space (ss);
> -      current_target_sections->sections.clear ();
> +      current_target_sections->clear ();
>        exec_close ();
>      }
>  }
> @@ -598,8 +598,8 @@ build_section_table (struct bfd *some_bfd)
>        if (!(aflag & SEC_ALLOC))
>  	continue;
>  
> -      table.sections.emplace_back ();
> -      target_section &sect = table.sections.back ();
> +      table.emplace_back ();
> +      target_section &sect = table.back ();
>        sect.owner = NULL;
>        sect.the_bfd_section = asect;
>        sect.addr = bfd_section_vma (asect);
> @@ -616,14 +616,14 @@ void
>  add_target_sections (void *owner,
>  		     const target_section_table &sections)
>  {
> -  struct target_section_table *table = current_target_sections;
> +  target_section_table *table = current_target_sections;
>  
> -  if (!sections.sections.empty ())
> +  if (!sections.empty ())
>      {
> -      for (const target_section &s : sections.sections)
> +      for (const target_section &s : sections)
>  	{
> -	  table->sections.push_back (s);
> -	  table->sections.back ().owner = owner;
> +	  table->push_back (s);
> +	  table->back ().owner = owner;
>  	}
>  
>        scoped_restore_current_pspace_and_thread restore_pspace_thread;
> @@ -651,7 +651,7 @@ add_target_sections (void *owner,
>  void
>  add_target_sections_of_objfile (struct objfile *objfile)
>  {
> -  struct target_section_table *table = current_target_sections;
> +  target_section_table *table = current_target_sections;
>    struct obj_section *osect;
>  
>    gdb_assert (objfile != nullptr);
> @@ -662,8 +662,8 @@ add_target_sections_of_objfile (struct objfile *objfile)
>        if (bfd_section_size (osect->the_bfd_section) == 0)
>  	continue;
>  
> -      table->sections.emplace_back ();
> -      target_section &ts = table->sections.back ();
> +      table->emplace_back ();
> +      target_section &ts = table->back ();
>        ts.addr = obj_section_addr (osect);
>        ts.endaddr = obj_section_endaddr (osect);
>        ts.the_bfd_section = osect->the_bfd_section;
> @@ -677,22 +677,22 @@ add_target_sections_of_objfile (struct objfile *objfile)
>  void
>  remove_target_sections (void *owner)
>  {
> -  struct target_section_table *table = current_target_sections;
> +  target_section_table *table = current_target_sections;
>  
>    gdb_assert (owner != NULL);
>  
> -  auto it = std::remove_if (table->sections.begin (),
> -			    table->sections.end (),
> +  auto it = std::remove_if (table->begin (),
> +			    table->end (),
>  			    [&] (target_section &sect)
>  			    {
>  			      return sect.owner == owner;
>  			    });
> -  table->sections.erase (it, table->sections.end ());
> +  table->erase (it, table->end ());
>  
>    /* If we don't have any more sections to read memory from,
>       remove the file_stratum target from the stack of each
>       inferior sharing the program space.  */
> -  if (table->sections.empty ())
> +  if (table->empty ())
>      {
>        scoped_restore_current_pspace_and_thread restore_pspace_thread;
>        program_space *curr_pspace = current_program_space;
> @@ -702,7 +702,7 @@ remove_target_sections (void *owner)
>  	  if (inf->pspace != curr_pspace)
>  	    continue;
>  
> -	  if (!inf->pspace->target_sections.sections.empty ())
> +	  if (!inf->pspace->target_sections.empty ())
>  	    continue;
>  
>  	  switch_to_inferior_no_thread (inf);
> @@ -716,7 +716,7 @@ remove_target_sections (void *owner)
>  void
>  exec_on_vfork ()
>  {
> -  if (!current_program_space->target_sections.sections.empty ())
> +  if (!current_program_space->target_sections.empty ())
>      push_target (&exec_ops);
>  }
>  
> @@ -779,7 +779,7 @@ section_table_available_memory (CORE_ADDR memaddr, ULONGEST len,
>  {
>    std::vector<mem_range> memory;
>  
> -  for (const target_section &p : sections.sections)
> +  for (const target_section &p : sections)
>      {
>        if ((bfd_section_flags (p.the_bfd_section) & SEC_READONLY) == 0)
>  	continue;
> @@ -858,7 +858,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
>  
>    gdb_assert (len != 0);
>  
> -  for (const target_section &p : sections.sections)
> +  for (const target_section &p : sections)
>      {
>        struct bfd_section *asect = p.the_bfd_section;
>        bfd *abfd = asect->owner;
> @@ -918,7 +918,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
>    return TARGET_XFER_EOF;		/* We can't help.  */
>  }
>  
> -struct target_section_table *
> +target_section_table *
>  exec_target::get_section_table ()
>  {
>    return current_target_sections;
> @@ -930,7 +930,7 @@ exec_target::xfer_partial (enum target_object object,
>  			   const gdb_byte *writebuf,
>  			   ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
>  {
> -  struct target_section_table *table = get_section_table ();
> +  target_section_table *table = get_section_table ();
>  
>    if (object == TARGET_OBJECT_MEMORY)
>      return section_table_xfer_memory_partial (readbuf, writebuf,
> @@ -942,7 +942,7 @@ exec_target::xfer_partial (enum target_object object,
>  \f
>  
>  void
> -print_section_info (struct target_section_table *t, bfd *abfd)
> +print_section_info (target_section_table *t, bfd *abfd)
>  {
>    struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
>    /* FIXME: 16 is not wide enough when gdbarch_addr_bit > 64.  */
> @@ -961,7 +961,7 @@ print_section_info (struct target_section_table *t, bfd *abfd)
>        bfd_vma entry_point;
>        bool found = false;
>  
> -      for (const target_section &p : t->sections)
> +      for (const target_section &p : *t)
>  	{
>  	  struct bfd_section *psect = p.the_bfd_section;
>  
> @@ -989,7 +989,7 @@ print_section_info (struct target_section_table *t, bfd *abfd)
>        printf_filtered (_("\tEntry point: %s\n"),
>  		       paddress (gdbarch, entry_point));
>      }
> -  for (const target_section &p : t->sections)
> +  for (const target_section &p : *t)
>      {
>        struct bfd_section *psect = p.the_bfd_section;
>        bfd *pbfd = psect->owner;
> @@ -1032,7 +1032,6 @@ set_section_command (const char *args, int from_tty)
>    unsigned long secaddr;
>    char secprint[100];
>    long offset;
> -  struct target_section_table *table;
>  
>    if (args == 0)
>      error (_("Must specify section name and its virtual address"));
> @@ -1044,8 +1043,7 @@ set_section_command (const char *args, int from_tty)
>    /* Parse out new virtual address.  */
>    secaddr = parse_and_eval_address (args);
>  
> -  table = current_target_sections;
> -  for (target_section &p : table->sections)
> +  for (target_section &p : *current_target_sections)
>      {
>        if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen)
>  	  && bfd_section_name (p.the_bfd_section)[seclen] == '\0')
> @@ -1071,10 +1069,7 @@ set_section_command (const char *args, int from_tty)
>  void
>  exec_set_section_address (const char *filename, int index, CORE_ADDR address)
>  {
> -  struct target_section_table *table;
> -
> -  table = current_target_sections;
> -  for (target_section &p : table->sections)
> +  for (target_section &p : *current_target_sections)
>      {
>        if (filename_cmp (filename,
>  			bfd_get_filename (p.the_bfd_section->owner)) == 0
> @@ -1091,7 +1086,7 @@ exec_target::has_memory ()
>  {
>    /* We can provide memory if we have any file/target sections to read
>       from.  */
> -  return !current_target_sections->sections.empty ();
> +  return !current_target_sections->empty ();
>  }
>  
>  char *
> diff --git a/gdb/exec.h b/gdb/exec.h
> index f28a033428d..24489654ddc 100644
> --- a/gdb/exec.h
> +++ b/gdb/exec.h
> @@ -115,7 +115,7 @@ extern void add_target_sections_of_objfile (struct objfile *objfile);
>     special cased --- it's filename is omitted; if it is the executable
>     file, its entry point is printed.  */
>  
> -extern void print_section_info (struct target_section_table *table,
> +extern void print_section_info (target_section_table *table,
>  				bfd *abfd);
>  
>  extern void exec_close (void);
> diff --git a/gdb/progspace.h b/gdb/progspace.h
> index 099b4dc0b3a..6a0e9036399 100644
> --- a/gdb/progspace.h
> +++ b/gdb/progspace.h
> @@ -325,7 +325,7 @@ struct program_space
>  
>    /* The set of target sections matching the sections mapped into
>       this program space.  Managed by both exec_ops and solib.c.  */
> -  struct target_section_table target_sections {};
> +  target_section_table target_sections;
>  
>    /* List of shared objects mapped into this space.  Managed by
>       solib.c.  */
> diff --git a/gdb/record-full.c b/gdb/record-full.c
> index 40740f216ce..b5447e5a9a6 100644
> --- a/gdb/record-full.c
> +++ b/gdb/record-full.c
> @@ -2138,7 +2138,7 @@ record_full_core_target::xfer_partial (enum target_object object,
>      {
>        if (record_full_gdb_operation_disable || !writebuf)
>  	{
> -	  for (target_section &p : record_full_core_sections.sections)
> +	  for (target_section &p : record_full_core_sections)
>  	    {
>  	      if (offset >= p.addr)
>  		{
> diff --git a/gdb/remote.c b/gdb/remote.c
> index c9c5ed03ea2..29c7ee64614 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -8889,7 +8889,6 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
>  						  ULONGEST *xfered_len)
>  {
>    struct target_section *secp;
> -  struct target_section_table *table;
>  
>    secp = target_section_by_addr (this, memaddr);
>    if (secp != NULL
> @@ -8897,9 +8896,8 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
>      {
>        ULONGEST memend = memaddr + len;
>  
> -      table = target_get_section_table (this);
> -
> -      for (target_section &p : table->sections)
> +      target_section_table *table = target_get_section_table (this);
> +      for (target_section &p : *table)
>  	{
>  	  if (memaddr >= p.addr)
>  	    {
> diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
> index 59089216314..57c7ab18430 100644
> --- a/gdb/solib-dsbt.c
> +++ b/gdb/solib-dsbt.c
> @@ -424,7 +424,7 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
>      return 0;
>  
>    bool found = false;
> -  for (target_section &target_section : current_target_sections->sections)
> +  for (target_section &target_section : *current_target_sections)
>      if (sect == target_section.the_bfd_section)
>        {
>  	dyn_addr = target_section.addr;
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index 9bb728ae9b9..a780f8d3467 100644
> --- a/gdb/solib-svr4.c
> +++ b/gdb/solib-svr4.c
> @@ -608,7 +608,7 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
>      return 0;
>  
>    bool found = false;
> -  for (target_section &target_section : current_target_sections->sections)
> +  for (target_section &target_section : *current_target_sections)
>      if (sect == target_section.the_bfd_section)
>        {
>  	dyn_addr = target_section.addr;
> diff --git a/gdb/solib.c b/gdb/solib.c
> index bd6a27d8983..b4864429e9a 100644
> --- a/gdb/solib.c
> +++ b/gdb/solib.c
> @@ -556,7 +556,7 @@ solib_map_sections (struct so_list *so)
>      so->sections = new target_section_table;
>    *so->sections = build_section_table (so->abfd);
>  
> -  for (target_section &p : so->sections->sections)
> +  for (target_section &p : *so->sections)
>      {
>        /* Relocate the section binding addresses as recorded in the shared
>           object's file by the base address to which the object was actually
> @@ -1113,7 +1113,7 @@ bool
>  solib_contains_address_p (const struct so_list *const solib,
>  			  CORE_ADDR address)
>  {
> -  for (target_section &p : solib->sections->sections)
> +  for (target_section &p : *solib->sections)
>      if (p.addr <= address && address < p.endaddr)
>        return true;
>  
> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index f4acec50cca..3332e7f69ff 100644
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -216,13 +216,13 @@ build_section_addr_info_from_section_table (const target_section_table &table)
>  {
>    section_addr_info sap;
>  
> -  for (const target_section &stp : table.sections)
> +  for (const target_section &stp : table)
>      {
>        struct bfd_section *asect = stp.the_bfd_section;
>        bfd *abfd = asect->owner;
>  
>        if (bfd_section_flags (asect) & (SEC_ALLOC | SEC_LOAD)
> -	  && sap.size () < table.sections.size ())
> +	  && sap.size () < table.size ())
>  	sap.emplace_back (stp.addr,
>  			  bfd_section_name (asect),
>  			  gdb_bfd_section_index (abfd, asect));
> diff --git a/gdb/target-debug.h b/gdb/target-debug.h
> index 1b2feb2c7fb..65a14c41787 100644
> --- a/gdb/target-debug.h
> +++ b/gdb/target-debug.h
> @@ -106,7 +106,7 @@
>    target_debug_do_print (host_address_to_string (X))
>  #define target_debug_print_struct_ui_file_p(X)	\
>    target_debug_do_print (host_address_to_string (X))
> -#define target_debug_print_struct_target_section_table_p(X)	\
> +#define target_debug_print_target_section_table_p(X)	\
>    target_debug_do_print (host_address_to_string (X))
>  #define target_debug_print_async_callback_ftype_p(X) \
>    target_debug_do_print (host_address_to_string (X))
> diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
> index c0968e2040e..e9c349fb7ba 100644
> --- a/gdb/target-delegates.c
> +++ b/gdb/target-delegates.c
> @@ -77,7 +77,7 @@ struct dummy_target : public target_ops
>    void rcmd (const char *arg0, struct ui_file *arg1) override;
>    char *pid_to_exec_file (int arg0) override;
>    void log_command (const char *arg0) override;
> -  struct target_section_table *get_section_table () override;
> +  target_section_table *get_section_table () override;
>    thread_control_capabilities get_thread_control_capabilities () override;
>    bool attach_no_wait () override;
>    bool can_async_p () override;
> @@ -248,7 +248,7 @@ struct debug_target : public target_ops
>    void rcmd (const char *arg0, struct ui_file *arg1) override;
>    char *pid_to_exec_file (int arg0) override;
>    void log_command (const char *arg0) override;
> -  struct target_section_table *get_section_table () override;
> +  target_section_table *get_section_table () override;
>    thread_control_capabilities get_thread_control_capabilities () override;
>    bool attach_no_wait () override;
>    bool can_async_p () override;
> @@ -2021,27 +2021,27 @@ debug_target::log_command (const char *arg0)
>    fputs_unfiltered (")\n", gdb_stdlog);
>  }
>  
> -struct target_section_table *
> +target_section_table *
>  target_ops::get_section_table ()
>  {
>    return this->beneath ()->get_section_table ();
>  }
>  
> -struct target_section_table *
> +target_section_table *
>  dummy_target::get_section_table ()
>  {
>    return NULL;
>  }
>  
> -struct target_section_table *
> +target_section_table *
>  debug_target::get_section_table ()
>  {
> -  struct target_section_table * result;
> +  target_section_table * result;
>    fprintf_unfiltered (gdb_stdlog, "-> %s->get_section_table (...)\n", this->beneath ()->shortname ());
>    result = this->beneath ()->get_section_table ();
>    fprintf_unfiltered (gdb_stdlog, "<- %s->get_section_table (", this->beneath ()->shortname ());
>    fputs_unfiltered (") = ", gdb_stdlog);
> -  target_debug_print_struct_target_section_table_p (result);
> +  target_debug_print_target_section_table_p (result);
>    fputs_unfiltered ("\n", gdb_stdlog);
>    return result;
>  }
> diff --git a/gdb/target-section.h b/gdb/target-section.h
> index 8c81f3d79ba..fc4c800158d 100644
> --- a/gdb/target-section.h
> +++ b/gdb/target-section.h
> @@ -41,9 +41,6 @@ struct target_section
>  
>  /* Holds an array of target sections.  */
>  
> -struct target_section_table
> -{
> -  std::vector<struct target_section> sections;
> -};
> +using target_section_table = std::vector<target_section>;
>  
>  #endif /* GDB_TARGET_SECTION_H */
> diff --git a/gdb/target.c b/gdb/target.c
> index f828d3d6cc3..e3b561649ed 100644
> --- a/gdb/target.c
> +++ b/gdb/target.c
> @@ -811,7 +811,7 @@ target_read_string (CORE_ADDR memaddr, int len, int *bytes_read)
>    return gdb::unique_xmalloc_ptr<char> ((char *) buffer.release ());
>  }
>  
> -struct target_section_table *
> +target_section_table *
>  target_get_section_table (struct target_ops *target)
>  {
>    return target->get_section_table ();
> @@ -822,12 +822,12 @@ target_get_section_table (struct target_ops *target)
>  struct target_section *
>  target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
>  {
> -  struct target_section_table *table = target_get_section_table (target);
> +  target_section_table *table = target_get_section_table (target);
>  
>    if (table == NULL)
>      return NULL;
>  
> -  for (target_section &secp : table->sections)
> +  for (target_section &secp : *table)
>      {
>        if (addr >= secp.addr && addr < secp.endaddr)
>  	return &secp;
> @@ -964,8 +964,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
>  
>        if (pc_in_unmapped_range (memaddr, section))
>  	{
> -	  struct target_section_table *table
> -	    = target_get_section_table (ops);
> +	  target_section_table *table = target_get_section_table (ops);
>  	  const char *section_name = section->the_bfd_section->name;
>  
>  	  memaddr = overlay_mapped_address (memaddr, section);
> @@ -985,13 +984,12 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
>    if (readbuf != NULL && trust_readonly)
>      {
>        struct target_section *secp;
> -      struct target_section_table *table;
>  
>        secp = target_section_by_addr (ops, memaddr);
>        if (secp != NULL
>  	  && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
>  	{
> -	  table = target_get_section_table (ops);
> +	  target_section_table *table = target_get_section_table (ops);
>  	  return section_table_xfer_memory_partial (readbuf, writebuf,
>  						    memaddr, len, xfered_len,
>  						    *table);
> diff --git a/gdb/target.h b/gdb/target.h
> index 369394aa929..5eca0e27ef3 100644
> --- a/gdb/target.h
> +++ b/gdb/target.h
> @@ -29,7 +29,6 @@ struct target_ops;
>  struct bp_location;
>  struct bp_target_info;
>  struct regcache;
> -struct target_section_table;
>  struct trace_state_variable;
>  struct trace_status;
>  struct uploaded_tsv;
> @@ -681,7 +680,7 @@ struct target_ops
>        TARGET_DEFAULT_RETURN (NULL);
>      virtual void log_command (const char *)
>        TARGET_DEFAULT_IGNORE ();
> -    virtual struct target_section_table *get_section_table ()
> +    virtual target_section_table *get_section_table ()
>        TARGET_DEFAULT_RETURN (NULL);
>  
>      /* Provide default values for all "must have" methods.  */
> @@ -2421,7 +2420,7 @@ struct target_section *target_section_by_addr (struct target_ops *target,
>  /* Return the target section table this target (or the targets
>     beneath) currently manipulate.  */
>  
> -extern struct target_section_table *target_get_section_table
> +extern target_section_table *target_get_section_table
>    (struct target_ops *target);
>  
>  /* From mem-break.c */
> -- 
> 2.17.2
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/6] Introduce target-section.h
  2020-10-04  8:29   ` Andrew Burgess
@ 2020-10-09  1:17     ` Tom Tromey
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Tromey @ 2020-10-09  1:17 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Tom Tromey, gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

>> +/* Struct target_section maps address ranges to file sections.  It is
>> +   mostly used with BFD files, but can be used without (e.g. for handling
>> +   raw disks, or files not in formats handled by BFD).  */
>> +
>> +struct target_section
>> +  {
>> +    CORE_ADDR addr;		/* Lowest address in section */
>> +    CORE_ADDR endaddr;		/* 1+highest address in section */
>> +
>> +    struct bfd_section *the_bfd_section;
>> +
>> +    /* The "owner" of the section.
>> +       It can be any unique value.  It is set by add_target_sections
>> +       and used by remove_target_sections.
>> +       For example, for executables it is a pointer to exec_bfd and
>> +       for shlibs it is the so_list pointer.  */
>> +    void *owner;
>> +  };

Andrew> I know that this is copy & paste code, but it would be awesome if we
Andrew> could take this opportunity to fix the whitespace formatting, place
Andrew> the comments in the correct place, reword them as proper sentences,
Andrew> and add a comment to the missing field.

Andrew> Generally bring this code up to our current coding standard :)

I've done this.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/6] Change target section table management
  2020-10-03 19:37 [PATCH 0/6] Change target section table management Tom Tromey
                   ` (5 preceding siblings ...)
  2020-10-03 19:37 ` [PATCH 6/6] Change target_section_table to std::vector alias Tom Tromey
@ 2020-10-13  2:19 ` Tom Tromey
  6 siblings, 0 replies; 24+ messages in thread
From: Tom Tromey @ 2020-10-13  2:19 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> I looked into resurrecting my series to remove the macros from
Tom> progspace.h and exec.h, but found that this would be improved by first
Tom> changing how target section tables are managed.

Tom> This series changes target section tables to use a std::vector and
Tom> cleans up various related things.

I'm checking this in now.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-03 19:37 ` [PATCH 2/6] Use a std::vector in target_section_table Tom Tromey
@ 2020-10-13 16:41   ` Luis Machado
  2020-10-13 20:35     ` Tom Tromey
  2020-10-14  9:09   ` Tom de Vries
  2020-11-10 17:38   ` Simon Marchi
  2 siblings, 1 reply; 24+ messages in thread
From: Luis Machado @ 2020-10-13 16:41 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

Hi,

FTR, this has regressed AArch64-linux...

FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[0]@4
FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[pagesize-4]@4
FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[-3]@6
FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_rw[pagesize-3]@6
FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[pagesize-3]@6

I haven't investigated the failure, but I've bisected the failure to 
this commit.

On 10/3/20 4:37 PM, Tom Tromey wrote:
> This changes target_section_table to wrap a std::vector.  This
> simplifies some code, and also enables the simplifications coming in
> the subsequent patches.
> 
> Note that for solib, I chose to have it use a pointer to a
> target_section_table.  This is more convoluted than would be ideal,
> but I didn't want to convert solib to new/delete as a prerequisite for
> this series.
> 
> gdb/ChangeLog
> 2020-10-03  Tom Tromey  <tom@tromey.com>
> 
> 	* target.c (target_section_by_addr, memory_xfer_partial_1):
> 	Update.
> 	* target-section.h (struct target_section_table): Use
> 	std::vector.
> 	* symfile.h (build_section_addr_info_from_section_table): Take a
> 	target_section_table.
> 	* symfile.c (build_section_addr_info_from_section_table): Take a
> 	target_section_table.
> 	* solist.h (struct so_list) <sections>: Change type.
> 	<sections_end>: Remove.
> 	* solib.c (solib_map_sections, clear_so, solib_read_symbols)
> 	(solib_contains_address_p): Update.
> 	* solib-svr4.c (scan_dyntag): Update.
> 	* solib-dsbt.c (scan_dyntag): Update.
> 	* remote.c (remote_target::remote_xfer_live_readonly_partial):
> 	Update.
> 	* record-full.c (record_full_core_start, record_full_core_end):
> 	Remove.
> 	(record_full_core_sections): New global.
> 	(record_full_core_open_1, record_full_core_target::xfer_partial):
> 	Update.
> 	* exec.h (build_section_table, section_table_xfer_memory_partial)
> 	(add_target_sections): Take a target_section_table.
> 	* exec.c (exec_file_attach, clear_section_table): Update.
> 	(resize_section_table): Remove.
> 	(build_section_table, add_target_sections): Take a
> 	target_section_table.
> 	(add_target_sections_of_objfile, remove_target_sections)
> 	(exec_on_vfork): Update.
> 	(section_table_available_memory): Take a target_section_table.
> 	(section_table_read_available_memory): Update.
> 	(section_table_xfer_memory_partial): Take a target_section_table.
> 	(print_section_info, set_section_command)
> 	(exec_set_section_address, exec_target::has_memory): Update.
> 	* corelow.c (class core_target) <m_core_section_table,
> 	m_core_file_mappings>: Remove braces.
> 	<~core_target>: Remove.
> 	(core_target::core_target): Update.
> 	(core_target::~core_target): Remove.
> 	(core_target::build_file_mappings)
> 	(core_target::xfer_memory_via_mappings)
> 	(core_target::xfer_partial, core_target::info_proc_mappings):
> 	Update.
> 	* bfd-target.c (target_bfd::xfer_partial): Update.
> 	(target_bfd::target_bfd): Update.
> 	(target_bfd::~target_bfd): Remove.
> ---
>   gdb/ChangeLog        |  49 +++++++++
>   gdb/bfd-target.c     |  13 +--
>   gdb/corelow.c        |  58 ++++------
>   gdb/exec.c           | 247 +++++++++++++++----------------------------
>   gdb/exec.h           |   9 +-
>   gdb/record-full.c    |  33 +++---
>   gdb/remote.c         |  11 +-
>   gdb/solib-dsbt.c     |  18 ++--
>   gdb/solib-svr4.c     |  18 ++--
>   gdb/solib.c          |  33 +++---
>   gdb/solist.h         |   4 +-
>   gdb/symfile.c        |  13 +--
>   gdb/symfile.h        |   6 +-
>   gdb/target-section.h |   5 +-
>   gdb/target.c         |  14 +--
>   15 files changed, 230 insertions(+), 301 deletions(-)
> 
> diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
> index 3d266951c5a..8a58e92eb1c 100644
> --- a/gdb/bfd-target.c
> +++ b/gdb/bfd-target.c
> @@ -35,7 +35,6 @@ class target_bfd : public target_ops
>   {
>   public:
>     explicit target_bfd (struct bfd *bfd);
> -  ~target_bfd () override;
>   
>     const target_info &info () const override
>     { return target_bfd_target_info; }
> @@ -76,8 +75,7 @@ target_bfd::xfer_partial (target_object object,
>         {
>   	return section_table_xfer_memory_partial (readbuf, writebuf,
>   						  offset, len, xfered_len,
> -						  m_table.sections,
> -						  m_table.sections_end);
> +						  m_table);
>         }
>       default:
>         return TARGET_XFER_E_IO;
> @@ -93,14 +91,7 @@ target_bfd::get_section_table ()
>   target_bfd::target_bfd (struct bfd *abfd)
>     : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
>   {
> -  m_table.sections = NULL;
> -  m_table.sections_end = NULL;
> -  build_section_table (abfd, &m_table.sections, &m_table.sections_end);
> -}
> -
> -target_bfd::~target_bfd ()
> -{
> -  xfree (m_table.sections);
> +  build_section_table (abfd, &m_table);
>   }
>   
>   target_ops *
> diff --git a/gdb/corelow.c b/gdb/corelow.c
> index e82c183eae5..554561dbb36 100644
> --- a/gdb/corelow.c
> +++ b/gdb/corelow.c
> @@ -67,7 +67,6 @@ class core_target final : public process_stratum_target
>   {
>   public:
>     core_target ();
> -  ~core_target () override;
>   
>     const target_info &info () const override
>     { return core_target_info; }
> @@ -126,11 +125,11 @@ class core_target final : public process_stratum_target
>        shared library bfds.  The core bfd sections are an implementation
>        detail of the core target, just like ptrace is for unix child
>        targets.  */
> -  target_section_table m_core_section_table {};
> +  target_section_table m_core_section_table;
>   
>     /* File-backed address space mappings: some core files include
>        information about memory mapped files.  */
> -  target_section_table m_core_file_mappings {};
> +  target_section_table m_core_file_mappings;
>   
>     /* Unavailable mappings.  These correspond to pathnames which either
>        weren't found or could not be opened.  Knowing these addresses can
> @@ -162,21 +161,13 @@ core_target::core_target ()
>   	   bfd_get_filename (core_bfd));
>   
>     /* Find the data section */
> -  if (build_section_table (core_bfd,
> -			   &m_core_section_table.sections,
> -			   &m_core_section_table.sections_end))
> +  if (build_section_table (core_bfd, &m_core_section_table))
>       error (_("\"%s\": Can't find sections: %s"),
>   	   bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
>   
>     build_file_mappings ();
>   }
>   
> -core_target::~core_target ()
> -{
> -  xfree (m_core_section_table.sections);
> -  xfree (m_core_file_mappings.sections);
> -}
> -
>   /* Construct the target_section_table for file-backed mappings if
>      they exist.
>   
> @@ -202,12 +193,9 @@ core_target::build_file_mappings ()
>     gdbarch_read_core_file_mappings (m_core_gdbarch, core_bfd,
>   
>       /* After determining the number of mappings, read_core_file_mappings
> -       will invoke this lambda which allocates target_section storage for
> -       the mappings.  */
> -    [&] (ULONGEST count)
> +       will invoke this lambda.  */
> +    [&] (ULONGEST)
>         {
> -	m_core_file_mappings.sections = XNEWVEC (struct target_section, count);
> -	m_core_file_mappings.sections_end = m_core_file_mappings.sections;
>         },
>   
>       /* read_core_file_mappings will invoke this lambda for each mapping
> @@ -280,11 +268,12 @@ core_target::build_file_mappings ()
>   	bfd_set_section_alignment (sec, 2);
>   
>   	/* Set target_section fields.  */
> -	struct target_section *ts = m_core_file_mappings.sections_end++;
> -	ts->addr = start;
> -	ts->endaddr = end;
> -	ts->owner = nullptr;
> -	ts->the_bfd_section = sec;
> +	m_core_file_mappings.sections.emplace_back ();
> +	target_section &ts = m_core_file_mappings.sections.back ();
> +	ts.addr = start;
> +	ts.endaddr = end;
> +	ts.owner = nullptr;
> +	ts.the_bfd_section = sec;
>         });
>   
>     normalize_mem_ranges (&m_core_unavailable_mappings);
> @@ -759,8 +748,7 @@ core_target::xfer_memory_via_mappings (gdb_byte *readbuf,
>     xfer_status = (section_table_xfer_memory_partial
>   		   (readbuf, writebuf,
>   		    offset, len, xfered_len,
> -		    m_core_file_mappings.sections,
> -		    m_core_file_mappings.sections_end));
> +		    m_core_file_mappings));
>   
>     if (xfer_status == TARGET_XFER_OK || m_core_unavailable_mappings.empty ())
>       return xfer_status;
> @@ -818,8 +806,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>   	xfer_status = section_table_xfer_memory_partial
>   			(readbuf, writebuf,
>   			 offset, len, xfered_len,
> -			 m_core_section_table.sections,
> -			 m_core_section_table.sections_end,
> +			 m_core_section_table,
>   			 has_contents_cb);
>   	if (xfer_status == TARGET_XFER_OK)
>   	  return TARGET_XFER_OK;
> @@ -829,7 +816,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>   	   or the like) as this should provide a more accurate
>   	   result.  If not, check the stratum beneath us, which should
>   	   be the file stratum.  */
> -	if (m_core_file_mappings.sections != nullptr)
> +	if (!m_core_file_mappings.sections.empty ())
>   	  xfer_status = xfer_memory_via_mappings (readbuf, writebuf, offset,
>   						  len, xfered_len);
>   	else
> @@ -848,8 +835,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>   	xfer_status = section_table_xfer_memory_partial
>   			(readbuf, writebuf,
>   			 offset, len, xfered_len,
> -			 m_core_section_table.sections,
> -			 m_core_section_table.sections_end,
> +			 m_core_section_table,
>   			 no_contents_cb);
>   
>   	return xfer_status;
> @@ -1114,7 +1100,7 @@ get_current_core_target ()
>   void
>   core_target::info_proc_mappings (struct gdbarch *gdbarch)
>   {
> -  if (m_core_file_mappings.sections != m_core_file_mappings.sections_end)
> +  if (!m_core_file_mappings.sections.empty ())
>       {
>         printf_filtered (_("Mapped address spaces:\n\n"));
>         if (gdbarch_addr_bit (gdbarch) == 32)
> @@ -1133,14 +1119,12 @@ core_target::info_proc_mappings (struct gdbarch *gdbarch)
>   	}
>       }
>   
> -  for (const struct target_section *tsp = m_core_file_mappings.sections;
> -       tsp < m_core_file_mappings.sections_end;
> -       tsp++)
> +  for (const target_section &tsp : m_core_file_mappings.sections)
>       {
> -      ULONGEST start = tsp->addr;
> -      ULONGEST end = tsp->endaddr;
> -      ULONGEST file_ofs = tsp->the_bfd_section->filepos;
> -      const char *filename = bfd_get_filename (tsp->the_bfd_section->owner);
> +      ULONGEST start = tsp.addr;
> +      ULONGEST end = tsp.endaddr;
> +      ULONGEST file_ofs = tsp.the_bfd_section->filepos;
> +      const char *filename = bfd_get_filename (tsp.the_bfd_section->owner);
>   
>         if (gdbarch_addr_bit (gdbarch) == 32)
>   	printf_filtered ("\t%10s %10s %10s %10s %s\n",
> diff --git a/gdb/exec.c b/gdb/exec.c
> index 251e24dd26b..e3e515fedec 100644
> --- a/gdb/exec.c
> +++ b/gdb/exec.c
> @@ -413,7 +413,7 @@ exec_file_attach (const char *filename, int from_tty)
>         int load_via_target = 0;
>         const char *scratch_pathname, *canonical_pathname;
>         int scratch_chan;
> -      struct target_section *sections = NULL, *sections_end = NULL;
> +      target_section_table sections;
>         char **matching;
>   
>         if (is_target_filename (filename))
> @@ -503,7 +503,7 @@ exec_file_attach (const char *filename, int from_tty)
>   		 gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
>   	}
>   
> -      if (build_section_table (exec_bfd, &sections, &sections_end))
> +      if (build_section_table (exec_bfd, &sections))
>   	{
>   	  /* Make sure to close exec_bfd, or else "run" might try to use
>   	     it.  */
> @@ -522,8 +522,7 @@ exec_file_attach (const char *filename, int from_tty)
>         /* Add the executable's sections to the current address spaces'
>   	 list of sections.  This possibly pushes the exec_ops
>   	 target.  */
> -      add_target_sections (&exec_bfd, sections, sections_end);
> -      xfree (sections);
> +      add_target_sections (&exec_bfd, sections);
>   
>         /* Tell display code (if any) about the changed file name.  */
>         if (deprecated_exec_file_display_hook)
> @@ -592,50 +591,16 @@ file_command (const char *arg, int from_tty)
>   void
>   clear_section_table (struct target_section_table *table)
>   {
> -  xfree (table->sections);
> -  table->sections = table->sections_end = NULL;
> +  table->sections.clear ();
>   }
>   
> -/* Resize section table TABLE by ADJUSTMENT.
> -   ADJUSTMENT may be negative, in which case the caller must have already
> -   removed the sections being deleted.
> -   Returns the old size.  */
> -
> -static int
> -resize_section_table (struct target_section_table *table, int adjustment)
> -{
> -  int old_count;
> -  int new_count;
> -
> -  old_count = table->sections_end - table->sections;
> -
> -  new_count = adjustment + old_count;
> -
> -  if (new_count)
> -    {
> -      table->sections = XRESIZEVEC (struct target_section, table->sections,
> -				    new_count);
> -      table->sections_end = table->sections + new_count;
> -    }
> -  else
> -    clear_section_table (table);
> -
> -  return old_count;
> -}
> -
> -/* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
> +/* Builds a section table, given args BFD, TABLE.
>      Returns 0 if OK, 1 on error.  */
>   
>   int
> -build_section_table (struct bfd *some_bfd, struct target_section **start,
> -		     struct target_section **end)
> +build_section_table (struct bfd *some_bfd, target_section_table *table)
>   {
> -  unsigned count;
> -
> -  count = bfd_count_sections (some_bfd);
> -  xfree (*start);
> -  *start = XNEWVEC (struct target_section, count);
> -  *end = *start;
> +  table->sections.clear ();
>     for (asection *asect : gdb_bfd_sections (some_bfd))
>       {
>         flagword aflag;
> @@ -650,15 +615,14 @@ build_section_table (struct bfd *some_bfd, struct target_section **start,
>         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)++;
> +      table->sections.emplace_back ();
> +      target_section &sect = table->sections.back ();
> +      sect.owner = NULL;
> +      sect.the_bfd_section = asect;
> +      sect.addr = bfd_section_vma (asect);
> +      sect.endaddr = sect.addr + bfd_section_size (asect);
>       }
>   
> -  gdb_assert (*end <= *start + count);
> -
>     /* We could realloc the table, but it probably loses for most files.  */
>     return 0;
>   }
> @@ -668,23 +632,16 @@ build_section_table (struct bfd *some_bfd, struct target_section **start,
>   
>   void
>   add_target_sections (void *owner,
> -		     struct target_section *sections,
> -		     struct target_section *sections_end)
> +		     const target_section_table &sections)
>   {
> -  int count;
>     struct target_section_table *table = current_target_sections;
>   
> -  count = sections_end - sections;
> -
> -  if (count > 0)
> +  if (!sections.sections.empty ())
>       {
> -      int space = resize_section_table (table, count);
> -      int i;
> -
> -      for (i = 0; i < count; ++i)
> +      for (const target_section &s : sections.sections)
>   	{
> -	  table->sections[space + i] = sections[i];
> -	  table->sections[space + i].owner = owner;
> +	  table->sections.push_back (s);
> +	  table->sections.back ().owner = owner;
>   	}
>   
>         scoped_restore_current_pspace_and_thread restore_pspace_thread;
> @@ -714,9 +671,7 @@ add_target_sections_of_objfile (struct objfile *objfile)
>   {
>     struct target_section_table *table = current_target_sections;
>     struct obj_section *osect;
> -  int space;
>     unsigned count = 0;
> -  struct target_section *ts;
>   
>     if (objfile == NULL)
>       return;
> @@ -732,23 +687,17 @@ add_target_sections_of_objfile (struct objfile *objfile)
>     if (count == 0)
>       return;
>   
> -  space = resize_section_table (table, count);
> -
> -  ts = table->sections + space;
> -
>     ALL_OBJFILE_OSECTIONS (objfile, osect)
>       {
>         if (bfd_section_size (osect->the_bfd_section) == 0)
>   	continue;
>   
> -      gdb_assert (ts < table->sections + space + count);
> -
> -      ts->addr = obj_section_addr (osect);
> -      ts->endaddr = obj_section_endaddr (osect);
> -      ts->the_bfd_section = osect->the_bfd_section;
> -      ts->owner = (void *) objfile;
> -
> -      ts++;
> +      table->sections.emplace_back ();
> +      target_section &ts = table->sections.back ();
> +      ts.addr = obj_section_addr (osect);
> +      ts.endaddr = obj_section_endaddr (osect);
> +      ts.the_bfd_section = osect->the_bfd_section;
> +      ts.owner = (void *) objfile;
>       }
>   }
>   
> @@ -758,48 +707,36 @@ add_target_sections_of_objfile (struct objfile *objfile)
>   void
>   remove_target_sections (void *owner)
>   {
> -  struct target_section *src, *dest;
>     struct target_section_table *table = current_target_sections;
>   
>     gdb_assert (owner != NULL);
>   
> -  dest = table->sections;
> -  for (src = table->sections; src < table->sections_end; src++)
> -    if (src->owner != owner)
> -      {
> -	/* Keep this section.  */
> -	if (dest < src)
> -	  *dest = *src;
> -	dest++;
> -      }
> -
> -  /* If we've dropped any sections, resize the section table.  */
> -  if (dest < src)
> +  auto it = std::remove_if (table->sections.begin (),
> +			    table->sections.end (),
> +			    [&] (target_section &sect)
> +			    {
> +			      return sect.owner == owner;
> +			    });
> +  table->sections.erase (it, table->sections.end ());
> +
> +  /* If we don't have any more sections to read memory from,
> +     remove the file_stratum target from the stack of each
> +     inferior sharing the program space.  */
> +  if (table->sections.empty ())
>       {
> -      int old_count;
> -
> -      old_count = resize_section_table (table, dest - src);
> +      scoped_restore_current_pspace_and_thread restore_pspace_thread;
> +      program_space *curr_pspace = current_program_space;
>   
> -      /* If we don't have any more sections to read memory from,
> -	 remove the file_stratum target from the stack of each
> -	 inferior sharing the program space.  */
> -      if (old_count + (dest - src) == 0)
> +      for (inferior *inf : all_inferiors ())
>   	{
> -	  scoped_restore_current_pspace_and_thread restore_pspace_thread;
> -	  program_space *curr_pspace = current_program_space;
> -
> -	  for (inferior *inf : all_inferiors ())
> -	    {
> -	      if (inf->pspace != curr_pspace)
> -		continue;
> +	  if (inf->pspace != curr_pspace)
> +	    continue;
>   
> -	      if (inf->pspace->target_sections.sections
> -		  != inf->pspace->target_sections.sections_end)
> -		continue;
> +	  if (!inf->pspace->target_sections.sections.empty ())
> +	    continue;
>   
> -	      switch_to_inferior_no_thread (inf);
> -	      unpush_target (&exec_ops);
> -	    }
> +	  switch_to_inferior_no_thread (inf);
> +	  unpush_target (&exec_ops);
>   	}
>       }
>   }
> @@ -809,8 +746,7 @@ remove_target_sections (void *owner)
>   void
>   exec_on_vfork ()
>   {
> -  if (current_program_space->target_sections.sections
> -      != current_program_space->target_sections.sections_end)
> +  if (!current_program_space->target_sections.sections.empty ())
>       push_target (&exec_ops);
>   }
>   
> @@ -869,26 +805,25 @@ exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
>   
>   static std::vector<mem_range>
>   section_table_available_memory (CORE_ADDR memaddr, ULONGEST len,
> -				struct target_section *sections,
> -				struct target_section *sections_end)
> +				const target_section_table &sections)
>   {
>     std::vector<mem_range> memory;
>   
> -  for (target_section *p = sections; p < sections_end; p++)
> +  for (const target_section &p : sections.sections)
>       {
> -      if ((bfd_section_flags (p->the_bfd_section) & SEC_READONLY) == 0)
> +      if ((bfd_section_flags (p.the_bfd_section) & SEC_READONLY) == 0)
>   	continue;
>   
>         /* Copy the meta-data, adjusted.  */
> -      if (mem_ranges_overlap (p->addr, p->endaddr - p->addr, memaddr, len))
> +      if (mem_ranges_overlap (p.addr, p.endaddr - p.addr, memaddr, len))
>   	{
>   	  ULONGEST lo1, hi1, lo2, hi2;
>   
>   	  lo1 = memaddr;
>   	  hi1 = memaddr + len;
>   
> -	  lo2 = p->addr;
> -	  hi2 = p->endaddr;
> +	  lo2 = p.addr;
> +	  hi2 = p.endaddr;
>   
>   	  CORE_ADDR start = std::max (lo1, lo2);
>   	  int length = std::min (hi1, hi2) - start;
> @@ -906,8 +841,7 @@ section_table_read_available_memory (gdb_byte *readbuf, ULONGEST offset,
>   {
>     target_section_table *table = target_get_section_table (&exec_ops);
>     std::vector<mem_range> available_memory
> -    = section_table_available_memory (offset, len,
> -				      table->sections, table->sections_end);
> +    = section_table_available_memory (offset, len, *table);
>   
>     normalize_mem_ranges (&available_memory);
>   
> @@ -944,37 +878,35 @@ enum target_xfer_status
>   section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
>   				   ULONGEST offset, ULONGEST len,
>   				   ULONGEST *xfered_len,
> -				   struct target_section *sections,
> -				   struct target_section *sections_end,
> +				   const target_section_table &sections,
>   				   gdb::function_view<bool
>   				     (const struct target_section *)> match_cb)
>   {
>     int res;
> -  struct target_section *p;
>     ULONGEST memaddr = offset;
>     ULONGEST memend = memaddr + len;
>   
>     gdb_assert (len != 0);
>   
> -  for (p = sections; p < sections_end; p++)
> +  for (const target_section &p : sections.sections)
>       {
> -      struct bfd_section *asect = p->the_bfd_section;
> +      struct bfd_section *asect = p.the_bfd_section;
>         bfd *abfd = asect->owner;
>   
> -      if (match_cb != nullptr && !match_cb (p))
> +      if (match_cb != nullptr && !match_cb (&p))
>   	continue;		/* not the section we need.  */
> -      if (memaddr >= p->addr)
> +      if (memaddr >= p.addr)
>           {
> -	  if (memend <= p->endaddr)
> +	  if (memend <= p.endaddr)
>   	    {
>   	      /* Entire transfer is within this section.  */
>   	      if (writebuf)
>   		res = bfd_set_section_contents (abfd, asect,
> -						writebuf, memaddr - p->addr,
> +						writebuf, memaddr - p.addr,
>   						len);
>   	      else
>   		res = bfd_get_section_contents (abfd, asect,
> -						readbuf, memaddr - p->addr,
> +						readbuf, memaddr - p.addr,
>   						len);
>   
>   	      if (res != 0)
> @@ -985,7 +917,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
>   	      else
>   		return TARGET_XFER_EOF;
>   	    }
> -	  else if (memaddr >= p->endaddr)
> +	  else if (memaddr >= p.endaddr)
>   	    {
>   	      /* This section ends before the transfer starts.  */
>   	      continue;
> @@ -993,14 +925,14 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
>   	  else
>   	    {
>   	      /* This section overlaps the transfer.  Just do half.  */
> -	      len = p->endaddr - memaddr;
> +	      len = p.endaddr - memaddr;
>   	      if (writebuf)
>   		res = bfd_set_section_contents (abfd, asect,
> -						writebuf, memaddr - p->addr,
> +						writebuf, memaddr - p.addr,
>   						len);
>   	      else
>   		res = bfd_get_section_contents (abfd, asect,
> -						readbuf, memaddr - p->addr,
> +						readbuf, memaddr - p.addr,
>   						len);
>   	      if (res != 0)
>   		{
> @@ -1033,8 +965,7 @@ exec_target::xfer_partial (enum target_object object,
>     if (object == TARGET_OBJECT_MEMORY)
>       return section_table_xfer_memory_partial (readbuf, writebuf,
>   					      offset, len, xfered_len,
> -					      table->sections,
> -					      table->sections_end);
> +					      *table);
>     else
>       return TARGET_XFER_E_IO;
>   }
> @@ -1044,7 +975,6 @@ void
>   print_section_info (struct target_section_table *t, bfd *abfd)
>   {
>     struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
> -  struct target_section *p;
>     /* FIXME: 16 is not wide enough when gdbarch_addr_bit > 64.  */
>     int wid = gdbarch_addr_bit (gdbarch) <= 32 ? 8 : 16;
>   
> @@ -1059,10 +989,11 @@ print_section_info (struct target_section_table *t, bfd *abfd)
>   	 <p == t->sections_end>.  */
>         bfd_vma displacement = 0;
>         bfd_vma entry_point;
> +      bool found = false;
>   
> -      for (p = t->sections; p < t->sections_end; p++)
> +      for (const target_section &p : t->sections)
>   	{
> -	  struct bfd_section *psect = p->the_bfd_section;
> +	  struct bfd_section *psect = p.the_bfd_section;
>   
>   	  if ((bfd_section_flags (psect) & (SEC_ALLOC | SEC_LOAD))
>   	      != (SEC_ALLOC | SEC_LOAD))
> @@ -1072,11 +1003,12 @@ print_section_info (struct target_section_table *t, bfd *abfd)
>   	      && abfd->start_address < (bfd_section_vma (psect)
>   					+ bfd_section_size (psect)))
>   	    {
> -	      displacement = p->addr - bfd_section_vma (psect);
> +	      displacement = p.addr - bfd_section_vma (psect);
> +	      found = true;
>   	      break;
>   	    }
>   	}
> -      if (p == t->sections_end)
> +      if (!found)
>   	warning (_("Cannot find section for the entry point of %ps."),
>   		 styled_string (file_name_style.style (),
>   				bfd_get_filename (abfd)));
> @@ -1087,13 +1019,13 @@ print_section_info (struct target_section_table *t, bfd *abfd)
>         printf_filtered (_("\tEntry point: %s\n"),
>   		       paddress (gdbarch, entry_point));
>       }
> -  for (p = t->sections; p < t->sections_end; p++)
> +  for (const target_section &p : t->sections)
>       {
> -      struct bfd_section *psect = p->the_bfd_section;
> +      struct bfd_section *psect = p.the_bfd_section;
>         bfd *pbfd = psect->owner;
>   
> -      printf_filtered ("\t%s", hex_string_custom (p->addr, wid));
> -      printf_filtered (" - %s", hex_string_custom (p->endaddr, wid));
> +      printf_filtered ("\t%s", hex_string_custom (p.addr, wid));
> +      printf_filtered (" - %s", hex_string_custom (p.endaddr, wid));
>   
>         /* FIXME: A format of "08l" is not wide enough for file offsets
>   	 larger than 4GB.  OTOH, making it "016l" isn't desirable either
> @@ -1125,7 +1057,6 @@ exec_target::files_info ()
>   static void
>   set_section_command (const char *args, int from_tty)
>   {
> -  struct target_section *p;
>     const char *secname;
>     unsigned seclen;
>     unsigned long secaddr;
> @@ -1144,14 +1075,14 @@ set_section_command (const char *args, int from_tty)
>     secaddr = parse_and_eval_address (args);
>   
>     table = current_target_sections;
> -  for (p = table->sections; p < table->sections_end; p++)
> +  for (target_section &p : table->sections)
>       {
> -      if (!strncmp (secname, bfd_section_name (p->the_bfd_section), seclen)
> -	  && bfd_section_name (p->the_bfd_section)[seclen] == '\0')
> +      if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen)
> +	  && bfd_section_name (p.the_bfd_section)[seclen] == '\0')
>   	{
> -	  offset = secaddr - p->addr;
> -	  p->addr += offset;
> -	  p->endaddr += offset;
> +	  offset = secaddr - p.addr;
> +	  p.addr += offset;
> +	  p.endaddr += offset;
>   	  if (from_tty)
>   	    exec_ops.files_info ();
>   	  return;
> @@ -1170,18 +1101,17 @@ set_section_command (const char *args, int from_tty)
>   void
>   exec_set_section_address (const char *filename, int index, CORE_ADDR address)
>   {
> -  struct target_section *p;
>     struct target_section_table *table;
>   
>     table = current_target_sections;
> -  for (p = table->sections; p < table->sections_end; p++)
> +  for (target_section &p : table->sections)
>       {
>         if (filename_cmp (filename,
> -			bfd_get_filename (p->the_bfd_section->owner)) == 0
> -	  && index == p->the_bfd_section->index)
> +			bfd_get_filename (p.the_bfd_section->owner)) == 0
> +	  && index == p.the_bfd_section->index)
>   	{
> -	  p->endaddr += address - p->addr;
> -	  p->addr = address;
> +	  p.endaddr += address - p.addr;
> +	  p.addr = address;
>   	}
>       }
>   }
> @@ -1191,8 +1121,7 @@ exec_target::has_memory ()
>   {
>     /* We can provide memory if we have any file/target sections to read
>        from.  */
> -  return (current_target_sections->sections
> -	  != current_target_sections->sections_end);
> +  return !current_target_sections->sections.empty ();
>   }
>   
>   char *
> diff --git a/gdb/exec.h b/gdb/exec.h
> index 82eb39c55d8..d26eba49236 100644
> --- a/gdb/exec.h
> +++ b/gdb/exec.h
> @@ -37,8 +37,7 @@ struct objfile;
>   /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
>      Returns 0 if OK, 1 on error.  */
>   
> -extern int build_section_table (struct bfd *, struct target_section **,
> -				struct target_section **);
> +extern int build_section_table (struct bfd *, struct target_section_table *);
>   
>   /* Remove all entries from TABLE.  */
>   
> @@ -86,8 +85,7 @@ extern enum target_xfer_status
>     section_table_xfer_memory_partial (gdb_byte *,
>   				     const gdb_byte *,
>   				     ULONGEST, ULONGEST, ULONGEST *,
> -				     struct target_section *,
> -				     struct target_section *,
> +				     const target_section_table &,
>   				     gdb::function_view<bool
>   				       (const struct target_section *)> match_cb
>   				         = nullptr);
> @@ -111,8 +109,7 @@ extern void remove_target_sections (void *owner);
>      current set of target sections.  */
>   
>   extern void add_target_sections (void *owner,
> -				 struct target_section *sections,
> -				 struct target_section *sections_end);
> +				 const target_section_table &sections);
>   
>   /* Add the sections of OBJFILE to the current set of target sections.
>    * OBJFILE owns the new target sections.  */
> diff --git a/gdb/record-full.c b/gdb/record-full.c
> index 9a6187e8104..5dcb42d2f4e 100644
> --- a/gdb/record-full.c
> +++ b/gdb/record-full.c
> @@ -171,8 +171,7 @@ struct record_full_core_buf_entry
>   
>   /* Record buf with core target.  */
>   static detached_regcache *record_full_core_regbuf = NULL;
> -static struct target_section *record_full_core_start;
> -static struct target_section *record_full_core_end;
> +static target_section_table record_full_core_sections;
>   static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
>   
>   /* The following variables are used for managing the linked list that
> @@ -924,9 +923,7 @@ record_full_core_open_1 (const char *name, int from_tty)
>     for (i = 0; i < regnum; i ++)
>       record_full_core_regbuf->raw_supply (i, *regcache);
>   
> -  /* Get record_full_core_start and record_full_core_end.  */
> -  if (build_section_table (core_bfd, &record_full_core_start,
> -			   &record_full_core_end))
> +  if (build_section_table (core_bfd, &record_full_core_sections))
>       {
>         delete record_full_core_regbuf;
>         record_full_core_regbuf = NULL;
> @@ -2147,27 +2144,25 @@ record_full_core_target::xfer_partial (enum target_object object,
>       {
>         if (record_full_gdb_operation_disable || !writebuf)
>   	{
> -	  struct target_section *p;
> -
> -	  for (p = record_full_core_start; p < record_full_core_end; p++)
> +	  for (target_section &p : record_full_core_sections.sections)
>   	    {
> -	      if (offset >= p->addr)
> +	      if (offset >= p.addr)
>   		{
>   		  struct record_full_core_buf_entry *entry;
>   		  ULONGEST sec_offset;
>   
> -		  if (offset >= p->endaddr)
> +		  if (offset >= p.endaddr)
>   		    continue;
>   
> -		  if (offset + len > p->endaddr)
> -		    len = p->endaddr - offset;
> +		  if (offset + len > p.endaddr)
> +		    len = p.endaddr - offset;
>   
> -		  sec_offset = offset - p->addr;
> +		  sec_offset = offset - p.addr;
>   
>   		  /* Read readbuf or write writebuf p, offset, len.  */
>   		  /* Check flags.  */
> -		  if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
> -		      || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
> +		  if (p.the_bfd_section->flags & SEC_CONSTRUCTOR
> +		      || (p.the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
>   		    {
>   		      if (readbuf)
>   			memset (readbuf, 0, len);
> @@ -2178,7 +2173,7 @@ record_full_core_target::xfer_partial (enum target_object object,
>   		  /* Get record_full_core_buf_entry.  */
>   		  for (entry = record_full_core_buf_list; entry;
>   		       entry = entry->prev)
> -		    if (entry->p == p)
> +		    if (entry->p == &p)
>   		      break;
>   		  if (writebuf)
>   		    {
> @@ -2186,10 +2181,10 @@ record_full_core_target::xfer_partial (enum target_object object,
>   			{
>   			  /* Add a new entry.  */
>   			  entry = XNEW (struct record_full_core_buf_entry);
> -			  entry->p = p;
> +			  entry->p = &p;
>   			  if (!bfd_malloc_and_get_section
> -			        (p->the_bfd_section->owner,
> -				 p->the_bfd_section,
> +			        (p.the_bfd_section->owner,
> +				 p.the_bfd_section,
>   				 &entry->buf))
>   			    {
>   			      xfree (entry);
> diff --git a/gdb/remote.c b/gdb/remote.c
> index f95148643f8..c9c5ed03ea2 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -8895,22 +8895,21 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
>     if (secp != NULL
>         && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
>       {
> -      struct target_section *p;
>         ULONGEST memend = memaddr + len;
>   
>         table = target_get_section_table (this);
>   
> -      for (p = table->sections; p < table->sections_end; p++)
> +      for (target_section &p : table->sections)
>   	{
> -	  if (memaddr >= p->addr)
> +	  if (memaddr >= p.addr)
>   	    {
> -	      if (memend <= p->endaddr)
> +	      if (memend <= p.endaddr)
>   		{
>   		  /* Entire transfer is within this section.  */
>   		  return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
>   					      xfered_len);
>   		}
> -	      else if (memaddr >= p->endaddr)
> +	      else if (memaddr >= p.endaddr)
>   		{
>   		  /* This section ends before the transfer starts.  */
>   		  continue;
> @@ -8918,7 +8917,7 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
>   	      else
>   		{
>   		  /* This section overlaps the transfer.  Just do half.  */
> -		  len = p->endaddr - memaddr;
> +		  len = p.endaddr - memaddr;
>   		  return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
>   					      xfered_len);
>   		}
> diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
> index 0f146725dba..59089216314 100644
> --- a/gdb/solib-dsbt.c
> +++ b/gdb/solib-dsbt.c
> @@ -407,7 +407,6 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
>     Elf32_External_Dyn *x_dynp_32;
>     Elf64_External_Dyn *x_dynp_64;
>     struct bfd_section *sect;
> -  struct target_section *target_section;
>   
>     if (abfd == NULL)
>       return 0;
> @@ -424,14 +423,15 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
>     if (sect == NULL)
>       return 0;
>   
> -  for (target_section = current_target_sections->sections;
> -       target_section < current_target_sections->sections_end;
> -       target_section++)
> -    if (sect == target_section->the_bfd_section)
> -      break;
> -  if (target_section < current_target_sections->sections_end)
> -    dyn_addr = target_section->addr;
> -  else
> +  bool found = false;
> +  for (target_section &target_section : current_target_sections->sections)
> +    if (sect == target_section.the_bfd_section)
> +      {
> +	dyn_addr = target_section.addr;
> +	found = true;
> +	break;
> +      }
> +  if (!found)
>       {
>         /* ABFD may come from OBJFILE acting only as a symbol file without being
>   	 loaded into the target (see add_symbol_file_command).  This case is
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index 4ae21d190bf..9bb728ae9b9 100644
> --- a/gdb/solib-svr4.c
> +++ b/gdb/solib-svr4.c
> @@ -591,7 +591,6 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
>     Elf32_External_Dyn *x_dynp_32;
>     Elf64_External_Dyn *x_dynp_64;
>     struct bfd_section *sect;
> -  struct target_section *target_section;
>   
>     if (abfd == NULL)
>       return 0;
> @@ -608,14 +607,15 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
>     if (sect == NULL)
>       return 0;
>   
> -  for (target_section = current_target_sections->sections;
> -       target_section < current_target_sections->sections_end;
> -       target_section++)
> -    if (sect == target_section->the_bfd_section)
> -      break;
> -  if (target_section < current_target_sections->sections_end)
> -    dyn_addr = target_section->addr;
> -  else
> +  bool found = false;
> +  for (target_section &target_section : current_target_sections->sections)
> +    if (sect == target_section.the_bfd_section)
> +      {
> +	dyn_addr = target_section.addr;
> +	found = true;
> +	break;
> +      }
> +  if (!found)
>       {
>         /* ABFD may come from OBJFILE acting only as a symbol file without being
>   	 loaded into the target (see add_symbol_file_command).  This case is
> diff --git a/gdb/solib.c b/gdb/solib.c
> index cf5d05e83b2..906e1788c49 100644
> --- a/gdb/solib.c
> +++ b/gdb/solib.c
> @@ -532,7 +532,6 @@ static int
>   solib_map_sections (struct so_list *so)
>   {
>     const struct target_so_ops *ops = solib_ops (target_gdbarch ());
> -  struct target_section *p;
>   
>     gdb::unique_xmalloc_ptr<char> filename (tilde_expand (so->so_name));
>     gdb_bfd_ref_ptr abfd (ops->bfd_open (filename.get ()));
> @@ -553,27 +552,29 @@ solib_map_sections (struct so_list *so)
>       error (_("Shared library file name is too long."));
>     strcpy (so->so_name, bfd_get_filename (so->abfd));
>   
> -  if (build_section_table (so->abfd, &so->sections, &so->sections_end))
> +  if (so->sections == nullptr)
> +    so->sections = new target_section_table;
> +  if (build_section_table (so->abfd, so->sections))
>       {
>         error (_("Can't find the file sections in `%s': %s"),
>   	     bfd_get_filename (so->abfd), bfd_errmsg (bfd_get_error ()));
>       }
>   
> -  for (p = so->sections; p < so->sections_end; p++)
> +  for (target_section &p : so->sections->sections)
>       {
>         /* Relocate the section binding addresses as recorded in the shared
>            object's file by the base address to which the object was actually
>            mapped.  */
> -      ops->relocate_section_addresses (so, p);
> +      ops->relocate_section_addresses (so, &p);
>   
>         /* If the target didn't provide information about the address
>   	 range of the shared object, assume we want the location of
>   	 the .text section.  */
>         if (so->addr_low == 0 && so->addr_high == 0
> -	  && strcmp (p->the_bfd_section->name, ".text") == 0)
> +	  && strcmp (p.the_bfd_section->name, ".text") == 0)
>   	{
> -	  so->addr_low = p->addr;
> -	  so->addr_high = p->endaddr;
> +	  so->addr_low = p.addr;
> +	  so->addr_high = p.endaddr;
>   	}
>       }
>   
> @@ -581,7 +582,7 @@ solib_map_sections (struct so_list *so)
>        section tables.  Do this immediately after mapping the object so
>        that later nodes in the list can query this object, as is needed
>        in solib-osf.c.  */
> -  add_target_sections (so, so->sections, so->sections_end);
> +  add_target_sections (so, *so->sections);
>   
>     return 1;
>   }
> @@ -600,11 +601,8 @@ clear_so (struct so_list *so)
>   {
>     const struct target_so_ops *ops = solib_ops (target_gdbarch ());
>   
> -  if (so->sections)
> -    {
> -      xfree (so->sections);
> -      so->sections = so->sections_end = NULL;
> -    }
> +  delete so->sections;
> +  so->sections = NULL;
>   
>     gdb_bfd_unref (so->abfd);
>     so->abfd = NULL;
> @@ -683,8 +681,7 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags)
>   	  if (so->objfile == NULL)
>   	    {
>   	      section_addr_info sap
> -		= build_section_addr_info_from_section_table (so->sections,
> -							      so->sections_end);
> +		= build_section_addr_info_from_section_table (*so->sections);
>   	      so->objfile = symbol_file_add_from_bfd (so->abfd, so->so_name,
>   						      flags, &sap,
>   						      OBJF_SHARED, NULL);
> @@ -1120,10 +1117,8 @@ bool
>   solib_contains_address_p (const struct so_list *const solib,
>   			  CORE_ADDR address)
>   {
> -  struct target_section *p;
> -
> -  for (p = solib->sections; p < solib->sections_end; p++)
> -    if (p->addr <= address && address < p->endaddr)
> +  for (target_section &p : solib->sections->sections)
> +    if (p.addr <= address && address < p.endaddr)
>         return true;
>   
>     return false;
> diff --git a/gdb/solist.h b/gdb/solist.h
> index 0360d342ae8..1de797cc14b 100644
> --- a/gdb/solist.h
> +++ b/gdb/solist.h
> @@ -23,6 +23,7 @@
>   /* For domain_enum domain.  */
>   #include "symtab.h"
>   #include "gdb_bfd.h"
> +#include "target-section.h"
>   
>   /* Base class for target-specific link map information.  */
>   
> @@ -71,8 +72,7 @@ struct so_list
>        the file cannot be found or after the command "nosharedlibrary".  */
>     struct objfile *objfile;
>   
> -  struct target_section *sections;
> -  struct target_section *sections_end;
> +  target_section_table *sections;
>   
>     /* Record the range of addresses belonging to this shared library.
>        There may not be just one (e.g. if two segments are relocated
> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index baed72e936e..f4acec50cca 100644
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -212,21 +212,18 @@ find_lowest_section (asection *sect, asection **lowest)
>      an existing section table.  */
>   
>   section_addr_info
> -build_section_addr_info_from_section_table (const struct target_section *start,
> -                                            const struct target_section *end)
> +build_section_addr_info_from_section_table (const target_section_table &table)
>   {
> -  const struct target_section *stp;
> -
>     section_addr_info sap;
>   
> -  for (stp = start; stp != end; stp++)
> +  for (const target_section &stp : table.sections)
>       {
> -      struct bfd_section *asect = stp->the_bfd_section;
> +      struct bfd_section *asect = stp.the_bfd_section;
>         bfd *abfd = asect->owner;
>   
>         if (bfd_section_flags (asect) & (SEC_ALLOC | SEC_LOAD)
> -	  && sap.size () < end - start)
> -	sap.emplace_back (stp->addr,
> +	  && sap.size () < table.sections.size ())
> +	sap.emplace_back (stp.addr,
>   			  bfd_section_name (asect),
>   			  gdb_bfd_section_index (abfd, asect));
>       }
> diff --git a/gdb/symfile.h b/gdb/symfile.h
> index ae29451fc6a..df646f0736f 100644
> --- a/gdb/symfile.h
> +++ b/gdb/symfile.h
> @@ -27,6 +27,7 @@
>   #include "objfile-flags.h"
>   #include "gdb_bfd.h"
>   #include "gdbsupport/function-view.h"
> +#include "target-section.h"
>   
>   /* Opaque declarations.  */
>   struct target_section;
> @@ -451,10 +452,7 @@ extern std::string find_separate_debug_file_by_debuglink (struct objfile *);
>      existing section table.  */
>   
>   extern section_addr_info
> -   build_section_addr_info_from_section_table (const struct target_section
> -					       *start,
> -					       const struct target_section
> -					       *end);
> +    build_section_addr_info_from_section_table (const target_section_table &table);
>   
>   			/*   Variables   */
>   
> diff --git a/gdb/target-section.h b/gdb/target-section.h
> index 581bc1dbe9f..8c81f3d79ba 100644
> --- a/gdb/target-section.h
> +++ b/gdb/target-section.h
> @@ -39,12 +39,11 @@ struct target_section
>       void *owner;
>     };
>   
> -/* Holds an array of target sections.  Defined by [SECTIONS..SECTIONS_END[.  */
> +/* Holds an array of target sections.  */
>   
>   struct target_section_table
>   {
> -  struct target_section *sections;
> -  struct target_section *sections_end;
> +  std::vector<struct target_section> sections;
>   };
>   
>   #endif /* GDB_TARGET_SECTION_H */
> diff --git a/gdb/target.c b/gdb/target.c
> index dd78a848cae..f828d3d6cc3 100644
> --- a/gdb/target.c
> +++ b/gdb/target.c
> @@ -823,15 +823,14 @@ struct target_section *
>   target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
>   {
>     struct target_section_table *table = target_get_section_table (target);
> -  struct target_section *secp;
>   
>     if (table == NULL)
>       return NULL;
>   
> -  for (secp = table->sections; secp < table->sections_end; secp++)
> +  for (target_section &secp : table->sections)
>       {
> -      if (addr >= secp->addr && addr < secp->endaddr)
> -	return secp;
> +      if (addr >= secp.addr && addr < secp.endaddr)
> +	return &secp;
>       }
>     return NULL;
>   }
> @@ -978,9 +977,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
>   
>   	  return section_table_xfer_memory_partial (readbuf, writebuf,
>   						    memaddr, len, xfered_len,
> -						    table->sections,
> -						    table->sections_end,
> -						    match_cb);
> +						    *table, match_cb);
>   	}
>       }
>   
> @@ -997,8 +994,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
>   	  table = target_get_section_table (ops);
>   	  return section_table_xfer_memory_partial (readbuf, writebuf,
>   						    memaddr, len, xfered_len,
> -						    table->sections,
> -						    table->sections_end);
> +						    *table);
>   	}
>       }
>   
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-13 16:41   ` Luis Machado
@ 2020-10-13 20:35     ` Tom Tromey
  2020-10-13 22:48       ` Luis Machado
  0 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-10-13 20:35 UTC (permalink / raw)
  To: Luis Machado via Gdb-patches; +Cc: Tom Tromey, Luis Machado

>>>>> "Luis" == Luis Machado via Gdb-patches <gdb-patches@sourceware.org> writes:

Luis> FTR, this has regressed AArch64-linux...

Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[0]@4
Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[pagesize-4]@4
Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[-3]@6
Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_rw[pagesize-3]@6
Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[pagesize-3]@6

Luis> I haven't investigated the failure, but I've bisected the failure to
Luis> this commit.

Sorry about that.  I tried again here on my x86-64 machine and I can't
reproduce.  It looks like there is an aarch64-linux machine in the gcc
compile farm, so I will see if I can try that.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-13 20:35     ` Tom Tromey
@ 2020-10-13 22:48       ` Luis Machado
  2020-10-14 12:58         ` Tom Tromey
  0 siblings, 1 reply; 24+ messages in thread
From: Luis Machado @ 2020-10-13 22:48 UTC (permalink / raw)
  To: Tom Tromey, Luis Machado via Gdb-patches

On 10/13/20 5:35 PM, Tom Tromey wrote:
>>>>>> "Luis" == Luis Machado via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Luis> FTR, this has regressed AArch64-linux...
> 
> Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[0]@4
> Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[pagesize-4]@4
> Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[-3]@6
> Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_rw[pagesize-3]@6
> Luis> FAIL: gdb.base/corefile2.exp: renamed binfile: print/x mbuf_ro[pagesize-3]@6
> 
> Luis> I haven't investigated the failure, but I've bisected the failure to
> Luis> this commit.
> 
> Sorry about that.  I tried again here on my x86-64 machine and I can't
> reproduce.  It looks like there is an aarch64-linux machine in the gcc
> compile farm, so I will see if I can try that.

No worries. Thanks for looking into this.

 From seeing the before/after log files, I only noticed differences in 
the values printed. Maybe something is not getting relocated/reloaded 
properly?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-03 19:37 ` [PATCH 2/6] Use a std::vector in target_section_table Tom Tromey
  2020-10-13 16:41   ` Luis Machado
@ 2020-10-14  9:09   ` Tom de Vries
  2020-11-10 17:38   ` Simon Marchi
  2 siblings, 0 replies; 24+ messages in thread
From: Tom de Vries @ 2020-10-14  9:09 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 10/3/20 9:37 PM, Tom Tromey wrote:
> This changes target_section_table to wrap a std::vector.  This
> simplifies some code, and also enables the simplifications coming in
> the subsequent patches.
> 
> Note that for solib, I chose to have it use a pointer to a
> target_section_table.  This is more convoluted than would be ideal,
> but I didn't want to convert solib to new/delete as a prerequisite for
> this series.
> 

This caused this and similar regressions:
...
ERROR: GDB process no longer exists
GDB process exited with wait status 22239 exp12 0 0 CHILDKILLED SIGABRT
SIGABRT
UNRESOLVED: gdb.base/exec-invalid-sysroot.exp: continue to exec catchpoint
...

Filed as https://sourceware.org/bugzilla/show_bug.cgi?id=26733 .

Thanks,
- Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-13 22:48       ` Luis Machado
@ 2020-10-14 12:58         ` Tom Tromey
  2020-10-14 13:01           ` Luis Machado
  0 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-10-14 12:58 UTC (permalink / raw)
  To: Luis Machado; +Cc: Tom Tromey, Luis Machado via Gdb-patches

Luis> From seeing the before/after log files, I only noticed differences in
Luis> the values printed. Maybe something is not getting relocated/reloaded 
Luis> properly?

I tried on gcc113 today and couldn't reproduce the bug.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-14 12:58         ` Tom Tromey
@ 2020-10-14 13:01           ` Luis Machado
  2020-10-14 13:18             ` Tom Tromey
  0 siblings, 1 reply; 24+ messages in thread
From: Luis Machado @ 2020-10-14 13:01 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Luis Machado via Gdb-patches

On 10/14/20 9:58 AM, Tom Tromey wrote:
> Luis> From seeing the before/after log files, I only noticed differences in
> Luis> the values printed. Maybe something is not getting relocated/reloaded
> Luis> properly?
> 
> I tried on gcc113 today and couldn't reproduce the bug.

I have a Ubuntu 18.04 system with the standard GCC 7.5.0. What OS is 
gcc113 running?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-14 13:01           ` Luis Machado
@ 2020-10-14 13:18             ` Tom Tromey
  2020-10-14 13:23               ` Luis Machado
  0 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-10-14 13:18 UTC (permalink / raw)
  To: Luis Machado; +Cc: Tom Tromey, Luis Machado via Gdb-patches

>>>>> "Luis" == Luis Machado <luis.machado@linaro.org> writes:

Luis> On 10/14/20 9:58 AM, Tom Tromey wrote:
Luis> From seeing the before/after log files, I only noticed differences in
Luis> the values printed. Maybe something is not getting relocated/reloaded
Luis> properly?
>> I tried on gcc113 today and couldn't reproduce the bug.

Luis> I have a Ubuntu 18.04 system with the standard GCC 7.5.0. What OS is
Luis> gcc113 running?

Ubuntu 14.04.6 LTS.
There doesn't seem to be a newer OS available.
But ... did Tom de Vries' patch help?

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-14 13:18             ` Tom Tromey
@ 2020-10-14 13:23               ` Luis Machado
  2020-10-14 14:06                 ` Simon Marchi
  0 siblings, 1 reply; 24+ messages in thread
From: Luis Machado @ 2020-10-14 13:23 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Luis Machado via Gdb-patches

On 10/14/20 10:18 AM, Tom Tromey wrote:
>>>>>> "Luis" == Luis Machado <luis.machado@linaro.org> writes:
> 
> Luis> On 10/14/20 9:58 AM, Tom Tromey wrote:
> Luis> From seeing the before/after log files, I only noticed differences in
> Luis> the values printed. Maybe something is not getting relocated/reloaded
> Luis> properly?
>>> I tried on gcc113 today and couldn't reproduce the bug.
> 
> Luis> I have a Ubuntu 18.04 system with the standard GCC 7.5.0. What OS is
> Luis> gcc113 running?
> 
> Ubuntu 14.04.6 LTS.
> There doesn't seem to be a newer OS available.

That's unfortunate.

It should really be updated. I'll check who is the owner of that machine.

> But ... did Tom de Vries' patch help?

I tried Tom's patch this morning and it did not help. It isn't a crash, 
but rather it appears as if something is stale or not relocated/reloaded 
properly.

I'll investigate.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-14 13:23               ` Luis Machado
@ 2020-10-14 14:06                 ` Simon Marchi
  0 siblings, 0 replies; 24+ messages in thread
From: Simon Marchi @ 2020-10-14 14:06 UTC (permalink / raw)
  To: Luis Machado, Tom Tromey; +Cc: Luis Machado via Gdb-patches

On 2020-10-14 9:23 a.m., Luis Machado via Gdb-patches wrote:
> On 10/14/20 10:18 AM, Tom Tromey wrote:
>>>>>>> "Luis" == Luis Machado <luis.machado@linaro.org> writes:
>>
>> Luis> On 10/14/20 9:58 AM, Tom Tromey wrote:
>> Luis> From seeing the before/after log files, I only noticed differences in
>> Luis> the values printed. Maybe something is not getting relocated/reloaded
>> Luis> properly?
>>>> I tried on gcc113 today and couldn't reproduce the bug.
>>
>> Luis> I have a Ubuntu 18.04 system with the standard GCC 7.5.0. What OS is
>> Luis> gcc113 running?
>>
>> Ubuntu 14.04.6 LTS.
>> There doesn't seem to be a newer OS available.
>
> That's unfortunate.
>
> It should really be updated. I'll check who is the owner of that machine.
>
>> But ... did Tom de Vries' patch help?
>
> I tried Tom's patch this morning and it did not help. It isn't a crash, but rather it appears as if something is stale or not relocated/reloaded properly.
>
> I'll investigate.

The difference between the two might simply be that on 14.04, PIE was
not enabled by default (I don't remember on which release they enabled
it by default).  You might be able to reproduce on 14.04 by passing
"pie" to the gdb_compile options, to force the test case to generate
PIEs.

Simon

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/6] Use a std::vector in target_section_table
  2020-10-03 19:37 ` [PATCH 2/6] Use a std::vector in target_section_table Tom Tromey
  2020-10-13 16:41   ` Luis Machado
  2020-10-14  9:09   ` Tom de Vries
@ 2020-11-10 17:38   ` Simon Marchi
  2 siblings, 0 replies; 24+ messages in thread
From: Simon Marchi @ 2020-11-10 17:38 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2020-10-03 3:37 p.m., Tom Tromey wrote:
> This changes target_section_table to wrap a std::vector.  This
> simplifies some code, and also enables the simplifications coming in
> the subsequent patches.
> 
> Note that for solib, I chose to have it use a pointer to a
> target_section_table.  This is more convoluted than would be ideal,
> but I didn't want to convert solib to new/delete as a prerequisite for
> this series.

FYI, this caused this regression:

https://sourceware.org/bugzilla/show_bug.cgi?id=26863

Simon

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2020-11-10 17:38 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-03 19:37 [PATCH 0/6] Change target section table management Tom Tromey
2020-10-03 19:37 ` [PATCH 1/6] Introduce target-section.h Tom Tromey
2020-10-04  8:29   ` Andrew Burgess
2020-10-09  1:17     ` Tom Tromey
2020-10-03 19:37 ` [PATCH 2/6] Use a std::vector in target_section_table Tom Tromey
2020-10-13 16:41   ` Luis Machado
2020-10-13 20:35     ` Tom Tromey
2020-10-13 22:48       ` Luis Machado
2020-10-14 12:58         ` Tom Tromey
2020-10-14 13:01           ` Luis Machado
2020-10-14 13:18             ` Tom Tromey
2020-10-14 13:23               ` Luis Machado
2020-10-14 14:06                 ` Simon Marchi
2020-10-14  9:09   ` Tom de Vries
2020-11-10 17:38   ` Simon Marchi
2020-10-03 19:37 ` [PATCH 3/6] build_section_table cannot fail Tom Tromey
2020-10-04  8:38   ` Andrew Burgess
2020-10-03 19:37 ` [PATCH 4/6] Simplify add_target_sections_of_objfile Tom Tromey
2020-10-04  8:40   ` Andrew Burgess
2020-10-03 19:37 ` [PATCH 5/6] Remove clear_section_table Tom Tromey
2020-10-04  8:44   ` Andrew Burgess
2020-10-03 19:37 ` [PATCH 6/6] Change target_section_table to std::vector alias Tom Tromey
2020-10-04  8:46   ` Andrew Burgess
2020-10-13  2:19 ` [PATCH 0/6] Change target section table management Tom Tromey

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).