+2019-01-10 Pedro Alves <palves@redhat.com>
+
+ * breakpoint.c (read_uploaded_action)
+ (create_tracepoint_from_upload): Adjust to use
+ gdb::unique_xmalloc_ptr.
+ * ctf.c (ctf_write_uploaded_tp):
+ (SET_ARRAY_FIELD): Use emplace_back.
+ (SET_STRING_FIELD): Adjust to use gdb::unique_xmalloc_ptr.
+ * tracefile-tfile.c (tfile_write_uploaded_tp):
+ * tracepoint.c (parse_tracepoint_definition): Adjust to use
+ gdb::unique_xmalloc_ptr.
+ * tracepoint.h (struct uploaded_tp) <cond, actions, step_actions,
+ at_string, cond_string, cmd_strings>: Replace char pointers
+ with gdb::unique_xmalloc_ptr.
+
2019-01-10 Pedro Alves <palves@redhat.com>
* solib-target.c (library_list_start_library): Don't xstrdup name.
if (next_cmd < this_utp->cmd_strings.size ())
{
- rslt = this_utp->cmd_strings[next_cmd];
+ rslt = this_utp->cmd_strings[next_cmd].get ();
next_cmd++;
}
struct tracepoint *tp;
if (utp->at_string)
- addr_str = utp->at_string;
+ addr_str = utp->at_string.get ();
else
{
/* In the absence of a source location, fall back to raw
current_language);
if (!create_breakpoint (get_current_arch (),
location.get (),
- utp->cond_string, -1, addr_str,
+ utp->cond_string.get (), -1, addr_str,
0 /* parse cond/thread */,
0 /* tempflag */,
utp->type /* type_wanted */,
/* condition */
if (tp->cond != NULL)
- ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond, strlen (tp->cond));
+ ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond.get (),
+ strlen (tp->cond.get ()));
ctf_save_write (&writer->tcs, &zero, 1);
/* actions */
u32 = tp->actions.size ();
ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
- for (char *act : tp->actions)
- ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
+ for (const auto &act : tp->actions)
+ ctf_save_write (&writer->tcs, (gdb_byte *) act.get (),
+ strlen (act.get ()) + 1);
/* step_actions */
u32 = tp->step_actions.size ();
ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
- for (char *act : tp->step_actions)
- ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
+ for (const auto &act : tp->step_actions)
+ ctf_save_write (&writer->tcs, (gdb_byte *) act.get (),
+ strlen (act.get ()) + 1);
/* at_string */
if (tp->at_string != NULL)
- ctf_save_write (&writer->tcs, (gdb_byte *) tp->at_string,
- strlen (tp->at_string));
+ ctf_save_write (&writer->tcs, (gdb_byte *) tp->at_string.get (),
+ strlen (tp->at_string.get ()));
ctf_save_write (&writer->tcs, &zero, 1);
/* cond_string */
if (tp->cond_string != NULL)
- ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond_string,
- strlen (tp->cond_string));
+ ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond_string.get (),
+ strlen (tp->cond_string.get ()));
ctf_save_write (&writer->tcs, &zero, 1);
/* cmd_strings */
u32 = tp->cmd_strings.size ();
ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
- for (char *act : tp->cmd_strings)
- ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
+ for (const auto &act : tp->cmd_strings)
+ ctf_save_write (&writer->tcs, (gdb_byte *) act.get (),
+ strlen (act.get ()) + 1);
}
const struct bt_definition *element \
= bt_ctf_get_index ((EVENT), def, i); \
\
- (VAR)->ARRAY.push_back \
+ (VAR)->ARRAY.emplace_back \
(xstrdup (bt_ctf_get_string (element))); \
} \
} \
#FIELD)); \
\
if (strlen (p) > 0) \
- (VAR)->FIELD = xstrdup (p); \
+ (VAR)->FIELD.reset (xstrdup (p)); \
else \
(VAR)->FIELD = NULL; \
} \
fprintf (writer->fp, ":F%x", utp->orig_size);
if (utp->cond)
fprintf (writer->fp,
- ":X%x,%s", (unsigned int) strlen (utp->cond) / 2,
- utp->cond);
+ ":X%x,%s", (unsigned int) strlen (utp->cond.get ()) / 2,
+ utp->cond.get ());
fprintf (writer->fp, "\n");
- for (char *act : utp->actions)
+ for (const auto &act : utp->actions)
fprintf (writer->fp, "tp A%x:%s:%s\n",
- utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
- for (char *act : utp->step_actions)
+ utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act.get ());
+ for (const auto &act : utp->step_actions)
fprintf (writer->fp, "tp S%x:%s:%s\n",
- utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
+ utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act.get ());
if (utp->at_string)
{
encode_source_string (utp->number, utp->addr,
- "at", utp->at_string, buf, MAX_TRACE_UPLOAD);
+ "at", utp->at_string.get (),
+ buf, MAX_TRACE_UPLOAD);
fprintf (writer->fp, "tp Z%s\n", buf);
}
if (utp->cond_string)
{
encode_source_string (utp->number, utp->addr,
- "cond", utp->cond_string,
+ "cond", utp->cond_string.get (),
buf, MAX_TRACE_UPLOAD);
fprintf (writer->fp, "tp Z%s\n", buf);
}
- for (char *act : utp->cmd_strings)
+ for (const auto &act : utp->cmd_strings)
{
- encode_source_string (utp->number, utp->addr, "cmd", act,
+ encode_source_string (utp->number, utp->addr, "cmd", act.get (),
buf, MAX_TRACE_UPLOAD);
fprintf (writer->fp, "tp Z%s\n", buf);
}
if (b->type == utp->type
&& t->step_count == utp->step
&& t->pass_count == utp->pass
- && cond_string_is_same (t->cond_string, utp->cond_string)
+ && cond_string_is_same (t->cond_string,
+ utp->cond_string.get ())
/* FIXME also test actions. */
)
{
int enabled, end;
enum bptype type;
const char *srctype;
- char *cond, *buf;
+ char *buf;
struct uploaded_tp *utp = NULL;
p = line;
p++; /* skip a colon */
if (piece == 'T')
{
+ gdb::unique_xmalloc_ptr<char[]> cond;
+
enabled = (*p++ == 'E');
p++; /* skip a colon */
p = unpack_varlen_hex (p, &step);
p++; /* skip a colon */
p = unpack_varlen_hex (p, &pass);
type = bp_tracepoint;
- cond = NULL;
/* Thumb through optional fields. */
while (*p == ':')
{
p++;
p = unpack_varlen_hex (p, &xlen);
p++; /* skip a comma */
- cond = (char *) xmalloc (2 * xlen + 1);
- strncpy (cond, p, 2 * xlen);
+ cond.reset ((char *) xmalloc (2 * xlen + 1));
+ strncpy (&cond[0], p, 2 * xlen);
cond[2 * xlen] = '\0';
p += 2 * xlen;
}
utp->enabled = enabled;
utp->step = step;
utp->pass = pass;
- utp->cond = cond;
+ utp->cond = std::move (cond);
}
else if (piece == 'A')
{
utp = get_uploaded_tp (num, addr, utpp);
- utp->actions.push_back (xstrdup (p));
+ utp->actions.emplace_back (xstrdup (p));
}
else if (piece == 'S')
{
utp = get_uploaded_tp (num, addr, utpp);
- utp->step_actions.push_back (xstrdup (p));
+ utp->step_actions.emplace_back (xstrdup (p));
}
else if (piece == 'Z')
{
buf[end] = '\0';
if (startswith (srctype, "at:"))
- utp->at_string = xstrdup (buf);
+ utp->at_string.reset (xstrdup (buf));
else if (startswith (srctype, "cond:"))
- utp->cond_string = xstrdup (buf);
+ utp->cond_string.reset (xstrdup (buf));
else if (startswith (srctype, "cmd:"))
- utp->cmd_strings.push_back (xstrdup (buf));
+ utp->cmd_strings.emplace_back (xstrdup (buf));
}
else if (piece == 'V')
{
int orig_size = 0;
/* String that is the encoded form of the tracepoint's condition. */
- char *cond = nullptr;
+ gdb::unique_xmalloc_ptr<char[]> cond;
/* Vectors of strings that are the encoded forms of a tracepoint's
actions. */
- std::vector<char *> actions;
- std::vector<char *> step_actions;
+ std::vector<gdb::unique_xmalloc_ptr<char[]>> actions;
+ std::vector<gdb::unique_xmalloc_ptr<char[]>> step_actions;
/* The original string defining the location of the tracepoint. */
- char *at_string = nullptr;
+ gdb::unique_xmalloc_ptr<char[]> at_string;
/* The original string defining the tracepoint's condition. */
- char *cond_string = nullptr;
+ gdb::unique_xmalloc_ptr<char[]> cond_string;
/* List of original strings defining the tracepoint's actions. */
- std::vector<char *> cmd_strings;
+ std::vector<gdb::unique_xmalloc_ptr<char[]>> cmd_strings;
/* The tracepoint's current hit count. */
int hit_count = 0;