aboutsummaryrefslogtreecommitdiff
path: root/gdb/symfile.c
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
commit62982abdee45cb20a7cfadb2b1bcc358655d4ad3 (patch)
treee4b4bc04a83dfc55cecc865b20ad561f8ec13939 /gdb/symfile.c
parent8ac10c5bfca0602398b38cc69976db213a7d9917 (diff)
downloadgdb-62982abdee45cb20a7cfadb2b1bcc358655d4ad3.zip
gdb-62982abdee45cb20a7cfadb2b1bcc358655d4ad3.tar.gz
gdb-62982abdee45cb20a7cfadb2b1bcc358655d4ad3.tar.bz2
gdb: allocate symfile_segment_data with new
- Allocate this structure with new instead of XNEW, use a unique pointer to manage its lifetime. - Change a few functions to return a unique pointer instead of a plain pointer. - Change free_symfile_segment_data to be symfile_segment_data's destructor. gdb/ChangeLog: * 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.
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r--gdb/symfile.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 946443f..9d5e282 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -717,12 +717,11 @@ default_symfile_offsets (struct objfile *objfile,
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
@@ -745,7 +744,7 @@ default_symfile_segments (bfd *abfd)
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);
@@ -3621,7 +3620,7 @@ symfile_relocate_debug_section (struct objfile *objfile,
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);
@@ -3632,15 +3631,6 @@ get_symfile_segment_data (bfd *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,
@@ -3703,17 +3693,14 @@ symfile_find_segment_sections (struct objfile *objfile)
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)
{
@@ -3736,8 +3723,6 @@ symfile_find_segment_sections (struct objfile *objfile)
objfile->sect_index_bss = sect->index;
}
}
-
- free_symfile_segment_data (data);
}
/* Listen for free_objfile events. */