Fix build failure in inf-ptrace.c.
[binutils-gdb.git] / gdb / tracepoint.c
index 2e3e2e84f5c11266055ffe0611671a1703184267..fd7c1616409d0a24ed5863f274f360e6339dd0db 100644 (file)
@@ -525,6 +525,12 @@ collect_pseudocommand (char *args, int from_tty)
   error (_("This command can only be used in a tracepoint actions list."));
 }
 
+static void
+teval_pseudocommand (char *args, int from_tty)
+{
+  error (_("This command can only be used in a tracepoint actions list."));
+}
+
 /* Enter a list of actions for a tracepoint.  */
 static void
 trace_actions_command (char *args, int from_tty)
@@ -761,6 +767,34 @@ validate_actionline (char **line, struct breakpoint *t)
       while (p && *p++ == ',');
       return GENERIC;
     }
+  else if (cmd_cfunc_eq (c, teval_pseudocommand))
+    {
+      struct agent_expr *aexpr;
+
+      do
+       {                       /* repeat over a comma-separated list */
+         QUIT;                 /* allow user to bail out with ^C */
+         while (isspace ((int) *p))
+           p++;
+
+         /* Only expressions are allowed for this action.  */
+         exp = parse_exp_1 (&p, block_for_pc (t->loc->address), 1);
+         old_chain = make_cleanup (free_current_contents, &exp);
+
+         /* We have something to evaluate, make sure that the expr to
+            bytecode translator can handle it and that it's not too
+            long.  */
+         aexpr = gen_eval_for_expr (t->loc->address, exp);
+         make_cleanup_free_agent_expr (aexpr);
+
+         if (aexpr->len > MAX_AGENT_EXPR_LEN)
+           error (_("expression too complicated, try simplifying"));
+
+         do_cleanups (old_chain);
+       }
+      while (p && *p++ == ',');
+      return GENERIC;
+    }
   else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
     {
       char *steparg;           /* in case warning is necessary */
@@ -1464,6 +1498,46 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
            }
          while (action_exp && *action_exp++ == ',');
        }                       /* if */
+      else if (cmd_cfunc_eq (cmd, teval_pseudocommand))
+       {
+         do
+           {                   /* repeat over a comma-separated list */
+             QUIT;             /* allow user to bail out with ^C */
+             while (isspace ((int) *action_exp))
+               action_exp++;
+
+               {
+                 unsigned long addr, len;
+                 struct cleanup *old_chain = NULL;
+                 struct cleanup *old_chain1 = NULL;
+                 struct agent_reqs areqs;
+
+                 exp = parse_exp_1 (&action_exp, 
+                                    block_for_pc (t->loc->address), 1);
+                 old_chain = make_cleanup (free_current_contents, &exp);
+
+                 aexpr = gen_eval_for_expr (t->loc->address, exp);
+                 old_chain1 = make_cleanup_free_agent_expr (aexpr);
+
+                 ax_reqs (aexpr, &areqs);
+                 if (areqs.flaw != agent_flaw_none)
+                   error (_("malformed expression"));
+
+                 if (areqs.min_height < 0)
+                   error (_("gdb: Internal error: expression has min height < 0"));
+                 if (areqs.max_height > 20)
+                   error (_("expression too complicated, try simplifying"));
+
+                 discard_cleanups (old_chain1);
+                 /* Even though we're not officially collecting, add
+                    to the collect list anyway.  */
+                 add_aexpr (collect, aexpr);
+
+                 do_cleanups (old_chain);
+               }               /* do */
+           }
+         while (action_exp && *action_exp++ == ',');
+       }                       /* if */
       else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
        {
          collect = &stepping_list;
@@ -1736,6 +1810,18 @@ trace_status_command (char *args, int from_tty)
 
       /* exported for use by the GUI */
       trace_running_p = (target_buf[1] == '1');
+
+      if (trace_running_p)
+       printf_filtered (_("Trace is running on the target.\n"));
+      else
+       printf_filtered (_("Trace is not running on the target.\n"));
+
+      if (traceframe_number >= 0)
+       printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
+                        traceframe_number, tracepoint_number);
+      else
+       printf_filtered (_("Not looking at any trace frame.\n"));
+
     }
   else
     error (_("Trace can only be run on remote targets."));
@@ -1863,6 +1949,9 @@ trace_find_command (char *args, int from_tty)
 
   if (target_is_remote ())
     {
+      if (trace_running_p)
+       error ("May not look at trace frames while trace is running.");
+
       if (deprecated_trace_find_hook)
        deprecated_trace_find_hook (args, from_tty);
 
@@ -1925,6 +2014,9 @@ trace_find_pc_command (char *args, int from_tty)
 
   if (target_is_remote ())
     {
+      if (trace_running_p)
+       error ("May not look at trace frames while trace is running.");
+
       if (args == 0 || *args == 0)
        pc = regcache_read_pc (get_current_regcache ());
       else
@@ -1946,6 +2038,9 @@ trace_find_tracepoint_command (char *args, int from_tty)
 
   if (target_is_remote ())
     {
+      if (trace_running_p)
+       error ("May not look at trace frames while trace is running.");
+
       if (args == 0 || *args == 0)
        {
          if (tracepoint_number == -1)
@@ -1982,6 +2077,9 @@ trace_find_line_command (char *args, int from_tty)
 
   if (target_is_remote ())
     {
+      if (trace_running_p)
+       error ("May not look at trace frames while trace is running.");
+
       if (args == 0 || *args == 0)
        {
          sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
@@ -2077,6 +2175,9 @@ trace_find_range_command (char *args, int from_tty)
 
   if (target_is_remote ())
     {
+      if (trace_running_p)
+       error ("May not look at trace frames while trace is running.");
+
       if (args == 0 || *args == 0)
        { /* XXX FIXME: what should default behavior be?  */
          printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
@@ -2116,6 +2217,9 @@ trace_find_outside_command (char *args, int from_tty)
 
   if (target_is_remote ())
     {
+      if (trace_running_p)
+       error ("May not look at trace frames while trace is running.");
+
       if (args == 0 || *args == 0)
        { /* XXX FIXME: what should default behavior be? */
          printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
@@ -2594,6 +2698,12 @@ Also accepts the following special arguments:\n\
     $locals -- all variables local to the block/function scope.\n\
 Note: this command can only be used in a tracepoint \"actions\" list."));
 
+  add_com ("teval", class_trace, teval_pseudocommand, _("\
+Specify one or more expressions to be evaluated at a tracepoint.\n\
+Accepts a comma-separated list of (one or more) expressions.\n\
+The result of each evaluation will be discarded.\n\
+Note: this command can only be used in a tracepoint \"actions\" list."));
+
   add_com ("actions", class_trace, trace_actions_command, _("\
 Specify the actions to be taken at a tracepoint.\n\
 Tracepoint actions may include collecting of specified data, \n\