From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120221 invoked by alias); 19 Apr 2017 04:30:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 119831 invoked by uid 89); 19 Apr 2017 04:30:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=3259, relocate X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Apr 2017 04:30:03 +0000 X-ASG-Debug-ID: 1492576203-0c856e65d41d23a70001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id fvHl2Xfjm3HwahGK (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 19 Apr 2017 00:30:03 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (173-246-11-162.qc.cable.ebox.net [173.246.11.162]) by smtp.electronicbox.net (Postfix) with ESMTP id 25756440E7C; Wed, 19 Apr 2017 00:30:03 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 173-246-11-162.qc.cable.ebox.net[173.246.11.162] X-Barracuda-Apparent-Source-IP: 173.246.11.162 X-Barracuda-RBL-IP: 173.246.11.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2] Use std::vector in solib-target lm_info Date: Wed, 19 Apr 2017 04:30:00 -0000 X-ASG-Orig-Subj: [PATCH v2] Use std::vector in solib-target lm_info Message-Id: <20170419042956.27694-1-simon.marchi@polymtl.ca> In-Reply-To: <614e9e92-fa8b-35f3-c15c-9dde043962e8@redhat.com> References: <614e9e92-fa8b-35f3-c15c-9dde043962e8@redhat.com> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1492576203 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 6822 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.38181 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00548.txt.bz2 New in v2: - lm_info pointer fields initialized in-class. - Added lm_info destructor. Replace the two VEC fields with std::vector. I found only one place where these lm_infos were allocated, but two where they are freed. It looks like solib_target_free_so missed freeing section_bases before. More c++ification is obviously possible, but my goal right now is to get rid of VEC (CORE_ADDR). gdb/ChangeLog: * solib-target.c (struct lm_info): Add default constructor, delete copy constructor and operator=. : Change type to std::vector. (library_list_start_segment, library_list_start_section, library_list_start_library, library_list_end_library, solib_target_free_library_list, solib_target_free_so, solib_target_relocate_section_addresses): Adjust. --- gdb/solib-target.c | 65 +++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/gdb/solib-target.c b/gdb/solib-target.c index 1b10e4ea41..58b494bde7 100644 --- a/gdb/solib-target.c +++ b/gdb/solib-target.c @@ -25,28 +25,39 @@ #include "target.h" #include "vec.h" #include "solib-target.h" +#include /* Private data for each loaded library. */ struct lm_info { + lm_info () = default; + lm_info (const lm_info &) = delete; + lm_info &operator= (const lm_info &) = delete; + + ~lm_info () + { + xfree (name); + xfree (offsets); + } + /* The library's name. The name is normally kept in the struct so_list; it is only here during XML parsing. */ - char *name; + char *name {}; /* The target can either specify segment bases or section bases, not both. */ /* The base addresses for each independently relocatable segment of this shared library. */ - VEC(CORE_ADDR) *segment_bases; + std::vector segment_bases; /* The base addresses for each independently allocatable, relocatable section of this shared library. */ - VEC(CORE_ADDR) *section_bases; + std::vector section_bases; /* The cached offsets for each section of this shared library, determined from SEGMENT_BASES, or SECTION_BASES. */ - struct section_offsets *offsets; + struct section_offsets *offsets {}; }; typedef struct lm_info *lm_info_p; @@ -86,11 +97,11 @@ library_list_start_segment (struct gdb_xml_parser *parser, = (ULONGEST *) xml_find_attribute (attributes, "address")->value; CORE_ADDR address = (CORE_ADDR) *address_p; - if (last->section_bases != NULL) + if (!last->section_bases.empty ()) gdb_xml_error (parser, _("Library list with both segments and sections")); - VEC_safe_push (CORE_ADDR, last->segment_bases, address); + last->segment_bases.push_back (address); } static void @@ -104,11 +115,11 @@ library_list_start_section (struct gdb_xml_parser *parser, = (ULONGEST *) xml_find_attribute (attributes, "address")->value; CORE_ADDR address = (CORE_ADDR) *address_p; - if (last->segment_bases != NULL) + if (!last->segment_bases.empty ()) gdb_xml_error (parser, _("Library list with both segments and sections")); - VEC_safe_push (CORE_ADDR, last->section_bases, address); + last->section_bases.push_back (address); } /* Handle the start of a element. */ @@ -119,7 +130,7 @@ library_list_start_library (struct gdb_xml_parser *parser, void *user_data, VEC(gdb_xml_value_s) *attributes) { VEC(lm_info_p) **list = (VEC(lm_info_p) **) user_data; - struct lm_info *item = XCNEW (struct lm_info); + lm_info *item = new lm_info; const char *name = (const char *) xml_find_attribute (attributes, "name")->value; @@ -135,10 +146,8 @@ library_list_end_library (struct gdb_xml_parser *parser, VEC(lm_info_p) **list = (VEC(lm_info_p) **) user_data; struct lm_info *lm_info = VEC_last (lm_info_p, *list); - if (lm_info->segment_bases == NULL - && lm_info->section_bases == NULL) - gdb_xml_error (parser, - _("No segment or section bases defined")); + if (lm_info->segment_bases.empty () && lm_info->section_bases.empty ()) + gdb_xml_error (parser, _("No segment or section bases defined")); } @@ -173,12 +182,8 @@ solib_target_free_library_list (void *p) int ix; for (ix = 0; VEC_iterate (lm_info_p, *result, ix, info); ix++) - { - xfree (info->name); - VEC_free (CORE_ADDR, info->segment_bases); - VEC_free (CORE_ADDR, info->section_bases); - xfree (info); - } + delete info; + VEC_free (lm_info_p, *result); *result = NULL; } @@ -325,9 +330,8 @@ static void solib_target_free_so (struct so_list *so) { gdb_assert (so->lm_info->name == NULL); - xfree (so->lm_info->offsets); - VEC_free (CORE_ADDR, so->lm_info->segment_bases); - xfree (so->lm_info); + + delete so->lm_info; } static void @@ -346,12 +350,11 @@ solib_target_relocate_section_addresses (struct so_list *so, = ((struct section_offsets *) xzalloc (SIZEOF_N_SECTION_OFFSETS (num_sections))); - if (so->lm_info->section_bases) + if (!so->lm_info->section_bases.empty ()) { int i; asection *sect; - int num_section_bases - = VEC_length (CORE_ADDR, so->lm_info->section_bases); + int num_section_bases = so->lm_info->section_bases.size (); int num_alloc_sections = 0; for (i = 0, sect = so->abfd->sections; @@ -368,10 +371,7 @@ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), { int bases_index = 0; int found_range = 0; - CORE_ADDR *section_bases; - - section_bases = VEC_address (CORE_ADDR, - so->lm_info->section_bases); + CORE_ADDR *section_bases = so->lm_info->section_bases.data (); so->addr_low = ~(CORE_ADDR) 0; so->addr_high = 0; @@ -404,7 +404,7 @@ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), gdb_assert (so->addr_low <= so->addr_high); } } - else if (so->lm_info->segment_bases) + else if (!so->lm_info->segment_bases.empty ()) { struct symfile_segment_data *data; @@ -419,9 +419,8 @@ Could not relocate shared library \"%s\": no segments"), so->so_name); int num_bases; CORE_ADDR *segment_bases; - num_bases = VEC_length (CORE_ADDR, so->lm_info->segment_bases); - segment_bases = VEC_address (CORE_ADDR, - so->lm_info->segment_bases); + num_bases = so->lm_info->segment_bases.size (); + segment_bases = so->lm_info->segment_bases.data (); if (!symfile_map_offsets_to_segments (so->abfd, data, so->lm_info->offsets, -- 2.12.2