* source.c (openp): Skip $cdir in PATH.
[deliverable/binutils-gdb.git] / gdb / tracepoint.c
index ac109970837e328b7e889a58c262adb285a101aa..c25be707259c8334fa53b144d1519dcebad337ed 100644 (file)
@@ -45,6 +45,7 @@
 #include "filenames.h"
 #include "gdbthread.h"
 #include "stack.h"
+#include "gdbcore.h"
 
 #include "ax.h"
 #include "ax-gdb.h"
@@ -2370,54 +2371,21 @@ replace_comma (void *data)
   *comma = ',';
 }
 
-/* tdump command */
+
+/* Helper for trace_dump_command.  Dump the action list starting at
+   ACTION.  STEPPING_ACTIONS is true if we're iterating over the
+   actions of the body of a while-stepping action.  STEPPING_FRAME is
+   set if the current traceframe was determined to be a while-stepping
+   traceframe.  */
+
 static void
-trace_dump_command (char *args, int from_tty)
+trace_dump_actions (struct command_line *action,
+                   int stepping_actions, int stepping_frame,
+                   int from_tty)
 {
-  struct regcache *regcache;
-  struct gdbarch *gdbarch;
-  struct breakpoint *t;
-  struct command_line *action;
   char *action_exp, *next_comma;
-  struct cleanup *old_cleanups;
-  int stepping_actions = 0;
-  int stepping_frame = 0;
-  struct bp_location *loc;
 
-  if (tracepoint_number == -1)
-    {
-      warning (_("No current trace frame."));
-      return;
-    }
-
-  t = get_tracepoint (tracepoint_number);
-
-  if (t == NULL)
-    error (_("No known tracepoint matches 'current' tracepoint #%d."),
-          tracepoint_number);
-
-  old_cleanups = make_cleanup (null_cleanup, NULL);
-
-  printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
-                  tracepoint_number, traceframe_number);
-
-  /* The current frame is a trap frame if the frame PC is equal
-     to the tracepoint PC.  If not, then the current frame was
-     collected during single-stepping.  */
-
-  regcache = get_current_regcache ();
-  gdbarch = get_regcache_arch (regcache);
-
-  /* If the traceframe's address matches any of the tracepoint's
-     locations, assume it is a direct hit rather than a while-stepping
-     frame.  (FIXME this is not reliable, should record each frame's
-     type.)  */
-  stepping_frame = 1;
-  for (loc = t->loc; loc; loc = loc->next)
-    if (loc->address == regcache_read_pc (regcache))
-      stepping_frame = 0;
-
-  for (action = breakpoint_commands (t); action; action = action->next)
+  for (; action != NULL; action = action->next)
     {
       struct cmd_list_element *cmd;
 
@@ -2437,9 +2405,13 @@ trace_dump_command (char *args, int from_tty)
        error (_("Bad action list item: %s"), action_exp);
 
       if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
-       stepping_actions = 1;
-      else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
-       stepping_actions = 0;
+       {
+         int i;
+
+         for (i = 0; i < action->body_count; ++i)
+           trace_dump_actions (action->body_list[i],
+                               1, stepping_frame, from_tty);
+       }
       else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
        {
          /* Display the collected data.
@@ -2485,7 +2457,49 @@ trace_dump_command (char *args, int from_tty)
            }
        }
     }
-  discard_cleanups (old_cleanups);
+}
+
+/* The tdump command.  */
+
+static void
+trace_dump_command (char *args, int from_tty)
+{
+  struct regcache *regcache;
+  struct breakpoint *t;
+  int stepping_frame = 0;
+  struct bp_location *loc;
+
+  if (tracepoint_number == -1)
+    {
+      warning (_("No current trace frame."));
+      return;
+    }
+
+  t = get_tracepoint (tracepoint_number);
+
+  if (t == NULL)
+    error (_("No known tracepoint matches 'current' tracepoint #%d."),
+          tracepoint_number);
+
+  printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
+                  tracepoint_number, traceframe_number);
+
+  /* The current frame is a trap frame if the frame PC is equal
+     to the tracepoint PC.  If not, then the current frame was
+     collected during single-stepping.  */
+
+  regcache = get_current_regcache ();
+
+  /* If the traceframe's address matches any of the tracepoint's
+     locations, assume it is a direct hit rather than a while-stepping
+     frame.  (FIXME this is not reliable, should record each frame's
+     type.)  */
+  stepping_frame = 1;
+  for (loc = t->loc; loc; loc = loc->next)
+    if (loc->address == regcache_read_pc (regcache))
+      stepping_frame = 0;
+
+  trace_dump_actions (breakpoint_commands (t), 0, stepping_frame, from_tty);
 }
 
 /* Encode a piece of a tracepoint's source-level definition in a form
@@ -2524,7 +2538,7 @@ trace_save (const char *filename, int target_does_save)
   struct uploaded_tp *uploaded_tps = NULL, *utp;
   struct uploaded_tsv *uploaded_tsvs = NULL, *utsv;
   int a;
-  struct uploaded_string *cmd;
+  char *act;
   LONGEST gotten = 0;
   ULONGEST offset = 0;
 #define MAX_TRACE_UPLOAD 2000
@@ -2632,14 +2646,12 @@ trace_save (const char *filename, int target_does_save)
        fprintf (fp, ":X%x,%s", (unsigned int) strlen (utp->cond) / 2,
                 utp->cond);
       fprintf (fp, "\n");
-      for (a = 0; a < utp->numactions; ++a)
+      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)),
-                utp->actions[a]);
-      for (a = 0; a < utp->num_step_actions; ++a)
+                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)),
-                utp->step_actions[a]);
+                utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
       if (utp->at_string)
        {
          encode_source_string (utp->number, utp->addr,
@@ -2652,9 +2664,9 @@ trace_save (const char *filename, int target_does_save)
                                "cond", utp->cond_string, buf, MAX_TRACE_UPLOAD);
          fprintf (fp, "tp Z%s\n", buf);
        }
-      for (cmd = utp->cmd_strings; cmd; cmd = cmd->next)
+      for (a = 0; VEC_iterate (char_ptr, utp->cmd_strings, a, act); ++a)
        {
-         encode_source_string (utp->number, utp->addr, "cmd", cmd->str,
+         encode_source_string (utp->number, utp->addr, "cmd", act,
                                buf, MAX_TRACE_UPLOAD);
          fprintf (fp, "tp Z%s\n", buf);
        }
@@ -2856,6 +2868,9 @@ get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp)
   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;
@@ -3410,12 +3425,12 @@ parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
   else if (piece == 'A')
     {
       utp = get_uploaded_tp (num, addr, utpp);
-      utp->actions[utp->numactions++] = xstrdup (p);
+      VEC_safe_push (char_ptr, utp->actions, xstrdup (p));
     }
   else if (piece == 'S')
     {
       utp = get_uploaded_tp (num, addr, utpp);
-      utp->step_actions[utp->num_step_actions++] = xstrdup (p);
+      VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p));
     }
   else if (piece == 'Z')
     {
@@ -3439,21 +3454,7 @@ parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
       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;
-       }
+       VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf));
     }
   else
     {
@@ -3658,7 +3659,7 @@ tfile_fetch_registers (struct target_ops *ops,
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   char block_type;
-  int i, pos, offset, regn, regsize, gotten;
+  int i, pos, offset, regn, regsize, gotten, pc_regno;
   unsigned short mlen;
   char *regs;
 
@@ -3733,6 +3734,44 @@ tfile_fetch_registers (struct target_ops *ops,
          break;
        }
     }
+
+  /* We get here if no register data has been found.  Although we
+     don't like making up numbers, GDB has all manner of troubles when
+     the target says some register is not available.  Filling in with
+     zeroes is a reasonable fallback.  */
+  for (regn = 0; regn < gdbarch_num_regs (gdbarch); regn++)
+    regcache_raw_supply (regcache, regn, NULL);
+
+  /* We can often usefully guess that the PC is going to be the same
+     as the address of the tracepoint.  */
+  pc_regno = gdbarch_pc_regnum (gdbarch);
+  if (pc_regno >= 0 && (regno == -1 || regno == pc_regno))
+    {
+      struct breakpoint *tp = get_tracepoint (tracepoint_number);
+
+      if (tp && tp->loc)
+       {
+         /* But don't try to guess if tracepoint is multi-location...  */
+         if (tp->loc->next)
+           {
+             warning ("Tracepoint %d has multiple locations, cannot infer $pc",
+                      tp->number);
+             return;
+           }
+         /* ... or does while-stepping.  */
+         if (tp->step_count > 0)
+           {
+             warning ("Tracepoint %d does while-stepping, cannot infer $pc",
+                      tp->number);
+             return;
+           }
+
+         store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
+                                 gdbarch_byte_order (gdbarch),
+                                 tp->loc->address);
+         regcache_raw_supply (regcache, pc_regno, regs);
+       }
+    }
 }
 
 static LONGEST
@@ -3742,7 +3781,7 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
 {
   char block_type;
   int pos, gotten;
-  ULONGEST maddr;
+  ULONGEST maddr, amt;
   unsigned short mlen;
 
   /* We're only doing regular memory for now.  */
@@ -3780,16 +3819,19 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
            perror_with_name (trace_filename);
          else if (gotten < 2)
            error (_("Premature end of file while reading trace file"));
-         if (maddr <= offset && (offset + len) <= (maddr + mlen))
-           {
-             gotten = read (trace_fd, readbuf, mlen);
-             if (gotten < 0)
-               perror_with_name (trace_filename);
-             else if (gotten < mlen)
-               error (_("Premature end of file qwhile reading trace file"));
-
-             return mlen;
-           }
+         /* If the block includes the first part of the desired
+            range, return as much it has; GDB will re-request the
+            remainder, which might be in a different block of this
+            trace frame.  */
+         if (maddr <= offset && offset < (maddr + mlen))
+           {
+             amt = (maddr + mlen) - offset;
+             if (amt > len)
+               amt = len;
+
+             read (trace_fd, readbuf, amt);
+             return amt;
+           }
          lseek (trace_fd, mlen, SEEK_CUR);
          pos += (8 + 2 + mlen);
          break;
@@ -3803,6 +3845,38 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
          break;
        }
     }
+
+  /* It's unduly pedantic to refuse to look at the executable for
+     read-only pieces; so do the equivalent of readonly regions aka
+     QTro packet.  */
+  /* FIXME account for relocation at some point */
+  if (exec_bfd)
+    {
+      asection *s;
+      bfd_size_type size;
+      bfd_vma lma;
+
+      for (s = exec_bfd->sections; s; s = s->next)
+       {
+         if ((s->flags & SEC_LOAD) == 0 ||
+             (s->flags & SEC_READONLY) == 0)
+           continue;
+
+         lma = s->lma;
+         size = bfd_get_section_size (s);
+         if (lma <= offset && offset < (lma + size))
+           {
+             amt = (lma + size) - offset;
+             if (amt > len)
+               amt = len;
+
+             amt = bfd_get_section_contents (exec_bfd, s,
+                                             readbuf, offset - lma, amt);
+             return amt;
+           }
+       }
+    }
+
   /* Indicate failure to find the requested memory block.  */
   return -1;
 }
@@ -3871,6 +3945,12 @@ tfile_get_trace_state_variable_value (int tsvnum, LONGEST *val)
   return 0;
 }
 
+static int
+tfile_has_all_memory (struct target_ops *ops)
+{
+  return 1;
+}
+
 static int
 tfile_has_memory (struct target_ops *ops)
 {
@@ -3907,6 +3987,7 @@ init_tfile_ops (void)
   /* core_stratum might seem more logical, but GDB doesn't like having
      more than one core_stratum vector.  */
   tfile_ops.to_stratum = process_stratum;
+  tfile_ops.to_has_all_memory = tfile_has_all_memory;
   tfile_ops.to_has_memory = tfile_has_memory;
   tfile_ops.to_has_stack = tfile_has_stack;
   tfile_ops.to_has_registers = tfile_has_registers;
This page took 0.02823 seconds and 4 git commands to generate.