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>
Thu, 4 Jun 2020 19:04:21 +0000 (15:04 -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 284353004d99baa61a6592d2651b5c57544f9761..7a1f9351e833bbc63ba6839d95dfdedc0356230a 100644 (file)
@@ -1727,7 +1727,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);
+    tp->inf->top_target ()->displaced_step_prepare (tp);
 
   if (status == DISPLACED_STEP_PREPARE_STATUS_ERROR)
     {
@@ -1869,8 +1869,8 @@ 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);
+    event_thread->inf->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 c28af097183d5bd628879e92eb9824354451edd9..14206c1375f99e2245830e38c64fa1acd64d142a 100644 (file)
@@ -171,6 +171,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
@@ -340,6 +342,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
@@ -4363,3 +4367,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 37bfb29882a4c53f2c6932f6c067bbbb1e1672d2..255c71fef09f7c19807fbd82bea5abef494b49a2 100644 (file)
@@ -81,6 +81,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.  */
 
@@ -1252,6 +1253,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.030227 seconds and 4 git commands to generate.