btrace: split record_btrace_step_thread
[deliverable/binutils-gdb.git] / gdb / record-btrace.c
index 6bd9d0118914e40e867b969109dac70d03180331..fdf7afba8bba863bbba238810fffb295f489786a 100644 (file)
@@ -80,6 +80,10 @@ static struct cmd_list_element *record_btrace_cmdlist;
 static struct cmd_list_element *set_record_btrace_bts_cmdlist;
 static struct cmd_list_element *show_record_btrace_bts_cmdlist;
 
+/* Command lists for "set/show record btrace pt".  */
+static struct cmd_list_element *set_record_btrace_pt_cmdlist;
+static struct cmd_list_element *show_record_btrace_pt_cmdlist;
+
 /* Print a record-btrace debug message.  Use do ... while (0) to avoid
    ambiguities when used in if statements.  */
 
@@ -278,17 +282,14 @@ record_btrace_close (struct target_ops *self)
 /* The to_async method of target record-btrace.  */
 
 static void
-record_btrace_async (struct target_ops *ops,
-                    void (*callback) (enum inferior_event_type event_type,
-                                      void *context),
-                    void *context)
+record_btrace_async (struct target_ops *ops, int enable)
 {
-  if (callback != NULL)
+  if (enable)
     mark_async_event_handler (record_btrace_async_inferior_event_handler);
   else
     clear_async_event_handler (record_btrace_async_inferior_event_handler);
 
-  ops->beneath->to_async (ops->beneath, callback, context);
+  ops->beneath->to_async (ops->beneath, enable);
 }
 
 /* Adjusts the size and returns a human readable size suffix.  */
@@ -335,6 +336,22 @@ record_btrace_print_bts_conf (const struct btrace_config_bts *conf)
     }
 }
 
+/* Print an Intel(R) Processor Trace configuration.  */
+
+static void
+record_btrace_print_pt_conf (const struct btrace_config_pt *conf)
+{
+  const char *suffix;
+  unsigned int size;
+
+  size = conf->size;
+  if (size > 0)
+    {
+      suffix = record_btrace_adjust_size (&size);
+      printf_unfiltered (_("Buffer size: %u%s.\n"), size, suffix);
+    }
+}
+
 /* Print a branch tracing configuration.  */
 
 static void
@@ -351,6 +368,10 @@ record_btrace_print_conf (const struct btrace_config *conf)
     case BTRACE_FORMAT_BTS:
       record_btrace_print_bts_conf (&conf->bts);
       return;
+
+    case BTRACE_FORMAT_PT:
+      record_btrace_print_pt_conf (&conf->pt);
+      return;
     }
 
   internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
@@ -461,6 +482,33 @@ btrace_ui_out_decode_error (struct ui_out *uiout, int errcode,
          break;
        }
       break;
+
+#if defined (HAVE_LIBIPT)
+    case BTRACE_FORMAT_PT:
+      switch (errcode)
+       {
+       case BDE_PT_USER_QUIT:
+         is_error = 0;
+         errstr = _("trace decode cancelled");
+         break;
+
+       case BDE_PT_DISABLED:
+         is_error = 0;
+         errstr = _("disabled");
+         break;
+
+       case BDE_PT_OVERFLOW:
+         is_error = 0;
+         errstr = _("overflow");
+         break;
+
+       default:
+         if (errcode < 0)
+           errstr = pt_errstr (pt_errcode (errcode));
+         break;
+       }
+      break;
+#endif /* defined (HAVE_LIBIPT)  */
     }
 
   ui_out_text (uiout, _("["));
@@ -519,14 +567,35 @@ btrace_insn_history (struct ui_out *uiout,
        }
       else
        {
+         char prefix[4];
+
+         /* We may add a speculation prefix later.  We use the same space
+            that is used for the pc prefix.  */
+         if ((flags & DISASSEMBLY_OMIT_PC) == 0)
+           strncpy (prefix, pc_prefix (insn->pc), 3);
+         else
+           {
+             prefix[0] = ' ';
+             prefix[1] = ' ';
+             prefix[2] = ' ';
+           }
+         prefix[3] = 0;
+
          /* Print the instruction index.  */
          ui_out_field_uint (uiout, "index", btrace_insn_number (&it));
          ui_out_text (uiout, "\t");
 
+         /* Indicate speculative execution by a leading '?'.  */
+         if ((insn->flags & BTRACE_INSN_FLAG_SPECULATIVE) != 0)
+           prefix[0] = '?';
+
+         /* Print the prefix; we tell gdb_disassembly below to omit it.  */
+         ui_out_field_fmt (uiout, "prefix", "%s", prefix);
+
          /* Disassembly with '/m' flag may not produce the expected result.
             See PR gdb/11833.  */
-         gdb_disassembly (gdbarch, uiout, NULL, flags, 1, insn->pc,
-                          insn->pc + 1);
+         gdb_disassembly (gdbarch, uiout, NULL, flags | DISASSEMBLY_OMIT_PC,
+                          1, insn->pc, insn->pc + 1);
        }
     }
 }
@@ -1155,14 +1224,13 @@ record_btrace_insert_breakpoint (struct target_ops *ops,
     {
       ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
     }
-
-  replay_memory_access = old;
-
   CATCH (except, RETURN_MASK_ALL)
     {
+      replay_memory_access = old;
       throw_exception (except);
     }
   END_CATCH
+  replay_memory_access = old;
 
   return ret;
 }
@@ -1187,14 +1255,13 @@ record_btrace_remove_breakpoint (struct target_ops *ops,
     {
       ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch, bp_tgt);
     }
-
-  replay_memory_access = old;
-
   CATCH (except, RETURN_MASK_ALL)
     {
+      replay_memory_access = old;
       throw_exception (except);
     }
   END_CATCH
+  replay_memory_access = old;
 
   return ret;
 }
@@ -1592,6 +1659,32 @@ record_btrace_to_get_tailcall_unwinder (struct target_ops *self)
   return &record_btrace_tailcall_frame_unwind;
 }
 
+/* Return a human-readable string for FLAG.  */
+
+static const char *
+btrace_thread_flag_to_str (enum btrace_thread_flag flag)
+{
+  switch (flag)
+    {
+    case BTHR_STEP:
+      return "step";
+
+    case BTHR_RSTEP:
+      return "reverse-step";
+
+    case BTHR_CONT:
+      return "cont";
+
+    case BTHR_RCONT:
+      return "reverse-cont";
+
+    case BTHR_STOP:
+      return "stop";
+    }
+
+  return "<invalid>";
+}
+
 /* Indicate that TP should be resumed according to FLAG.  */
 
 static void
@@ -1600,7 +1693,8 @@ record_btrace_resume_thread (struct thread_info *tp,
 {
   struct btrace_thread_info *btinfo;
 
-  DEBUG ("resuming %d (%s): %u", tp->num, target_pid_to_str (tp->ptid), flag);
+  DEBUG ("resuming thread %d (%s): %x (%s)", tp->num,
+        target_pid_to_str (tp->ptid), flag, btrace_thread_flag_to_str (flag));
 
   btinfo = &tp->btrace;
 
@@ -1610,6 +1704,8 @@ record_btrace_resume_thread (struct thread_info *tp,
   /* Fetch the latest branch trace.  */
   btrace_fetch (tp);
 
+  /* A resume request overwrites a preceding stop request.  */
+  btinfo->flags &= ~BTHR_STOP;
   btinfo->flags |= flag;
 }
 
@@ -1676,7 +1772,7 @@ record_btrace_start_replaying (struct thread_info *tp)
 
       /* We start replaying at the end of the branch trace.  This corresponds
         to the current instruction.  */
-      replay = xmalloc (sizeof (*replay));
+      replay = XNEW (struct btrace_insn_iterator);
       btrace_insn_end (replay, btinfo);
 
       /* Skip gaps at the end of the trace.  */
@@ -1706,12 +1802,11 @@ record_btrace_start_replaying (struct thread_info *tp)
       if (upd_step_stack_frame_id)
        tp->control.step_stack_frame_id = frame_id;
     }
-
-  /* Restore the previous execution state.  */
-  set_executing (tp->ptid, executing);
-
   CATCH (except, RETURN_MASK_ALL)
     {
+      /* Restore the previous execution state.  */
+      set_executing (tp->ptid, executing);
+
       xfree (btinfo->replay);
       btinfo->replay = NULL;
 
@@ -1721,6 +1816,9 @@ record_btrace_start_replaying (struct thread_info *tp)
     }
   END_CATCH
 
+  /* Restore the previous execution state.  */
+  set_executing (tp->ptid, executing);
+
   return replay;
 }
 
@@ -1749,7 +1847,9 @@ record_btrace_resume (struct target_ops *ops, ptid_t ptid, int step,
   struct thread_info *tp, *other;
   enum btrace_thread_flag flag;
 
-  DEBUG ("resume %s: %s", target_pid_to_str (ptid), step ? "step" : "cont");
+  DEBUG ("resume %s: %s%s", target_pid_to_str (ptid),
+        execution_direction == EXEC_REVERSE ? "reverse-" : "",
+        step ? "step" : "cont");
 
   /* Store the execution direction of the last resume.  */
   record_btrace_resume_exec_dir = execution_direction;
@@ -1789,11 +1889,29 @@ record_btrace_resume (struct target_ops *ops, ptid_t ptid, int step,
   /* Async support.  */
   if (target_can_async_p ())
     {
-      target_async (inferior_event_handler, 0);
+      target_async (1);
       mark_async_event_handler (record_btrace_async_inferior_event_handler);
     }
 }
 
+/* Cancel resuming TP.  */
+
+static void
+record_btrace_cancel_resume (struct thread_info *tp)
+{
+  enum btrace_thread_flag flags;
+
+  flags = tp->btrace.flags & (BTHR_MOVE | BTHR_STOP);
+  if (flags == 0)
+    return;
+
+  DEBUG ("cancel resume thread %d (%s): %x (%s)", tp->num,
+        target_pid_to_str (tp->ptid), flags,
+        btrace_thread_flag_to_str (flags));
+
+  tp->btrace.flags &= ~(BTHR_MOVE | BTHR_STOP);
+}
+
 /* Find a thread to move.  */
 
 static struct thread_info *
@@ -1803,12 +1921,12 @@ record_btrace_find_thread_to_move (ptid_t ptid)
 
   /* First check the parameter thread.  */
   tp = find_thread_ptid (ptid);
-  if (tp != NULL && (tp->btrace.flags & BTHR_MOVE) != 0)
+  if (tp != NULL && (tp->btrace.flags & (BTHR_MOVE | BTHR_STOP)) != 0)
     return tp;
 
   /* Otherwise, find one other thread that has been resumed.  */
   ALL_NON_EXITED_THREADS (tp)
-    if ((tp->btrace.flags & BTHR_MOVE) != 0)
+    if ((tp->btrace.flags & (BTHR_MOVE | BTHR_STOP)) != 0)
       return tp;
 
   return NULL;
@@ -1839,6 +1957,32 @@ btrace_step_stopped (void)
   return status;
 }
 
+/* Return a target_waitstatus indicating that a thread was stopped as
+   requested.  */
+
+static struct target_waitstatus
+btrace_step_stopped_on_request (void)
+{
+  struct target_waitstatus status;
+
+  status.kind = TARGET_WAITKIND_STOPPED;
+  status.value.sig = GDB_SIGNAL_0;
+
+  return status;
+}
+
+/* Return a target_waitstatus indicating a spurious stop.  */
+
+static struct target_waitstatus
+btrace_step_spurious (void)
+{
+  struct target_waitstatus status;
+
+  status.kind = TARGET_WAITKIND_SPURIOUS;
+
+  return status;
+}
+
 /* Clear the record histories.  */
 
 static void
@@ -1851,154 +1995,189 @@ record_btrace_clear_histories (struct btrace_thread_info *btinfo)
   btinfo->call_history = NULL;
 }
 
-/* Step a single thread.  */
+/* Check whether TP's current replay position is at a breakpoint.  */
+
+static int
+record_btrace_replay_at_breakpoint (struct thread_info *tp)
+{
+  struct btrace_insn_iterator *replay;
+  struct btrace_thread_info *btinfo;
+  const struct btrace_insn *insn;
+  struct inferior *inf;
+
+  btinfo = &tp->btrace;
+  replay = btinfo->replay;
+
+  if (replay == NULL)
+    return 0;
+
+  insn = btrace_insn_get (replay);
+  if (insn == NULL)
+    return 0;
+
+  inf = find_inferior_ptid (tp->ptid);
+  if (inf == NULL)
+    return 0;
+
+  return record_check_stopped_by_breakpoint (inf->aspace, insn->pc,
+                                            &btinfo->stop_reason);
+}
+
+/* Step one instruction in forward direction.  */
 
 static struct target_waitstatus
-record_btrace_step_thread (struct thread_info *tp)
+record_btrace_single_step_forward (struct thread_info *tp)
 {
   struct btrace_insn_iterator *replay, end;
   struct btrace_thread_info *btinfo;
-  struct address_space *aspace;
-  struct inferior *inf;
-  enum btrace_thread_flag flags;
-  unsigned int steps;
 
-  /* We can't step without an execution history.  */
-  if (btrace_is_empty (tp))
+  btinfo = &tp->btrace;
+  replay = btinfo->replay;
+
+  /* We're done if we're not replaying.  */
+  if (replay == NULL)
     return btrace_step_no_history ();
 
+  /* Skip gaps during replay.  */
+  do
+    {
+      unsigned int steps;
+
+      steps = btrace_insn_next (replay, 1);
+      if (steps == 0)
+       {
+         record_btrace_stop_replaying (tp);
+         return btrace_step_no_history ();
+       }
+    }
+  while (btrace_insn_get (replay) == NULL);
+
+  /* Determine the end of the instruction trace.  */
+  btrace_insn_end (&end, btinfo);
+
+  /* We stop replaying if we reached the end of the trace.  */
+  if (btrace_insn_cmp (replay, &end) == 0)
+    record_btrace_stop_replaying (tp);
+
+  return btrace_step_spurious ();
+}
+
+/* Step one instruction in backward direction.  */
+
+static struct target_waitstatus
+record_btrace_single_step_backward (struct thread_info *tp)
+{
+  struct btrace_insn_iterator *replay;
+  struct btrace_thread_info *btinfo;
+
   btinfo = &tp->btrace;
   replay = btinfo->replay;
 
-  flags = btinfo->flags & BTHR_MOVE;
-  btinfo->flags &= ~BTHR_MOVE;
-
-  DEBUG ("stepping %d (%s): %u", tp->num, target_pid_to_str (tp->ptid), flags);
+  /* Start replaying if we're not already doing so.  */
+  if (replay == NULL)
+    replay = record_btrace_start_replaying (tp);
 
-  switch (flags)
+  /* If we can't step any further, we reached the end of the history.
+     Skip gaps during replay.  */
+  do
     {
-    default:
-      internal_error (__FILE__, __LINE__, _("invalid stepping type."));
+      unsigned int steps;
 
-    case BTHR_STEP:
-      /* We're done if we're not replaying.  */
-      if (replay == NULL)
+      steps = btrace_insn_prev (replay, 1);
+      if (steps == 0)
        return btrace_step_no_history ();
+    }
+  while (btrace_insn_get (replay) == NULL);
 
-      /* Skip gaps during replay.  */
-      do
-       {
-         steps = btrace_insn_next (replay, 1);
-         if (steps == 0)
-           {
-             record_btrace_stop_replaying (tp);
-             return btrace_step_no_history ();
-           }
-       }
-      while (btrace_insn_get (replay) == NULL);
+  return btrace_step_spurious ();
+}
 
-      /* Determine the end of the instruction trace.  */
-      btrace_insn_end (&end, btinfo);
+/* Step a single thread.  */
 
-      /* We stop replaying if we reached the end of the trace.  */
-      if (btrace_insn_cmp (replay, &end) == 0)
-       record_btrace_stop_replaying (tp);
+static struct target_waitstatus
+record_btrace_step_thread (struct thread_info *tp)
+{
+  struct btrace_thread_info *btinfo;
+  struct target_waitstatus status;
+  enum btrace_thread_flag flags;
 
-      return btrace_step_stopped ();
+  btinfo = &tp->btrace;
 
-    case BTHR_RSTEP:
-      /* Start replaying if we're not already doing so.  */
-      if (replay == NULL)
-       replay = record_btrace_start_replaying (tp);
+  flags = btinfo->flags & (BTHR_MOVE | BTHR_STOP);
+  btinfo->flags &= ~(BTHR_MOVE | BTHR_STOP);
 
-      /* If we can't step any further, we reached the end of the history.
-        Skip gaps during replay.  */
-      do
-       {
-         steps = btrace_insn_prev (replay, 1);
-         if (steps == 0)
-           return btrace_step_no_history ();
+  DEBUG ("stepping thread %d (%s): %x (%s)", tp->num,
+        target_pid_to_str (tp->ptid), flags,
+        btrace_thread_flag_to_str (flags));
 
-       }
-      while (btrace_insn_get (replay) == NULL);
+  /* We can't step without an execution history.  */
+  if ((flags & BTHR_MOVE) != 0 && btrace_is_empty (tp))
+    return btrace_step_no_history ();
 
-      return btrace_step_stopped ();
+  switch (flags)
+    {
+    default:
+      internal_error (__FILE__, __LINE__, _("invalid stepping type."));
 
-    case BTHR_CONT:
-      /* We're done if we're not replaying.  */
-      if (replay == NULL)
-       return btrace_step_no_history ();
+    case BTHR_STOP:
+      return btrace_step_stopped_on_request ();
 
-      inf = find_inferior_ptid (tp->ptid);
-      aspace = inf->aspace;
+    case BTHR_STEP:
+      status = record_btrace_single_step_forward (tp);
+      if (status.kind != TARGET_WAITKIND_SPURIOUS)
+       return status;
 
-      /* Determine the end of the instruction trace.  */
-      btrace_insn_end (&end, btinfo);
+      return btrace_step_stopped ();
+
+    case BTHR_RSTEP:
+      status = record_btrace_single_step_backward (tp);
+      if (status.kind != TARGET_WAITKIND_SPURIOUS)
+       return status;
+
+      return btrace_step_stopped ();
 
+    case BTHR_CONT:
       for (;;)
        {
-         const struct btrace_insn *insn;
+         status = record_btrace_single_step_forward (tp);
+         if (status.kind != TARGET_WAITKIND_SPURIOUS)
+           return status;
 
-         /* Skip gaps during replay.  */
-         do
+         if (btinfo->replay != NULL)
            {
-             steps = btrace_insn_next (replay, 1);
-             if (steps == 0)
-               {
-                 record_btrace_stop_replaying (tp);
-                 return btrace_step_no_history ();
-               }
+             const struct btrace_insn *insn;
 
-             insn = btrace_insn_get (replay);
-           }
-         while (insn == NULL);
+             insn = btrace_insn_get (btinfo->replay);
+             gdb_assert (insn != NULL);
 
-         /* We stop replaying if we reached the end of the trace.  */
-         if (btrace_insn_cmp (replay, &end) == 0)
-           {
-             record_btrace_stop_replaying (tp);
-             return btrace_step_no_history ();
+             DEBUG ("stepping %d (%s) ... %s", tp->num,
+                    target_pid_to_str (tp->ptid),
+                    core_addr_to_string_nz (insn->pc));
            }
 
-         DEBUG ("stepping %d (%s) ... %s", tp->num,
-                target_pid_to_str (tp->ptid),
-                core_addr_to_string_nz (insn->pc));
-
-         if (record_check_stopped_by_breakpoint (aspace, insn->pc,
-                                                 &btinfo->stop_reason))
+         if (record_btrace_replay_at_breakpoint (tp))
            return btrace_step_stopped ();
        }
 
     case BTHR_RCONT:
-      /* Start replaying if we're not already doing so.  */
-      if (replay == NULL)
-       replay = record_btrace_start_replaying (tp);
-
-      inf = find_inferior_ptid (tp->ptid);
-      aspace = inf->aspace;
-
       for (;;)
        {
          const struct btrace_insn *insn;
 
-         /* If we can't step any further, we reached the end of the history.
-            Skip gaps during replay.  */
-         do
-           {
-             steps = btrace_insn_prev (replay, 1);
-             if (steps == 0)
-               return btrace_step_no_history ();
+         status = record_btrace_single_step_backward (tp);
+         if (status.kind != TARGET_WAITKIND_SPURIOUS)
+           return status;
 
-             insn = btrace_insn_get (replay);
-           }
-         while (insn == NULL);
+         gdb_assert (btinfo->replay != NULL);
+
+         insn = btrace_insn_get (btinfo->replay);
+         gdb_assert (insn != NULL);
 
          DEBUG ("reverse-stepping %d (%s) ... %s", tp->num,
                 target_pid_to_str (tp->ptid),
                 core_addr_to_string_nz (insn->pc));
 
-         if (record_check_stopped_by_breakpoint (aspace, insn->pc,
-                                                 &btinfo->stop_reason))
+         if (record_btrace_replay_at_breakpoint (tp))
            return btrace_step_stopped ();
        }
     }
@@ -2035,9 +2214,9 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid,
   *status = record_btrace_step_thread (tp);
 
   /* Stop all other threads. */
-  if (!non_stop)
+  if (!target_is_non_stop_p ())
     ALL_NON_EXITED_THREADS (other)
-      other->btrace.flags &= ~BTHR_MOVE;
+      record_btrace_cancel_resume (other);
 
   /* Start record histories anew from the current position.  */
   record_btrace_clear_histories (&tp->btrace);
@@ -2048,6 +2227,32 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid,
   return tp->ptid;
 }
 
+/* The to_stop method of target record-btrace.  */
+
+static void
+record_btrace_stop (struct target_ops *ops, ptid_t ptid)
+{
+  DEBUG ("stop %s", target_pid_to_str (ptid));
+
+  /* As long as we're not replaying, just forward the request.  */
+  if (!record_btrace_is_replaying (ops) && execution_direction != EXEC_REVERSE)
+    {
+      ops = ops->beneath;
+      ops->to_stop (ops, ptid);
+    }
+  else
+    {
+      struct thread_info *tp;
+
+      ALL_NON_EXITED_THREADS (tp)
+       if (ptid_match (tp->ptid, ptid))
+         {
+           tp->btrace.flags &= ~BTHR_MOVE;
+           tp->btrace.flags |= BTHR_STOP;
+         }
+    }
+ }
+
 /* The to_can_execute_reverse method of target record-btrace.  */
 
 static int
@@ -2164,6 +2369,9 @@ record_btrace_set_replay (struct thread_info *tp,
 
   /* Start anew from the new replay position.  */
   record_btrace_clear_histories (btinfo);
+
+  stop_pc = regcache_read_pc (get_current_regcache ());
+  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 
 /* The to_goto_record_begin method of target record-btrace.  */
@@ -2178,8 +2386,6 @@ record_btrace_goto_begin (struct target_ops *self)
 
   btrace_insn_begin (&begin, &tp->btrace);
   record_btrace_set_replay (tp, &begin);
-
-  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 
 /* The to_goto_record_end method of target record-btrace.  */
@@ -2192,8 +2398,6 @@ record_btrace_goto_end (struct target_ops *ops)
   tp = require_btrace_thread ();
 
   record_btrace_set_replay (tp, NULL);
-
-  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 
 /* The to_goto_record method of target record-btrace.  */
@@ -2219,8 +2423,6 @@ record_btrace_goto (struct target_ops *self, ULONGEST insn)
     error (_("No such instruction."));
 
   record_btrace_set_replay (tp, &it);
-
-  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 
 /* The to_execution_direction target method.  */
@@ -2284,6 +2486,7 @@ init_record_btrace_ops (void)
   ops->to_get_tailcall_unwinder = &record_btrace_to_get_tailcall_unwinder;
   ops->to_resume = record_btrace_resume;
   ops->to_wait = record_btrace_wait;
+  ops->to_stop = record_btrace_stop;
   ops->to_update_thread_list = record_btrace_update_thread_list;
   ops->to_thread_alive = record_btrace_thread_alive;
   ops->to_goto_record_begin = record_btrace_goto_begin;
@@ -2308,7 +2511,6 @@ init_record_btrace_ops (void)
 static void
 cmd_record_btrace_bts_start (char *args, int from_tty)
 {
-
   if (args != NULL && *args != 0)
     error (_("Invalid argument."));
 
@@ -2326,16 +2528,15 @@ cmd_record_btrace_bts_start (char *args, int from_tty)
   END_CATCH
 }
 
-/* Alias for "target record".  */
+/* Start recording Intel(R) Processor Trace.  */
 
 static void
-cmd_record_btrace_start (char *args, int from_tty)
+cmd_record_btrace_pt_start (char *args, int from_tty)
 {
-
   if (args != NULL && *args != 0)
     error (_("Invalid argument."));
 
-  record_btrace_conf.format = BTRACE_FORMAT_BTS;
+  record_btrace_conf.format = BTRACE_FORMAT_PT;
 
   TRY
     {
@@ -2349,6 +2550,38 @@ cmd_record_btrace_start (char *args, int from_tty)
   END_CATCH
 }
 
+/* Alias for "target record".  */
+
+static void
+cmd_record_btrace_start (char *args, int from_tty)
+{
+  if (args != NULL && *args != 0)
+    error (_("Invalid argument."));
+
+  record_btrace_conf.format = BTRACE_FORMAT_PT;
+
+  TRY
+    {
+      execute_command ("target record-btrace", from_tty);
+    }
+  CATCH (exception, RETURN_MASK_ALL)
+    {
+      record_btrace_conf.format = BTRACE_FORMAT_BTS;
+
+      TRY
+       {
+         execute_command ("target record-btrace", from_tty);
+       }
+      CATCH (exception, RETURN_MASK_ALL)
+       {
+         record_btrace_conf.format = BTRACE_FORMAT_NONE;
+         throw_exception (exception);
+       }
+      END_CATCH
+    }
+  END_CATCH
+}
+
 /* The "set record btrace" command.  */
 
 static void
@@ -2381,7 +2614,7 @@ static void
 cmd_set_record_btrace_bts (char *args, int from_tty)
 {
   printf_unfiltered (_("\"set record btrace bts\" must be followed "
-                      "by an apporpriate subcommand.\n"));
+                      "by an appropriate subcommand.\n"));
   help_list (set_record_btrace_bts_cmdlist, "set record btrace bts ",
             all_commands, gdb_stdout);
 }
@@ -2394,6 +2627,47 @@ cmd_show_record_btrace_bts (char *args, int from_tty)
   cmd_show_list (show_record_btrace_bts_cmdlist, from_tty, "");
 }
 
+/* The "set record btrace pt" command.  */
+
+static void
+cmd_set_record_btrace_pt (char *args, int from_tty)
+{
+  printf_unfiltered (_("\"set record btrace pt\" must be followed "
+                      "by an appropriate subcommand.\n"));
+  help_list (set_record_btrace_pt_cmdlist, "set record btrace pt ",
+            all_commands, gdb_stdout);
+}
+
+/* The "show record btrace pt" command.  */
+
+static void
+cmd_show_record_btrace_pt (char *args, int from_tty)
+{
+  cmd_show_list (show_record_btrace_pt_cmdlist, from_tty, "");
+}
+
+/* The "record bts buffer-size" show value function.  */
+
+static void
+show_record_bts_buffer_size_value (struct ui_file *file, int from_tty,
+                                  struct cmd_list_element *c,
+                                  const char *value)
+{
+  fprintf_filtered (file, _("The record/replay bts buffer size is %s.\n"),
+                   value);
+}
+
+/* The "record pt buffer-size" show value function.  */
+
+static void
+show_record_pt_buffer_size_value (struct ui_file *file, int from_tty,
+                                 struct cmd_list_element *c,
+                                 const char *value)
+{
+  fprintf_filtered (file, _("The record/replay pt buffer size is %s.\n"),
+                   value);
+}
+
 void _initialize_record_btrace (void);
 
 /* Initialize btrace commands.  */
@@ -2414,6 +2688,13 @@ This format may not be available on all processors."),
           &record_btrace_cmdlist);
   add_alias_cmd ("bts", "btrace bts", class_obscure, 1, &record_cmdlist);
 
+  add_cmd ("pt", class_obscure, cmd_record_btrace_pt_start,
+          _("\
+Start branch trace recording in Intel(R) Processor Trace format.\n\n\
+This format may not be available on all processors."),
+          &record_btrace_cmdlist);
+  add_alias_cmd ("pt", "btrace pt", class_obscure, 1, &record_cmdlist);
+
   add_prefix_cmd ("btrace", class_support, cmd_set_record_btrace,
                  _("Set record options"), &set_record_btrace_cmdlist,
                  "set record btrace ", 0, &set_record_cmdlist);
@@ -2456,10 +2737,32 @@ The actual buffer size may differ from the requested size.  \
 Use \"info record\" to see the actual buffer size.\n\n\
 Bigger buffers allow longer recording but also take more time to process \
 the recorded execution trace.\n\n\
-The trace buffer size may not be changed while recording."), NULL, NULL,
+The trace buffer size may not be changed while recording."), NULL,
+                           show_record_bts_buffer_size_value,
                            &set_record_btrace_bts_cmdlist,
                            &show_record_btrace_bts_cmdlist);
 
+  add_prefix_cmd ("pt", class_support, cmd_set_record_btrace_pt,
+                 _("Set record btrace pt options"),
+                 &set_record_btrace_pt_cmdlist,
+                 "set record btrace pt ", 0, &set_record_btrace_cmdlist);
+
+  add_prefix_cmd ("pt", class_support, cmd_show_record_btrace_pt,
+                 _("Show record btrace pt options"),
+                 &show_record_btrace_pt_cmdlist,
+                 "show record btrace pt ", 0, &show_record_btrace_cmdlist);
+
+  add_setshow_uinteger_cmd ("buffer-size", no_class,
+                           &record_btrace_conf.pt.size,
+                           _("Set the record/replay pt buffer size."),
+                           _("Show the record/replay pt buffer size."), _("\
+Bigger buffers allow longer recording but also take more time to process \
+the recorded execution.\n\
+The actual buffer size may differ from the requested size.  Use \"info record\" \
+to see the actual buffer size."), NULL, show_record_pt_buffer_size_value,
+                           &set_record_btrace_pt_cmdlist,
+                           &show_record_btrace_pt_cmdlist);
+
   init_record_btrace_ops ();
   add_target (&record_btrace_ops);
 
@@ -2467,4 +2770,5 @@ The trace buffer size may not be changed while recording."), NULL, NULL,
                               xcalloc, xfree);
 
   record_btrace_conf.bts.size = 64 * 1024;
+  record_btrace_conf.pt.size = 16 * 1024;
 }
This page took 0.032537 seconds and 4 git commands to generate.