public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org
Subject: Re: [RFA] Remove a VEC from record-full.c
Date: Sun, 10 Jun 2018 15:57:00 -0000	[thread overview]
Message-ID: <87o9gi7hyp.fsf@tromey.com> (raw)
In-Reply-To: <b29dd3508ec267b6cffdf8e296e394f2@polymtl.ca> (Simon Marchi's	message of "Sat, 09 Jun 2018 08:10:37 -0400")

>>>>> "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;
 	}
     }

  reply	other threads:[~2018-06-10 15:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08  2:56 Tom Tromey
2018-06-09 12:11 ` Simon Marchi
2018-06-10 15:57   ` Tom Tromey [this message]
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

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=87o9gi7hyp.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).