This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add default-collect for tracepoints


This patch adds a default-collect variable that is a list of expressions that every tracepoint should collect. It is a minor convenience in that it is entirely equivalent to a first collect action attached to every tracepoint; but in a multiple-tracepoint scenario, it is frequently useful to know that registers are always available, or that a global timestamp was always collected. It is also handy to be able to affect every tracepoint's action list just by changing this variable.

As with other changes in this area, it has been mostly tested with our inhouse target agent; full FSF testsuite will need the queued-up gdbserver patches for tracepoints.

Stan

2009-12-29 Stan Shebs <stan@codesourcery.com>

   Add default-collect variable.
   * tracepoint.c (default_collect): New global.
   (encode_actions): Use it.
   (download_tracepoint): Test it, for otherwise
   action-less tracepoints.
   (_initialize_tracepoint): Add set/show.
   * NEWS: Mention default-collect.

* gdb.texinfo (Tracepoint Actions): Describe default-collect.
* gdb.trace/actions.exp: Test default-collect.



Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.342
diff -p -r1.342 NEWS
*** NEWS	28 Dec 2009 23:39:08 -0000	1.342
--- NEWS	29 Dec 2009 18:47:24 -0000
*************** show follow-exec-mode
*** 105,110 ****
--- 105,116 ----
    creates a new one.  This is useful to be able to restart the old
    executable after the inferior having done an exec call.
  
+ set default-collect EXPR, ...
+ show default-collect
+    Define a list of expressions to be collected at each tracepoint.
+    This is a useful way to ensure essential items are not overlooked,
+    such as registers or a critical global variable.
+ 
  * New remote packets
  
  QTDV
Index: tracepoint.c
===================================================================
RCS file: /cvs/src/src/gdb/tracepoint.c,v
retrieving revision 1.129
diff -p -r1.129 tracepoint.c
*** tracepoint.c	28 Dec 2009 23:39:08 -0000	1.129
--- tracepoint.c	29 Dec 2009 18:47:24 -0000
*************** static struct symtab_and_line traceframe
*** 140,148 ****
  /* Tracing command lists */
  static struct cmd_list_element *tfindlist;
  
  static char *target_buf;
  static long target_buf_size;
! 
  /* ======= Important command functions: ======= */
  static void trace_actions_command (char *, int);
  static void trace_start_command (char *, int);
--- 140,151 ----
  /* Tracing command lists */
  static struct cmd_list_element *tfindlist;
  
+ /* List of expressions to collect by default at each tracepoint hit.  */
+ static char *default_collect = "";
+ 
  static char *target_buf;
  static long target_buf_size;
!   
  /* ======= Important command functions: ======= */
  static void trace_actions_command (char *, int);
  static void trace_start_command (char *, int);
*************** encode_actions (struct breakpoint *t, ch
*** 1285,1291 ****
    struct agent_expr *aexpr;
    int frame_reg;
    LONGEST frame_offset;
! 
  
    clear_collection_list (&tracepoint_list);
    clear_collection_list (&stepping_list);
--- 1288,1295 ----
    struct agent_expr *aexpr;
    int frame_reg;
    LONGEST frame_offset;
!   char *default_collect_line = NULL;
!   struct action_line *default_collect_action = NULL;
  
    clear_collection_list (&tracepoint_list);
    clear_collection_list (&stepping_list);
*************** encode_actions (struct breakpoint *t, ch
*** 1297,1303 ****
    gdbarch_virtual_frame_pointer (t->gdbarch,
  				 t->loc->address, &frame_reg, &frame_offset);
  
!   for (action = t->actions; action; action = action->next)
      {
        QUIT;			/* allow user to bail out with ^C */
        action_exp = action->action;
--- 1301,1332 ----
    gdbarch_virtual_frame_pointer (t->gdbarch,
  				 t->loc->address, &frame_reg, &frame_offset);
  
!   action = t->actions;
! 
!   /* If there are default expressions to collect, make up a collect
!      action and prepend to the action list to encode.  Note that since
!      validation is per-tracepoint (local var "xyz" might be valid for
!      one tracepoint and not another, etc), we make up the action on
!      the fly, and don't cache it.  */
!   if (*default_collect)
!     {
!       char *line;
!       enum actionline_type linetype;
! 
!       default_collect_line = xmalloc (12 + strlen (default_collect));
!       sprintf (default_collect_line, "collect %s", default_collect);
!       line = default_collect_line;
!       linetype = validate_actionline (&line, t);
!       if (linetype != BADLINE)
! 	{
! 	  default_collect_action = xmalloc (sizeof (struct action_line));
! 	  default_collect_action->next = t->actions;
! 	  default_collect_action->action = line;
! 	  action = default_collect_action;
! 	}
!     }
! 
!   for (; action; action = action->next)
      {
        QUIT;			/* allow user to bail out with ^C */
        action_exp = action->action;
*************** encode_actions (struct breakpoint *t, ch
*** 1454,1459 ****
--- 1483,1491 ----
  					    tdp_buff);
    *stepping_actions = stringify_collection_list (&stepping_list, 
  						 step_buff);
+ 
+   xfree (default_collect_line);
+   xfree (default_collect_action);
  }
  
  static void
*************** download_tracepoint (struct breakpoint *
*** 1616,1629 ****
  	warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t->number);
      }
  
!   if (t->actions)
      strcat (buf, "-");
    putpkt (buf);
    remote_get_noisy_reply (&target_buf, &target_buf_size);
    if (strcmp (target_buf, "OK"))
      error (_("Target does not support tracepoints."));
  
!   if (!t->actions)
      return;
  
    encode_actions (t, &tdp_actions, &stepping_actions);
--- 1648,1661 ----
  	warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t->number);
      }
  
!   if (t->actions || *default_collect)
      strcat (buf, "-");
    putpkt (buf);
    remote_get_noisy_reply (&target_buf, &target_buf_size);
    if (strcmp (target_buf, "OK"))
      error (_("Target does not support tracepoints."));
  
!   if (!t->actions && !*default_collect)
      return;
  
    encode_actions (t, &tdp_actions, &stepping_actions);
*************** Tracepoint actions may include collectin
*** 2568,2573 ****
--- 2600,2613 ----
  single-stepping, or enabling/disabling other tracepoints, \n\
  depending on target's capabilities."));
  
+   default_collect = xstrdup ("");
+   add_setshow_string_cmd ("default-collect", class_trace,
+ 			  &default_collect, _("\
+ Set the list of expressions to collect by default"), _("\
+ Show the list of expressions to collect by default"), NULL,
+ 			  NULL, NULL,
+ 			  &setlist, &showlist);
+ 
    target_buf_size = 2048;
    target_buf = xmalloc (target_buf_size);
  }
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.651
diff -p -r1.651 gdb.texinfo
*** doc/gdb.texinfo	28 Dec 2009 23:39:09 -0000	1.651
--- doc/gdb.texinfo	29 Dec 2009 18:47:24 -0000
*************** its own @code{end} command):
*** 9643,9648 ****
--- 9643,9664 ----
  @noindent
  You may abbreviate @code{while-stepping} as @code{ws} or
  @code{stepping}.
+ 
+ @item set default-collect @var{expr1}, @var{expr2}, @dots{}
+ @kindex set default-collect
+ @cindex default collection action
+ This variable is a list of expressions to collect at each tracepoint
+ hit.  It is effectively an additional @code{collect} action prepended
+ to every tracepoint action list.  The expressions are parsed
+ individually for each tracepoint, so for instance a variable named
+ @code{xyz} may be interpreted as a global for one tracepoint, and a
+ local for another, as appropriate to the tracepoint's location.
+ 
+ @item show default-collect
+ @kindex show default-collect
+ Show the list of expressions that are collected by default at each
+ tracepoint hit.
+ 
  @end table
  
  @node Listing Tracepoints
Index: testsuite/gdb.trace/actions.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.trace/actions.exp,v
retrieving revision 1.12
diff -p -r1.12 actions.exp
*** testsuite/gdb.trace/actions.exp	5 Nov 2009 20:06:03 -0000	1.12
--- testsuite/gdb.trace/actions.exp	29 Dec 2009 18:47:24 -0000
*************** gdb_test "help while-stepping" \
*** 203,205 ****
--- 203,214 ----
  gdb_test "help end" "Ends a list of commands or actions.*" \
  			"5.8d: help end"
  
+ # 5.9 default-collect
+ 
+ gdb_test "set default-collect gdb_char_test, gdb_long_test - 100" \
+     "" \
+     "5.9a: set default-collect"
+ 
+ gdb_test "show default-collect" \
+     "The list of expressions to collect by default is \"gdb_char_test, gdb_long_test - 100\"..*" \
+     "5.9b: show default-collect"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]