+2020-05-19 Simon Marchi <simon.marchi@efficios.com>
+
+ * symfile.h (struct symfile_segment_data) <struct segment>: New.
+ <segments>: New.
+ <segment_bases, segment_sizes>: Remove.
+ * symfile.c (default_symfile_segments): Update.
+ * elfread.c (elf_symfile_segments): Update.
+ * remote.c (remote_target::get_offsets): Update.
+ * solib-target.c (solib_target_relocate_section_addresses):
+ Update.
+
2020-05-19 Simon Marchi <simon.marchi@efficios.com>
* symfile.h (struct symfile_segment_data): Initialize fields.
return NULL;
symfile_segment_data_up data (new symfile_segment_data);
- data->num_segments = num_segments;
- data->segment_bases = XCNEWVEC (CORE_ADDR, num_segments);
- data->segment_sizes = XCNEWVEC (CORE_ADDR, num_segments);
+ data->segments.reserve (num_segments);
for (i = 0; i < num_segments; i++)
- {
- data->segment_bases[i] = segments[i]->p_vaddr;
- data->segment_sizes[i] = segments[i]->p_memsz;
- }
+ data->segments.emplace_back (segments[i]->p_vaddr, segments[i]->p_memsz);
num_sections = bfd_count_sections (abfd);
data->segment_info = XCNEWVEC (int, num_sections);
by assuming that the .text and .data offsets apply to the whole
text and data segments. Convert the offsets given in the packet
to base addresses for symfile_map_offsets_to_segments. */
- else if (data && data->num_segments == 2)
+ else if (data != nullptr && data->segments.size () == 2)
{
- segments[0] = data->segment_bases[0] + text_addr;
- segments[1] = data->segment_bases[1] + data_addr;
+ segments[0] = data->segments[0].base + text_addr;
+ segments[1] = data->segments[1].base + data_addr;
num_segments = 2;
}
/* If the object file has only one segment, assume that it is text
but programs with no code are useless. Of course the code might
have ended up in the data segment... to detect that we would need
the permissions here. */
- else if (data && data->num_segments == 1)
+ else if (data && data->segments.size () == 1)
{
- segments[0] = data->segment_bases[0] + text_addr;
+ segments[0] = data->segments[0].base + text_addr;
num_segments = 1;
}
/* There's no way to relocate by segment. */
"info sharedlibrary". Report any consecutive segments
which were relocated as a single unit. */
gdb_assert (li->segment_bases.size () > 0);
- orig_delta = li->segment_bases[0] - data->segment_bases[0];
+ orig_delta = li->segment_bases[0] - data->segments[0].base;
- for (i = 1; i < data->num_segments; i++)
+ for (i = 1; i < data->segments.size (); i++)
{
/* If we have run out of offsets, assume all
remaining segments have the same offset. */
/* If this segment does not have the same offset, do
not include it in the library's range. */
- if (li->segment_bases[i] - data->segment_bases[i]
+ if (li->segment_bases[i] - data->segments[i].base
!= orig_delta)
break;
}
so->addr_low = li->segment_bases[0];
- so->addr_high = (data->segment_bases[i - 1]
- + data->segment_sizes[i - 1]
+ so->addr_high = (data->segments[i - 1].base
+ + data->segments[i - 1].size
+ orig_delta);
gdb_assert (so->addr_low <= so->addr_high);
}
high = low + bfd_section_size (sect);
symfile_segment_data_up data (new symfile_segment_data);
- data->num_segments = 1;
- data->segment_bases = XCNEW (CORE_ADDR);
- data->segment_sizes = XCNEW (CORE_ADDR);
num_sections = bfd_count_sections (abfd);
data->segment_info = XCNEWVEC (int, num_sections);
data->segment_info[i] = 1;
}
- data->segment_bases[0] = low;
- data->segment_sizes[0] = high - low;
+ data->segments.emplace_back (low, high - low);
return data;
}
/* If we do not have segment mappings for the object file, we
can not relocate it by segments. */
gdb_assert (data != NULL);
- gdb_assert (data->num_segments > 0);
+ gdb_assert (data->segments.size () > 0);
for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
{
int which = data->segment_info[i];
- gdb_assert (0 <= which && which <= data->num_segments);
+ gdb_assert (0 <= which && which <= data->segments.size ());
/* Don't bother computing offsets for sections that aren't
loaded as part of any segment. */
if (which > num_segment_bases)
which = num_segment_bases;
- offsets[i] = segment_bases[which - 1] - data->segment_bases[which - 1];
+ offsets[i] = segment_bases[which - 1] - data->segments[which - 1].base;
}
return 1;
if (data == NULL)
return;
- if (data->num_segments != 1 && data->num_segments != 2)
+ if (data->segments.size () != 1 && data->segments.size () != 2)
return;
for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
each BFD section belongs to. */
struct symfile_segment_data
{
+ struct segment
+ {
+ segment (CORE_ADDR base, CORE_ADDR size)
+ : base (base), size (size)
+ {}
+
+ /* The original base address the segment. */
+ CORE_ADDR base;
+
+ /* The memory size of the segment. */
+ CORE_ADDR size;
+ };
+
~symfile_segment_data ()
{
- xfree (this->segment_bases);
- xfree (this->segment_sizes);
xfree (this->segment_info);
}
- /* How many segments are present in this file. If there are
+ /* The segments present in this file. If there are
two, the text segment is the first one and the data segment
is the second one. */
- int num_segments = 0;
-
- /* If NUM_SEGMENTS is greater than zero, the original base address
- of each segment. */
- CORE_ADDR *segment_bases = nullptr;
-
- /* If NUM_SEGMENTS is greater than zero, the memory size of each
- segment. */
- CORE_ADDR *segment_sizes = nullptr;
+ std::vector<segment> segments;
- /* If NUM_SEGMENTS is greater than zero, this is an array of entries
- recording which segment contains each BFD section.
- SEGMENT_INFO[I] is S+1 if the I'th BFD section belongs to segment
+ /* This is an array of entries recording which segment contains each BFD
+ section. SEGMENT_INFO[I] is S+1 if the I'th BFD section belongs to segment
S, or zero if it is not in any segment. */
int *segment_info = nullptr;
};