diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2017-11-08 19:42:08 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2017-11-08 19:42:08 -0500 |
commit | b44ec61915f10a953ca85da5bf7a97911554f1aa (patch) | |
tree | 421334d6ae1d6e425e1ee1d496979304d7b75067 /gdb/tracepoint.c | |
parent | dc8d2d90da3f191ae0461900ab98e3b29cc2b280 (diff) | |
download | gdb-b44ec61915f10a953ca85da5bf7a97911554f1aa.zip gdb-b44ec61915f10a953ca85da5bf7a97911554f1aa.tar.gz gdb-b44ec61915f10a953ca85da5bf7a97911554f1aa.tar.bz2 |
Make encode_actions_rsp use std::vector
Currently, encode_actions_rsp returns two malloc'ed arrays of malloc'ed
strings (char *) by pointer. Change this to use
std::vector<std::string>. This eliminates some cleanups in remote.c.
Regtested on the buildbot.
gdb/ChangeLog:
* tracepoint.h (class collection_list) <stringify>: Return
std::vector<std::string>.
(encode_actions_rsp): Change parameters to
std::vector<std::string> *.
* tracepoint.c (collection_list::stringify): Return
std::vector<std::string> and adjust accordingly.
(encode_actions_rsp): Changee parameters to
std::vector<std::string> and adjust accordingly.
* remote.c (free_actions_list),
free_actions_list_cleanup_wrapper): Remove.
(remote_download_tracepoint): Adjust to std::vector.
Diffstat (limited to 'gdb/tracepoint.c')
-rw-r--r-- | gdb/tracepoint.c | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 134695e..59a7b64 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -1118,18 +1118,14 @@ collection_list::collection_list () /* Reduce a collection list to string form (for gdb protocol). */ -char ** +std::vector<std::string> collection_list::stringify () { char temp_buf[2048]; int count; - int ndx = 0; - char *(*str_list)[]; char *end; long i; - - count = 1 + 1 + m_memranges.size () + m_aexprs.size () + 1; - str_list = (char *(*)[]) xmalloc (count * sizeof (char *)); + std::vector<std::string> str_list; if (m_strace_data) { @@ -1137,8 +1133,7 @@ collection_list::stringify () printf_filtered ("\nCollecting static trace data\n"); end = temp_buf; *end++ = 'L'; - (*str_list)[ndx] = savestring (temp_buf, end - temp_buf); - ndx++; + str_list.emplace_back (temp_buf, end - temp_buf); } for (i = sizeof (m_regs_mask) - 1; i > 0; i--) @@ -1158,8 +1153,7 @@ collection_list::stringify () sprintf (end, "%02X", m_regs_mask[i]); end += 2; } - (*str_list)[ndx] = xstrdup (temp_buf); - ndx++; + str_list.emplace_back (temp_buf); } if (info_verbose) printf_filtered ("\n"); @@ -1179,8 +1173,7 @@ collection_list::stringify () } if (count + 27 > MAX_AGENT_EXPR_LEN) { - (*str_list)[ndx] = savestring (temp_buf, count); - ndx++; + str_list.emplace_back (temp_buf, count); count = 0; end = temp_buf; } @@ -1210,8 +1203,7 @@ collection_list::stringify () QUIT; /* Allow user to bail out with ^C. */ if ((count + 10 + 2 * m_aexprs[i]->len) > MAX_AGENT_EXPR_LEN) { - (*str_list)[ndx] = savestring (temp_buf, count); - ndx++; + str_list.emplace_back (temp_buf, count); count = 0; end = temp_buf; } @@ -1225,20 +1217,12 @@ collection_list::stringify () if (count != 0) { - (*str_list)[ndx] = savestring (temp_buf, count); - ndx++; + str_list.emplace_back (temp_buf, count); count = 0; end = temp_buf; } - (*str_list)[ndx] = NULL; - if (ndx == 0) - { - xfree (str_list); - return NULL; - } - else - return *str_list; + return str_list; } /* Add the printed expression EXP to *LIST. */ @@ -1513,14 +1497,12 @@ encode_actions (struct bp_location *tloc, /* Render all actions into gdb protocol. */ void -encode_actions_rsp (struct bp_location *tloc, char ***tdp_actions, - char ***stepping_actions) +encode_actions_rsp (struct bp_location *tloc, + std::vector<std::string> *tdp_actions, + std::vector<std::string> *stepping_actions) { struct collection_list tracepoint_list, stepping_list; - *tdp_actions = NULL; - *stepping_actions = NULL; - encode_actions (tloc, &tracepoint_list, &stepping_list); *tdp_actions = tracepoint_list.stringify (); |