From: Simon Marchi Date: Fri, 30 Mar 2018 21:18:54 +0000 (-0400) Subject: Use std::vector in uploaded_tp X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=a18ba4e4c9d64eeb2ea65e5315fbd8b4261a1756;hp=a7961323e2fce4f831e117cc43e20e5144192240;p=deliverable%2Fbinutils-gdb.git Use std::vector in uploaded_tp This patch changes the VEC(char_ptr) fields in uploaded_tp to use std::vector. 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. : Change type to std::vector. * 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d0cabed434..f96adf72be 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2018-03-30 Simon Marchi + + * tracepoint.h (struct uploaded_tp): Initialize fields. + : Change type to + std::vector. + * 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 * solib-svr4.c (lm_info_read): Use gdb::byte_vector. Return diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 9de0e6330c..991c29c1e2 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -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); diff --git a/gdb/ctf.c b/gdb/ctf.c index d589ed31a2..07ae93b999 100644 --- 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) diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 4f0dc591a2..d7e934770a 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -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); diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 965c236e22..954d039caf 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -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') { diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h index c82b62aae6..8613cb2dd6 100644 --- a/gdb/tracepoint.h +++ b/gdb/tracepoint.h @@ -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 actions; + std::vector 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 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. */