mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-25 04:49:54 +08:00
Use std::vector in uploaded_tp
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.
This commit is contained in:
@ -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>
|
2018-03-30 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* solib-svr4.c (lm_info_read): Use gdb::byte_vector. Return
|
* solib-svr4.c (lm_info_read): Use gdb::byte_vector. Return
|
||||||
|
@ -14738,11 +14738,13 @@ static int next_cmd;
|
|||||||
static char *
|
static char *
|
||||||
read_uploaded_action (void)
|
read_uploaded_action (void)
|
||||||
{
|
{
|
||||||
char *rslt;
|
char *rslt = nullptr;
|
||||||
|
|
||||||
VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
|
if (next_cmd < this_utp->cmd_strings.size ())
|
||||||
|
{
|
||||||
next_cmd++;
|
rslt = this_utp->cmd_strings[next_cmd];
|
||||||
|
next_cmd++;
|
||||||
|
}
|
||||||
|
|
||||||
return rslt;
|
return rslt;
|
||||||
}
|
}
|
||||||
@ -14814,7 +14816,7 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
|
|||||||
special-purpose "reader" function and call the usual command line
|
special-purpose "reader" function and call the usual command line
|
||||||
reader, then pass the result to the breakpoint command-setting
|
reader, then pass the result to the breakpoint command-setting
|
||||||
function. */
|
function. */
|
||||||
if (!VEC_empty (char_ptr, utp->cmd_strings))
|
if (!utp->cmd_strings.empty ())
|
||||||
{
|
{
|
||||||
command_line_up cmd_list;
|
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));
|
breakpoint_set_commands (tp, std::move (cmd_list));
|
||||||
}
|
}
|
||||||
else if (!VEC_empty (char_ptr, utp->actions)
|
else if (!utp->actions.empty ()
|
||||||
|| !VEC_empty (char_ptr, utp->step_actions))
|
|| !utp->step_actions.empty ())
|
||||||
warning (_("Uploaded tracepoint %d actions "
|
warning (_("Uploaded tracepoint %d actions "
|
||||||
"have no source form, ignoring them"),
|
"have no source form, ignoring them"),
|
||||||
utp->number);
|
utp->number);
|
||||||
|
18
gdb/ctf.c
18
gdb/ctf.c
@ -530,8 +530,6 @@ ctf_write_uploaded_tp (struct trace_file_writer *self,
|
|||||||
int64_t int64;
|
int64_t int64;
|
||||||
uint32_t u32;
|
uint32_t u32;
|
||||||
const gdb_byte zero = 0;
|
const gdb_byte zero = 0;
|
||||||
int a;
|
|
||||||
char *act;
|
|
||||||
|
|
||||||
/* Event Id. */
|
/* Event Id. */
|
||||||
int32 = CTF_EVENT_ID_TP_DEF;
|
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);
|
ctf_save_write (&writer->tcs, &zero, 1);
|
||||||
|
|
||||||
/* actions */
|
/* actions */
|
||||||
u32 = VEC_length (char_ptr, tp->actions);
|
u32 = tp->actions.size ();
|
||||||
ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
|
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);
|
ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
|
||||||
|
|
||||||
/* step_actions */
|
/* 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);
|
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);
|
ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
|
||||||
|
|
||||||
/* at_string */
|
/* at_string */
|
||||||
@ -593,9 +591,9 @@ ctf_write_uploaded_tp (struct trace_file_writer *self,
|
|||||||
ctf_save_write (&writer->tcs, &zero, 1);
|
ctf_save_write (&writer->tcs, &zero, 1);
|
||||||
|
|
||||||
/* cmd_strings */
|
/* 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);
|
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);
|
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 \
|
const struct bt_definition *element \
|
||||||
= bt_ctf_get_index ((EVENT), def, i); \
|
= bt_ctf_get_index ((EVENT), def, i); \
|
||||||
\
|
\
|
||||||
VEC_safe_push (char_ptr, (VAR)->ARRAY, \
|
(VAR)->ARRAY.push_back \
|
||||||
xstrdup (bt_ctf_get_string (element))); \
|
(xstrdup (bt_ctf_get_string (element))); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
while (0)
|
while (0)
|
||||||
|
@ -221,8 +221,6 @@ tfile_write_uploaded_tp (struct trace_file_writer *self,
|
|||||||
{
|
{
|
||||||
struct tfile_trace_file_writer *writer
|
struct tfile_trace_file_writer *writer
|
||||||
= (struct tfile_trace_file_writer *) self;
|
= (struct tfile_trace_file_writer *) self;
|
||||||
int a;
|
|
||||||
char *act;
|
|
||||||
char buf[MAX_TRACE_UPLOAD];
|
char buf[MAX_TRACE_UPLOAD];
|
||||||
|
|
||||||
fprintf (writer->fp, "tp T%x:%s:%c:%x:%x",
|
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,
|
":X%x,%s", (unsigned int) strlen (utp->cond) / 2,
|
||||||
utp->cond);
|
utp->cond);
|
||||||
fprintf (writer->fp, "\n");
|
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",
|
fprintf (writer->fp, "tp A%x:%s:%s\n",
|
||||||
utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
|
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",
|
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);
|
||||||
if (utp->at_string)
|
if (utp->at_string)
|
||||||
@ -254,7 +252,7 @@ tfile_write_uploaded_tp (struct trace_file_writer *self,
|
|||||||
buf, MAX_TRACE_UPLOAD);
|
buf, MAX_TRACE_UPLOAD);
|
||||||
fprintf (writer->fp, "tp Z%s\n", buf);
|
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,
|
encode_source_string (utp->number, utp->addr, "cmd", act,
|
||||||
buf, MAX_TRACE_UPLOAD);
|
buf, MAX_TRACE_UPLOAD);
|
||||||
|
@ -3062,12 +3062,9 @@ get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp)
|
|||||||
if (utp->number == num && utp->addr == addr)
|
if (utp->number == num && utp->addr == addr)
|
||||||
return utp;
|
return utp;
|
||||||
|
|
||||||
utp = XCNEW (struct uploaded_tp);
|
utp = new uploaded_tp;
|
||||||
utp->number = num;
|
utp->number = num;
|
||||||
utp->addr = addr;
|
utp->addr = addr;
|
||||||
utp->actions = NULL;
|
|
||||||
utp->step_actions = NULL;
|
|
||||||
utp->cmd_strings = NULL;
|
|
||||||
utp->next = *utpp;
|
utp->next = *utpp;
|
||||||
*utpp = utp;
|
*utpp = utp;
|
||||||
|
|
||||||
@ -3082,7 +3079,7 @@ free_uploaded_tps (struct uploaded_tp **utpp)
|
|||||||
while (*utpp)
|
while (*utpp)
|
||||||
{
|
{
|
||||||
next_one = (*utpp)->next;
|
next_one = (*utpp)->next;
|
||||||
xfree (*utpp);
|
delete *utpp;
|
||||||
*utpp = next_one;
|
*utpp = next_one;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3599,12 +3596,12 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
|
|||||||
else if (piece == 'A')
|
else if (piece == 'A')
|
||||||
{
|
{
|
||||||
utp = get_uploaded_tp (num, addr, utpp);
|
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')
|
else if (piece == 'S')
|
||||||
{
|
{
|
||||||
utp = get_uploaded_tp (num, addr, utpp);
|
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')
|
else if (piece == 'Z')
|
||||||
{
|
{
|
||||||
@ -3628,7 +3625,7 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
|
|||||||
else if (startswith (srctype, "cond:"))
|
else if (startswith (srctype, "cond:"))
|
||||||
utp->cond_string = xstrdup (buf);
|
utp->cond_string = xstrdup (buf);
|
||||||
else if (startswith (srctype, "cmd:"))
|
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')
|
else if (piece == 'V')
|
||||||
{
|
{
|
||||||
|
@ -165,38 +165,38 @@ extern const char *stop_reason_names[];
|
|||||||
|
|
||||||
struct uploaded_tp
|
struct uploaded_tp
|
||||||
{
|
{
|
||||||
int number;
|
int number = 0;
|
||||||
enum bptype type;
|
enum bptype type = bp_none;
|
||||||
ULONGEST addr;
|
ULONGEST addr = 0;
|
||||||
int enabled;
|
int enabled = 0;
|
||||||
int step;
|
int step = 0;
|
||||||
int pass;
|
int pass = 0;
|
||||||
int orig_size;
|
int orig_size = 0;
|
||||||
|
|
||||||
/* String that is the encoded form of the tracepoint's condition. */
|
/* 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
|
/* Vectors of strings that are the encoded forms of a tracepoint's
|
||||||
actions. */
|
actions. */
|
||||||
VEC(char_ptr) *actions;
|
std::vector<char *> actions;
|
||||||
VEC(char_ptr) *step_actions;
|
std::vector<char *> step_actions;
|
||||||
|
|
||||||
/* The original string defining the location of the tracepoint. */
|
/* The original string defining the location of the tracepoint. */
|
||||||
char *at_string;
|
char *at_string = nullptr;
|
||||||
|
|
||||||
/* The original string defining the tracepoint's condition. */
|
/* The original string defining the tracepoint's condition. */
|
||||||
char *cond_string;
|
char *cond_string = nullptr;
|
||||||
|
|
||||||
/* List of original strings defining the tracepoint's actions. */
|
/* 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. */
|
/* The tracepoint's current hit count. */
|
||||||
int hit_count;
|
int hit_count = 0;
|
||||||
|
|
||||||
/* The tracepoint's current traceframe usage. */
|
/* 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. */
|
/* Struct recording info about trace state variables on the target. */
|
||||||
|
Reference in New Issue
Block a user