aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2020-05-19 12:18:04 -0400
committerSimon Marchi <simon.marchi@efficios.com>2020-05-19 12:18:36 -0400
commit68b888fff3164b5e8e347d9c1ca351c366f0aac4 (patch)
tree407df662edc349c3ec33bf23379f33d3bce06cd4 /gdb
parent62982abdee45cb20a7cfadb2b1bcc358655d4ad3 (diff)
downloadgdb-68b888fff3164b5e8e347d9c1ca351c366f0aac4.zip
gdb-68b888fff3164b5e8e347d9c1ca351c366f0aac4.tar.gz
gdb-68b888fff3164b5e8e347d9c1ca351c366f0aac4.tar.bz2
gdb: use std::vector to store segments in symfile_segment_data
Instead of maintaining two vectors, I added a small `segment` class which holds both the base address and size of one segment and replaced the two `segment_bases` and `segment_sizes` arrays with a single vector. The rest of the changes are straightforward, no behavior changes are expected. gdb/ChangeLog: * 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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog11
-rw-r--r--gdb/elfread.c9
-rw-r--r--gdb/remote.c10
-rw-r--r--gdb/solib-target.c10
-rw-r--r--gdb/symfile.c14
-rw-r--r--gdb/symfile.h32
6 files changed, 45 insertions, 41 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ac9e1cc..c9f4a5e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,16 @@
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.
<~symfile_segment_data>: Add.
(symfile_segment_data_up): New.
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 4804d62..4318ebf 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -112,15 +112,10 @@ elf_symfile_segments (bfd *abfd)
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);
diff --git a/gdb/remote.c b/gdb/remote.c
index a28f34d..312a03c 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4198,10 +4198,10 @@ remote_target::get_offsets ()
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
@@ -4209,9 +4209,9 @@ remote_target::get_offsets ()
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. */
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 35e50a3..ba05647 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -386,9 +386,9 @@ Could not relocate shared library \"%s\": bad offsets"), so->so_name);
"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. */
@@ -397,14 +397,14 @@ Could not relocate shared library \"%s\": bad offsets"), so->so_name);
/* 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);
}
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 9d5e282..22793e7 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -745,9 +745,6 @@ default_symfile_segments (bfd *abfd)
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);
@@ -768,8 +765,7 @@ default_symfile_segments (bfd *abfd)
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;
}
@@ -3663,13 +3659,13 @@ symfile_map_offsets_to_segments (bfd *abfd,
/* 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. */
@@ -3681,7 +3677,7 @@ symfile_map_offsets_to_segments (bfd *abfd,
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;
@@ -3699,7 +3695,7 @@ symfile_find_segment_sections (struct objfile *objfile)
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)
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 2dfa655..1f23951 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -80,29 +80,31 @@ typedef std::vector<other_sections> section_addr_info;
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;
};