Fix build failure in inf-ptrace.c.
[binutils-gdb.git] / gdb / tracepoint.c
index 317d1238d3979fa33b22bae06bfde715bed4520d..fd7c1616409d0a24ed5863f274f360e6339dd0db 100644 (file)
@@ -19,6 +19,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include "symtab.h"
 #include "frame.h"
 #include "gdbtypes.h"
@@ -32,6 +33,8 @@
 #include "breakpoint.h"
 #include "tracepoint.h"
 #include "remote.h"
+extern int remote_supports_cond_tracepoints (void);
+extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
 #include "linespec.h"
 #include "regcache.h"
 #include "completer.h"
@@ -41,6 +44,7 @@
 #include "user-regs.h"
 #include "valprint.h"
 #include "gdbcore.h"
+#include "objfiles.h"
 
 #include "ax.h"
 #include "ax-gdb.h"
    large.  (400 - 31)/2 == 184 */
 #define MAX_AGENT_EXPR_LEN     184
 
+/* A hook used to notify the UI of tracepoint operations.  */
+
+void (*deprecated_trace_find_hook) (char *arg, int from_tty);
+void (*deprecated_trace_start_stop_hook) (int start, int from_tty);
 
 extern void (*deprecated_readline_begin_hook) (char *, ...);
 extern char *(*deprecated_readline_hook) (char *);
@@ -104,6 +112,19 @@ extern void output_command (char *, int);
 
 /* ======= Important global variables: ======= */
 
+/* The list of all trace state variables.  We don't retain pointers to
+   any of these for any reason - API is by name or number only - so it
+   works to have a vector of objects.  */
+
+typedef struct trace_state_variable tsv_s;
+DEF_VEC_O(tsv_s);
+
+static VEC(tsv_s) *tvariables;
+
+/* The next integer to assign to a variable.  */
+
+static int next_tsv_number = 1;
+
 /* Number of last traceframe collected.  */
 static int traceframe_number;
 
@@ -119,6 +140,12 @@ static struct symtab_and_line traceframe_sal;
 /* 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);
@@ -208,8 +235,7 @@ static void
 set_traceframe_num (int num)
 {
   traceframe_number = num;
-  set_internalvar (lookup_internalvar ("trace_frame"),
-                  value_from_longest (builtin_type_int32, (LONGEST) num));
+  set_internalvar_integer (lookup_internalvar ("trace_frame"), num);
 }
 
 /* Set tracepoint number to NUM.  */
@@ -217,8 +243,7 @@ static void
 set_tracepoint_num (int num)
 {
   tracepoint_number = num;
-  set_internalvar (lookup_internalvar ("tracepoint"),
-                  value_from_longest (builtin_type_int32, (LONGEST) num));
+  set_internalvar_integer (lookup_internalvar ("tracepoint"), num);
 }
 
 /* Set externally visible debug variables for querying/printing
@@ -229,24 +254,14 @@ set_traceframe_context (struct frame_info *trace_frame)
 {
   CORE_ADDR trace_pc;
 
-  static struct type *func_string, *file_string;
-  static struct type *func_range, *file_range;
-  struct value *func_val;
-  struct value *file_val;
-  int len;
-
   if (trace_frame == NULL)             /* Cease debugging any trace buffers.  */
     {
       traceframe_fun = 0;
       traceframe_sal.pc = traceframe_sal.line = 0;
       traceframe_sal.symtab = NULL;
-      set_internalvar (lookup_internalvar ("trace_func"),
-                      allocate_value (builtin_type_void));
-      set_internalvar (lookup_internalvar ("trace_file"),
-                      allocate_value (builtin_type_void));
-      set_internalvar (lookup_internalvar ("trace_line"),
-                      value_from_longest (builtin_type_int32,
-                                          (LONGEST) - 1));
+      clear_internalvar (lookup_internalvar ("trace_func"));
+      clear_internalvar (lookup_internalvar ("trace_file"));
+      set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
       return;
     }
 
@@ -257,52 +272,224 @@ set_traceframe_context (struct frame_info *trace_frame)
 
   /* Save linenumber as "$trace_line", a debugger variable visible to
      users.  */
-  set_internalvar (lookup_internalvar ("trace_line"),
-                  value_from_longest (builtin_type_int32,
-                                      (LONGEST) traceframe_sal.line));
+  set_internalvar_integer (lookup_internalvar ("trace_line"),
+                          traceframe_sal.line);
 
   /* Save func name as "$trace_func", a debugger variable visible to
      users.  */
-  if (traceframe_fun == NULL ||
-      SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
-    set_internalvar (lookup_internalvar ("trace_func"),
-                    allocate_value (builtin_type_void));
+  if (traceframe_fun == NULL
+      || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
+    clear_internalvar (lookup_internalvar ("trace_func"));
   else
-    {
-      len = strlen (SYMBOL_LINKAGE_NAME (traceframe_fun));
-      func_range = create_range_type (func_range,
-                                     builtin_type_int32, 0, len - 1);
-      func_string = create_array_type (func_string,
-                                      builtin_type_true_char, func_range);
-      func_val = allocate_value (func_string);
-      deprecated_set_value_type (func_val, func_string);
-      memcpy (value_contents_raw (func_val),
-             SYMBOL_LINKAGE_NAME (traceframe_fun),
-             len);
-      deprecated_set_value_modifiable (func_val, 0);
-      set_internalvar (lookup_internalvar ("trace_func"), func_val);
-    }
+    set_internalvar_string (lookup_internalvar ("trace_func"),
+                           SYMBOL_LINKAGE_NAME (traceframe_fun));
 
   /* Save file name as "$trace_file", a debugger variable visible to
      users.  */
-  if (traceframe_sal.symtab == NULL ||
-      traceframe_sal.symtab->filename == NULL)
-    set_internalvar (lookup_internalvar ("trace_file"),
-                    allocate_value (builtin_type_void));
+  if (traceframe_sal.symtab == NULL
+      || traceframe_sal.symtab->filename == NULL)
+    clear_internalvar (lookup_internalvar ("trace_file"));
   else
+    set_internalvar_string (lookup_internalvar ("trace_file"),
+                           traceframe_sal.symtab->filename);
+}
+
+/* Create a new trace state variable with the given name.  */
+
+struct trace_state_variable *
+create_trace_state_variable (const char *name)
+{
+  struct trace_state_variable tsv;
+
+  memset (&tsv, 0, sizeof (tsv));
+  tsv.name = name;
+  tsv.number = next_tsv_number++;
+  return VEC_safe_push (tsv_s, tvariables, &tsv);
+}
+
+/* Look for a trace state variable of the given name.  */
+
+struct trace_state_variable *
+find_trace_state_variable (const char *name)
+{
+  struct trace_state_variable *tsv;
+  int ix;
+
+  for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+    if (strcmp (name, tsv->name) == 0)
+      return tsv;
+
+  return NULL;
+}
+
+void
+delete_trace_state_variable (const char *name)
+{
+  struct trace_state_variable *tsv;
+  int ix;
+
+  for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+    if (strcmp (name, tsv->name) == 0)
+      {
+       VEC_unordered_remove (tsv_s, tvariables, ix);
+       return;
+      }
+
+  warning (_("No trace variable named \"$%s\", not deleting"), name);
+}
+
+/* The 'tvariable' command collects a name and optional expression to
+   evaluate into an initial value.  */
+
+void
+trace_variable_command (char *args, int from_tty)
+{
+  struct expression *expr;
+  struct cleanup *old_chain;
+  struct internalvar *intvar = NULL;
+  LONGEST initval = 0;
+  struct trace_state_variable *tsv;
+
+  if (!args || !*args)
+    error_no_arg (_("trace state variable name"));
+
+  /* All the possible valid arguments are expressions.  */
+  expr = parse_expression (args);
+  old_chain = make_cleanup (free_current_contents, &expr);
+
+  if (expr->nelts == 0)
+    error (_("No expression?"));
+
+  /* Only allow two syntaxes; "$name" and "$name=value".  */
+  if (expr->elts[0].opcode == OP_INTERNALVAR)
+    {
+      intvar = expr->elts[1].internalvar;
+    }
+  else if (expr->elts[0].opcode == BINOP_ASSIGN
+          && expr->elts[1].opcode == OP_INTERNALVAR)
+    {
+      intvar = expr->elts[2].internalvar;
+      initval = value_as_long (evaluate_subexpression_type (expr, 4));
+    }
+  else
+    error (_("Syntax must be $NAME [ = EXPR ]"));
+
+  if (!intvar)
+    error (_("No name given"));
+
+  if (strlen (internalvar_name (intvar)) <= 0)
+    error (_("Must supply a non-empty variable name"));
+
+  /* If the variable already exists, just change its initial value.  */
+  tsv = find_trace_state_variable (internalvar_name (intvar));
+  if (tsv)
+    {
+      tsv->initial_value = initval;
+      printf_filtered (_("Trace state variable $%s now has initial value %s.\n"),
+                      tsv->name, plongest (tsv->initial_value));
+      return;
+    }
+
+  /* Create a new variable.  */
+  tsv = create_trace_state_variable (internalvar_name (intvar));
+  tsv->initial_value = initval;
+
+  printf_filtered (_("Trace state variable $%s created, with initial value %s.\n"),
+                  tsv->name, plongest (tsv->initial_value));
+
+  do_cleanups (old_chain);
+}
+
+void
+delete_trace_variable_command (char *args, int from_tty)
+{
+  int i, ix;
+  char **argv;
+  struct cleanup *back_to;
+  struct trace_state_variable *tsv;
+
+  if (args == NULL)
+    {
+      if (query (_("Delete all trace state variables? ")))
+       VEC_free (tsv_s, tvariables);
+      dont_repeat ();
+      return;
+    }
+
+  argv = gdb_buildargv (args);
+  back_to = make_cleanup_freeargv (argv);
+
+  for (i = 0; argv[i] != NULL; i++)
     {
-      len = strlen (traceframe_sal.symtab->filename);
-      file_range = create_range_type (file_range,
-                                     builtin_type_int32, 0, len - 1);
-      file_string = create_array_type (file_string,
-                                      builtin_type_true_char, file_range);
-      file_val = allocate_value (file_string);
-      deprecated_set_value_type (file_val, file_string);
-      memcpy (value_contents_raw (file_val),
-             traceframe_sal.symtab->filename,
-             len);
-      deprecated_set_value_modifiable (file_val, 0);
-      set_internalvar (lookup_internalvar ("trace_file"), file_val);
+      if (*argv[i] == '$')
+       delete_trace_state_variable (argv[i] + 1);
+      else
+       warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv[i]);
+    }
+
+  do_cleanups (back_to);
+
+  dont_repeat ();
+}
+
+/* List all the trace state variables.  */
+
+static void
+tvariables_info (char *args, int from_tty)
+{
+  struct trace_state_variable *tsv;
+  int ix;
+  char *reply;
+  ULONGEST tval;
+
+  if (target_is_remote ())
+    {
+      char buf[20];
+
+      for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+       {
+         /* We don't know anything about the value until we get a
+            valid packet.  */
+         tsv->value_known = 0;
+         sprintf (buf, "qTV:%x", tsv->number);
+         putpkt (buf);
+         reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
+         if (reply && *reply)
+           {
+             if (*reply == 'V')
+               {
+                 unpack_varlen_hex (reply + 1, &tval);
+                 tsv->value = (LONGEST) tval;
+                 tsv->value_known = 1;
+               }
+             /* FIXME say anything about oddball replies? */
+           }
+       }
+    }
+
+  if (VEC_length (tsv_s, tvariables) == 0)
+    {
+      printf_filtered (_("No trace state variables.\n"));
+      return;
+    }
+
+  printf_filtered (_("Name\t\t  Initial\tCurrent\n"));
+
+  for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+    {
+      printf_filtered ("$%s", tsv->name);
+      print_spaces_filtered (17 - strlen (tsv->name), gdb_stdout);
+      printf_filtered ("%s ", plongest (tsv->initial_value));
+      print_spaces_filtered (11 - strlen (plongest (tsv->initial_value)), gdb_stdout);
+      if (tsv->value_known)
+       printf_filtered ("  %s", plongest (tsv->value));
+      else if (trace_running_p || traceframe_number >= 0)
+       /* The value is/was defined, but we don't have it.  */
+       printf_filtered (_("  <unknown>"));
+      else
+       /* It is not meaningful to ask about the value.  */
+       printf_filtered (_("  <undefined>"));
+      printf_filtered ("\n");
     }
 }
 
@@ -338,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)
@@ -574,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 */
@@ -760,7 +981,9 @@ add_memrange (struct collection_list *memranges,
 static void
 collect_symbol (struct collection_list *collect, 
                struct symbol *sym,
-               long frame_regno, long frame_offset)
+               struct gdbarch *gdbarch,
+               long frame_regno, long frame_offset,
+               CORE_ADDR scope)
 {
   unsigned long len;
   unsigned int reg;
@@ -792,7 +1015,7 @@ collect_symbol (struct collection_list *collect,
       add_memrange (collect, memrange_absolute, offset, len);
       break;
     case LOC_REGISTER:
-      reg = SYMBOL_VALUE (sym);
+      reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
       if (info_verbose)
        printf_filtered ("LOC_REG[parm] %s: ", 
                         SYMBOL_PRINT_NAME (sym));
@@ -800,7 +1023,7 @@ collect_symbol (struct collection_list *collect,
       /* Check for doubles stored in two registers.  */
       /* FIXME: how about larger types stored in 3 or more regs?  */
       if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
-         len > register_size (current_gdbarch, reg))
+         len > register_size (gdbarch, reg))
        add_register (collect, reg + 1);
       break;
     case LOC_REF_ARG:
@@ -852,12 +1075,57 @@ collect_symbol (struct collection_list *collect,
       printf_filtered ("%s has been optimized out of existence.\n",
                       SYMBOL_PRINT_NAME (sym));
       break;
+
+    case LOC_COMPUTED:
+      {
+       struct agent_expr *aexpr;
+       struct cleanup *old_chain1 = NULL;
+       struct agent_reqs areqs;
+
+       aexpr = gen_trace_for_var (scope, sym);
+
+       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);
+       add_aexpr (collect, aexpr);
+
+       /* take care of the registers */
+       if (areqs.reg_mask_len > 0)
+         {
+           int ndx1, ndx2;
+
+           for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++)
+             {
+               QUIT;   /* allow user to bail out with ^C */
+               if (areqs.reg_mask[ndx1] != 0)
+                 {
+                   /* assume chars have 8 bits */
+                   for (ndx2 = 0; ndx2 < 8; ndx2++)
+                     if (areqs.reg_mask[ndx1] & (1 << ndx2))
+                       /* it's used -- record it */
+                       add_register (collect, 
+                                     ndx1 * 8 + ndx2);
+                 }
+             }
+         }
+      }
+      break;
     }
 }
 
 /* Add all locals (or args) symbols to collection list */
 static void
-add_local_symbols (struct collection_list *collect, CORE_ADDR pc,
+add_local_symbols (struct collection_list *collect,
+                  struct gdbarch *gdbarch, CORE_ADDR pc,
                   long frame_regno, long frame_offset, int type)
 {
   struct symbol *sym;
@@ -876,8 +1144,8 @@ add_local_symbols (struct collection_list *collect, CORE_ADDR pc,
              : type == 'L')    /* collecting Locals */
            {
              count++;
-             collect_symbol (collect, sym, frame_regno, 
-                             frame_offset);
+             collect_symbol (collect, sym, gdbarch,
+                             frame_regno, frame_offset, pc);
            }
        }
       if (BLOCK_FUNCTION (block))
@@ -938,7 +1206,7 @@ stringify_collection_list (struct collection_list *list, char *string)
          sprintf (end, "%02X", list->regs_mask[i]);
          end += 2;
        }
-      (*str_list)[ndx] = savestring (temp_buf, end - temp_buf);
+      (*str_list)[ndx] = xstrdup (temp_buf);
       ndx++;
     }
   if (info_verbose)
@@ -1054,7 +1322,8 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
   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);
@@ -1063,10 +1332,35 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
   *tdp_actions = NULL;
   *stepping_actions = NULL;
 
-  gdbarch_virtual_frame_pointer (current_gdbarch, 
+  gdbarch_virtual_frame_pointer (t->gdbarch,
                                 t->loc->address, &frame_reg, &frame_offset);
 
-  for (action = t->actions; action; action = action->next)
+  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;
@@ -1090,13 +1384,14 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
 
              if (0 == strncasecmp ("$reg", action_exp, 4))
                {
-                 for (i = 0; i < gdbarch_num_regs (current_gdbarch); i++)
+                 for (i = 0; i < gdbarch_num_regs (t->gdbarch); i++)
                    add_register (collect, i);
                  action_exp = strchr (action_exp, ',');        /* more? */
                }
              else if (0 == strncasecmp ("$arg", action_exp, 4))
                {
                  add_local_symbols (collect,
+                                    t->gdbarch,
                                     t->loc->address,
                                     frame_reg,
                                     frame_offset,
@@ -1106,6 +1401,7 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
              else if (0 == strncasecmp ("$loc", action_exp, 4))
                {
                  add_local_symbols (collect,
+                                    t->gdbarch,
                                     t->loc->address,
                                     frame_reg,
                                     frame_offset,
@@ -1129,7 +1425,7 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
                      {
                        const char *name = &exp->elts[2].string;
 
-                       i = user_reg_map_name_to_regnum (current_gdbarch,
+                       i = user_reg_map_name_to_regnum (t->gdbarch,
                                                         name, strlen (name));
                        if (i == -1)
                          internal_error (__FILE__, __LINE__,
@@ -1144,7 +1440,7 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
                    case UNOP_MEMVAL:
                      /* safe because we know it's a simple expression */
                      tempval = evaluate_expression (exp);
-                     addr = VALUE_ADDRESS (tempval) + value_offset (tempval);
+                     addr = value_address (tempval);
                      len = TYPE_LENGTH (check_typedef (exp->elts[1].type));
                      add_memrange (collect, memrange_absolute, addr, len);
                      break;
@@ -1152,8 +1448,10 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
                    case OP_VAR_VALUE:
                      collect_symbol (collect,
                                      exp->elts[2].symbol,
+                                     t->gdbarch,
                                      frame_reg,
-                                     frame_offset);
+                                     frame_offset,
+                                     t->loc->address);
                      break;
 
                    default:    /* full-fledged expression */
@@ -1200,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;
@@ -1219,6 +1557,9 @@ encode_actions (struct breakpoint *t, char ***tdp_actions,
                                            tdp_buff);
   *stepping_actions = stringify_collection_list (&stepping_list, 
                                                 step_buff);
+
+  xfree (default_collect_line);
+  xfree (default_collect_action);
 }
 
 static void
@@ -1235,9 +1576,6 @@ add_aexpr (struct collection_list *collect, struct agent_expr *aexpr)
   collect->next_aexpr_elt++;
 }
 
-static char *target_buf;
-static long target_buf_size;
-
 /* Set "transparent" memory ranges
 
    Allow trace mechanism to treat text-like sections
@@ -1293,9 +1631,11 @@ void download_tracepoint (struct breakpoint *t);
 static void
 trace_start_command (char *args, int from_tty)
 {
+  char buf[2048];
   VEC(breakpoint_p) *tp_vec = NULL;
   int ix;
   struct breakpoint *t;
+  struct trace_state_variable *tsv;
 
   dont_repeat ();      /* Like "run", dangerous to repeat accidentally.  */
 
@@ -1313,6 +1653,19 @@ trace_start_command (char *args, int from_tty)
        }
       VEC_free (breakpoint_p, tp_vec);
 
+      /* Init any trace state variables that start with nonzero values.  */
+
+      for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+       {
+         if (tsv->initial_value != 0)
+           {
+             sprintf (buf, "QTDV:%x:%s",
+                      tsv->number, phex ((ULONGEST) tsv->initial_value, 8));
+             putpkt (buf);
+             remote_get_noisy_reply (&target_buf, &target_buf_size);
+           }
+       }
+
       /* Tell target to treat text-like sections as transparent.  */
       remote_set_transparent_ranges ();
       /* Now insert traps and begin collecting data.  */
@@ -1343,21 +1696,40 @@ download_tracepoint (struct breakpoint *t)
   char **stepping_actions;
   int ndx;
   struct cleanup *old_chain = NULL;
+  struct agent_expr *aexpr;
+  struct cleanup *aexpr_chain = NULL;
 
   sprintf_vma (tmp, (t->loc ? t->loc->address : 0));
   sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", t->number, 
           tmp, /* address */
           (t->enable_state == bp_enabled ? 'E' : 'D'),
           t->step_count, t->pass_count);
+  /* If the tracepoint has a conditional, make it into an agent
+     expression and append to the definition.  */
+  if (t->loc->cond)
+    {
+      /* Only test support at download time, we may not know target
+        capabilities at definition time.  */
+      if (remote_supports_cond_tracepoints ())
+       {
+         aexpr = gen_eval_for_expr (t->loc->address, t->loc->cond);
+         aexpr_chain = make_cleanup_free_agent_expr (aexpr);
+         sprintf (buf + strlen (buf), ":X%x,", aexpr->len);
+         mem2hex (aexpr->buf, buf + strlen (buf), aexpr->len);
+         do_cleanups (aexpr_chain);
+       }
+      else
+       warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t->number);
+    }
 
-  if (t->actions)
+  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)
+  if (!t->actions && !*default_collect)
     return;
 
   encode_actions (t, &tdp_actions, &stepping_actions);
@@ -1438,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."));
@@ -1565,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);
 
@@ -1627,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
@@ -1648,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)
@@ -1684,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);
@@ -1701,6 +2097,8 @@ trace_find_line_command (char *args, int from_tty)
       old_chain = make_cleanup (xfree, sals.sals);
       if (sal.symtab == 0)
        {
+         struct gdbarch *gdbarch = get_current_arch ();
+
          printf_filtered ("TFIND: No line number information available");
          if (sal.pc != 0)
            {
@@ -1709,7 +2107,7 @@ trace_find_line_command (char *args, int from_tty)
                 have the symbolic address.  */
              printf_filtered (" for address ");
              wrap_here ("  ");
-             print_address (sal.pc, gdb_stdout);
+             print_address (gdbarch, sal.pc, gdb_stdout);
              printf_filtered (";\n -- will attempt to find by PC. \n");
            }
          else
@@ -1721,13 +2119,15 @@ trace_find_line_command (char *args, int from_tty)
       else if (sal.line > 0
               && find_line_pc_range (sal, &start_pc, &end_pc))
        {
+         struct gdbarch *gdbarch = get_objfile_arch (sal.symtab->objfile);
+
          if (start_pc == end_pc)
            {
              printf_filtered ("Line %d of \"%s\"",
                               sal.line, sal.symtab->filename);
              wrap_here ("  ");
              printf_filtered (" is at address ");
-             print_address (start_pc, gdb_stdout);
+             print_address (gdbarch, start_pc, gdb_stdout);
              wrap_here ("  ");
              printf_filtered (" but contains no code.\n");
              sal = find_pc_line (start_pc, 0);
@@ -1775,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");
@@ -1814,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");
@@ -1854,6 +2260,8 @@ scope_info (char *args, int from_tty)
   char **canonical, *symname, *save_args = args;
   struct dict_iterator iter;
   int j, count = 0;
+  struct gdbarch *gdbarch;
+  int regno;
 
   if (args == 0 || *args == 0)
     error (_("requires an argument (function, line or *addr) to define a scope"));
@@ -1880,6 +2288,8 @@ scope_info (char *args, int from_tty)
          if (symname == NULL || *symname == '\0')
            continue;           /* probably botched, certainly useless */
 
+         gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile);
+
          printf_filtered ("Symbol %s is ", symname);
          switch (SYMBOL_CLASS (sym))
            {
@@ -1902,17 +2312,25 @@ scope_info (char *args, int from_tty)
              break;
            case LOC_STATIC:
              printf_filtered ("in static storage at address ");
-             printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym)));
+             printf_filtered ("%s", paddress (gdbarch,
+                                              SYMBOL_VALUE_ADDRESS (sym)));
              break;
            case LOC_REGISTER:
+             /* GDBARCH is the architecture associated with the objfile
+                the symbol is defined in; the target architecture may be
+                different, and may provide additional registers.  However,
+                we do not know the target architecture at this point.
+                We assume the objfile architecture will contain all the
+                standard registers that occur in debug info in that
+                objfile.  */
+             regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
+
              if (SYMBOL_IS_ARGUMENT (sym))
                printf_filtered ("an argument in register $%s",
-                                gdbarch_register_name
-                                (current_gdbarch, SYMBOL_VALUE (sym)));
+                                gdbarch_register_name (gdbarch, regno));
              else
                printf_filtered ("a local variable in register $%s",
-                                gdbarch_register_name
-                                (current_gdbarch, SYMBOL_VALUE (sym)));
+                                gdbarch_register_name (gdbarch, regno));
              break;
            case LOC_ARG:
              printf_filtered ("an argument at stack/frame offset %ld",
@@ -1927,20 +2345,23 @@ scope_info (char *args, int from_tty)
                               SYMBOL_VALUE (sym));
              break;
            case LOC_REGPARM_ADDR:
+             /* Note comment at LOC_REGISTER.  */
+             regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
              printf_filtered ("the address of an argument, in register $%s",
-                              gdbarch_register_name
-                                (current_gdbarch, SYMBOL_VALUE (sym)));
+                              gdbarch_register_name (gdbarch, regno));
              break;
            case LOC_TYPEDEF:
              printf_filtered ("a typedef.\n");
              continue;
            case LOC_LABEL:
              printf_filtered ("a label at address ");
-             printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym)));
+             printf_filtered ("%s", paddress (gdbarch,
+                                              SYMBOL_VALUE_ADDRESS (sym)));
              break;
            case LOC_BLOCK:
              printf_filtered ("a function at address ");
-             printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
+             printf_filtered ("%s",
+               paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
              break;
            case LOC_UNRESOLVED:
              msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
@@ -1950,14 +2371,15 @@ scope_info (char *args, int from_tty)
              else
                {
                  printf_filtered ("static storage at address ");
-                 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym)));
+                 printf_filtered ("%s",
+                   paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym)));
                }
              break;
            case LOC_OPTIMIZED_OUT:
              printf_filtered ("optimized out.\n");
              continue;
            case LOC_COMPUTED:
-             SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
+             SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, gdb_stdout);
              break;
            }
          if (SYMBOL_TYPE (sym))
@@ -2177,6 +2599,23 @@ _initialize_tracepoint (void)
   add_com ("tdump", class_trace, trace_dump_command,
           _("Print everything collected at the current tracepoint."));
 
+  c = add_com ("tvariable", class_trace, trace_variable_command,_("\
+Define a trace state variable.\n\
+Argument is a $-prefixed name, optionally followed\n\
+by '=' and an expression that sets the initial value\n\
+at the start of tracing."));
+  set_cmd_completer (c, expression_completer);
+
+  add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\
+Delete one or more trace state variables.\n\
+Arguments are the names of the variables to delete.\n\
+If no arguments are supplied, delete all variables."), &deletelist);
+  /* FIXME add a trace variable completer */
+
+  add_info ("tvariables", tvariables_info, _("\
+Status of trace state variables and their values.\n\
+"));
+
   add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\
 Select a trace frame;\n\
 No argument means forward by one frame; '-' means backward by one frame."),
@@ -2259,12 +2698,26 @@ 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\
 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);
 }