Unbreak PPC gdb builds
[deliverable/binutils-gdb.git] / gdb / record-btrace.c
index 6bd9d0118914e40e867b969109dac70d03180331..6f4ee669422c0757259e4e8bd55f34bc62ce30fa 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, _("["));
@@ -1155,14 +1203,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 +1234,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;
 }
@@ -1706,12 +1752,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 +1766,9 @@ record_btrace_start_replaying (struct thread_info *tp)
     }
   END_CATCH
 
+  /* Restore the previous execution state.  */
+  set_executing (tp->ptid, executing);
+
   return replay;
 }
 
@@ -1789,7 +1837,7 @@ 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);
     }
 }
@@ -2164,6 +2212,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 +2229,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 +2241,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 +2266,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.  */
@@ -2308,7 +2353,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 +2370,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 +2392,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 +2456,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 +2469,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 +2530,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 +2579,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 +2612,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.030286 seconds and 4 git commands to generate.