This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Use vectors in uploaded tracepoints
- From: Stan Shebs <stan at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 05 Apr 2010 12:46:08 -0700
- Subject: [PATCH] Use vectors in uploaded tracepoints
This patch changes the arrays of uploaded tracepoints into vectors,
clearing out some silly arbitary limits.
Despite being pretty obvious, I'm not committing immediately, because I
have a couple questions.
1. This is now the third place that has a "char_ptr" typedef for use
with vectors. Is there any reason not to consolidate into one typedef
in defs.h?
2. Should it be renamed to "char_p"? There is a quasi-standard of using
"_s" for struct and "_p" for pointer typedefs for vectors; but "char_p"
seems a little cryptic to me.
Stan
2010-04-05 Stan Shebs <stan@codesourcery.com>
* tracepoint.h (struct uploaded_string): Remove.
(char_ptr): Define.
(struct uploaded_tp): Use vectors for string arrays.
* tracepoint.c (trace_save): Use vectors of actions.
(parse_tracepoint_definition): Ditto.
(get_uploaded_tp): Clear vectors.
* breakpoint.c (create_tracepoint_from_upload): Use vectors.
(next_cmd): Change to an int.
(read_next_cmd): Use vector of command strings.
Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.478
diff -p -r1.478 breakpoint.c
*** breakpoint.c 5 Apr 2010 10:07:30 -0000 1.478
--- breakpoint.c 5 Apr 2010 19:37:10 -0000
*************** ftrace_command (char *arg, int from_tty)
*** 10348,10365 ****
list that was acquired during tracepoint uploading. */
static struct uploaded_tp *this_utp;
! static struct uploaded_string *next_cmd;
static char *
read_uploaded_action (void)
{
char *rslt;
! if (!next_cmd)
! return NULL;
! rslt = next_cmd->str;
! next_cmd = next_cmd->next;
return rslt;
}
--- 10348,10363 ----
list that was acquired during tracepoint uploading. */
static struct uploaded_tp *this_utp;
! static int next_cmd;
static char *
read_uploaded_action (void)
{
char *rslt;
! VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
! next_cmd++;
return rslt;
}
*************** create_tracepoint_from_upload (struct up
*** 10425,10442 ****
special-purpose "reader" function and call the usual command line
reader, then pass the result to the breakpoint command-setting
function. */
! if (utp->cmd_strings)
{
struct command_line *cmd_list;
this_utp = utp;
! next_cmd = utp->cmd_strings;
cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
breakpoint_set_commands (tp, cmd_list);
}
! else if (utp->numactions > 0 || utp->num_step_actions > 0)
warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
utp->number);
--- 10423,10441 ----
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))
{
struct command_line *cmd_list;
this_utp = utp;
! next_cmd = 0;
cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
breakpoint_set_commands (tp, cmd_list);
}
! else if (!VEC_empty (char_ptr, utp->actions)
! || !VEC_empty (char_ptr, utp->step_actions))
warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
utp->number);
Index: tracepoint.c
===================================================================
RCS file: /cvs/src/src/gdb/tracepoint.c,v
retrieving revision 1.171
diff -p -r1.171 tracepoint.c
*** tracepoint.c 4 Apr 2010 23:31:28 -0000 1.171
--- tracepoint.c 5 Apr 2010 19:37:10 -0000
*************** trace_save (const char *filename, int ta
*** 2537,2543 ****
struct uploaded_tp *uploaded_tps = NULL, *utp;
struct uploaded_tsv *uploaded_tsvs = NULL, *utsv;
int a;
! struct uploaded_string *cmd;
LONGEST gotten = 0;
ULONGEST offset = 0;
#define MAX_TRACE_UPLOAD 2000
--- 2537,2543 ----
struct uploaded_tp *uploaded_tps = NULL, *utp;
struct uploaded_tsv *uploaded_tsvs = NULL, *utsv;
int a;
! char *act;
LONGEST gotten = 0;
ULONGEST offset = 0;
#define MAX_TRACE_UPLOAD 2000
*************** trace_save (const char *filename, int ta
*** 2645,2658 ****
fprintf (fp, ":X%x,%s", (unsigned int) strlen (utp->cond) / 2,
utp->cond);
fprintf (fp, "\n");
! for (a = 0; a < utp->numactions; ++a)
fprintf (fp, "tp A%x:%s:%s\n",
! utp->number, phex_nz (utp->addr, sizeof (utp->addr)),
! utp->actions[a]);
! for (a = 0; a < utp->num_step_actions; ++a)
fprintf (fp, "tp S%x:%s:%s\n",
! utp->number, phex_nz (utp->addr, sizeof (utp->addr)),
! utp->step_actions[a]);
if (utp->at_string)
{
encode_source_string (utp->number, utp->addr,
--- 2645,2656 ----
fprintf (fp, ":X%x,%s", (unsigned int) strlen (utp->cond) / 2,
utp->cond);
fprintf (fp, "\n");
! for (a = 0; VEC_iterate (char_ptr, utp->actions, a, act); ++a)
fprintf (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->actions, a, act); ++a)
fprintf (fp, "tp S%x:%s:%s\n",
! utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
if (utp->at_string)
{
encode_source_string (utp->number, utp->addr,
*************** trace_save (const char *filename, int ta
*** 2665,2673 ****
"cond", utp->cond_string, buf, MAX_TRACE_UPLOAD);
fprintf (fp, "tp Z%s\n", buf);
}
! for (cmd = utp->cmd_strings; cmd; cmd = cmd->next)
{
! encode_source_string (utp->number, utp->addr, "cmd", cmd->str,
buf, MAX_TRACE_UPLOAD);
fprintf (fp, "tp Z%s\n", buf);
}
--- 2663,2671 ----
"cond", utp->cond_string, buf, MAX_TRACE_UPLOAD);
fprintf (fp, "tp Z%s\n", buf);
}
! for (a = 0; VEC_iterate (char_ptr, utp->cmd_strings, a, act); ++a)
{
! encode_source_string (utp->number, utp->addr, "cmd", act,
buf, MAX_TRACE_UPLOAD);
fprintf (fp, "tp Z%s\n", buf);
}
*************** get_uploaded_tp (int num, ULONGEST addr,
*** 2869,2874 ****
--- 2867,2875 ----
memset (utp, 0, sizeof (struct uploaded_tp));
utp->number = num;
utp->addr = addr;
+ utp->actions = NULL;
+ utp->step_actions = NULL;
+ utp->cmd_strings = NULL;
utp->next = *utpp;
*utpp = utp;
return utp;
*************** parse_tracepoint_definition (char *line,
*** 3423,3434 ****
else if (piece == 'A')
{
utp = get_uploaded_tp (num, addr, utpp);
! utp->actions[utp->numactions++] = xstrdup (p);
}
else if (piece == 'S')
{
utp = get_uploaded_tp (num, addr, utpp);
! utp->step_actions[utp->num_step_actions++] = xstrdup (p);
}
else if (piece == 'Z')
{
--- 3424,3435 ----
else if (piece == 'A')
{
utp = get_uploaded_tp (num, addr, utpp);
! VEC_safe_push (char_ptr, utp->actions, xstrdup (p));
}
else if (piece == 'S')
{
utp = get_uploaded_tp (num, addr, utpp);
! VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p));
}
else if (piece == 'Z')
{
*************** parse_tracepoint_definition (char *line,
*** 3452,3472 ****
else if (strncmp (srctype, "cond:", strlen ("cond:")) == 0)
utp->cond_string = xstrdup (buf);
else if (strncmp (srctype, "cmd:", strlen ("cmd:")) == 0)
! {
! /* FIXME consider using a vector? */
! struct uploaded_string *last, *newlast;
! newlast = (struct uploaded_string *) xmalloc (sizeof (struct uploaded_string));
! newlast->str = xstrdup (buf);
! newlast->next = NULL;
! if (utp->cmd_strings)
! {
! for (last = utp->cmd_strings; last->next; last = last->next)
! ;
! last->next = newlast;
! }
! else
! utp->cmd_strings = newlast;
! }
}
else
{
--- 3453,3459 ----
else if (strncmp (srctype, "cond:", strlen ("cond:")) == 0)
utp->cond_string = xstrdup (buf);
else if (strncmp (srctype, "cmd:", strlen ("cmd:")) == 0)
! VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf));
}
else
{
Index: tracepoint.h
===================================================================
RCS file: /cvs/src/src/gdb/tracepoint.h,v
retrieving revision 1.33
diff -p -r1.33 tracepoint.h
*** tracepoint.h 1 Apr 2010 22:57:25 -0000 1.33
--- tracepoint.h 5 Apr 2010 19:37:10 -0000
*************** extern char *default_collect;
*** 114,124 ****
/* Struct to collect random info about tracepoints on the target. */
! struct uploaded_string
! {
! char *str;
! struct uploaded_string *next;
! };
struct uploaded_tp
{
--- 114,121 ----
/* Struct to collect random info about tracepoints on the target. */
! typedef char *char_ptr;
! DEF_VEC_P (char_ptr);
struct uploaded_tp
{
*************** struct uploaded_tp
*** 129,139 ****
int step;
int pass;
int orig_size;
char *cond;
! int numactions;
! char *actions[100];
! int num_step_actions;
! char *step_actions[100];
/* The original string defining the location of the tracepoint. */
char *at_string;
--- 126,138 ----
int step;
int pass;
int orig_size;
+
+ /* String that is the encoded form of the tracepoint's condition. */
char *cond;
!
! /* Vectors of strings that are the encoded forms of a tracepoint's actions. */
! VEC(char_ptr) *actions;
! VEC(char_ptr) *step_actions;
/* The original string defining the location of the tracepoint. */
char *at_string;
*************** struct uploaded_tp
*** 142,148 ****
char *cond_string;
/* List of original strings defining the tracepoint's actions. */
! struct uploaded_string *cmd_strings;
struct uploaded_tp *next;
};
--- 141,147 ----
char *cond_string;
/* List of original strings defining the tracepoint's actions. */
! VEC(char_ptr) *cmd_strings;
struct uploaded_tp *next;
};