]> Git Repo - binutils.git/blobdiff - gdb/tracepoint.c
* gdbtypes.c (arch_flags_type): Fix comment.
[binutils.git] / gdb / tracepoint.c
index b61362f4bdd34c7cd19bb64444e814b74c038a28..0dfe23cdf8a35ada9236eb2fba27af7a26ef4f5d 100644 (file)
@@ -32,9 +32,6 @@
 #include "inferior.h"
 #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"
@@ -45,6 +42,7 @@ extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
 #include "valprint.h"
 #include "gdbcore.h"
 #include "objfiles.h"
+#include "filenames.h"
 
 #include "ax.h"
 #include "ax-gdb.h"
@@ -60,6 +58,8 @@ extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
 #include <unistd.h>
 #endif
 
+extern void stop_tracing ();
+
 /* Maximum length of an agent aexpression.
    This accounts for the fact that packets are limited to 400 bytes
    (which includes everything -- including the checksum), and assumes
@@ -141,11 +141,10 @@ static struct symtab_and_line traceframe_sal;
 static struct cmd_list_element *tfindlist;
 
 /* List of expressions to collect by default at each tracepoint hit.  */
-static char *default_collect = "";
+char *default_collect = "";
+
+static int disconnected_tracing;
 
-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);
@@ -168,67 +167,10 @@ static char *mem2hex (gdb_byte *, char *, int);
 static void add_register (struct collection_list *collection,
                          unsigned int regno);
 static struct cleanup *make_cleanup_free_actions (struct breakpoint *t);
-static void free_actions_list (char **actions_list);
-static void free_actions_list_cleanup_wrapper (void *);
 
-extern void _initialize_tracepoint (void);
+extern void send_disconnected_tracing_value (int value);
 
-/* Utility: returns true if "target remote" */
-static int
-target_is_remote (void)
-{
-  if (current_target.to_shortname &&
-      (strcmp (current_target.to_shortname, "remote") == 0
-       || strcmp (current_target.to_shortname, "extended-remote") == 0))
-    return 1;
-  else
-    return 0;
-}
-
-/* Utility: generate error from an incoming stub packet.  */
-static void
-trace_error (char *buf)
-{
-  if (*buf++ != 'E')
-    return;                    /* not an error msg */
-  switch (*buf)
-    {
-    case '1':                  /* malformed packet error */
-      if (*++buf == '0')       /*   general case: */
-       error (_("tracepoint.c: error in outgoing packet."));
-      else
-       error (_("tracepoint.c: error in outgoing packet at field #%ld."),
-              strtol (buf, NULL, 16));
-    case '2':
-      error (_("trace API error 0x%s."), ++buf);
-    default:
-      error (_("Target returns error code '%s'."), buf);
-    }
-}
-
-/* Utility: wait for reply from stub, while accepting "O" packets.  */
-static char *
-remote_get_noisy_reply (char **buf_p,
-                       long *sizeof_buf)
-{
-  do                           /* Loop on reply from remote stub.  */
-    {
-      char *buf;
-      QUIT;                    /* allow user to bail out with ^C */
-      getpkt (buf_p, sizeof_buf, 0);
-      buf = *buf_p;
-      if (buf[0] == 0)
-       error (_("Target does not support this command."));
-      else if (buf[0] == 'E')
-       trace_error (buf);
-      else if (buf[0] == 'O' &&
-              buf[1] != 'K')
-       remote_console_output (buf + 1);        /* 'O' message from stub */
-      else
-       return buf;             /* here's the actual reply */
-    }
-  while (1);
-}
+extern void _initialize_tracepoint (void);
 
 /* Set traceframe number to NUM.  */
 static void
@@ -442,37 +384,17 @@ tvariables_info (char *args, int from_tty)
   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;
     }
 
+  /* Try to acquire values from the target.  */
+  for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
+    tsv->value_known = target_get_trace_state_variable_value (tsv->number,
+                                                             &(tsv->value));
+
   printf_filtered (_("Name\t\t  Initial\tCurrent\n"));
 
   for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
@@ -1286,28 +1208,8 @@ stringify_collection_list (struct collection_list *list, char *string)
     return *str_list;
 }
 
-static void
-free_actions_list_cleanup_wrapper (void *al)
-{
-  free_actions_list (al);
-}
-
-static void
-free_actions_list (char **actions_list)
-{
-  int ndx;
-
-  if (actions_list == 0)
-    return;
-
-  for (ndx = 0; actions_list[ndx]; ndx++)
-    xfree (actions_list[ndx]);
-
-  xfree (actions_list);
-}
-
 /* Render all actions into gdb protocol.  */
-static void
+/*static*/ void
 encode_actions (struct breakpoint *t, char ***tdp_actions,
                char ***stepping_actions)
 {
@@ -1576,49 +1478,6 @@ add_aexpr (struct collection_list *collect, struct agent_expr *aexpr)
   collect->next_aexpr_elt++;
 }
 
-/* Set "transparent" memory ranges
-
-   Allow trace mechanism to treat text-like sections
-   (and perhaps all read-only sections) transparently, 
-   i.e. don't reject memory requests from these address ranges
-   just because they haven't been collected.  */
-
-static void
-remote_set_transparent_ranges (void)
-{
-  asection *s;
-  bfd_size_type size;
-  bfd_vma lma;
-  int anysecs = 0;
-
-  if (!exec_bfd)
-    return;                    /* No information to give.  */
-
-  strcpy (target_buf, "QTro");
-  for (s = exec_bfd->sections; s; s = s->next)
-    {
-      char tmp1[40], tmp2[40];
-
-      if ((s->flags & SEC_LOAD) == 0 ||
-      /* (s->flags & SEC_CODE)     == 0 || */
-         (s->flags & SEC_READONLY) == 0)
-       continue;
-
-      anysecs = 1;
-      lma = s->lma;
-      size = bfd_get_section_size (s);
-      sprintf_vma (tmp1, lma);
-      sprintf_vma (tmp2, lma + size);
-      sprintf (target_buf + strlen (target_buf), 
-              ":%s,%s", tmp1, tmp2);
-    }
-  if (anysecs)
-    {
-      putpkt (target_buf);
-      getpkt (&target_buf, &target_buf_size, 0);
-    }
-}
-
 /* tstart command:
 
    Tell target to clear any previous trace experiment.
@@ -1626,8 +1485,6 @@ remote_set_transparent_ranges (void)
    to the target.  If no errors, 
    Tell target to start a new trace experiment.  */
 
-void download_tracepoint (struct breakpoint *t);
-
 static void
 trace_start_command (char *args, int from_tty)
 {
@@ -1636,271 +1493,182 @@ trace_start_command (char *args, int from_tty)
   int ix;
   struct breakpoint *t;
   struct trace_state_variable *tsv;
+  int any_downloaded = 0;
 
   dont_repeat ();      /* Like "run", dangerous to repeat accidentally.  */
 
-  if (target_is_remote ())
+  target_trace_init ();
+  
+  tp_vec = all_tracepoints ();
+  for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
     {
-      putpkt ("QTinit");
-      remote_get_noisy_reply (&target_buf, &target_buf_size);
-      if (strcmp (target_buf, "OK"))
-       error (_("Target does not support this command."));
-
-      tp_vec = all_tracepoints ();
-      for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
-       {
-         download_tracepoint (t);
-       }
-      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.  */
-      putpkt ("QTStart");
-      remote_get_noisy_reply (&target_buf, &target_buf_size);
-      if (strcmp (target_buf, "OK"))
-       error (_("Bogus reply from target: %s"), target_buf);
-      set_traceframe_num (-1); /* All old traceframes invalidated.  */
-      set_tracepoint_num (-1);
-      set_traceframe_context (NULL);
-      trace_running_p = 1;
-      if (deprecated_trace_start_stop_hook)
-       deprecated_trace_start_stop_hook (1, from_tty);
-
+      t->number_on_target = 0;
+      target_download_tracepoint (t);
+      t->number_on_target = t->number;
+      any_downloaded = 1;
     }
-  else
-    error (_("Trace can only be run on remote targets."));
-}
-
-/* Send the definition of a single tracepoint to the target.  */
-
-void
-download_tracepoint (struct breakpoint *t)
-{
-  char tmp[40];
-  char buf[2048];
-  char **tdp_actions;
-  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)
+  VEC_free (breakpoint_p, tp_vec);
+  
+  /* No point in tracing without any tracepoints... */
+  if (!any_downloaded)
+    error ("No tracepoints downloaded, not starting trace");
+  
+  /* Init any trace state variables that start with nonzero values.  */
+  for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
     {
-      /* 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 (tsv->initial_value != 0)
+       target_download_trace_state_variable (tsv);
     }
+  
+  /* Tell target to treat text-like sections as transparent.  */
+  target_trace_set_readonly_regions ();
 
-  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);
-  old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
-                           tdp_actions);
-  (void) make_cleanup (free_actions_list_cleanup_wrapper, stepping_actions);
+  /* Now insert traps and begin collecting data.  */
+  target_trace_start ();
 
-  /* do_single_steps (t); */
-  if (tdp_actions)
-    {
-      for (ndx = 0; tdp_actions[ndx]; ndx++)
-       {
-         QUIT; /* allow user to bail out with ^C */
-         sprintf (buf, "QTDP:-%x:%s:%s%c",
-                  t->number, tmp, /* address */
-                  tdp_actions[ndx],
-                  ((tdp_actions[ndx + 1] || stepping_actions)
-                   ? '-' : 0));
-         putpkt (buf);
-         remote_get_noisy_reply (&target_buf,
-                                 &target_buf_size);
-         if (strcmp (target_buf, "OK"))
-           error (_("Error on target while setting tracepoints."));
-       }
-    }
-  if (stepping_actions)
-    {
-      for (ndx = 0; stepping_actions[ndx]; ndx++)
-       {
-         QUIT; /* allow user to bail out with ^C */
-         sprintf (buf, "QTDP:-%x:%s:%s%s%s",
-                  t->number, tmp, /* address */
-                  ((ndx == 0) ? "S" : ""),
-                  stepping_actions[ndx],
-                  (stepping_actions[ndx + 1] ? "-" : ""));
-         putpkt (buf);
-         remote_get_noisy_reply (&target_buf,
-                                 &target_buf_size);
-         if (strcmp (target_buf, "OK"))
-           error (_("Error on target while setting tracepoints."));
-       }
-    }
-  do_cleanups (old_chain);
+  /* Reset our local state.  */
+  set_traceframe_num (-1);
+  set_tracepoint_num (-1);
+  set_traceframe_context (NULL);
+  trace_running_p = 1;
 }
 
 /* tstop command */
 static void
 trace_stop_command (char *args, int from_tty)
 {
-  if (target_is_remote ())
-    {
-      putpkt ("QTStop");
-      remote_get_noisy_reply (&target_buf, &target_buf_size);
-      if (strcmp (target_buf, "OK"))
-       error (_("Bogus reply from target: %s"), target_buf);
-      trace_running_p = 0;
-      if (deprecated_trace_start_stop_hook)
-       deprecated_trace_start_stop_hook (0, from_tty);
-    }
-  else
-    error (_("Trace can only be run on remote targets."));
+  stop_tracing ();
+}
+
+void
+stop_tracing ()
+{
+  target_trace_stop ();
+  trace_running_p = 0;
 }
 
 unsigned long trace_running_p;
 
+int
+get_trace_status ()
+{
+  int status = target_get_trace_status (NULL);
+
+  /* exported for use by the GUI */
+  trace_running_p = (status > 0);
+
+  return status;
+}
+
 /* tstatus command */
 static void
 trace_status_command (char *args, int from_tty)
 {
-  if (target_is_remote ())
+  int status = get_trace_status ();
+  
+  if (status < 0)
+    printf_filtered (_("Trace can not be run on the target.\n"));
+  else if (trace_running_p)
     {
-      putpkt ("qTStatus");
-      remote_get_noisy_reply (&target_buf, &target_buf_size);
-
-      if (target_buf[0] != 'T' ||
-         (target_buf[1] != '0' && target_buf[1] != '1'))
-       error (_("Bogus reply from target: %s"), target_buf);
-
-      /* 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"));
+      printf_filtered (_("Trace is running on the target.\n"));
+      if (disconnected_tracing)
+       printf_filtered (_("Trace will continue if GDB disconnects.\n"));
       else
-       printf_filtered (_("Trace is not running on the target.\n"));
+       printf_filtered (_("Trace will stop if GDB disconnects.\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"));
+  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"));
+}
 
+void
+disconnect_or_stop_tracing (int from_tty)
+{
+  if (trace_running_p && from_tty)
+    {
+      int cont = query (_("Trace is running.  Continue tracing after detach? "));
+      /* Note that we send the query result without affecting the
+        user's setting of disconnected_tracing, so that the answer is
+        a one-time-only.  */
+      send_disconnected_tracing_value (cont);
+
+      /* Also ensure that we do the equivalent of a tstop command if
+        tracing is not to continue after the detach.  */
+      if (!cont)
+       stop_tracing ();
     }
-  else
-    error (_("Trace can only be run on remote targets."));
 }
 
 /* Worker function for the various flavors of the tfind command.  */
 static void
-finish_tfind_command (char **msg,
-                     long *sizeof_msg,
+finish_tfind_command (enum trace_find_type type, int num,
+                     ULONGEST addr1, ULONGEST addr2,
                      int from_tty)
 {
   int target_frameno = -1, target_tracept = -1;
   struct frame_id old_frame_id;
   char *reply;
+  struct breakpoint *tp;
 
   old_frame_id = get_frame_id (get_current_frame ());
 
-  putpkt (*msg);
-  reply = remote_get_noisy_reply (msg, sizeof_msg);
-
-  while (reply && *reply)
-    switch (*reply)
-      {
-      case 'F':
-       if ((target_frameno = (int) strtol (++reply, &reply, 16)) == -1)
-         {
-           /* A request for a non-existant trace frame has failed.
-              Our response will be different, depending on FROM_TTY:
-
-              If FROM_TTY is true, meaning that this command was 
-              typed interactively by the user, then give an error
-              and DO NOT change the state of traceframe_number etc.
-
-              However if FROM_TTY is false, meaning that we're either
-              in a script, a loop, or a user-defined command, then 
-              DON'T give an error, but DO change the state of
-              traceframe_number etc. to invalid.
-
-              The rationalle is that if you typed the command, you
-              might just have committed a typo or something, and you'd
-              like to NOT lose your current debugging state.  However
-              if you're in a user-defined command or especially in a
-              loop, then you need a way to detect that the command
-              failed WITHOUT aborting.  This allows you to write
-              scripts that search thru the trace buffer until the end,
-              and then continue on to do something else.  */
-
-           if (from_tty)
-             error (_("Target failed to find requested trace frame."));
-           else
-             {
-               if (info_verbose)
-                 printf_filtered ("End of trace buffer.\n");
-               /* The following will not recurse, since it's
-                  special-cased.  */
-               trace_find_command ("-1", from_tty);
-               reply = NULL;   /* Break out of loop 
-                                  (avoid recursive nonsense).  */
-             }
-         }
-       break;
-      case 'T':
-       if ((target_tracept = (int) strtol (++reply, &reply, 16)) == -1)
-         error (_("Target failed to find requested trace frame."));
-       break;
-      case 'O':                /* "OK"? */
-       if (reply[1] == 'K' && reply[2] == '\0')
-         reply += 2;
-       else
-         error (_("Bogus reply from target: %s"), reply);
-       break;
-      default:
-       error (_("Bogus reply from target: %s"), reply);
-      }
+  target_frameno = target_trace_find (type, num, addr1, addr2,
+                                     &target_tracept);
+  
+  if (type == tfind_number
+      && num == -1
+      && target_frameno == -1)
+    {
+      /* We told the target to get out of tfind mode, and it did.  */
+    }
+  else if (target_frameno == -1)
+    {
+      /* A request for a non-existant trace frame has failed.
+        Our response will be different, depending on FROM_TTY:
+
+        If FROM_TTY is true, meaning that this command was 
+        typed interactively by the user, then give an error
+        and DO NOT change the state of traceframe_number etc.
+
+        However if FROM_TTY is false, meaning that we're either
+        in a script, a loop, or a user-defined command, then 
+        DON'T give an error, but DO change the state of
+        traceframe_number etc. to invalid.
+
+        The rationalle is that if you typed the command, you
+        might just have committed a typo or something, and you'd
+        like to NOT lose your current debugging state.  However
+        if you're in a user-defined command or especially in a
+        loop, then you need a way to detect that the command
+        failed WITHOUT aborting.  This allows you to write
+        scripts that search thru the trace buffer until the end,
+        and then continue on to do something else.  */
+  
+      if (from_tty)
+       error (_("Target failed to find requested trace frame."));
+      else
+       {
+         if (info_verbose)
+           printf_filtered ("End of trace buffer.\n");
+#if 0 /* dubious now? */
+         /* The following will not recurse, since it's
+            special-cased.  */
+         trace_find_command ("-1", from_tty);
+#endif
+       }
+    }
+  
+  tp = get_tracepoint_by_number_on_target (target_tracept);
 
   reinit_frame_cache ();
   registers_changed ();
   set_traceframe_num (target_frameno);
-  set_tracepoint_num (target_tracept);
+  set_tracepoint_num (tp ? tp->number : target_tracept);
   if (target_frameno == -1)
     set_traceframe_context (NULL);
   else
@@ -1947,41 +1715,35 @@ trace_find_command (char *args, int from_tty)
 { /* this should only be called with a numeric argument */
   int frameno = -1;
 
-  if (target_is_remote ())
+  if (trace_running_p)
+    error ("May not look at trace frames while trace is running.");
+  
+  if (args == 0 || *args == 0)
+    { /* TFIND with no args means find NEXT trace frame.  */
+      if (traceframe_number == -1)
+       frameno = 0;    /* "next" is first one */
+        else
+       frameno = traceframe_number + 1;
+    }
+  else if (0 == strcmp (args, "-"))
     {
-      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);
-
-      if (args == 0 || *args == 0)
-       { /* TFIND with no args means find NEXT trace frame.  */
-         if (traceframe_number == -1)
-           frameno = 0;        /* "next" is first one */
-         else
-           frameno = traceframe_number + 1;
-       }
-      else if (0 == strcmp (args, "-"))
-       {
-         if (traceframe_number == -1)
-           error (_("not debugging trace buffer"));
-         else if (from_tty && traceframe_number == 0)
-           error (_("already at start of trace buffer"));
-
-         frameno = traceframe_number - 1;
-       }
-      else
-       frameno = parse_and_eval_long (args);
+      if (traceframe_number == -1)
+       error (_("not debugging trace buffer"));
+      else if (from_tty && traceframe_number == 0)
+       error (_("already at start of trace buffer"));
+      
+      frameno = traceframe_number - 1;
+      }
+  /* A hack to work around eval's need for fp to have been collected.  */
+  else if (0 == strcmp (args, "-1"))
+    frameno = -1;
+  else
+    frameno = parse_and_eval_long (args);
 
-      if (frameno < -1)
-       error (_("invalid input (%d is less than zero)"), frameno);
+  if (frameno < -1)
+    error (_("invalid input (%d is less than zero)"), frameno);
 
-      sprintf (target_buf, "QTFrame:%x", frameno);
-      finish_tfind_command (&target_buf, &target_buf_size, from_tty);
-    }
-  else
-    error (_("Trace can only be run on remote targets."));
+  finish_tfind_command (tfind_number, frameno, 0, 0, from_tty);
 }
 
 /* tfind end */
@@ -2012,22 +1774,15 @@ trace_find_pc_command (char *args, int from_tty)
   CORE_ADDR pc;
   char tmp[40];
 
-  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
-       pc = parse_and_eval_address (args);
+  if (trace_running_p)
+    error ("May not look at trace frames while trace is running.");
 
-      sprintf_vma (tmp, pc);
-      sprintf (target_buf, "QTFrame:pc:%s", tmp);
-      finish_tfind_command (&target_buf, &target_buf_size, from_tty);
-    }
+  if (args == 0 || *args == 0)
+    pc = regcache_read_pc (get_current_regcache ());
   else
-    error (_("Trace can only be run on remote targets."));
+    pc = parse_and_eval_address (args);
+
+  finish_tfind_command (tfind_pc, 0, pc, 0, from_tty);
 }
 
 /* tfind tracepoint command */
@@ -2035,27 +1790,29 @@ static void
 trace_find_tracepoint_command (char *args, int from_tty)
 {
   int tdp;
+  struct breakpoint *tp;
 
-  if (target_is_remote ())
-    {
-      if (trace_running_p)
-       error ("May not look at trace frames while trace is running.");
+  if (trace_running_p)
+    error ("May not look at trace frames while trace is running.");
 
-      if (args == 0 || *args == 0)
-       {
-         if (tracepoint_number == -1)
-           error (_("No current tracepoint -- please supply an argument."));
-         else
-           tdp = tracepoint_number;    /* default is current TDP */
-       }
+  if (args == 0 || *args == 0)
+    {
+      if (tracepoint_number == -1)
+       error (_("No current tracepoint -- please supply an argument."));
       else
-       tdp = parse_and_eval_long (args);
-
-      sprintf (target_buf, "QTFrame:tdp:%x", tdp);
-      finish_tfind_command (&target_buf, &target_buf_size, from_tty);
+       tdp = tracepoint_number;        /* default is current TDP */
     }
   else
-    error (_("Trace can only be run on remote targets."));
+    tdp = parse_and_eval_long (args);
+
+  /* If we have the tracepoint on hand, use the number that the
+     target knows about (which may be different if we disconnected
+     and reconnected).  */
+  tp = get_tracepoint (tdp);
+  if (tp)
+    tdp = tp->number_on_target;
+
+  finish_tfind_command (tfind_tp, tdp, 0, 0, from_tty);
 }
 
 /* TFIND LINE command:
@@ -2075,94 +1832,78 @@ trace_find_line_command (char *args, int from_tty)
   struct cleanup *old_chain;
   char   startpc_str[40], endpc_str[40];
 
-  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);
-         sals.nelts = 1;
-         sals.sals = (struct symtab_and_line *)
-           xmalloc (sizeof (struct symtab_and_line));
-         sals.sals[0] = sal;
-       }
-      else
-       {
-         sals = decode_line_spec (args, 1);
-         sal = sals.sals[0];
-       }
-
-      old_chain = make_cleanup (xfree, sals.sals);
-      if (sal.symtab == 0)
-       {
-         struct gdbarch *gdbarch = get_current_arch ();
+  if (trace_running_p)
+    error ("May not look at trace frames while trace is running.");
 
-         printf_filtered ("TFIND: No line number information available");
-         if (sal.pc != 0)
-           {
-             /* This is useful for "info line *0x7f34".  If we can't
-                tell the user about a source line, at least let them
-                have the symbolic address.  */
-             printf_filtered (" for address ");
-             wrap_here ("  ");
-             print_address (gdbarch, sal.pc, gdb_stdout);
-             printf_filtered (";\n -- will attempt to find by PC. \n");
-           }
-         else
-           {
-             printf_filtered (".\n");
-             return;           /* No line, no PC; what can we do?  */
-           }
-       }
-      else if (sal.line > 0
-              && find_line_pc_range (sal, &start_pc, &end_pc))
+  if (args == 0 || *args == 0)
+    {
+      sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
+      sals.nelts = 1;
+      sals.sals = (struct symtab_and_line *)
+       xmalloc (sizeof (struct symtab_and_line));
+      sals.sals[0] = sal;
+    }
+  else
+      {
+      sals = decode_line_spec (args, 1);
+      sal = sals.sals[0];
+    }
+  
+  old_chain = make_cleanup (xfree, sals.sals);
+  if (sal.symtab == 0)
+    {
+      printf_filtered ("TFIND: No line number information available");
+      if (sal.pc != 0)
        {
-         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 (gdbarch, start_pc, gdb_stdout);
-             wrap_here ("  ");
-             printf_filtered (" but contains no code.\n");
-             sal = find_pc_line (start_pc, 0);
-             if (sal.line > 0 &&
-                 find_line_pc_range (sal, &start_pc, &end_pc) &&
-                 start_pc != end_pc)
-               printf_filtered ("Attempting to find line %d instead.\n",
-                                sal.line);
-             else
-               error (_("Cannot find a good line."));
-           }
-       }
-      else
-       /* Is there any case in which we get here, and have an address
-          which the user would want to see?  If we have debugging
-          symbols and no line numbers?  */
-       error (_("Line number %d is out of range for \"%s\"."),
-              sal.line, sal.symtab->filename);
-
-      sprintf_vma (startpc_str, start_pc);
-      sprintf_vma (endpc_str, end_pc - 1);
-      /* Find within range of stated line.  */
-      if (args && *args)
-       sprintf (target_buf, "QTFrame:range:%s:%s", 
-                startpc_str, endpc_str);
-      /* Find OUTSIDE OF range of CURRENT line.  */
-      else
-       sprintf (target_buf, "QTFrame:outside:%s:%s", 
-                startpc_str, endpc_str);
-      finish_tfind_command (&target_buf, &target_buf_size,
-                           from_tty);
-      do_cleanups (old_chain);
+         /* This is useful for "info line *0x7f34".  If we can't
+            tell the user about a source line, at least let them
+            have the symbolic address.  */
+         printf_filtered (" for address ");
+         wrap_here ("  ");
+         print_address (get_current_arch (), sal.pc, gdb_stdout);
+         printf_filtered (";\n -- will attempt to find by PC. \n");
+       }
+        else
+       {
+         printf_filtered (".\n");
+         return;               /* No line, no PC; what can we do?  */
+       }
     }
+  else if (sal.line > 0
+          && find_line_pc_range (sal, &start_pc, &end_pc))
+    {
+      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 (get_current_arch (), start_pc, gdb_stdout);
+         wrap_here ("  ");
+         printf_filtered (" but contains no code.\n");
+         sal = find_pc_line (start_pc, 0);
+         if (sal.line > 0
+             && find_line_pc_range (sal, &start_pc, &end_pc)
+             && start_pc != end_pc)
+           printf_filtered ("Attempting to find line %d instead.\n",
+                            sal.line);
+         else
+           error (_("Cannot find a good line."));
+       }
+      }
+    else
+    /* Is there any case in which we get here, and have an address
+       which the user would want to see?  If we have debugging
+       symbols and no line numbers?  */
+    error (_("Line number %d is out of range for \"%s\"."),
+          sal.line, sal.symtab->filename);
+
+  /* Find within range of stated line.  */
+  if (args && *args)
+    finish_tfind_command (tfind_range, 0, start_pc, end_pc - 1, from_tty);
   else
-    error (_("Trace can only be run on remote targets."));
+    finish_tfind_command (tfind_outside, 0, start_pc, end_pc - 1, from_tty);
+  do_cleanups (old_chain);
 }
 
 /* tfind range command */
@@ -2173,38 +1914,30 @@ trace_find_range_command (char *args, int from_tty)
   char start_str[40], stop_str[40];
   char *tmp;
 
-  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");
-         return;
-       }
+  if (trace_running_p)
+    error ("May not look at trace frames while trace is running.");
 
-      if (0 != (tmp = strchr (args, ',')))
-       {
-         *tmp++ = '\0';        /* terminate start address */
-         while (isspace ((int) *tmp))
-           tmp++;
-         start = parse_and_eval_address (args);
-         stop = parse_and_eval_address (tmp);
-       }
-      else
-       {                       /* no explicit end address? */
-         start = parse_and_eval_address (args);
-         stop = start + 1;     /* ??? */
-       }
+  if (args == 0 || *args == 0)
+    { /* XXX FIXME: what should default behavior be?  */
+      printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
+      return;
+    }
 
-      sprintf_vma (start_str, start);
-      sprintf_vma (stop_str, stop);
-      sprintf (target_buf, "QTFrame:range:%s:%s", start_str, stop_str);
-      finish_tfind_command (&target_buf, &target_buf_size, from_tty);
+  if (0 != (tmp = strchr (args, ',')))
+    {
+      *tmp++ = '\0';   /* terminate start address */
+      while (isspace ((int) *tmp))
+       tmp++;
+      start = parse_and_eval_address (args);
+      stop = parse_and_eval_address (tmp);
     }
   else
-    error (_("Trace can only be run on remote targets."));
+    {                  /* no explicit end address? */
+      start = parse_and_eval_address (args);
+      stop = start + 1;        /* ??? */
+    }
+
+  finish_tfind_command (tfind_range, 0, start, stop, from_tty);
 }
 
 /* tfind outside command */
@@ -2215,38 +1948,30 @@ trace_find_outside_command (char *args, int from_tty)
   char start_str[40], stop_str[40];
   char *tmp;
 
-  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");
-         return;
-       }
+  if (trace_running_p)
+    error ("May not look at trace frames while trace is running.");
 
-      if (0 != (tmp = strchr (args, ',')))
-       {
-         *tmp++ = '\0';        /* terminate start address */
-         while (isspace ((int) *tmp))
-           tmp++;
-         start = parse_and_eval_address (args);
-         stop = parse_and_eval_address (tmp);
-       }
-      else
-       {                       /* no explicit end address? */
-         start = parse_and_eval_address (args);
-         stop = start + 1;     /* ??? */
-       }
+  if (args == 0 || *args == 0)
+    { /* XXX FIXME: what should default behavior be? */
+      printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
+      return;
+    }
 
-      sprintf_vma (start_str, start);
-      sprintf_vma (stop_str, stop);
-      sprintf (target_buf, "QTFrame:outside:%s:%s", start_str, stop_str);
-      finish_tfind_command (&target_buf, &target_buf_size, from_tty);
+  if (0 != (tmp = strchr (args, ',')))
+    {
+      *tmp++ = '\0';   /* terminate start address */
+      while (isspace ((int) *tmp))
+       tmp++;
+      start = parse_and_eval_address (args);
+      stop = parse_and_eval_address (tmp);
     }
   else
-    error (_("Trace can only be run on remote targets."));
+    {                  /* no explicit end address? */
+      start = parse_and_eval_address (args);
+      stop = start + 1;        /* ??? */
+    }
+
+  finish_tfind_command (tfind_outside, 0, start, stop, from_tty);
 }
 
 /* info scope command: list the locals for a scope.  */
@@ -2417,12 +2142,6 @@ trace_dump_command (char *args, int from_tty)
   int stepping_actions = 0;
   int stepping_frame = 0;
 
-  if (!target_is_remote ())
-    {
-      error (_("Trace can only be run on remote targets."));
-      return;
-    }
-
   if (tracepoint_number == -1)
     {
       warning (_("No current trace frame."));
@@ -2447,8 +2166,7 @@ trace_dump_command (char *args, int from_tty)
   regcache = get_current_regcache ();
   gdbarch = get_regcache_arch (regcache);
 
-  stepping_frame = (t->loc->address != (regcache_read_pc (regcache)
-                                  - gdbarch_decr_pc_after_break (gdbarch)));
+  stepping_frame = (t->loc->address != (regcache_read_pc (regcache)));
 
   for (action = t->actions; action; action = action->next)
     {
@@ -2521,6 +2239,22 @@ trace_dump_command (char *args, int from_tty)
   discard_cleanups (old_cleanups);
 }
 
+/* Tell the target what to do with an ongoing tracing run if GDB
+   disconnects for some reason.  */
+
+void
+send_disconnected_tracing_value (int value)
+{
+  target_set_disconnected_tracing (value);
+}
+
+static void
+set_disconnected_tracing (char *args, int from_tty,
+                         struct cmd_list_element *c)
+{
+  send_disconnected_tracing_value (disconnected_tracing);
+}
+
 /* Convert the memory pointed to by mem into hex, placing result in buf.
  * Return a pointer to the last char put in buf (null)
  * "stolen" from sparc-stub.c
@@ -2552,7 +2286,6 @@ get_traceframe_number (void)
   return traceframe_number;
 }
 
-
 /* module initialization */
 void
 _initialize_tracepoint (void)
@@ -2718,6 +2451,15 @@ Show the list of expressions to collect by default"), NULL,
                          NULL, NULL,
                          &setlist, &showlist);
 
-  target_buf_size = 2048;
-  target_buf = xmalloc (target_buf_size);
+  add_setshow_boolean_cmd ("disconnected-tracing", no_class,
+                          &disconnected_tracing, _("\
+Set whether tracing continues after GDB disconnects."), _("\
+Show whether tracing continues after GDB disconnects."), _("\
+Use this to continue a tracing run even if GDB disconnects\n\
+or detaches from the target.  You can reconnect later and look at\n\
+trace data collected in the meantime."),
+                          set_disconnected_tracing,
+                          NULL,
+                          &setlist,
+                          &showlist);
 }
This page took 0.056181 seconds and 4 git commands to generate.