From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 3/4] Use std::vector in solib-target lm_info
Date: Sun, 16 Apr 2017 14:14:00 -0000 [thread overview]
Message-ID: <20170416141430.2585-4-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20170416141430.2585-1-simon.marchi@polymtl.ca>
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).
I wasn't really able to test this, since the list of remote targets that use
this method of fetching solibs is quite limited (windows, dicos and
arm-symbian, from what I can see).
gdb/ChangeLog:
* solib-target.c (struct lm_info): Add default constructor,
delete copy constructor and operator=.
<segment_bases, section_bases>: Change type to
std::vector<CORE_ADDR>.
(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 | 49 ++++++++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 27 deletions(-)
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 1b10e4ea41..09b3e4f124 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -25,10 +25,15 @@
#include "target.h"
#include "vec.h"
#include "solib-target.h"
+#include <vector>
/* 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;
+
/* The library's name. The name is normally kept in the struct
so_list; it is only here during XML parsing. */
char *name;
@@ -38,11 +43,11 @@ struct lm_info
/* The base addresses for each independently relocatable segment of
this shared library. */
- VEC(CORE_ADDR) *segment_bases;
+ std::vector<CORE_ADDR> segment_bases;
/* The base addresses for each independently allocatable,
relocatable section of this shared library. */
- VEC(CORE_ADDR) *section_bases;
+ std::vector<CORE_ADDR> section_bases;
/* The cached offsets for each section of this shared library,
determined from SEGMENT_BASES, or SECTION_BASES. */
@@ -86,11 +91,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 +109,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 <library> element. */
@@ -119,7 +124,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);
+ struct lm_info *item = new lm_info;
const char *name
= (const char *) xml_find_attribute (attributes, "name")->value;
@@ -135,10 +140,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"));
}
@@ -175,9 +178,7 @@ solib_target_free_library_list (void *p)
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;
@@ -326,8 +327,7 @@ 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 +346,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 +367,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 +400,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 +415,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
next prev parent reply other threads:[~2017-04-16 14:14 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-16 14:14 [PATCH 0/4] Remove VEC (CORE_ADDR) Simon Marchi
2017-04-16 14:14 ` [PATCH 1/4] Change field separator in gdbarch.sh Simon Marchi
2017-04-18 20:17 ` Pedro Alves
2017-04-18 20:20 ` Pedro Alves
2017-04-19 4:03 ` Simon Marchi
2017-04-19 10:31 ` Pedro Alves
2017-04-16 14:14 ` Simon Marchi [this message]
2017-04-18 20:18 ` [PATCH 3/4] Use std::vector in solib-target lm_info Pedro Alves
2017-04-19 4:18 ` Simon Marchi
2017-04-19 4:30 ` [PATCH v2] " Simon Marchi
2017-04-30 0:35 ` [PATCH v3] Use std::vector in lm_info_target Simon Marchi
2017-04-30 0:42 ` Simon Marchi
2017-05-02 16:06 ` Pedro Alves
2017-05-02 16:12 ` Pedro Alves
2017-05-02 17:25 ` Simon Marchi
2017-05-02 17:37 ` Pedro Alves
2017-05-02 17:50 ` Simon Marchi
2017-04-16 14:14 ` [PATCH 4/4] Remove definition of VEC (CORE_ADDR) Simon Marchi
2017-04-18 20:18 ` Pedro Alves
2017-04-16 14:15 ` [PATCH 2/4] Change return type of gdbarch_software_single_step to vector<CORE_ADDR> Simon Marchi
2017-04-18 20:17 ` Pedro Alves
2017-04-19 4:08 ` Simon Marchi
2017-04-19 10:32 ` Pedro Alves
2017-05-02 17:35 ` [PATCH 0/4] Remove VEC (CORE_ADDR) Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170416141430.2585-4-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox