+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.
+ (struct sym_fns) <sym_segments>: Return a
+ symfile_segment_data_up.
+ (default_symfile_segments): Return a symfile_segment_data_up.
+ (free_symfile_segment_data): Remove.
+ (get_symfile_segment_data): Return a symfile_segment_data_up.
+ * symfile.c (default_symfile_segments): Likewise.
+ (get_symfile_segment_data): Likewise.
+ (free_symfile_segment_data): Remove.
+ (symfile_find_segment_sections): Update.
+ * elfread.c (elf_symfile_segments): Return a
+ symfile_segment_data_up.
+ * remote.c (remote_target::get_offsets): Update.
+ * solib-target.c (solib_target_relocate_section_addresses):
+ Update.
+ * symfile-debug.c (debug_sym_segments): Return a
+ symfile_segment_data_up.
+
2020-05-18 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
PR build/25981
/* Locate the segments in ABFD. */
-static struct symfile_segment_data *
+static symfile_segment_data_up
elf_symfile_segments (bfd *abfd)
{
Elf_Internal_Phdr *phdrs, **segments;
long phdrs_size;
int num_phdrs, num_segments, num_sections, i;
asection *sect;
- struct symfile_segment_data *data;
phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
if (phdrs_size == -1)
if (num_segments == 0)
return NULL;
- data = XCNEW (struct symfile_segment_data);
+ 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);
char *ptr;
int lose, num_segments = 0, do_sections, do_segments;
CORE_ADDR text_addr, data_addr, bss_addr, segments[2];
- struct symfile_segment_data *data;
if (symfile_objfile == NULL)
return;
section_offsets offs = symfile_objfile->section_offsets;
- data = get_symfile_segment_data (symfile_objfile->obfd);
+ symfile_segment_data_up data
+ = get_symfile_segment_data (symfile_objfile->obfd);
do_segments = (data != NULL);
do_sections = num_segments == 0;
if (do_segments)
{
- int ret = symfile_map_offsets_to_segments (symfile_objfile->obfd, data,
- offs, num_segments, segments);
+ int ret = symfile_map_offsets_to_segments (symfile_objfile->obfd,
+ data.get (), offs,
+ num_segments, segments);
if (ret == 0 && !do_sections)
error (_("Can not handle qOffsets TextSeg "
do_sections = 0;
}
- if (data)
- free_symfile_segment_data (data);
-
if (do_sections)
{
offs[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
}
else if (!li->segment_bases.empty ())
{
- struct symfile_segment_data *data;
+ symfile_segment_data_up data
+ = get_symfile_segment_data (so->abfd);
- data = get_symfile_segment_data (so->abfd);
if (data == NULL)
warning (_("\
Could not relocate shared library \"%s\": no segments"), so->so_name);
ULONGEST orig_delta;
int i;
- if (!symfile_map_offsets_to_segments (so->abfd, data,
+ if (!symfile_map_offsets_to_segments (so->abfd, data.get (),
li->offsets,
li->segment_bases.size (),
li->segment_bases.data ()))
+ data->segment_sizes[i - 1]
+ orig_delta);
gdb_assert (so->addr_low <= so->addr_high);
-
- free_symfile_segment_data (data);
}
}
}
debug_data->real_sf->sym_offsets (objfile, info);
}
-static struct symfile_segment_data *
+static symfile_segment_data_up
debug_sym_segments (bfd *abfd)
{
/* This API function is annoying, it doesn't take a "this" pointer.
It assumes that object files do not have segments, and fully linked
files have a single segment. */
-struct symfile_segment_data *
+symfile_segment_data_up
default_symfile_segments (bfd *abfd)
{
int num_sections, i;
asection *sect;
- struct symfile_segment_data *data;
CORE_ADDR low, high;
/* Relocatable files contain enough information to position each
low = bfd_section_vma (sect);
high = low + bfd_section_size (sect);
- data = XCNEW (struct symfile_segment_data);
+ 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);
return (*objfile->sf->sym_relocate) (objfile, sectp, buf);
}
-struct symfile_segment_data *
+symfile_segment_data_up
get_symfile_segment_data (bfd *abfd)
{
const struct sym_fns *sf = find_sym_fns (abfd);
return sf->sym_segments (abfd);
}
-void
-free_symfile_segment_data (struct symfile_segment_data *data)
-{
- xfree (data->segment_bases);
- xfree (data->segment_sizes);
- xfree (data->segment_info);
- xfree (data);
-}
-
/* Given:
- DATA, containing segment addresses from the object file ABFD, and
the mapping from ABFD's sections onto the segments that own them,
bfd *abfd = objfile->obfd;
int i;
asection *sect;
- struct symfile_segment_data *data;
- data = get_symfile_segment_data (objfile->obfd);
+ symfile_segment_data_up data
+ = get_symfile_segment_data (objfile->obfd);
if (data == NULL)
return;
if (data->num_segments != 1 && data->num_segments != 2)
- {
- free_symfile_segment_data (data);
- return;
- }
+ return;
for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
{
objfile->sect_index_bss = sect->index;
}
}
-
- free_symfile_segment_data (data);
}
/* Listen for free_objfile events. */
each BFD section belongs to. */
struct symfile_segment_data
{
+ ~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
two, the text segment is the first one and the data segment
is the second one. */
- int num_segments;
+ int num_segments = 0;
/* If NUM_SEGMENTS is greater than zero, the original base address
of each segment. */
- CORE_ADDR *segment_bases;
+ CORE_ADDR *segment_bases = nullptr;
/* If NUM_SEGMENTS is greater than zero, the memory size of each
segment. */
- CORE_ADDR *segment_sizes;
+ CORE_ADDR *segment_sizes = nullptr;
/* 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
S, or zero if it is not in any segment. */
- int *segment_info;
+ int *segment_info = nullptr;
};
+using symfile_segment_data_up = std::unique_ptr<symfile_segment_data>;
+
/* Callback for quick_symbol_functions->map_symbol_filenames. */
typedef void (symbol_filename_ftype) (const char *filename,
the segments of ABFD. Each segment is a unit of the file
which may be relocated independently. */
- struct symfile_segment_data *(*sym_segments) (bfd *abfd);
+ symfile_segment_data_up (*sym_segments) (bfd *abfd);
/* This function should read the linetable from the objfile when
the line table cannot be read while processing the debugging
/* The default version of sym_fns.sym_segments for readers that don't
do anything special. */
-extern struct symfile_segment_data *default_symfile_segments (bfd *abfd);
+extern symfile_segment_data_up default_symfile_segments (bfd *abfd);
/* The default version of sym_fns.sym_relocate for readers that don't
do anything special. */
const struct symfile_segment_data *,
section_offsets &,
int, const CORE_ADDR *);
-struct symfile_segment_data *get_symfile_segment_data (bfd *abfd);
-void free_symfile_segment_data (struct symfile_segment_data *data);
+symfile_segment_data_up get_symfile_segment_data (bfd *abfd);
extern scoped_restore_tmpl<int> increment_reading_symtab (void);