public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] Remove a VEC from record-full.c
@ 2018-06-08  2:56 Tom Tromey
  2018-06-09 12:11 ` Simon Marchi
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2018-06-08  2:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This replaces a VEC in record-full.c with a std::vector.

This patch is somewhat simplisitic and may affect the performance of
record_full_target::remove_breakpoint.  I suspect this does not matter
but your comments are appreciated.

Tested by the buildbot.

gdb/ChangeLog
2018-06-07  Tom Tromey  <tom@tromey.com>

	* record-full.c (record_full_breakpoint_p): Remove typedef.  Don't
	declare VEC.
	(record_full_breakpoints): Now a std::vector, static.
	(record_full_sync_record_breakpoints)
	(record_full_init_record_breakpoints)
	(record_full_target::insert_breakpoint)
	(record_full_target::remove_breakpoint): Update.
---
 gdb/ChangeLog     | 10 ++++++++++
 gdb/record-full.c | 37 ++++++++++++-------------------------
 2 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/gdb/record-full.c b/gdb/record-full.c
index 87c77e06ea9..e997ef2171b 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -1710,12 +1710,9 @@ struct record_full_breakpoint
   int in_target_beneath;
 };
 
-typedef struct record_full_breakpoint *record_full_breakpoint_p;
-DEF_VEC_P(record_full_breakpoint_p);
-
 /* The list of breakpoints inserted while the record target is
    active.  */
-VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
+static std::vector<record_full_breakpoint *> record_full_breakpoints;
 
 static void
 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
@@ -1732,7 +1729,7 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
 
       bp->in_target_beneath = 1;
 
-      VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
+      record_full_breakpoints.push_back (bp);
     }
 }
 
@@ -1741,7 +1738,7 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
 static void
 record_full_init_record_breakpoints (void)
 {
-  VEC_free (record_full_breakpoint_p, record_full_breakpoints);
+  record_full_breakpoints.clear ();
 
   iterate_over_bp_locations (record_full_sync_record_breakpoints);
 }
@@ -1754,9 +1751,7 @@ int
 record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
 				       struct bp_target_info *bp_tgt)
 {
-  struct record_full_breakpoint *bp;
   int in_target_beneath = 0;
-  int ix;
 
   if (!RECORD_FULL_IS_REPLAY)
     {
@@ -1779,10 +1774,7 @@ record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
   /* Use the existing entries if found in order to avoid duplication
      in record_full_breakpoints.  */
 
-  for (ix = 0;
-       VEC_iterate (record_full_breakpoint_p,
-		    record_full_breakpoints, ix, bp);
-       ++ix)
+  for (struct record_full_breakpoint *bp : record_full_breakpoints)
     {
       if (bp->addr == bp_tgt->placed_address
 	  && bp->address_space == bp_tgt->placed_address_space)
@@ -1792,11 +1784,11 @@ record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
 	}
     }
 
-  bp = XNEW (struct record_full_breakpoint);
+  struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
   bp->addr = bp_tgt->placed_address;
   bp->address_space = bp_tgt->placed_address_space;
   bp->in_target_beneath = in_target_beneath;
-  VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
+  record_full_breakpoints.push_back (bp);
   return 0;
 }
 
@@ -1807,14 +1799,12 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
 				       struct bp_target_info *bp_tgt,
 				       enum remove_bp_reason reason)
 {
-  struct record_full_breakpoint *bp;
-  int ix;
-
-  for (ix = 0;
-       VEC_iterate (record_full_breakpoint_p,
-		    record_full_breakpoints, ix, bp);
-       ++ix)
+  for (auto iter = record_full_breakpoints.begin ();
+       iter != record_full_breakpoints.end ();
+       ++iter)
     {
+      struct record_full_breakpoint *bp = *iter;
+
       if (bp->addr == bp_tgt->placed_address
 	  && bp->address_space == bp_tgt->placed_address_space)
 	{
@@ -1830,10 +1820,7 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
 	    }
 
 	  if (reason == REMOVE_BREAKPOINT)
-	    {
-	      VEC_unordered_remove (record_full_breakpoint_p,
-				    record_full_breakpoints, ix);
-	    }
+	    record_full_breakpoints.erase (iter);
 	  return 0;
 	}
     }
-- 
2.13.6

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Remove a VEC from record-full.c
  2018-06-08  2:56 [RFA] Remove a VEC from record-full.c Tom Tromey
@ 2018-06-09 12:11 ` Simon Marchi
  2018-06-10 15:57   ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2018-06-09 12:11 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2018-06-07 22:56, Tom Tromey wrote:
> @@ -1830,10 +1820,7 @@ record_full_target::remove_breakpoint (struct
> gdbarch *gdbarch,
>  	    }
> 
>  	  if (reason == REMOVE_BREAKPOINT)
> -	    {
> -	      VEC_unordered_remove (record_full_breakpoint_p,
> -				    record_full_breakpoints, ix);
> -	    }
> +	    record_full_breakpoints.erase (iter);
>  	  return 0;

You can use one of the overloads of unordered_remove in 
common/gdb_vecs.h to try to preserve the exact same behavior as with the 
VEC.

Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Remove a VEC from record-full.c
  2018-06-09 12:11 ` Simon Marchi
@ 2018-06-10 15:57   ` Tom Tromey
  2018-06-10 21:16     ` Simon Marchi
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2018-06-10 15:57 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> You can use one of the overloads of unordered_remove in
Simon> common/gdb_vecs.h to try to preserve the exact same behavior as with
Simon> the VEC.

Thanks, I didn't know about these.

How's this?

Tom

commit d95a705d09f189b29acf6aa06826bb660ae10903
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Jun 7 17:22:49 2018 -0600

    Remove a VEC from record-full.c
    
    This replaces a VEC in record-full.c with a std::vector.
    
    Tested by the buildbot.
    
    gdb/ChangeLog
    2018-06-07  Tom Tromey  <tom@tromey.com>
    
            * record-full.c (record_full_breakpoint_p): Remove typedef.  Don't
            declare VEC.
            (record_full_breakpoints): Now a std::vector, static.
            (record_full_sync_record_breakpoints)
            (record_full_init_record_breakpoints)
            (record_full_target::insert_breakpoint)
            (record_full_target::remove_breakpoint): Update.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 37fd0f9e127..2f7b1c883ea 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-06-07  Tom Tromey  <tom@tromey.com>
+
+	* record-full.c (record_full_breakpoint_p): Remove typedef.  Don't
+	declare VEC.
+	(record_full_breakpoints): Now a std::vector, static.
+	(record_full_sync_record_breakpoints)
+	(record_full_init_record_breakpoints)
+	(record_full_target::insert_breakpoint)
+	(record_full_target::remove_breakpoint): Update.
+
 2018-06-10  Tom Tromey  <tom@tromey.com>
 
 	* tracefile.c (struct trace_file_writer_deleter): New.
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 87c77e06ea9..ab1e265e579 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -1710,12 +1710,9 @@ struct record_full_breakpoint
   int in_target_beneath;
 };
 
-typedef struct record_full_breakpoint *record_full_breakpoint_p;
-DEF_VEC_P(record_full_breakpoint_p);
-
 /* The list of breakpoints inserted while the record target is
    active.  */
-VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
+static std::vector<record_full_breakpoint *> record_full_breakpoints;
 
 static void
 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
@@ -1732,7 +1729,7 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
 
       bp->in_target_beneath = 1;
 
-      VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
+      record_full_breakpoints.push_back (bp);
     }
 }
 
@@ -1741,7 +1738,7 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
 static void
 record_full_init_record_breakpoints (void)
 {
-  VEC_free (record_full_breakpoint_p, record_full_breakpoints);
+  record_full_breakpoints.clear ();
 
   iterate_over_bp_locations (record_full_sync_record_breakpoints);
 }
@@ -1754,9 +1751,7 @@ int
 record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
 				       struct bp_target_info *bp_tgt)
 {
-  struct record_full_breakpoint *bp;
   int in_target_beneath = 0;
-  int ix;
 
   if (!RECORD_FULL_IS_REPLAY)
     {
@@ -1779,10 +1774,7 @@ record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
   /* Use the existing entries if found in order to avoid duplication
      in record_full_breakpoints.  */
 
-  for (ix = 0;
-       VEC_iterate (record_full_breakpoint_p,
-		    record_full_breakpoints, ix, bp);
-       ++ix)
+  for (struct record_full_breakpoint *bp : record_full_breakpoints)
     {
       if (bp->addr == bp_tgt->placed_address
 	  && bp->address_space == bp_tgt->placed_address_space)
@@ -1792,11 +1784,11 @@ record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
 	}
     }
 
-  bp = XNEW (struct record_full_breakpoint);
+  struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
   bp->addr = bp_tgt->placed_address;
   bp->address_space = bp_tgt->placed_address_space;
   bp->in_target_beneath = in_target_beneath;
-  VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
+  record_full_breakpoints.push_back (bp);
   return 0;
 }
 
@@ -1807,14 +1799,12 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
 				       struct bp_target_info *bp_tgt,
 				       enum remove_bp_reason reason)
 {
-  struct record_full_breakpoint *bp;
-  int ix;
-
-  for (ix = 0;
-       VEC_iterate (record_full_breakpoint_p,
-		    record_full_breakpoints, ix, bp);
-       ++ix)
+  for (auto iter = record_full_breakpoints.begin ();
+       iter != record_full_breakpoints.end ();
+       ++iter)
     {
+      struct record_full_breakpoint *bp = *iter;
+
       if (bp->addr == bp_tgt->placed_address
 	  && bp->address_space == bp_tgt->placed_address_space)
 	{
@@ -1830,10 +1820,7 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
 	    }
 
 	  if (reason == REMOVE_BREAKPOINT)
-	    {
-	      VEC_unordered_remove (record_full_breakpoint_p,
-				    record_full_breakpoints, ix);
-	    }
+	    unordered_remove (record_full_breakpoints, iter);
 	  return 0;
 	}
     }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Remove a VEC from record-full.c
  2018-06-10 15:57   ` Tom Tromey
@ 2018-06-10 21:16     ` Simon Marchi
  2018-06-10 22:35       ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2018-06-10 21:16 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2018-06-10 11:57, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
> 
> Simon> You can use one of the overloads of unordered_remove in
> Simon> common/gdb_vecs.h to try to preserve the exact same behavior as 
> with
> Simon> the VEC.
> 
> Thanks, I didn't know about these.
> 
> How's this?

Maybe I'm missing something, but it seems like the 
record_full_breakpoint objects are never freed.  That's not related to 
your patch though, so your patch LGTM.

Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Remove a VEC from record-full.c
  2018-06-10 21:16     ` Simon Marchi
@ 2018-06-10 22:35       ` Tom Tromey
  2018-06-11  0:16         ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2018-06-10 22:35 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> Maybe I'm missing something, but it seems like the
Simon> record_full_breakpoint objects are never freed.  That's not related to
Simon> your patch though, so your patch LGTM.

Thanks for noticing this.  I think this is a good opportunity to fix the
problem, so I'll take a look at that.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Remove a VEC from record-full.c
  2018-06-10 22:35       ` Tom Tromey
@ 2018-06-11  0:16         ` Tom Tromey
  2018-06-11  0:28           ` Simon Marchi
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2018-06-11  0:16 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Simon Marchi, gdb-patches

Simon> Maybe I'm missing something, but it seems like the
Simon> record_full_breakpoint objects are never freed.  That's not related to
Simon> your patch though, so your patch LGTM.

Tom> Thanks for noticing this.  I think this is a good opportunity to fix the
Tom> problem, so I'll take a look at that.

How about this?

Tom

commit 35490568c3398dc9b11f71b003de1b0f829d039e
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Jun 7 17:22:49 2018 -0600

    Remove a VEC from record-full.c
    
    This replaces a VEC in record-full.c with a std::vector.  This version
    of the patch also catches a memory leak in the original code noticed
    by Simon.
    
    Tested by the buildbot.
    
    gdb/ChangeLog
    2018-06-07  Tom Tromey  <tom@tromey.com>
    
            * record-full.c (record_full_breakpoint_p): Remove typedef.  Don't
            declare VEC.  Add constructor.
            (record_full_breakpoints): Now a std::vector, static.
            (record_full_sync_record_breakpoints)
            (record_full_init_record_breakpoints)
            (record_full_target::insert_breakpoint)
            (record_full_target::remove_breakpoint): Update.  Don't use XNEW.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0e5c0685cc2..037bd9f5f3e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-06-07  Tom Tromey  <tom@tromey.com>
+
+	* record-full.c (record_full_breakpoint_p): Remove typedef.  Don't
+	declare VEC.  Add constructor.
+	(record_full_breakpoints): Now a std::vector, static.
+	(record_full_sync_record_breakpoints)
+	(record_full_init_record_breakpoints)
+	(record_full_target::insert_breakpoint)
+	(record_full_target::remove_breakpoint): Update.  Don't use XNEW.
+
 2018-06-10  Tom Tromey  <tom@tromey.com>
 
 	* procfs.c (procfs_target::xfer_partial): Use "beneath" as a
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 87c77e06ea9..6fd389d3dcd 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -1700,6 +1700,15 @@ record_full_target::xfer_partial (enum target_object object,
 
 struct record_full_breakpoint
 {
+  record_full_breakpoint (struct address_space *address_space_,
+			  CORE_ADDR addr_,
+			  int in_target_beneath_)
+    : address_space (address_space_),
+      addr (addr_),
+      in_target_beneath (in_target_beneath_)
+  {
+  }
+
   /* The address and address space the breakpoint was set at.  */
   struct address_space *address_space;
   CORE_ADDR addr;
@@ -1710,12 +1719,9 @@ struct record_full_breakpoint
   int in_target_beneath;
 };
 
-typedef struct record_full_breakpoint *record_full_breakpoint_p;
-DEF_VEC_P(record_full_breakpoint_p);
-
 /* The list of breakpoints inserted while the record target is
    active.  */
-VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
+static std::vector<record_full_breakpoint> record_full_breakpoints;
 
 static void
 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
@@ -1725,14 +1731,10 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
 
   if (loc->inserted)
     {
-      struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
-
-      bp->addr = loc->target_info.placed_address;
-      bp->address_space = loc->target_info.placed_address_space;
-
-      bp->in_target_beneath = 1;
-
-      VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
+      record_full_breakpoints.emplace_back
+	(loc->target_info.placed_address_space,
+	 loc->target_info.placed_address,
+	 1);
     }
 }
 
@@ -1741,7 +1743,7 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
 static void
 record_full_init_record_breakpoints (void)
 {
-  VEC_free (record_full_breakpoint_p, record_full_breakpoints);
+  record_full_breakpoints.clear ();
 
   iterate_over_bp_locations (record_full_sync_record_breakpoints);
 }
@@ -1754,9 +1756,7 @@ int
 record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
 				       struct bp_target_info *bp_tgt)
 {
-  struct record_full_breakpoint *bp;
   int in_target_beneath = 0;
-  int ix;
 
   if (!RECORD_FULL_IS_REPLAY)
     {
@@ -1779,24 +1779,19 @@ record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
   /* Use the existing entries if found in order to avoid duplication
      in record_full_breakpoints.  */
 
-  for (ix = 0;
-       VEC_iterate (record_full_breakpoint_p,
-		    record_full_breakpoints, ix, bp);
-       ++ix)
+  for (struct record_full_breakpoint &bp : record_full_breakpoints)
     {
-      if (bp->addr == bp_tgt->placed_address
-	  && bp->address_space == bp_tgt->placed_address_space)
+      if (bp.addr == bp_tgt->placed_address
+	  && bp.address_space == bp_tgt->placed_address_space)
 	{
-	  gdb_assert (bp->in_target_beneath == in_target_beneath);
+	  gdb_assert (bp.in_target_beneath == in_target_beneath);
 	  return 0;
 	}
     }
 
-  bp = XNEW (struct record_full_breakpoint);
-  bp->addr = bp_tgt->placed_address;
-  bp->address_space = bp_tgt->placed_address_space;
-  bp->in_target_beneath = in_target_beneath;
-  VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
+  record_full_breakpoints.emplace_back (bp_tgt->placed_address_space,
+					bp_tgt->placed_address,
+					in_target_beneath);
   return 0;
 }
 
@@ -1807,18 +1802,16 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
 				       struct bp_target_info *bp_tgt,
 				       enum remove_bp_reason reason)
 {
-  struct record_full_breakpoint *bp;
-  int ix;
-
-  for (ix = 0;
-       VEC_iterate (record_full_breakpoint_p,
-		    record_full_breakpoints, ix, bp);
-       ++ix)
+  for (auto iter = record_full_breakpoints.begin ();
+       iter != record_full_breakpoints.end ();
+       ++iter)
     {
-      if (bp->addr == bp_tgt->placed_address
-	  && bp->address_space == bp_tgt->placed_address_space)
+      struct record_full_breakpoint &bp = *iter;
+
+      if (bp.addr == bp_tgt->placed_address
+	  && bp.address_space == bp_tgt->placed_address_space)
 	{
-	  if (bp->in_target_beneath)
+	  if (bp.in_target_beneath)
 	    {
 	      scoped_restore restore_operation_disable
 		= record_full_gdb_operation_disable_set ();
@@ -1830,10 +1823,7 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
 	    }
 
 	  if (reason == REMOVE_BREAKPOINT)
-	    {
-	      VEC_unordered_remove (record_full_breakpoint_p,
-				    record_full_breakpoints, ix);
-	    }
+	    unordered_remove (record_full_breakpoints, iter);
 	  return 0;
 	}
     }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Remove a VEC from record-full.c
  2018-06-11  0:16         ` Tom Tromey
@ 2018-06-11  0:28           ` Simon Marchi
  2018-06-11  4:11             ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2018-06-11  0:28 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2018-06-10 20:16, Tom Tromey wrote:
> Simon> Maybe I'm missing something, but it seems like the
> Simon> record_full_breakpoint objects are never freed.  That's not 
> related to
> Simon> your patch though, so your patch LGTM.
> 
> Tom> Thanks for noticing this.  I think this is a good opportunity to 
> fix the
> Tom> problem, so I'll take a look at that.
> 
> How about this?
> 
> Tom

Thanks, LGTM.  You can get extra credits if you make the 
in_target_beneath field a bool :).

Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Remove a VEC from record-full.c
  2018-06-11  0:28           ` Simon Marchi
@ 2018-06-11  4:11             ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-06-11  4:11 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> Thanks, LGTM.  You can get extra credits if you make the
Simon> in_target_beneath field a bool :).

Here's what I'm checking in.

Tom

commit 98fe1618e47c7850a50ac882f229ec527c1e1eb1
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Jun 7 17:22:49 2018 -0600

    Remove a VEC from record-full.c
    
    This replaces a VEC in record-full.c with a std::vector.  This version
    of the patch also catches a memory leak in the original code noticed
    by Simon.
    
    Tested by the buildbot.
    
    gdb/ChangeLog
    2018-06-10  Tom Tromey  <tom@tromey.com>
    
            * record-full.c (record_full_breakpoint_p): Remove typedef.  Don't
            declare VEC.  Add constructor.
            <in_target_beneath>: Now bool.
            (record_full_breakpoints): Now a std::vector, static.
            (record_full_sync_record_breakpoints)
            (record_full_init_record_breakpoints)
            (record_full_target::insert_breakpoint)
            (record_full_target::remove_breakpoint): Update.  Don't use XNEW.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0e5c0685cc2..c00dc9817ef 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,16 @@
 2018-06-10  Tom Tromey  <tom@tromey.com>
 
+	* record-full.c (record_full_breakpoint_p): Remove typedef.  Don't
+	declare VEC.  Add constructor.
+	<in_target_beneath>: Now bool.
+	(record_full_breakpoints): Now a std::vector, static.
+	(record_full_sync_record_breakpoints)
+	(record_full_init_record_breakpoints)
+	(record_full_target::insert_breakpoint)
+	(record_full_target::remove_breakpoint): Update.  Don't use XNEW.
+
+2018-06-10  Tom Tromey  <tom@tromey.com>
+
 	* procfs.c (procfs_target::xfer_partial): Use "beneath" as a
 	method.
 	* nto-procfs.c (nto_procfs_target::xfer_partial): Use "beneath" as
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 87c77e06ea9..27c8065835c 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -1700,6 +1700,15 @@ record_full_target::xfer_partial (enum target_object object,
 
 struct record_full_breakpoint
 {
+  record_full_breakpoint (struct address_space *address_space_,
+			  CORE_ADDR addr_,
+			  bool in_target_beneath_)
+    : address_space (address_space_),
+      addr (addr_),
+      in_target_beneath (in_target_beneath_)
+  {
+  }
+
   /* The address and address space the breakpoint was set at.  */
   struct address_space *address_space;
   CORE_ADDR addr;
@@ -1707,15 +1716,12 @@ struct record_full_breakpoint
   /* True when the breakpoint has been also installed in the target
      beneath.  This will be false for breakpoints set during replay or
      when recording.  */
-  int in_target_beneath;
+  bool in_target_beneath;
 };
 
-typedef struct record_full_breakpoint *record_full_breakpoint_p;
-DEF_VEC_P(record_full_breakpoint_p);
-
 /* The list of breakpoints inserted while the record target is
    active.  */
-VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
+static std::vector<record_full_breakpoint> record_full_breakpoints;
 
 static void
 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
@@ -1725,14 +1731,10 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
 
   if (loc->inserted)
     {
-      struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
-
-      bp->addr = loc->target_info.placed_address;
-      bp->address_space = loc->target_info.placed_address_space;
-
-      bp->in_target_beneath = 1;
-
-      VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
+      record_full_breakpoints.emplace_back
+	(loc->target_info.placed_address_space,
+	 loc->target_info.placed_address,
+	 1);
     }
 }
 
@@ -1741,7 +1743,7 @@ record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
 static void
 record_full_init_record_breakpoints (void)
 {
-  VEC_free (record_full_breakpoint_p, record_full_breakpoints);
+  record_full_breakpoints.clear ();
 
   iterate_over_bp_locations (record_full_sync_record_breakpoints);
 }
@@ -1754,9 +1756,7 @@ int
 record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
 				       struct bp_target_info *bp_tgt)
 {
-  struct record_full_breakpoint *bp;
-  int in_target_beneath = 0;
-  int ix;
+  bool in_target_beneath = false;
 
   if (!RECORD_FULL_IS_REPLAY)
     {
@@ -1773,30 +1773,25 @@ record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
       if (ret != 0)
 	return ret;
 
-      in_target_beneath = 1;
+      in_target_beneath = true;
     }
 
   /* Use the existing entries if found in order to avoid duplication
      in record_full_breakpoints.  */
 
-  for (ix = 0;
-       VEC_iterate (record_full_breakpoint_p,
-		    record_full_breakpoints, ix, bp);
-       ++ix)
+  for (struct record_full_breakpoint &bp : record_full_breakpoints)
     {
-      if (bp->addr == bp_tgt->placed_address
-	  && bp->address_space == bp_tgt->placed_address_space)
+      if (bp.addr == bp_tgt->placed_address
+	  && bp.address_space == bp_tgt->placed_address_space)
 	{
-	  gdb_assert (bp->in_target_beneath == in_target_beneath);
+	  gdb_assert (bp.in_target_beneath == in_target_beneath);
 	  return 0;
 	}
     }
 
-  bp = XNEW (struct record_full_breakpoint);
-  bp->addr = bp_tgt->placed_address;
-  bp->address_space = bp_tgt->placed_address_space;
-  bp->in_target_beneath = in_target_beneath;
-  VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
+  record_full_breakpoints.emplace_back (bp_tgt->placed_address_space,
+					bp_tgt->placed_address,
+					in_target_beneath);
   return 0;
 }
 
@@ -1807,18 +1802,16 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
 				       struct bp_target_info *bp_tgt,
 				       enum remove_bp_reason reason)
 {
-  struct record_full_breakpoint *bp;
-  int ix;
-
-  for (ix = 0;
-       VEC_iterate (record_full_breakpoint_p,
-		    record_full_breakpoints, ix, bp);
-       ++ix)
+  for (auto iter = record_full_breakpoints.begin ();
+       iter != record_full_breakpoints.end ();
+       ++iter)
     {
-      if (bp->addr == bp_tgt->placed_address
-	  && bp->address_space == bp_tgt->placed_address_space)
+      struct record_full_breakpoint &bp = *iter;
+
+      if (bp.addr == bp_tgt->placed_address
+	  && bp.address_space == bp_tgt->placed_address_space)
 	{
-	  if (bp->in_target_beneath)
+	  if (bp.in_target_beneath)
 	    {
 	      scoped_restore restore_operation_disable
 		= record_full_gdb_operation_disable_set ();
@@ -1830,10 +1823,7 @@ record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
 	    }
 
 	  if (reason == REMOVE_BREAKPOINT)
-	    {
-	      VEC_unordered_remove (record_full_breakpoint_p,
-				    record_full_breakpoints, ix);
-	    }
+	    unordered_remove (record_full_breakpoints, iter);
 	  return 0;
 	}
     }

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-06-11  4:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08  2:56 [RFA] Remove a VEC from record-full.c Tom Tromey
2018-06-09 12:11 ` Simon Marchi
2018-06-10 15:57   ` Tom Tromey
2018-06-10 21:16     ` Simon Marchi
2018-06-10 22:35       ` Tom Tromey
2018-06-11  0:16         ` Tom Tromey
2018-06-11  0:28           ` Simon Marchi
2018-06-11  4:11             ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).