]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use std::vector in uploaded_tp
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 30 Mar 2018 21:18:54 +0000 (17:18 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 30 Mar 2018 21:18:54 +0000 (17:18 -0400)
This patch changes the VEC(char_ptr) fields in uploaded_tp to use
std::vector<char *>.  At first, I wanted to creep in more changes, like
using std::string, but it was making the patch too big and less focused,
so I decided to keep it to just that.

It also looks like the strings in those vectors are never free'd.  If
so, we can fix that in another patch.

gdb/ChangeLog:

* tracepoint.h (struct uploaded_tp): Initialize fields.
<actions, step_actions, cmd_strings>: Change type to
std::vector<char *>.
* tracepoint.c (get_uploaded_tp): Allocate with new.
(free_uploaded_tps): Free with delete.
(parse_tracepoint_definition): Adjust to std::vector change.
* breakpoint.c (read_uploaded_action): Likewise.
(create_tracepoint_from_upload): Likewise.
* ctf.c (ctf_write_uploaded_tp): Likewise.
(SET_ARRAY_FIELD): Likewise.
* tracefile-tfile.c (tfile_write_uploaded_tp): Likewise.

gdb/ChangeLog
gdb/breakpoint.c
gdb/ctf.c
gdb/tracefile-tfile.c
gdb/tracepoint.c
gdb/tracepoint.h

index d0cabed4343dfdf9239557191d1ca7eaa3d36058..f96adf72be049b79add0b290eadfa5d96bb9e0c7 100644 (file)
@@ -1,3 +1,17 @@
+2018-03-30  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * tracepoint.h (struct uploaded_tp): Initialize fields.
+       <actions, step_actions, cmd_strings>: Change type to
+       std::vector<char *>.
+       * tracepoint.c (get_uploaded_tp): Allocate with new.
+       (free_uploaded_tps): Free with delete.
+       (parse_tracepoint_definition): Adjust to std::vector change.
+       * breakpoint.c (read_uploaded_action): Likewise.
+       (create_tracepoint_from_upload): Likewise.
+       * ctf.c (ctf_write_uploaded_tp): Likewise.
+       (SET_ARRAY_FIELD): Likewise.
+       * tracefile-tfile.c (tfile_write_uploaded_tp): Likewise.
+
 2018-03-30  Tom Tromey  <tom@tromey.com>
 
        * solib-svr4.c (lm_info_read): Use gdb::byte_vector.  Return
index 9de0e6330c553f4dccfcd05fe20de8102472e2b0..991c29c1e2d951e5ad90519a54fe27a4f6a850f6 100644 (file)
@@ -14738,11 +14738,13 @@ static int next_cmd;
 static char *
 read_uploaded_action (void)
 {
-  char *rslt;
+  char *rslt = nullptr;
 
-  VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
-
-  next_cmd++;
+  if (next_cmd < this_utp->cmd_strings.size ())
+    {
+      rslt = this_utp->cmd_strings[next_cmd];
+      next_cmd++;
+    }
 
   return rslt;
 }
@@ -14814,7 +14816,7 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
      special-purpose "reader" function and call the usual command line
      reader, then pass the result to the breakpoint command-setting
      function.  */
-  if (!VEC_empty (char_ptr, utp->cmd_strings))
+  if (!utp->cmd_strings.empty ())
     {
       command_line_up cmd_list;
 
@@ -14825,8 +14827,8 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
 
       breakpoint_set_commands (tp, std::move (cmd_list));
     }
-  else if (!VEC_empty (char_ptr, utp->actions)
-          || !VEC_empty (char_ptr, utp->step_actions))
+  else if (!utp->actions.empty ()
+          || !utp->step_actions.empty ())
     warning (_("Uploaded tracepoint %d actions "
               "have no source form, ignoring them"),
             utp->number);
index d589ed31a2978e4a8fff17f393061e740b2e4cec..07ae93b999e4b88cd08c6f966ca1b11eca7fbea2 100644 (file)
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -530,8 +530,6 @@ ctf_write_uploaded_tp (struct trace_file_writer *self,
   int64_t int64;
   uint32_t u32;
   const gdb_byte zero = 0;
-  int a;
-  char *act;
 
   /* Event Id.  */
   int32 = CTF_EVENT_ID_TP_DEF;
@@ -569,15 +567,15 @@ ctf_write_uploaded_tp (struct trace_file_writer *self,
   ctf_save_write (&writer->tcs, &zero, 1);
 
   /* actions */
-  u32 = VEC_length (char_ptr, tp->actions);
+  u32 = tp->actions.size ();
   ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
-  for (a = 0; VEC_iterate (char_ptr, tp->actions, a, act); ++a)
+  for (char *act : tp->actions)
     ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
 
   /* step_actions */
-  u32 = VEC_length (char_ptr, tp->step_actions);
+  u32 = tp->step_actions.size ();
   ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
-  for (a = 0; VEC_iterate (char_ptr, tp->step_actions, a, act); ++a)
+  for (char *act : tp->step_actions)
     ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
 
   /* at_string */
@@ -593,9 +591,9 @@ ctf_write_uploaded_tp (struct trace_file_writer *self,
   ctf_save_write (&writer->tcs, &zero, 1);
 
   /* cmd_strings */
-  u32 = VEC_length (char_ptr, tp->cmd_strings);
+  u32 = tp->cmd_strings.size ();
   ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
-  for (a = 0; VEC_iterate (char_ptr, tp->cmd_strings, a, act); ++a)
+  for (char *act : tp->cmd_strings)
     ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
 
 }
@@ -992,8 +990,8 @@ ctf_read_tsv (struct uploaded_tsv **uploaded_tsvs)
          const struct bt_definition *element                           \
            = bt_ctf_get_index ((EVENT), def, i);                       \
                                                                        \
-         VEC_safe_push (char_ptr, (VAR)->ARRAY,                        \
-                        xstrdup (bt_ctf_get_string (element)));        \
+         (VAR)->ARRAY.push_back                                        \
+           (xstrdup (bt_ctf_get_string (element)));                    \
        }                                                               \
     }                                                                  \
   while (0)
index 4f0dc591a24a36832eac21f65018222adc374652..d7e934770a496124c445419ec96b750e0b906362 100644 (file)
@@ -221,8 +221,6 @@ tfile_write_uploaded_tp (struct trace_file_writer *self,
 {
   struct tfile_trace_file_writer *writer
     = (struct tfile_trace_file_writer *) self;
-  int a;
-  char *act;
   char buf[MAX_TRACE_UPLOAD];
 
   fprintf (writer->fp, "tp T%x:%s:%c:%x:%x",
@@ -235,10 +233,10 @@ tfile_write_uploaded_tp (struct trace_file_writer *self,
             ":X%x,%s", (unsigned int) strlen (utp->cond) / 2,
             utp->cond);
   fprintf (writer->fp, "\n");
-  for (a = 0; VEC_iterate (char_ptr, utp->actions, a, act); ++a)
+  for (char *act : utp->actions)
     fprintf (writer->fp, "tp A%x:%s:%s\n",
             utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
-  for (a = 0; VEC_iterate (char_ptr, utp->step_actions, a, act); ++a)
+  for (char *act : utp->step_actions)
     fprintf (writer->fp, "tp S%x:%s:%s\n",
             utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
   if (utp->at_string)
@@ -254,7 +252,7 @@ tfile_write_uploaded_tp (struct trace_file_writer *self,
                            buf, MAX_TRACE_UPLOAD);
       fprintf (writer->fp, "tp Z%s\n", buf);
     }
-  for (a = 0; VEC_iterate (char_ptr, utp->cmd_strings, a, act); ++a)
+  for (char *act : utp->cmd_strings)
     {
       encode_source_string (utp->number, utp->addr, "cmd", act,
                            buf, MAX_TRACE_UPLOAD);
index 965c236e22ee0a363157ee3e819840e76082626f..954d039caf783ff730fada4180a75758df1f5b3a 100644 (file)
@@ -3062,12 +3062,9 @@ get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp)
     if (utp->number == num && utp->addr == addr)
       return utp;
 
-  utp = XCNEW (struct uploaded_tp);
+  utp = new uploaded_tp;
   utp->number = num;
   utp->addr = addr;
-  utp->actions = NULL;
-  utp->step_actions = NULL;
-  utp->cmd_strings = NULL;
   utp->next = *utpp;
   *utpp = utp;
 
@@ -3082,7 +3079,7 @@ free_uploaded_tps (struct uploaded_tp **utpp)
   while (*utpp)
     {
       next_one = (*utpp)->next;
-      xfree (*utpp);
+      delete *utpp;
       *utpp = next_one;
     }
 }
@@ -3599,12 +3596,12 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
   else if (piece == 'A')
     {
       utp = get_uploaded_tp (num, addr, utpp);
-      VEC_safe_push (char_ptr, utp->actions, xstrdup (p));
+      utp->actions.push_back (xstrdup (p));
     }
   else if (piece == 'S')
     {
       utp = get_uploaded_tp (num, addr, utpp);
-      VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p));
+      utp->step_actions.push_back (xstrdup (p));
     }
   else if (piece == 'Z')
     {
@@ -3628,7 +3625,7 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
       else if (startswith (srctype, "cond:"))
        utp->cond_string = xstrdup (buf);
       else if (startswith (srctype, "cmd:"))
-       VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf));
+       utp->cmd_strings.push_back (xstrdup (buf));
     }
   else if (piece == 'V')
     {
index c82b62aae64fef9b672202ef324cdc78f579d2be..8613cb2dd69e314a5df791d690cd606e5a4cc0da 100644 (file)
@@ -165,38 +165,38 @@ extern const char *stop_reason_names[];
 
 struct uploaded_tp
 {
-  int number;
-  enum bptype type;
-  ULONGEST addr;
-  int enabled;
-  int step;
-  int pass;
-  int orig_size;
+  int number = 0;
+  enum bptype type = bp_none;
+  ULONGEST addr = 0;
+  int enabled = 0;
+  int step = 0;
+  int pass = 0;
+  int orig_size = 0;
 
   /* String that is the encoded form of the tracepoint's condition.  */
-  char *cond;
+  char *cond = nullptr;
 
   /* Vectors of strings that are the encoded forms of a tracepoint's
      actions.  */
-  VEC(char_ptr) *actions;
-  VEC(char_ptr) *step_actions;
+  std::vector<char *> actions;
+  std::vector<char *> step_actions;
 
   /* The original string defining the location of the tracepoint.  */
-  char *at_string;
+  char *at_string = nullptr;
 
   /* The original string defining the tracepoint's condition.  */
-  char *cond_string;
+  char *cond_string = nullptr;
 
   /* List of original strings defining the tracepoint's actions.  */
-  VEC(char_ptr) *cmd_strings;
+  std::vector<char *> cmd_strings;
 
   /* The tracepoint's current hit count.  */
-  int hit_count;
+  int hit_count = 0;
 
   /* The tracepoint's current traceframe usage.  */
-  ULONGEST traceframe_usage;
+  ULONGEST traceframe_usage = 0;
 
-  struct uploaded_tp *next;
+  struct uploaded_tp *next = nullptr;
 };
 
 /* Struct recording info about trace state variables on the target.  */