* doc/binutils.texi (c++filt): Remove spurious description of
[deliverable/binutils-gdb.git] / gdb / tracepoint.c
index dece79964f47a954ce623bb6ed1f472a274498bc..0d439efd3f81d13a3731586e366cc3902f8565eb 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,7 @@
 #include "breakpoint.h"
 #include "tracepoint.h"
 #include "remote.h"
+extern int remote_supports_cond_tracepoints (void);
 #include "linespec.h"
 #include "regcache.h"
 #include "completer.h"
@@ -40,6 +42,8 @@
 #include "observer.h"
 #include "user-regs.h"
 #include "valprint.h"
+#include "gdbcore.h"
+#include "objfiles.h"
 
 #include "ax.h"
 #include "ax-gdb.h"
@@ -207,8 +211,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.  */
@@ -216,8 +219,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
@@ -228,24 +230,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;
     }
 
@@ -256,53 +248,26 @@ 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
-    {
-      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);
-    }
+    set_internalvar_string (lookup_internalvar ("trace_file"),
+                           traceframe_sal.symtab->filename);
 }
 
 /* ACTIONS functions: */
@@ -759,6 +724,7 @@ add_memrange (struct collection_list *memranges,
 static void
 collect_symbol (struct collection_list *collect, 
                struct symbol *sym,
+               struct gdbarch *gdbarch,
                long frame_regno, long frame_offset)
 {
   unsigned long len;
@@ -791,7 +757,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));
@@ -799,7 +765,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:
@@ -856,7 +822,8 @@ collect_symbol (struct collection_list *collect,
 
 /* 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;
@@ -875,8 +842,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);
            }
        }
       if (BLOCK_FUNCTION (block))
@@ -937,7 +904,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)
@@ -1062,7 +1029,7 @@ 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)
@@ -1089,13 +1056,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,
@@ -1105,6 +1073,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,
@@ -1128,7 +1097,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__,
@@ -1143,7 +1112,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;
@@ -1151,6 +1120,7 @@ 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);
                      break;
@@ -1247,7 +1217,6 @@ static long target_buf_size;
 static void
 remote_set_transparent_ranges (void)
 {
-  extern bfd *exec_bfd;
   asection *s;
   bfd_size_type size;
   bfd_vma lma;
@@ -1343,12 +1312,31 @@ 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)
     strcat (buf, "-");
@@ -1701,6 +1689,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 +1699,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 +1711,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);
@@ -1854,6 +1846,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 +1874,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 +1898,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 +1931,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 +1957,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))
This page took 0.029294 seconds and 4 git commands to generate.