gdb: add target_ops methods for displaced stepping
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 30 Mar 2020 19:58:57 +0000 (15:58 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 10 Jun 2020 21:26:05 +0000 (17:26 -0400)
Currently, the gdbarch is responsible for preparing the threads for
displaced stepping.  Since some targets specifically provide some
resources for displaced stepping, add some target_ops methods to make it
possible for targets to override the default behavior.  The default
behavior, for targets that don't override it, is to defer to the
gdbarch.

gdb/displaced-stepping.c
gdb/displaced-stepping.h
gdb/infrun.c
gdb/target-debug.h
gdb/target-delegates.c
gdb/target.h

index f373be79642fcf52234ff7808962932812534bb0..5ada1632257a2d7f43046a3e7e6cac4e4c099f04 100644 (file)
@@ -176,3 +176,19 @@ multiple_displaced_buffer_manager::finish (gdbarch *arch, thread_info *thread,
 
   return status;
 }
+
+displaced_step_prepare_status
+  default_displaced_step_prepare (target_ops *target, thread_info *thread)
+{
+  gdbarch *arch = thread->arch ();
+  return gdbarch_displaced_step_prepare (arch, thread);
+}
+
+displaced_step_finish_status
+default_displaced_step_finish (target_ops *target,
+                              thread_info *thread,
+                              gdb_signal sig)
+{
+  gdbarch *arch = thread->arch ();
+  return gdbarch_displaced_step_finish (arch, thread, sig);
+}
index e637c3892505c2e341be78a6bdf1e81b680dca94..c46f99f549c0ceb8ad44b8bedff5b87543871598 100644 (file)
@@ -6,6 +6,7 @@
 
 struct gdbarch;
 struct thread_info;
+struct target_ops;
 
 enum displaced_step_prepare_status
 {
@@ -151,5 +152,11 @@ private:
   std::vector<displaced_step_buffer_state> m_buffers;
 };
 
+displaced_step_prepare_status
+  default_displaced_step_prepare (target_ops *target, thread_info *thread);
+
+displaced_step_finish_status
+  default_displaced_step_finish (target_ops *target, thread_info *thread,
+                                gdb_signal sig);
 
 #endif /* DISPLACED_STEPPING_H */
index 89a250a9599b1eede5707f071aed893de4a53dd7..9366cbe25ff838f1ed64051967cdfc26a83eac8c 100644 (file)
@@ -1696,7 +1696,7 @@ displaced_step_prepare_throw (thread_info *tp)
   CORE_ADDR original_pc = regcache_read_pc (regcache);
 
   displaced_step_prepare_status status =
-    gdbarch_displaced_step_prepare (gdbarch, tp);
+    current_top_target ()->displaced_step_prepare (tp);
 
   if (status == DISPLACED_STEP_PREPARE_STATUS_ERROR)
     {
@@ -1842,8 +1842,7 @@ displaced_step_finish (thread_info *event_thread, enum gdb_signal signal)
   /* Do the fixup, and release the resources acquired to do the displaced
      step. */
   displaced_step_finish_status finish_status =
-    gdbarch_displaced_step_finish (displaced->get_original_gdbarch (),
-                                  event_thread, signal);
+    current_top_target ()->displaced_step_finish (event_thread, signal);
 
   if (finish_status == DISPLACED_STEP_FINISH_STATUS_OK)
     return 1;
index 46d17a359d91ba74e46cc777acedfac8e1e50e66..1d52634c3b88bb0f82b89e89f783cd627b204f6f 100644 (file)
@@ -82,6 +82,8 @@
   target_debug_do_print (host_address_to_string (*(X)))
 #define target_debug_print_enum_gdb_signal(X)  \
   target_debug_do_print (gdb_signal_to_name (X))
+#define target_debug_print_gdb_signal(X)       \
+  target_debug_do_print (gdb_signal_to_name (X))
 #define target_debug_print_ULONGEST(X)         \
   target_debug_do_print (hex_string (X))
 #define target_debug_print_ULONGEST_p(X)       \
   target_debug_do_print ((X).c_str ())
 #define target_debug_print_gdb_byte_vector(X)  \
   target_debug_do_print (host_address_to_string (X.data ()))
+#define target_debug_print_displaced_step_finish_status(X) \
+  target_debug_do_print (host_address_to_string (X))
+#define target_debug_print_displaced_step_prepare_status(X) \
+  target_debug_do_print (host_address_to_string (X))
+
 
 static void
 target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
index 52034fe4360754077a0a985ffb713f7c7f95d5ae..04cfb825a46ec441e130248334cde7250b9e1eea 100644 (file)
@@ -170,6 +170,8 @@ struct dummy_target : public target_ops
   const struct frame_unwind *get_tailcall_unwinder () override;
   void prepare_to_generate_core () override;
   void done_generating_core () override;
+  displaced_step_prepare_status displaced_step_prepare (thread_info *arg0) override;
+  displaced_step_finish_status displaced_step_finish (thread_info *arg0, gdb_signal arg1) override;
 };
 
 struct debug_target : public target_ops
@@ -338,6 +340,8 @@ struct debug_target : public target_ops
   const struct frame_unwind *get_tailcall_unwinder () override;
   void prepare_to_generate_core () override;
   void done_generating_core () override;
+  displaced_step_prepare_status displaced_step_prepare (thread_info *arg0) override;
+  displaced_step_finish_status displaced_step_finish (thread_info *arg0, gdb_signal arg1) override;
 };
 
 void
@@ -4336,3 +4340,57 @@ debug_target::done_generating_core ()
   fputs_unfiltered (")\n", gdb_stdlog);
 }
 
+displaced_step_prepare_status
+target_ops::displaced_step_prepare (thread_info *arg0)
+{
+  return this->beneath ()->displaced_step_prepare (arg0);
+}
+
+displaced_step_prepare_status
+dummy_target::displaced_step_prepare (thread_info *arg0)
+{
+  return default_displaced_step_prepare (this, arg0);
+}
+
+displaced_step_prepare_status
+debug_target::displaced_step_prepare (thread_info *arg0)
+{
+  displaced_step_prepare_status result;
+  fprintf_unfiltered (gdb_stdlog, "-> %s->displaced_step_prepare (...)\n", this->beneath ()->shortname ());
+  result = this->beneath ()->displaced_step_prepare (arg0);
+  fprintf_unfiltered (gdb_stdlog, "<- %s->displaced_step_prepare (", this->beneath ()->shortname ());
+  target_debug_print_thread_info_p (arg0);
+  fputs_unfiltered (") = ", gdb_stdlog);
+  target_debug_print_displaced_step_prepare_status (result);
+  fputs_unfiltered ("\n", gdb_stdlog);
+  return result;
+}
+
+displaced_step_finish_status
+target_ops::displaced_step_finish (thread_info *arg0, gdb_signal arg1)
+{
+  return this->beneath ()->displaced_step_finish (arg0, arg1);
+}
+
+displaced_step_finish_status
+dummy_target::displaced_step_finish (thread_info *arg0, gdb_signal arg1)
+{
+  return default_displaced_step_finish (this, arg0, arg1);
+}
+
+displaced_step_finish_status
+debug_target::displaced_step_finish (thread_info *arg0, gdb_signal arg1)
+{
+  displaced_step_finish_status result;
+  fprintf_unfiltered (gdb_stdlog, "-> %s->displaced_step_finish (...)\n", this->beneath ()->shortname ());
+  result = this->beneath ()->displaced_step_finish (arg0, arg1);
+  fprintf_unfiltered (gdb_stdlog, "<- %s->displaced_step_finish (", this->beneath ()->shortname ());
+  target_debug_print_thread_info_p (arg0);
+  fputs_unfiltered (", ", gdb_stdlog);
+  target_debug_print_gdb_signal (arg1);
+  fputs_unfiltered (") = ", gdb_stdlog);
+  target_debug_print_displaced_step_finish_status (result);
+  fputs_unfiltered ("\n", gdb_stdlog);
+  return result;
+}
+
index 8e51516feab60e831652107a831bab3250760c74..90fe9a6fcd6f102f2beed85212299bd0b089bc4d 100644 (file)
@@ -80,6 +80,7 @@ struct inferior;
 #include "command.h"
 #include "disasm.h"
 #include "tracepoint.h"
+#include "displaced-stepping.h"
 
 #include "gdbsupport/break-common.h" /* For enum target_hw_bp_type.  */
 
@@ -1242,6 +1243,12 @@ struct target_ops
     /* Cleanup after generating a core file.  */
     virtual void done_generating_core ()
       TARGET_DEFAULT_IGNORE ();
+
+    virtual displaced_step_prepare_status displaced_step_prepare (thread_info *thread)
+      TARGET_DEFAULT_FUNC (default_displaced_step_prepare);
+
+    virtual displaced_step_finish_status displaced_step_finish (thread_info *thread, gdb_signal sig)
+      TARGET_DEFAULT_FUNC (default_displaced_step_finish);
   };
 
 /* Deleter for std::unique_ptr.  See comments in
This page took 0.029562 seconds and 4 git commands to generate.