summaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-11-08 19:42:08 -0500
committerSimon Marchi <simon.marchi@ericsson.com>2017-11-08 19:42:08 -0500
commitb44ec61915f10a953ca85da5bf7a97911554f1aa (patch)
tree421334d6ae1d6e425e1ee1d496979304d7b75067 /gdb/remote.c
parentdc8d2d90da3f191ae0461900ab98e3b29cc2b280 (diff)
downloadbinutils-gdb-b44ec61915f10a953ca85da5bf7a97911554f1aa.tar.gz
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/remote.c')
-rw-r--r--gdb/remote.c100
1 files changed, 37 insertions, 63 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index 3bf0596e094..c6535626520 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -12289,28 +12289,6 @@ remote_trace_init (struct target_ops *self)
error (_("Target does not support this command."));
}
-static void free_actions_list (char **actions_list);
-static void free_actions_list_cleanup_wrapper (void *);
-static void
-free_actions_list_cleanup_wrapper (void *al)
-{
- free_actions_list ((char **) al);
-}
-
-static void
-free_actions_list (char **actions_list)
-{
- int ndx;
-
- if (actions_list == 0)
- return;
-
- for (ndx = 0; actions_list[ndx]; ndx++)
- xfree (actions_list[ndx]);
-
- xfree (actions_list);
-}
-
/* Recursive routine to walk through command list including loops, and
download packets for each command. */
@@ -12359,20 +12337,14 @@ remote_download_tracepoint (struct target_ops *self, struct bp_location *loc)
CORE_ADDR tpaddr;
char addrbuf[40];
char buf[BUF_SIZE];
- char **tdp_actions;
- char **stepping_actions;
- int ndx;
- struct cleanup *old_chain = NULL;
+ std::vector<std::string> tdp_actions;
+ std::vector<std::string> stepping_actions;
char *pkt;
struct breakpoint *b = loc->owner;
struct tracepoint *t = (struct tracepoint *) b;
struct remote_state *rs = get_remote_state ();
encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
- old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
- tdp_actions);
- (void) make_cleanup (free_actions_list_cleanup_wrapper,
- stepping_actions);
tpaddr = loc->address;
sprintf_vma (addrbuf, tpaddr);
@@ -12438,7 +12410,7 @@ remote_download_tracepoint (struct target_ops *self, struct bp_location *loc)
xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,",
aexpr->len);
pkt = buf + strlen (buf);
- for (ndx = 0; ndx < aexpr->len; ++ndx)
+ for (int ndx = 0; ndx < aexpr->len; ++ndx)
pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
*pkt = '\0';
}
@@ -12455,39 +12427,43 @@ remote_download_tracepoint (struct target_ops *self, struct bp_location *loc)
error (_("Target does not support tracepoints."));
/* do_single_steps (t); */
- if (tdp_actions)
+ for (auto action_it = tdp_actions.begin ();
+ action_it != tdp_actions.end (); action_it++)
{
- for (ndx = 0; tdp_actions[ndx]; ndx++)
- {
- QUIT; /* Allow user to bail out with ^C. */
- xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
- b->number, addrbuf, /* address */
- tdp_actions[ndx],
- ((tdp_actions[ndx + 1] || stepping_actions)
- ? '-' : 0));
- putpkt (buf);
- remote_get_noisy_reply ();
- if (strcmp (rs->buf, "OK"))
- error (_("Error on target while setting tracepoints."));
- }
- }
- if (stepping_actions)
- {
- for (ndx = 0; stepping_actions[ndx]; ndx++)
- {
- QUIT; /* Allow user to bail out with ^C. */
- xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
- b->number, addrbuf, /* address */
- ((ndx == 0) ? "S" : ""),
- stepping_actions[ndx],
- (stepping_actions[ndx + 1] ? "-" : ""));
- putpkt (buf);
- remote_get_noisy_reply ();
- if (strcmp (rs->buf, "OK"))
- error (_("Error on target while setting tracepoints."));
- }
+ QUIT; /* Allow user to bail out with ^C. */
+
+ bool has_more = (action_it != tdp_actions.end ()
+ || !stepping_actions.empty ());
+
+ xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
+ b->number, addrbuf, /* address */
+ action_it->c_str (),
+ has_more ? '-' : 0);
+ putpkt (buf);
+ remote_get_noisy_reply ();
+ if (strcmp (rs->buf, "OK"))
+ error (_("Error on target while setting tracepoints."));
}
+ for (auto action_it = stepping_actions.begin ();
+ action_it != stepping_actions.end (); action_it++)
+ {
+ QUIT; /* Allow user to bail out with ^C. */
+
+ bool is_first = action_it == stepping_actions.begin ();
+ bool has_more = action_it != stepping_actions.end ();
+
+ xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
+ b->number, addrbuf, /* address */
+ is_first ? "S" : "",
+ action_it->c_str (),
+ has_more ? "-" : "");
+ putpkt (buf);
+ remote_get_noisy_reply ();
+ if (strcmp (rs->buf, "OK"))
+ error (_("Error on target while setting tracepoints."));
+ }
+
if (packet_support (PACKET_TracepointSource) == PACKET_ENABLE)
{
if (b->location != NULL)
@@ -12515,8 +12491,6 @@ remote_download_tracepoint (struct target_ops *self, struct bp_location *loc)
remote_download_command_source (b->number, loc->address,
breakpoint_commands (b));
}
-
- do_cleanups (old_chain);
}
static int