+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>
* target.h (struct target_section, struct target_section_table):
{
public:
explicit target_bfd (struct bfd *bfd);
- ~target_bfd () override;
const target_info &info () const override
{ return target_bfd_target_info; }
{
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;
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 *
{
public:
core_target ();
- ~core_target () override;
const target_info &info () const override
{ return core_target_info; }
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
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.
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
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);
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;
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;
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
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;
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)
}
}
- 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",
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))
gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
}
- if (build_section_table (exec_bfd, §ions, §ions_end))
+ if (build_section_table (exec_bfd, §ions))
{
/* Make sure to close exec_bfd, or else "run" might try to use
it. */
/* 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)
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;
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 § = 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;
}
void
add_target_sections (void *owner,
- struct target_section *sections,
- struct target_section *sections_end)
+ const target_section_table §ions)
{
- 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;
{
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;
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;
}
}
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 §)
+ {
+ 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);
}
}
}
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);
}
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 §ions)
{
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;
{
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);
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 §ions,
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)
else
return TARGET_XFER_EOF;
}
- else if (memaddr >= p->endaddr)
+ else if (memaddr >= p.endaddr)
{
/* This section ends before the transfer starts. */
continue;
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)
{
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;
}
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;
<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))
&& 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)));
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
static void
set_section_command (const char *args, int from_tty)
{
- struct target_section *p;
const char *secname;
unsigned seclen;
unsigned long secaddr;
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;
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;
}
}
}
{
/* 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 *
/* 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. */
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);
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 §ions);
/* Add the sections of OBJFILE to the current set of target sections.
* OBJFILE owns the new target sections. */
/* 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
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;
{
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);
/* 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)
{
{
/* 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);
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;
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);
}
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;
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
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;
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
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 ()));
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;
}
}
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;
}
{
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;
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);
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;
/* For domain_enum domain. */
#include "symtab.h"
#include "gdb_bfd.h"
+#include "target-section.h"
/* Base class for target-specific link map information. */
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
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));
}
#include "objfile-flags.h"
#include "gdb_bfd.h"
#include "gdbsupport/function-view.h"
+#include "target-section.h"
/* Opaque declarations. */
struct target_section;
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 */
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 */
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;
}
return section_table_xfer_memory_partial (readbuf, writebuf,
memaddr, len, xfered_len,
- table->sections,
- table->sections_end,
- match_cb);
+ *table, match_cb);
}
}
table = target_get_section_table (ops);
return section_table_xfer_memory_partial (readbuf, writebuf,
memaddr, len, xfered_len,
- table->sections,
- table->sections_end);
+ *table);
}
}