[v3] Use std::vector in lm_info_target

Message ID 20170430003455.13878-1-simon.marchi@polymtl.ca
State New, archived
Headers

Commit Message

Simon Marchi April 30, 2017, 12:34 a.m. UTC
  v3 simply updates the patch to the changes made to lm_info_target (previously
lm_info).

Replace the two VEC fields with std::vector.

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 | 41 +++++++++++++++--------------------------
 1 file changed, 15 insertions(+), 26 deletions(-)
  

Comments

Simon Marchi April 30, 2017, 12:42 a.m. UTC | #1
On 2017-04-29 20:34, Simon Marchi wrote:
> v3 simply updates the patch to the changes made to lm_info_target 
> (previously
> lm_info).
> 
> Replace the two VEC fields with std::vector.
> 
> 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.

Err I forgot to update the ChangeLog, here it is:

    gdb/ChangeLog:

            * solib-target.c: Include <vector>
            (struct lm_info_target) <~lm_info_target>: Remove.
            <segment_bases, section_bases>: Change type to
            std::vector<CORE_ADDR>.
            (library_list_start_segment, library_list_start_section,
            library_list_end_library,
            solib_target_relocate_section_addresses): Adjust.

Is the ChangeLog format acceptable for the destructor?

Simon
  
Pedro Alves May 2, 2017, 4:06 p.m. UTC | #2
On 04/30/2017 01:42 AM, Simon Marchi wrote:

> Err I forgot to update the ChangeLog, here it is:
> 
>    gdb/ChangeLog:
> 
>            * solib-target.c: Include <vector>
>            (struct lm_info_target) <~lm_info_target>: Remove.
>            <segment_bases, section_bases>: Change type to
>            std::vector<CORE_ADDR>.
>            (library_list_start_segment, library_list_start_section,
>            library_list_end_library,
>            solib_target_relocate_section_addresses): Adjust.
> 
> Is the ChangeLog format acceptable for the destructor?

Fine with me.

Thanks,
Pedro Alves
  
Pedro Alves May 2, 2017, 4:12 p.m. UTC | #3
On 04/30/2017 01:34 AM, Simon Marchi wrote:

> @@ -372,10 +364,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,
> -					   li->section_bases);
> +	      CORE_ADDR *section_bases = li->section_bases.data ();

I think this variable could be eliminated, and replaced by further
below doing:

 -		      low = section_bases[i];
 +		      low = li->section_bases[i];

in a couple places.

Otherwise LGTM.

Thanks,
Pedro Alves
  
Simon Marchi May 2, 2017, 5:25 p.m. UTC | #4
On 2017-05-02 12:12, Pedro Alves wrote:
> On 04/30/2017 01:34 AM, Simon Marchi wrote:
> 
>> @@ -372,10 +364,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,
>> -					   li->section_bases);
>> +	      CORE_ADDR *section_bases = li->section_bases.data ();
> 
> I think this variable could be eliminated, and replaced by further
> below doing:
> 
>  -		      low = section_bases[i];
>  +		      low = li->section_bases[i];
> 
> in a couple places.
> 
> Otherwise LGTM.

Indeed, I changed it.  Thanks.
  
Pedro Alves May 2, 2017, 5:37 p.m. UTC | #5
On 05/02/2017 06:25 PM, Simon Marchi wrote:
> On 2017-05-02 12:12, Pedro Alves wrote:
>> On 04/30/2017 01:34 AM, Simon Marchi wrote:
>>
>>> @@ -372,10 +364,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,
>>> -                       li->section_bases);
>>> +          CORE_ADDR *section_bases = li->section_bases.data ();
>>
>> I think this variable could be eliminated, and replaced by further
>> below doing:
>>
>>  -              low = section_bases[i];
>>  +              low = li->section_bases[i];
>>
>> in a couple places.
>>
>> Otherwise LGTM.
> 
> Indeed, I changed it.  Thanks.
> 

Thanks.  (There's a similar case in the segment_bases path, but
you probably saw it.)
  
Simon Marchi May 2, 2017, 5:50 p.m. UTC | #6
On 2017-05-02 13:37, Pedro Alves wrote:
> On 05/02/2017 06:25 PM, Simon Marchi wrote:
>> Indeed, I changed it.  Thanks.
>> 
> 
> Thanks.  (There's a similar case in the segment_bases path, but
> you probably saw it.)

Oops, no.  I'll look at it and push it as an obvious patch.
  

Patch

diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index e25f6ab252..373b5abe7f 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -25,16 +25,11 @@ 
 #include "target.h"
 #include "vec.h"
 #include "solib-target.h"
+#include <vector>
 
 /* Private data for each loaded library.  */
 struct lm_info_target : public lm_info_base
 {
-  ~lm_info_target ()
-  {
-    VEC_free (CORE_ADDR, this->segment_bases);
-    VEC_free (CORE_ADDR, this->section_bases);
-  }
-
   /* The library's name.  The name is normally kept in the struct
      so_list; it is only here during XML parsing.  */
   std::string name;
@@ -44,11 +39,11 @@  struct lm_info_target : public lm_info_base
 
   /* The base addresses for each independently relocatable segment of
      this shared library.  */
-  VEC(CORE_ADDR) *segment_bases = NULL;
+  std::vector<CORE_ADDR> segment_bases;
 
   /* The base addresses for each independently allocatable,
      relocatable section of this shared library.  */
-  VEC(CORE_ADDR) *section_bases = NULL;
+  std::vector<CORE_ADDR> section_bases;
 
   /* The cached offsets for each section of this shared library,
      determined from SEGMENT_BASES, or SECTION_BASES.  */
@@ -92,11 +87,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
@@ -110,11 +105,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.  */
@@ -141,10 +136,8 @@  library_list_end_library (struct gdb_xml_parser *parser,
   VEC(lm_info_target_p) **list = (VEC(lm_info_target_p) **) user_data;
   lm_info_target *lm_info = VEC_last (lm_info_target_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"));
 }
 
 
@@ -350,12 +343,11 @@  solib_target_relocate_section_addresses (struct so_list *so,
 	= ((struct section_offsets *)
 	   xzalloc (SIZEOF_N_SECTION_OFFSETS (num_sections)));
 
-      if (li->section_bases)
+      if (!li->section_bases.empty ())
 	{
 	  int i;
 	  asection *sect;
-	  int num_section_bases
-	    = VEC_length (CORE_ADDR, li->section_bases);
+	  int num_section_bases = li->section_bases.size ();
 	  int num_alloc_sections = 0;
 
 	  for (i = 0, sect = so->abfd->sections;
@@ -372,10 +364,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,
-					   li->section_bases);
+	      CORE_ADDR *section_bases = li->section_bases.data ();
 
 	      so->addr_low = ~(CORE_ADDR) 0;
 	      so->addr_high = 0;
@@ -408,7 +397,7 @@  Could not relocate shared library \"%s\": wrong number of ALLOC sections"),
 	      gdb_assert (so->addr_low <= so->addr_high);
 	    }
 	}
-      else if (li->segment_bases)
+      else if (!li->segment_bases.empty ())
 	{
 	  struct symfile_segment_data *data;
 
@@ -423,8 +412,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, li->segment_bases);
-	      segment_bases = VEC_address (CORE_ADDR, li->segment_bases);
+	      num_bases = li->segment_bases.size ();
+	      segment_bases = li->segment_bases.data ();
 
 	      if (!symfile_map_offsets_to_segments (so->abfd, data, li->offsets,
 						    num_bases, segment_bases))