Use a std::vector in target_section_table

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-12  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.
This commit is contained in:
Tom Tromey 2020-10-12 15:53:16 -06:00
parent 7b466b1024
commit bb2a67773c
15 changed files with 229 additions and 300 deletions

@ -1,3 +1,52 @@
2020-10-12 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.
2020-10-12 Tom Tromey <tom@tromey.com> 2020-10-12 Tom Tromey <tom@tromey.com>
* target.h (struct target_section, struct target_section_table): * target.h (struct target_section, struct target_section_table):

@ -35,7 +35,6 @@ class target_bfd : public target_ops
{ {
public: public:
explicit target_bfd (struct bfd *bfd); explicit target_bfd (struct bfd *bfd);
~target_bfd () override;
const target_info &info () const override const target_info &info () const override
{ return target_bfd_target_info; } { return target_bfd_target_info; }
@ -76,8 +75,7 @@ target_bfd::xfer_partial (target_object object,
{ {
return section_table_xfer_memory_partial (readbuf, writebuf, return section_table_xfer_memory_partial (readbuf, writebuf,
offset, len, xfered_len, offset, len, xfered_len,
m_table.sections, m_table);
m_table.sections_end);
} }
default: default:
return TARGET_XFER_E_IO; return TARGET_XFER_E_IO;
@ -93,14 +91,7 @@ target_bfd::get_section_table ()
target_bfd::target_bfd (struct bfd *abfd) 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.sections = NULL; build_section_table (abfd, &m_table);
m_table.sections_end = NULL;
build_section_table (abfd, &m_table.sections, &m_table.sections_end);
}
target_bfd::~target_bfd ()
{
xfree (m_table.sections);
} }
target_ops * target_ops *

@ -67,7 +67,6 @@ class core_target final : public process_stratum_target
{ {
public: public:
core_target (); core_target ();
~core_target () override;
const target_info &info () const override const target_info &info () const override
{ return core_target_info; } { return core_target_info; }
@ -126,11 +125,11 @@ private: /* per-core data */
shared library bfds. The core bfd sections are an implementation shared library bfds. The core bfd sections are an implementation
detail of the core target, just like ptrace is for unix child detail of the core target, just like ptrace is for unix child
targets. */ targets. */
target_section_table m_core_section_table {}; target_section_table m_core_section_table;
/* File-backed address space mappings: some core files include /* File-backed address space mappings: some core files include
information about memory mapped files. */ 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 /* Unavailable mappings. These correspond to pathnames which either
weren't found or could not be opened. Knowing these addresses can 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)); bfd_get_filename (core_bfd));
/* Find the data section */ /* Find the data section */
if (build_section_table (core_bfd, if (build_section_table (core_bfd, &m_core_section_table))
&m_core_section_table.sections,
&m_core_section_table.sections_end))
error (_("\"%s\": Can't find sections: %s"), error (_("\"%s\": Can't find sections: %s"),
bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ())); bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
build_file_mappings (); 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 /* Construct the target_section_table for file-backed mappings if
they exist. they exist.
@ -202,12 +193,9 @@ core_target::build_file_mappings ()
gdbarch_read_core_file_mappings (m_core_gdbarch, core_bfd, gdbarch_read_core_file_mappings (m_core_gdbarch, core_bfd,
/* After determining the number of mappings, read_core_file_mappings /* After determining the number of mappings, read_core_file_mappings
will invoke this lambda which allocates target_section storage for will invoke this lambda. */
the mappings. */ [&] (ULONGEST)
[&] (ULONGEST count)
{ {
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 /* 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); bfd_set_section_alignment (sec, 2);
/* Set target_section fields. */ /* Set target_section fields. */
struct target_section *ts = m_core_file_mappings.sections_end++; m_core_file_mappings.sections.emplace_back ();
ts->addr = start; target_section &ts = m_core_file_mappings.sections.back ();
ts->endaddr = end; ts.addr = start;
ts->owner = nullptr; ts.endaddr = end;
ts->the_bfd_section = sec; ts.owner = nullptr;
ts.the_bfd_section = sec;
}); });
normalize_mem_ranges (&m_core_unavailable_mappings); 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 xfer_status = (section_table_xfer_memory_partial
(readbuf, writebuf, (readbuf, writebuf,
offset, len, xfered_len, offset, len, xfered_len,
m_core_file_mappings.sections, m_core_file_mappings));
m_core_file_mappings.sections_end));
if (xfer_status == TARGET_XFER_OK || m_core_unavailable_mappings.empty ()) if (xfer_status == TARGET_XFER_OK || m_core_unavailable_mappings.empty ())
return xfer_status; 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 xfer_status = section_table_xfer_memory_partial
(readbuf, writebuf, (readbuf, writebuf,
offset, len, xfered_len, offset, len, xfered_len,
m_core_section_table.sections, m_core_section_table,
m_core_section_table.sections_end,
has_contents_cb); has_contents_cb);
if (xfer_status == TARGET_XFER_OK) if (xfer_status == TARGET_XFER_OK)
return 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 or the like) as this should provide a more accurate
result. If not, check the stratum beneath us, which should result. If not, check the stratum beneath us, which should
be the file stratum. */ 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, xfer_status = xfer_memory_via_mappings (readbuf, writebuf, offset,
len, xfered_len); len, xfered_len);
else else
@ -848,8 +835,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
xfer_status = section_table_xfer_memory_partial xfer_status = section_table_xfer_memory_partial
(readbuf, writebuf, (readbuf, writebuf,
offset, len, xfered_len, offset, len, xfered_len,
m_core_section_table.sections, m_core_section_table,
m_core_section_table.sections_end,
no_contents_cb); no_contents_cb);
return xfer_status; return xfer_status;
@ -1114,7 +1100,7 @@ get_current_core_target ()
void void
core_target::info_proc_mappings (struct gdbarch *gdbarch) 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")); printf_filtered (_("Mapped address spaces:\n\n"));
if (gdbarch_addr_bit (gdbarch) == 32) 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; for (const target_section &tsp : m_core_file_mappings.sections)
tsp < m_core_file_mappings.sections_end;
tsp++)
{ {
ULONGEST start = tsp->addr; ULONGEST start = tsp.addr;
ULONGEST end = tsp->endaddr; ULONGEST end = tsp.endaddr;
ULONGEST file_ofs = tsp->the_bfd_section->filepos; ULONGEST file_ofs = tsp.the_bfd_section->filepos;
const char *filename = bfd_get_filename (tsp->the_bfd_section->owner); const char *filename = bfd_get_filename (tsp.the_bfd_section->owner);
if (gdbarch_addr_bit (gdbarch) == 32) if (gdbarch_addr_bit (gdbarch) == 32)
printf_filtered ("\t%10s %10s %10s %10s %s\n", printf_filtered ("\t%10s %10s %10s %10s %s\n",

@ -413,7 +413,7 @@ exec_file_attach (const char *filename, int from_tty)
int load_via_target = 0; int load_via_target = 0;
const char *scratch_pathname, *canonical_pathname; const char *scratch_pathname, *canonical_pathname;
int scratch_chan; int scratch_chan;
struct target_section *sections = NULL, *sections_end = NULL; target_section_table sections;
char **matching; char **matching;
if (is_target_filename (filename)) 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 ()); 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 /* Make sure to close exec_bfd, or else "run" might try to use
it. */ it. */
@ -522,8 +522,7 @@ exec_file_attach (const char *filename, int from_tty)
/* Add the executable's sections to the current address spaces' /* Add the executable's sections to the current address spaces'
list of sections. This possibly pushes the exec_ops list of sections. This possibly pushes the exec_ops
target. */ target. */
add_target_sections (&exec_bfd, sections, sections_end); add_target_sections (&exec_bfd, sections);
xfree (sections);
/* Tell display code (if any) about the changed file name. */ /* Tell display code (if any) about the changed file name. */
if (deprecated_exec_file_display_hook) if (deprecated_exec_file_display_hook)
@ -592,50 +591,16 @@ file_command (const char *arg, int from_tty)
void void
clear_section_table (struct target_section_table *table) clear_section_table (struct target_section_table *table)
{ {
xfree (table->sections); table->sections.clear ();
table->sections = table->sections_end = NULL;
} }
/* Resize section table TABLE by ADJUSTMENT. /* Builds a section table, given args BFD, TABLE.
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.
Returns 0 if OK, 1 on error. */ Returns 0 if OK, 1 on error. */
int int
build_section_table (struct bfd *some_bfd, struct target_section **start, build_section_table (struct bfd *some_bfd, target_section_table *table)
struct target_section **end)
{ {
unsigned count; table->sections.clear ();
count = bfd_count_sections (some_bfd);
xfree (*start);
*start = XNEWVEC (struct target_section, count);
*end = *start;
for (asection *asect : gdb_bfd_sections (some_bfd)) for (asection *asect : gdb_bfd_sections (some_bfd))
{ {
flagword aflag; flagword aflag;
@ -650,15 +615,14 @@ build_section_table (struct bfd *some_bfd, struct target_section **start,
if (!(aflag & SEC_ALLOC)) if (!(aflag & SEC_ALLOC))
continue; continue;
(*end)->owner = NULL; table->sections.emplace_back ();
(*end)->the_bfd_section = asect; target_section &sect = table->sections.back ();
(*end)->addr = bfd_section_vma (asect); sect.owner = NULL;
(*end)->endaddr = (*end)->addr + bfd_section_size (asect); sect.the_bfd_section = asect;
(*end)++; 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. */ /* We could realloc the table, but it probably loses for most files. */
return 0; return 0;
} }
@ -668,23 +632,16 @@ build_section_table (struct bfd *some_bfd, struct target_section **start,
void void
add_target_sections (void *owner, add_target_sections (void *owner,
struct target_section *sections, const target_section_table &sections)
struct target_section *sections_end)
{ {
int count;
struct target_section_table *table = current_target_sections; struct target_section_table *table = current_target_sections;
count = sections_end - sections; if (!sections.sections.empty ())
if (count > 0)
{ {
int space = resize_section_table (table, count); for (const target_section &s : sections.sections)
int i;
for (i = 0; i < count; ++i)
{ {
table->sections[space + i] = sections[i]; table->sections.push_back (s);
table->sections[space + i].owner = owner; table->sections.back ().owner = owner;
} }
scoped_restore_current_pspace_and_thread restore_pspace_thread; 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 target_section_table *table = current_target_sections;
struct obj_section *osect; struct obj_section *osect;
int space;
unsigned count = 0; unsigned count = 0;
struct target_section *ts;
if (objfile == NULL) if (objfile == NULL)
return; return;
@ -732,23 +687,17 @@ add_target_sections_of_objfile (struct objfile *objfile)
if (count == 0) if (count == 0)
return; return;
space = resize_section_table (table, count);
ts = table->sections + space;
ALL_OBJFILE_OSECTIONS (objfile, osect) ALL_OBJFILE_OSECTIONS (objfile, osect)
{ {
if (bfd_section_size (osect->the_bfd_section) == 0) if (bfd_section_size (osect->the_bfd_section) == 0)
continue; continue;
gdb_assert (ts < table->sections + space + count); table->sections.emplace_back ();
target_section &ts = table->sections.back ();
ts->addr = obj_section_addr (osect); ts.addr = obj_section_addr (osect);
ts->endaddr = obj_section_endaddr (osect); ts.endaddr = obj_section_endaddr (osect);
ts->the_bfd_section = osect->the_bfd_section; ts.the_bfd_section = osect->the_bfd_section;
ts->owner = (void *) objfile; ts.owner = (void *) objfile;
ts++;
} }
} }
@ -758,48 +707,36 @@ add_target_sections_of_objfile (struct objfile *objfile)
void void
remove_target_sections (void *owner) remove_target_sections (void *owner)
{ {
struct target_section *src, *dest;
struct target_section_table *table = current_target_sections; struct target_section_table *table = current_target_sections;
gdb_assert (owner != NULL); gdb_assert (owner != NULL);
dest = table->sections; auto it = std::remove_if (table->sections.begin (),
for (src = table->sections; src < table->sections_end; src++) table->sections.end (),
if (src->owner != owner) [&] (target_section &sect)
{ {
/* Keep this section. */ return sect.owner == owner;
if (dest < src) });
*dest = *src; table->sections.erase (it, table->sections.end ());
dest++;
}
/* If we've dropped any sections, resize the section table. */ /* If we don't have any more sections to read memory from,
if (dest < src) remove the file_stratum target from the stack of each
inferior sharing the program space. */
if (table->sections.empty ())
{ {
int old_count; scoped_restore_current_pspace_and_thread restore_pspace_thread;
program_space *curr_pspace = current_program_space;
old_count = resize_section_table (table, dest - src); for (inferior *inf : all_inferiors ())
/* 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)
{ {
scoped_restore_current_pspace_and_thread restore_pspace_thread; if (inf->pspace != curr_pspace)
program_space *curr_pspace = current_program_space; continue;
for (inferior *inf : all_inferiors ()) if (!inf->pspace->target_sections.sections.empty ())
{ continue;
if (inf->pspace != curr_pspace)
continue;
if (inf->pspace->target_sections.sections switch_to_inferior_no_thread (inf);
!= inf->pspace->target_sections.sections_end) unpush_target (&exec_ops);
continue;
switch_to_inferior_no_thread (inf);
unpush_target (&exec_ops);
}
} }
} }
} }
@ -809,8 +746,7 @@ remove_target_sections (void *owner)
void void
exec_on_vfork () exec_on_vfork ()
{ {
if (current_program_space->target_sections.sections if (!current_program_space->target_sections.sections.empty ())
!= current_program_space->target_sections.sections_end)
push_target (&exec_ops); push_target (&exec_ops);
} }
@ -869,26 +805,25 @@ exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
static std::vector<mem_range> static std::vector<mem_range>
section_table_available_memory (CORE_ADDR memaddr, ULONGEST len, section_table_available_memory (CORE_ADDR memaddr, ULONGEST len,
struct target_section *sections, const target_section_table &sections)
struct target_section *sections_end)
{ {
std::vector<mem_range> memory; 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; continue;
/* Copy the meta-data, adjusted. */ /* 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; ULONGEST lo1, hi1, lo2, hi2;
lo1 = memaddr; lo1 = memaddr;
hi1 = memaddr + len; hi1 = memaddr + len;
lo2 = p->addr; lo2 = p.addr;
hi2 = p->endaddr; hi2 = p.endaddr;
CORE_ADDR start = std::max (lo1, lo2); CORE_ADDR start = std::max (lo1, lo2);
int length = std::min (hi1, hi2) - start; 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); target_section_table *table = target_get_section_table (&exec_ops);
std::vector<mem_range> available_memory std::vector<mem_range> available_memory
= section_table_available_memory (offset, len, = section_table_available_memory (offset, len, *table);
table->sections, table->sections_end);
normalize_mem_ranges (&available_memory); 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, section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
ULONGEST offset, ULONGEST len, ULONGEST offset, ULONGEST len,
ULONGEST *xfered_len, ULONGEST *xfered_len,
struct target_section *sections, const target_section_table &sections,
struct target_section *sections_end,
gdb::function_view<bool gdb::function_view<bool
(const struct target_section *)> match_cb) (const struct target_section *)> match_cb)
{ {
int res; int res;
struct target_section *p;
ULONGEST memaddr = offset; ULONGEST memaddr = offset;
ULONGEST memend = memaddr + len; ULONGEST memend = memaddr + len;
gdb_assert (len != 0); 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; bfd *abfd = asect->owner;
if (match_cb != nullptr && !match_cb (p)) if (match_cb != nullptr && !match_cb (&p))
continue; /* not the section we need. */ 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. */ /* Entire transfer is within this section. */
if (writebuf) if (writebuf)
res = bfd_set_section_contents (abfd, asect, res = bfd_set_section_contents (abfd, asect,
writebuf, memaddr - p->addr, writebuf, memaddr - p.addr,
len); len);
else else
res = bfd_get_section_contents (abfd, asect, res = bfd_get_section_contents (abfd, asect,
readbuf, memaddr - p->addr, readbuf, memaddr - p.addr,
len); len);
if (res != 0) if (res != 0)
@ -985,7 +917,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
else else
return TARGET_XFER_EOF; return TARGET_XFER_EOF;
} }
else if (memaddr >= p->endaddr) else if (memaddr >= p.endaddr)
{ {
/* This section ends before the transfer starts. */ /* This section ends before the transfer starts. */
continue; continue;
@ -993,14 +925,14 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
else else
{ {
/* This section overlaps the transfer. Just do half. */ /* This section overlaps the transfer. Just do half. */
len = p->endaddr - memaddr; len = p.endaddr - memaddr;
if (writebuf) if (writebuf)
res = bfd_set_section_contents (abfd, asect, res = bfd_set_section_contents (abfd, asect,
writebuf, memaddr - p->addr, writebuf, memaddr - p.addr,
len); len);
else else
res = bfd_get_section_contents (abfd, asect, res = bfd_get_section_contents (abfd, asect,
readbuf, memaddr - p->addr, readbuf, memaddr - p.addr,
len); len);
if (res != 0) if (res != 0)
{ {
@ -1033,8 +965,7 @@ exec_target::xfer_partial (enum target_object object,
if (object == TARGET_OBJECT_MEMORY) if (object == TARGET_OBJECT_MEMORY)
return section_table_xfer_memory_partial (readbuf, writebuf, return section_table_xfer_memory_partial (readbuf, writebuf,
offset, len, xfered_len, offset, len, xfered_len,
table->sections, *table);
table->sections_end);
else else
return TARGET_XFER_E_IO; return TARGET_XFER_E_IO;
} }
@ -1044,7 +975,6 @@ void
print_section_info (struct target_section_table *t, bfd *abfd) print_section_info (struct target_section_table *t, bfd *abfd)
{ {
struct gdbarch *gdbarch = gdbarch_from_bfd (abfd); struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
struct target_section *p;
/* FIXME: 16 is not wide enough when gdbarch_addr_bit > 64. */ /* FIXME: 16 is not wide enough when gdbarch_addr_bit > 64. */
int wid = gdbarch_addr_bit (gdbarch) <= 32 ? 8 : 16; 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>. */ <p == t->sections_end>. */
bfd_vma displacement = 0; bfd_vma displacement = 0;
bfd_vma entry_point; 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)) if ((bfd_section_flags (psect) & (SEC_ALLOC | SEC_LOAD))
!= (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) && abfd->start_address < (bfd_section_vma (psect)
+ bfd_section_size (psect))) + bfd_section_size (psect)))
{ {
displacement = p->addr - bfd_section_vma (psect); displacement = p.addr - bfd_section_vma (psect);
found = true;
break; break;
} }
} }
if (p == t->sections_end) if (!found)
warning (_("Cannot find section for the entry point of %ps."), warning (_("Cannot find section for the entry point of %ps."),
styled_string (file_name_style.style (), styled_string (file_name_style.style (),
bfd_get_filename (abfd))); bfd_get_filename (abfd)));
@ -1087,13 +1019,13 @@ print_section_info (struct target_section_table *t, bfd *abfd)
printf_filtered (_("\tEntry point: %s\n"), printf_filtered (_("\tEntry point: %s\n"),
paddress (gdbarch, entry_point)); 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; bfd *pbfd = psect->owner;
printf_filtered ("\t%s", hex_string_custom (p->addr, wid)); printf_filtered ("\t%s", hex_string_custom (p.addr, wid));
printf_filtered (" - %s", hex_string_custom (p->endaddr, wid)); printf_filtered (" - %s", hex_string_custom (p.endaddr, wid));
/* FIXME: A format of "08l" is not wide enough for file offsets /* FIXME: A format of "08l" is not wide enough for file offsets
larger than 4GB. OTOH, making it "016l" isn't desirable either larger than 4GB. OTOH, making it "016l" isn't desirable either
@ -1125,7 +1057,6 @@ exec_target::files_info ()
static void static void
set_section_command (const char *args, int from_tty) set_section_command (const char *args, int from_tty)
{ {
struct target_section *p;
const char *secname; const char *secname;
unsigned seclen; unsigned seclen;
unsigned long secaddr; unsigned long secaddr;
@ -1144,14 +1075,14 @@ set_section_command (const char *args, int from_tty)
secaddr = parse_and_eval_address (args); secaddr = parse_and_eval_address (args);
table = current_target_sections; 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) if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen)
&& bfd_section_name (p->the_bfd_section)[seclen] == '\0') && bfd_section_name (p.the_bfd_section)[seclen] == '\0')
{ {
offset = secaddr - p->addr; offset = secaddr - p.addr;
p->addr += offset; p.addr += offset;
p->endaddr += offset; p.endaddr += offset;
if (from_tty) if (from_tty)
exec_ops.files_info (); exec_ops.files_info ();
return; return;
@ -1170,18 +1101,17 @@ set_section_command (const char *args, int from_tty)
void void
exec_set_section_address (const char *filename, int index, CORE_ADDR address) exec_set_section_address (const char *filename, int index, CORE_ADDR address)
{ {
struct target_section *p;
struct target_section_table *table; struct target_section_table *table;
table = current_target_sections; table = current_target_sections;
for (p = table->sections; p < table->sections_end; p++) for (target_section &p : table->sections)
{ {
if (filename_cmp (filename, if (filename_cmp (filename,
bfd_get_filename (p->the_bfd_section->owner)) == 0 bfd_get_filename (p.the_bfd_section->owner)) == 0
&& index == p->the_bfd_section->index) && index == p.the_bfd_section->index)
{ {
p->endaddr += address - p->addr; p.endaddr += address - p.addr;
p->addr = address; p.addr = address;
} }
} }
} }
@ -1191,8 +1121,7 @@ exec_target::has_memory ()
{ {
/* We can provide memory if we have any file/target sections to read /* We can provide memory if we have any file/target sections to read
from. */ from. */
return (current_target_sections->sections return !current_target_sections->sections.empty ();
!= current_target_sections->sections_end);
} }
char * char *

@ -37,8 +37,7 @@ struct objfile;
/* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR. /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
Returns 0 if OK, 1 on error. */ Returns 0 if OK, 1 on error. */
extern int build_section_table (struct bfd *, struct target_section **, extern int build_section_table (struct bfd *, struct target_section_table *);
struct target_section **);
/* Remove all entries from TABLE. */ /* Remove all entries from TABLE. */
@ -86,8 +85,7 @@ extern enum target_xfer_status
section_table_xfer_memory_partial (gdb_byte *, section_table_xfer_memory_partial (gdb_byte *,
const gdb_byte *, const gdb_byte *,
ULONGEST, ULONGEST, ULONGEST *, ULONGEST, ULONGEST, ULONGEST *,
struct target_section *, const target_section_table &,
struct target_section *,
gdb::function_view<bool gdb::function_view<bool
(const struct target_section *)> match_cb (const struct target_section *)> match_cb
= nullptr); = nullptr);
@ -111,8 +109,7 @@ extern void remove_target_sections (void *owner);
current set of target sections. */ current set of target sections. */
extern void add_target_sections (void *owner, extern void add_target_sections (void *owner,
struct target_section *sections, const target_section_table &sections);
struct target_section *sections_end);
/* Add the sections of OBJFILE to the current set of target sections. /* Add the sections of OBJFILE to the current set of target sections.
* OBJFILE owns the new target sections. */ * OBJFILE owns the new target sections. */

@ -171,8 +171,7 @@ struct record_full_core_buf_entry
/* Record buf with core target. */ /* Record buf with core target. */
static detached_regcache *record_full_core_regbuf = NULL; static detached_regcache *record_full_core_regbuf = NULL;
static struct target_section *record_full_core_start; static target_section_table record_full_core_sections;
static struct target_section *record_full_core_end;
static struct record_full_core_buf_entry *record_full_core_buf_list = NULL; static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
/* The following variables are used for managing the linked list that /* 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 ++) for (i = 0; i < regnum; i ++)
record_full_core_regbuf->raw_supply (i, *regcache); 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_sections))
if (build_section_table (core_bfd, &record_full_core_start,
&record_full_core_end))
{ {
delete record_full_core_regbuf; delete record_full_core_regbuf;
record_full_core_regbuf = NULL; 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) if (record_full_gdb_operation_disable || !writebuf)
{ {
struct target_section *p; for (target_section &p : record_full_core_sections.sections)
for (p = record_full_core_start; p < record_full_core_end; p++)
{ {
if (offset >= p->addr) if (offset >= p.addr)
{ {
struct record_full_core_buf_entry *entry; struct record_full_core_buf_entry *entry;
ULONGEST sec_offset; ULONGEST sec_offset;
if (offset >= p->endaddr) if (offset >= p.endaddr)
continue; continue;
if (offset + len > p->endaddr) if (offset + len > p.endaddr)
len = p->endaddr - offset; len = p.endaddr - offset;
sec_offset = offset - p->addr; sec_offset = offset - p.addr;
/* Read readbuf or write writebuf p, offset, len. */ /* Read readbuf or write writebuf p, offset, len. */
/* Check flags. */ /* Check flags. */
if (p->the_bfd_section->flags & SEC_CONSTRUCTOR if (p.the_bfd_section->flags & SEC_CONSTRUCTOR
|| (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0) || (p.the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
{ {
if (readbuf) if (readbuf)
memset (readbuf, 0, len); memset (readbuf, 0, len);
@ -2178,7 +2173,7 @@ record_full_core_target::xfer_partial (enum target_object object,
/* Get record_full_core_buf_entry. */ /* Get record_full_core_buf_entry. */
for (entry = record_full_core_buf_list; entry; for (entry = record_full_core_buf_list; entry;
entry = entry->prev) entry = entry->prev)
if (entry->p == p) if (entry->p == &p)
break; break;
if (writebuf) if (writebuf)
{ {
@ -2186,10 +2181,10 @@ record_full_core_target::xfer_partial (enum target_object object,
{ {
/* Add a new entry. */ /* Add a new entry. */
entry = XNEW (struct record_full_core_buf_entry); entry = XNEW (struct record_full_core_buf_entry);
entry->p = p; entry->p = &p;
if (!bfd_malloc_and_get_section if (!bfd_malloc_and_get_section
(p->the_bfd_section->owner, (p.the_bfd_section->owner,
p->the_bfd_section, p.the_bfd_section,
&entry->buf)) &entry->buf))
{ {
xfree (entry); xfree (entry);

@ -8896,22 +8896,21 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
if (secp != NULL if (secp != NULL
&& (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY)) && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
{ {
struct target_section *p;
ULONGEST memend = memaddr + len; ULONGEST memend = memaddr + len;
table = target_get_section_table (this); 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. */ /* Entire transfer is within this section. */
return remote_read_bytes_1 (memaddr, readbuf, len, unit_size, return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
xfered_len); xfered_len);
} }
else if (memaddr >= p->endaddr) else if (memaddr >= p.endaddr)
{ {
/* This section ends before the transfer starts. */ /* This section ends before the transfer starts. */
continue; continue;
@ -8919,7 +8918,7 @@ remote_target::remote_xfer_live_readonly_partial (gdb_byte *readbuf,
else else
{ {
/* This section overlaps the transfer. Just do half. */ /* 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, return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
xfered_len); xfered_len);
} }

@ -407,7 +407,6 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
Elf32_External_Dyn *x_dynp_32; Elf32_External_Dyn *x_dynp_32;
Elf64_External_Dyn *x_dynp_64; Elf64_External_Dyn *x_dynp_64;
struct bfd_section *sect; struct bfd_section *sect;
struct target_section *target_section;
if (abfd == NULL) if (abfd == NULL)
return 0; return 0;
@ -424,14 +423,15 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
if (sect == NULL) if (sect == NULL)
return 0; return 0;
for (target_section = current_target_sections->sections; bool found = false;
target_section < current_target_sections->sections_end; for (target_section &target_section : current_target_sections->sections)
target_section++) if (sect == target_section.the_bfd_section)
if (sect == target_section->the_bfd_section) {
break; dyn_addr = target_section.addr;
if (target_section < current_target_sections->sections_end) found = true;
dyn_addr = target_section->addr; break;
else }
if (!found)
{ {
/* ABFD may come from OBJFILE acting only as a symbol file without being /* 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 loaded into the target (see add_symbol_file_command). This case is

@ -591,7 +591,6 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
Elf32_External_Dyn *x_dynp_32; Elf32_External_Dyn *x_dynp_32;
Elf64_External_Dyn *x_dynp_64; Elf64_External_Dyn *x_dynp_64;
struct bfd_section *sect; struct bfd_section *sect;
struct target_section *target_section;
if (abfd == NULL) if (abfd == NULL)
return 0; return 0;
@ -608,14 +607,15 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
if (sect == NULL) if (sect == NULL)
return 0; return 0;
for (target_section = current_target_sections->sections; bool found = false;
target_section < current_target_sections->sections_end; for (target_section &target_section : current_target_sections->sections)
target_section++) if (sect == target_section.the_bfd_section)
if (sect == target_section->the_bfd_section) {
break; dyn_addr = target_section.addr;
if (target_section < current_target_sections->sections_end) found = true;
dyn_addr = target_section->addr; break;
else }
if (!found)
{ {
/* ABFD may come from OBJFILE acting only as a symbol file without being /* 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 loaded into the target (see add_symbol_file_command). This case is

@ -532,7 +532,6 @@ static int
solib_map_sections (struct so_list *so) solib_map_sections (struct so_list *so)
{ {
const struct target_so_ops *ops = solib_ops (target_gdbarch ()); 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::unique_xmalloc_ptr<char> filename (tilde_expand (so->so_name));
gdb_bfd_ref_ptr abfd (ops->bfd_open (filename.get ())); 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.")); error (_("Shared library file name is too long."));
strcpy (so->so_name, bfd_get_filename (so->abfd)); 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"), error (_("Can't find the file sections in `%s': %s"),
bfd_get_filename (so->abfd), bfd_errmsg (bfd_get_error ())); 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 /* Relocate the section binding addresses as recorded in the shared
object's file by the base address to which the object was actually object's file by the base address to which the object was actually
mapped. */ mapped. */
ops->relocate_section_addresses (so, p); ops->relocate_section_addresses (so, &p);
/* If the target didn't provide information about the address /* If the target didn't provide information about the address
range of the shared object, assume we want the location of range of the shared object, assume we want the location of
the .text section. */ the .text section. */
if (so->addr_low == 0 && so->addr_high == 0 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_low = p.addr;
so->addr_high = p->endaddr; 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 section tables. Do this immediately after mapping the object so
that later nodes in the list can query this object, as is needed that later nodes in the list can query this object, as is needed
in solib-osf.c. */ in solib-osf.c. */
add_target_sections (so, so->sections, so->sections_end); add_target_sections (so, *so->sections);
return 1; return 1;
} }
@ -600,11 +601,8 @@ clear_so (struct so_list *so)
{ {
const struct target_so_ops *ops = solib_ops (target_gdbarch ()); const struct target_so_ops *ops = solib_ops (target_gdbarch ());
if (so->sections) delete so->sections;
{ so->sections = NULL;
xfree (so->sections);
so->sections = so->sections_end = NULL;
}
gdb_bfd_unref (so->abfd); gdb_bfd_unref (so->abfd);
so->abfd = NULL; so->abfd = NULL;
@ -683,8 +681,7 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags)
if (so->objfile == NULL) if (so->objfile == NULL)
{ {
section_addr_info sap section_addr_info sap
= build_section_addr_info_from_section_table (so->sections, = build_section_addr_info_from_section_table (*so->sections);
so->sections_end);
so->objfile = symbol_file_add_from_bfd (so->abfd, so->so_name, so->objfile = symbol_file_add_from_bfd (so->abfd, so->so_name,
flags, &sap, flags, &sap,
OBJF_SHARED, NULL); OBJF_SHARED, NULL);
@ -1120,10 +1117,8 @@ bool
solib_contains_address_p (const struct so_list *const solib, solib_contains_address_p (const struct so_list *const solib,
CORE_ADDR address) CORE_ADDR address)
{ {
struct target_section *p; for (target_section &p : solib->sections->sections)
if (p.addr <= address && address < p.endaddr)
for (p = solib->sections; p < solib->sections_end; p++)
if (p->addr <= address && address < p->endaddr)
return true; return true;
return false; return false;

@ -23,6 +23,7 @@
/* For domain_enum domain. */ /* For domain_enum domain. */
#include "symtab.h" #include "symtab.h"
#include "gdb_bfd.h" #include "gdb_bfd.h"
#include "target-section.h"
/* Base class for target-specific link map information. */ /* 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". */ the file cannot be found or after the command "nosharedlibrary". */
struct objfile *objfile; struct objfile *objfile;
struct target_section *sections; target_section_table *sections;
struct target_section *sections_end;
/* Record the range of addresses belonging to this shared library. /* Record the range of addresses belonging to this shared library.
There may not be just one (e.g. if two segments are relocated There may not be just one (e.g. if two segments are relocated

@ -212,21 +212,18 @@ find_lowest_section (asection *sect, asection **lowest)
an existing section table. */ an existing section table. */
section_addr_info section_addr_info
build_section_addr_info_from_section_table (const struct target_section *start, build_section_addr_info_from_section_table (const target_section_table &table)
const struct target_section *end)
{ {
const struct target_section *stp;
section_addr_info sap; 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; bfd *abfd = asect->owner;
if (bfd_section_flags (asect) & (SEC_ALLOC | SEC_LOAD) if (bfd_section_flags (asect) & (SEC_ALLOC | SEC_LOAD)
&& sap.size () < end - start) && sap.size () < table.sections.size ())
sap.emplace_back (stp->addr, sap.emplace_back (stp.addr,
bfd_section_name (asect), bfd_section_name (asect),
gdb_bfd_section_index (abfd, asect)); gdb_bfd_section_index (abfd, asect));
} }

@ -27,6 +27,7 @@
#include "objfile-flags.h" #include "objfile-flags.h"
#include "gdb_bfd.h" #include "gdb_bfd.h"
#include "gdbsupport/function-view.h" #include "gdbsupport/function-view.h"
#include "target-section.h"
/* Opaque declarations. */ /* Opaque declarations. */
struct target_section; struct target_section;
@ -451,10 +452,7 @@ extern std::string find_separate_debug_file_by_debuglink (struct objfile *);
existing section table. */ existing section table. */
extern section_addr_info extern section_addr_info
build_section_addr_info_from_section_table (const struct target_section build_section_addr_info_from_section_table (const target_section_table &table);
*start,
const struct target_section
*end);
/* Variables */ /* Variables */

@ -42,12 +42,11 @@ struct target_section
void *owner; 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_table
{ {
struct target_section *sections; std::vector<struct target_section> sections;
struct target_section *sections_end;
}; };
#endif /* GDB_TARGET_SECTION_H */ #endif /* GDB_TARGET_SECTION_H */

@ -824,15 +824,14 @@ struct target_section *
target_section_by_addr (struct target_ops *target, CORE_ADDR addr) target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
{ {
struct target_section_table *table = target_get_section_table (target); struct target_section_table *table = target_get_section_table (target);
struct target_section *secp;
if (table == NULL) if (table == NULL)
return 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) if (addr >= secp.addr && addr < secp.endaddr)
return secp; return &secp;
} }
return NULL; return NULL;
} }
@ -979,9 +978,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
return section_table_xfer_memory_partial (readbuf, writebuf, return section_table_xfer_memory_partial (readbuf, writebuf,
memaddr, len, xfered_len, memaddr, len, xfered_len,
table->sections, *table, match_cb);
table->sections_end,
match_cb);
} }
} }
@ -998,8 +995,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
table = target_get_section_table (ops); table = target_get_section_table (ops);
return section_table_xfer_memory_partial (readbuf, writebuf, return section_table_xfer_memory_partial (readbuf, writebuf,
memaddr, len, xfered_len, memaddr, len, xfered_len,
table->sections, *table);
table->sections_end);
} }
} }