From 9005fbbb0023f212fcd797227b839f21cb8bf0a1 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 19 May 2020 12:18:05 -0400 Subject: [PATCH] gdb: make symfile_segment_data::segment_info an std::vector Change the symfile_segment_data::segment_info array to be an std::vector. No functional changes are expected. gdb/ChangeLog: * symfile.h (struct symfile_segment_data) <~symfile_segment_data>: Remove. : Change to std::vector. * symfile.c (default_symfile_segments): Update. * elfread.c (elf_symfile_segments): Update. --- gdb/ChangeLog | 8 ++++++++ gdb/elfread.c | 4 +++- gdb/symfile.c | 4 +++- gdb/symfile.h | 7 +------ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c9f4a5ebb02..f086b5cf908 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2020-05-19 Simon Marchi + + * symfile.h (struct symfile_segment_data) + <~symfile_segment_data>: Remove. + : Change to std::vector. + * symfile.c (default_symfile_segments): Update. + * elfread.c (elf_symfile_segments): Update. + 2020-05-19 Simon Marchi * symfile.h (struct symfile_segment_data) : New. diff --git a/gdb/elfread.c b/gdb/elfread.c index 4318ebf9eb9..75bdd75250b 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -118,7 +118,9 @@ elf_symfile_segments (bfd *abfd) 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); + + /* All elements are initialized to 0 (map to no segment). */ + data->segment_info.resize (num_sections); for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next) { diff --git a/gdb/symfile.c b/gdb/symfile.c index 22793e73639..e6ec458504a 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -747,7 +747,9 @@ default_symfile_segments (bfd *abfd) symfile_segment_data_up data (new symfile_segment_data); num_sections = bfd_count_sections (abfd); - data->segment_info = XCNEWVEC (int, num_sections); + + /* All elements are initialized to 0 (map to no segment). */ + data->segment_info.resize (num_sections); for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next) { diff --git a/gdb/symfile.h b/gdb/symfile.h index 1f2395169af..fe79f79a048 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -93,11 +93,6 @@ struct symfile_segment_data CORE_ADDR size; }; - ~symfile_segment_data () - { - xfree (this->segment_info); - } - /* 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. */ @@ -106,7 +101,7 @@ struct symfile_segment_data /* 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; + std::vector segment_info; }; using symfile_segment_data_up = std::unique_ptr; -- 2.30.2