gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / record-btrace.c
index 7e5b7860df6ee5d8c7de9c00a45660b823827f1b..226d56dfe3774dad2660a4a33f6801b516c426ce 100644 (file)
 #include "frame-unwind.h"
 #include "hashtab.h"
 #include "infrun.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "inf-loop.h"
 #include "inferior.h"
 #include <algorithm>
 #include "gdbarch.h"
 #include "cli/cli-style.h"
+#include "async-event.h"
 
 static const target_info record_btrace_target_info = {
   "record-btrace",
@@ -283,6 +284,11 @@ require_btrace (void)
 static void
 record_btrace_enable_warn (struct thread_info *tp)
 {
+  /* Ignore this thread if its inferior is not recorded by us.  */
+  target_ops *rec = tp->inf->target_at (record_stratum);
+  if (rec != &record_btrace_ops)
+    return;
+
   try
     {
       btrace_enable (tp, &record_btrace_conf);
@@ -386,7 +392,7 @@ record_btrace_target_open (const char *args, int from_tty)
   if (!target_has_execution)
     error (_("The program is not being run."));
 
-  for (thread_info *tp : all_non_exited_threads ())
+  for (thread_info *tp : current_inferior ()->non_exited_threads ())
     if (args == NULL || *args == 0 || number_is_in_list (args, tp->global_num))
       {
        btrace_enable (tp, &record_btrace_conf);
@@ -408,7 +414,7 @@ record_btrace_target::stop_recording ()
 
   record_btrace_auto_disable ();
 
-  for (thread_info *tp : all_non_exited_threads ())
+  for (thread_info *tp : current_inferior ()->non_exited_threads ())
     if (tp->btrace.target != NULL)
       btrace_disable (tp);
 }
@@ -442,7 +448,7 @@ record_btrace_target::close ()
 
   /* We should have already stopped recording.
      Tear down btrace in case we have not.  */
-  for (thread_info *tp : all_non_exited_threads ())
+  for (thread_info *tp : current_inferior ()->non_exited_threads ())
     btrace_teardown (tp);
 }
 
@@ -541,7 +547,7 @@ record_btrace_print_conf (const struct btrace_config *conf)
       return;
     }
 
-  internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
+  internal_error (__FILE__, __LINE__, _("Unknown branch trace format."));
 }
 
 /* The info_record method of target record-btrace.  */
@@ -718,7 +724,16 @@ btrace_find_line_range (CORE_ADDR pc)
   range = btrace_mk_line_range (symtab, 0, 0);
   for (i = 0; i < nlines - 1; i++)
     {
-      if ((lines[i].pc == pc) && (lines[i].line != 0))
+      /* The test of is_stmt here was added when the is_stmt field was
+        introduced to the 'struct linetable_entry' structure.  This
+        ensured that this loop maintained the same behaviour as before we
+        introduced is_stmt.  That said, it might be that we would be
+        better off not checking is_stmt here, this would lead to us
+        possibly adding more line numbers to the range.  At the time this
+        change was made I was unsure how to test this so chose to go with
+        maintaining the existing experience.  */
+      if ((lines[i].pc == pc) && (lines[i].line != 0)
+         && (lines[i].is_stmt == 1))
        range = btrace_line_range_add (range, lines[i].line);
     }
 
@@ -1522,11 +1537,16 @@ record_btrace_target::remove_breakpoint (struct gdbarch *gdbarch,
 void
 record_btrace_target::fetch_registers (struct regcache *regcache, int regno)
 {
+  btrace_insn_iterator *replay = nullptr;
+
+  /* Thread-db may ask for a thread's registers before GDB knows about the
+     thread.  We forward the request to the target beneath in this
+     case.  */
   thread_info *tp = find_thread_ptid (regcache->target (), regcache->ptid ());
-  gdb_assert (tp != NULL);
+  if (tp != nullptr)
+    replay =  tp->btrace.replay;
 
-  btrace_insn_iterator *replay = tp->btrace.replay;
-  if (replay != NULL && !record_btrace_generating_corefile)
+  if (replay != nullptr && !record_btrace_generating_corefile)
     {
       const struct btrace_insn *insn;
       struct gdbarch *gdbarch;
@@ -1958,7 +1978,7 @@ static struct frame_id
 get_thread_current_frame_id (struct thread_info *tp)
 {
   struct frame_id id;
-  int executing;
+  bool executing;
 
   /* Set current thread, which is implicitly used by
      get_current_frame.  */
@@ -2615,7 +2635,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status,
   /* Stop all other threads. */
   if (!target_is_non_stop_p ())
     {
-      for (thread_info *tp : all_non_exited_threads ())
+      for (thread_info *tp : current_inferior ()->non_exited_threads ())
        record_btrace_cancel_resume (tp);
     }
 
@@ -2852,7 +2872,7 @@ record_btrace_target::goto_record (ULONGEST insn)
 void
 record_btrace_target::record_stop_replaying ()
 {
-  for (thread_info *tp : all_non_exited_threads ())
+  for (thread_info *tp : current_inferior ()->non_exited_threads ())
     record_btrace_stop_replaying (tp);
 }
 
@@ -2952,25 +2972,6 @@ cmd_record_btrace_start (const char *args, int from_tty)
     }
 }
 
-/* The "set record btrace" command.  */
-
-static void
-cmd_set_record_btrace (const char *args, int from_tty)
-{
-  printf_unfiltered (_("\"set record btrace\" must be followed "
-                      "by an appropriate subcommand.\n"));
-  help_list (set_record_btrace_cmdlist, "set record btrace ",
-            all_commands, gdb_stdout);
-}
-
-/* The "show record btrace" command.  */
-
-static void
-cmd_show_record_btrace (const char *args, int from_tty)
-{
-  cmd_show_list (show_record_btrace_cmdlist, from_tty, "");
-}
-
 /* The "show record btrace replay-memory-access" command.  */
 
 static void
@@ -3085,44 +3086,6 @@ cmd_show_record_btrace_cpu (const char *args, int from_tty)
   error (_("Internal error: bad cpu state."));
 }
 
-/* The "s record btrace bts" command.  */
-
-static void
-cmd_set_record_btrace_bts (const char *args, int from_tty)
-{
-  printf_unfiltered (_("\"set record btrace bts\" must be followed "
-                      "by an appropriate subcommand.\n"));
-  help_list (set_record_btrace_bts_cmdlist, "set record btrace bts ",
-            all_commands, gdb_stdout);
-}
-
-/* The "show record btrace bts" command.  */
-
-static void
-cmd_show_record_btrace_bts (const 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 (const 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 (const 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
@@ -3147,8 +3110,9 @@ show_record_pt_buffer_size_value (struct ui_file *file, int from_tty,
 
 /* Initialize btrace commands.  */
 
+void _initialize_record_btrace ();
 void
-_initialize_record_btrace (void)
+_initialize_record_btrace ()
 {
   add_prefix_cmd ("btrace", class_obscure, cmd_record_btrace_start,
                  _("Start branch trace recording."), &record_btrace_cmdlist,
@@ -3170,13 +3134,13 @@ 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);
+  add_basic_prefix_cmd ("btrace", class_support,
+                       _("Set record options."), &set_record_btrace_cmdlist,
+                       "set record btrace ", 0, &set_record_cmdlist);
 
-  add_prefix_cmd ("btrace", class_support, cmd_show_record_btrace,
-                 _("Show record options."), &show_record_btrace_cmdlist,
-                 "show record btrace ", 0, &show_record_cmdlist);
+  add_show_prefix_cmd ("btrace", class_support,
+                      _("Show record options."), &show_record_btrace_cmdlist,
+                      "show record btrace ", 0, &show_record_cmdlist);
 
   add_setshow_enum_cmd ("replay-memory-access", no_class,
                        replay_memory_access_types, &replay_memory_access, _("\
@@ -3219,15 +3183,17 @@ Do not enable errata workarounds for trace decode."),
 Show the cpu to be used for trace decode."),
           &show_record_btrace_cmdlist);
 
-  add_prefix_cmd ("bts", class_support, cmd_set_record_btrace_bts,
-                 _("Set record btrace bts options."),
-                 &set_record_btrace_bts_cmdlist,
-                 "set record btrace bts ", 0, &set_record_btrace_cmdlist);
+  add_basic_prefix_cmd ("bts", class_support,
+                       _("Set record btrace bts options."),
+                       &set_record_btrace_bts_cmdlist,
+                       "set record btrace bts ", 0,
+                       &set_record_btrace_cmdlist);
 
-  add_prefix_cmd ("bts", class_support, cmd_show_record_btrace_bts,
-                 _("Show record btrace bts options."),
-                 &show_record_btrace_bts_cmdlist,
-                 "show record btrace bts ", 0, &show_record_btrace_cmdlist);
+  add_show_prefix_cmd ("bts", class_support,
+                      _("Show record btrace bts options."),
+                      &show_record_btrace_bts_cmdlist,
+                      "show record btrace bts ", 0,
+                      &show_record_btrace_cmdlist);
 
   add_setshow_uinteger_cmd ("buffer-size", no_class,
                            &record_btrace_conf.bts.size,
@@ -3243,15 +3209,17 @@ The trace buffer size may not be changed while recording."), NULL,
                            &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_basic_prefix_cmd ("pt", class_support,
+                       _("Set record btrace pt options."),
+                       &set_record_btrace_pt_cmdlist,
+                       "set record btrace pt ", 0,
+                       &set_record_btrace_cmdlist);
+
+  add_show_prefix_cmd ("pt", class_support,
+                      _("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,
This page took 0.029931 seconds and 4 git commands to generate.