[PATCH 2/3] Introduce process_stratum_target

Tom Tromey tom@tromey.com
Thu Nov 29 23:16:00 GMT 2018


Tom> What if I added a protected constructor to target_ops that took the
Tom> stratum as an argument?  Would there be a problem with that?

Like this.  If it's reasonable I'll rebase it on top of yours after it
goes in.

Tom

commit 207fb6d5368f6406c536e8dee356ee1564e4d494
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Nov 29 16:04:37 2018 -0700

    Add target_ops constructor
    
    This adds a protected target_ops constructor that sets the to_stratum
    member, and updates subclasses to invoke it.
    
    gdb/ChangeLog
    2018-11-29  Tom Tromey  <tom@tromey.com>
    
            * spu-multiarch.c (spu_multiarch_target::spu_multiarch_target):
            Update.
            * ravenscar-thread.c
            (ravenscar_thread_target::ravenscar_thread_target): Update.
            * bsd-uthread.c (bsd_uthread_target::bsd_uthread_target): Update.
            * sol-thread.c (sol_thread_target::sol_thread_target): Update.
            * aix-thread.c (aix_thread_target::aix_thread_target): Update.
            * bsd-kvm.c (bsd_kvm_target::bsd_kvm_target): Update.
            * tracefile.c (tracefile_target::tracefile_target): Update.
            * target.h (struct target_ops) <target_ops>: New constructor.
            (struct memory_breakpoint_target) <memory_breakpoint_target>:
            Likewise.
            (test_target_ops::test_target_ops): Update.
            * target.c (dummy_target::dummy_target): Update.
            (debug_target::debug_target): Update.
            * remote.c (remote_target::remote_target): Update.
            * remote-sim.c (gdbsim_target::gdbsim_target): Update.
            * record-full.c
            (record_full_base_target::record_full_base_target): Update.
            * record-btrace.c (record_btrace_target::record_btrace_target):
            Update.
            * linux-thread-db.c (thread_db_target::thread_db_target): Update.
            * inf-child.c (inf_child_target::inf_child_target): Update.
            * exec.c (exec_target::exec_target): Update.
            * corelow.c (core_target::core_target): Update.
            * bfd-target.c (target_bfd::target_bfd): Update.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 70d4c06742..d1cd119484 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,32 @@
+2018-11-29  Tom Tromey  <tom@tromey.com>
+
+	* spu-multiarch.c (spu_multiarch_target::spu_multiarch_target):
+	Update.
+	* ravenscar-thread.c
+	(ravenscar_thread_target::ravenscar_thread_target): Update.
+	* bsd-uthread.c (bsd_uthread_target::bsd_uthread_target): Update.
+	* sol-thread.c (sol_thread_target::sol_thread_target): Update.
+	* aix-thread.c (aix_thread_target::aix_thread_target): Update.
+	* bsd-kvm.c (bsd_kvm_target::bsd_kvm_target): Update.
+	* tracefile.c (tracefile_target::tracefile_target): Update.
+	* target.h (struct target_ops) <target_ops>: New constructor.
+	(struct memory_breakpoint_target) <memory_breakpoint_target>:
+	Likewise.
+	(test_target_ops::test_target_ops): Update.
+	* target.c (dummy_target::dummy_target): Update.
+	(debug_target::debug_target): Update.
+	* remote.c (remote_target::remote_target): Update.
+	* remote-sim.c (gdbsim_target::gdbsim_target): Update.
+	* record-full.c
+	(record_full_base_target::record_full_base_target): Update.
+	* record-btrace.c (record_btrace_target::record_btrace_target):
+	Update.
+	* linux-thread-db.c (thread_db_target::thread_db_target): Update.
+	* inf-child.c (inf_child_target::inf_child_target): Update.
+	* exec.c (exec_target::exec_target): Update.
+	* corelow.c (core_target::core_target): Update.
+	* bfd-target.c (target_bfd::target_bfd): Update.
+
 2018-11-29  Tom Tromey  <tom@tromey.com>
 
 	* valarith.c (value_x_unop): Don't set argvec[3].
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index 97592e5b1f..a5460dc61f 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -118,7 +118,8 @@ class aix_thread_target final : public target_ops
 {
 public:
   aix_thread_target ()
-  { to_stratum = thread_stratum; }
+    : target_ops (thread_stratum)
+  { }
 
   const target_info &info () const override
   { return aix_thread_target_info; }
diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index 6138d450d9..837f0f32f3 100644
--- a/gdb/bfd-target.c
+++ b/gdb/bfd-target.c
@@ -90,9 +90,9 @@ target_bfd::get_section_table ()
 }
 
 target_bfd::target_bfd (struct bfd *abfd)
-  : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
+  : target_ops (file_stratum),
+    m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
 {
-  this->to_stratum = file_stratum;
   m_table.sections = NULL;
   m_table.sections_end = NULL;
   build_section_table (abfd, &m_table.sections, &m_table.sections_end);
diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c
index af8305f386..342645e3ad 100644
--- a/gdb/bsd-kvm.c
+++ b/gdb/bsd-kvm.c
@@ -75,7 +75,8 @@ class bsd_kvm_target final : public target_ops
 {
 public:
   bsd_kvm_target ()
-  { this->to_stratum = process_stratum; }
+    : target_ops (process_stratum)
+  { }
 
   const target_info &info () const override
   { return bsd_kvm_target_info; }
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index 3229a18055..7e456ad101 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -42,7 +42,8 @@ static const target_info bsd_uthread_target_info = {
 struct bsd_uthread_target final : public target_ops
 {
   bsd_uthread_target ()
-  { to_stratum = thread_stratum; }
+    : target_ops (thread_stratum)
+  { }
 
   const target_info &info () const override
   { return bsd_uthread_target_info; }
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 72f2807640..69e9d6e922 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -131,9 +131,8 @@ private: /* per-core data */
 };
 
 core_target::core_target ()
+  : target_ops (process_stratum)
 {
-  to_stratum = process_stratum;
-
   m_core_gdbarch = gdbarch_from_bfd (core_bfd);
 
   /* Find a suitable core file handler to munch on core_bfd */
diff --git a/gdb/exec.c b/gdb/exec.c
index 615fb2b5db..f95a0fbda4 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -61,7 +61,8 @@ Specify the filename of the executable file.")
 struct exec_target final : public target_ops
 {
   exec_target ()
-  { to_stratum = file_stratum; }
+    : target_ops (file_stratum)
+  { }
 
   const target_info &info () const override
   { return exec_target_info; }
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 44aa2f66fb..ab02f97f68 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -441,7 +441,6 @@ inf_child_target::can_use_agent ()
 
 inf_child_target::inf_child_target ()
 {
-  this->to_stratum = process_stratum;
 }
 
 /* See inf-child.h.  */
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 74acec2629..433cb5800c 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -108,8 +108,8 @@ public:
 };
 
 thread_db_target::thread_db_target ()
+  : target_ops (thread_stratum)
 {
-  this->to_stratum = thread_stratum;
 }
 
 static char *libthread_db_search_path;
diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index e60fad8746..6bbb4d13a2 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -82,7 +82,8 @@ static const target_info ravenscar_target_info = {
 struct ravenscar_thread_target final : public target_ops
 {
   ravenscar_thread_target ()
-  { to_stratum = thread_stratum; }
+    : target_ops (thread_stratum)
+  { }
 
   const target_info &info () const override
   { return ravenscar_target_info; }
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 814f080941..d33de7ee15 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -54,7 +54,8 @@ class record_btrace_target final : public target_ops
 {
 public:
   record_btrace_target ()
-  { to_stratum = record_stratum; }
+    : target_ops (record_stratum)
+  { }
 
   const target_info &info () const override
   { return record_btrace_target_info; }
diff --git a/gdb/record-full.c b/gdb/record-full.c
index dbaa8c3d40..ce799308a0 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -219,7 +219,8 @@ class record_full_base_target : public target_ops
 {
 public:
   record_full_base_target ()
-  { to_stratum = record_stratum; }
+    : target_ops (record_stratum)
+  { }
 
   const target_info &info () const override = 0;
 
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 63e41458d7..186503f34f 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -85,7 +85,7 @@ struct gdbsim_target final
   : public memory_breakpoint_target<target_ops>
 {
   gdbsim_target ()
-  { to_stratum = process_stratum; }
+  { }
 
   const target_info &info () const override
   { return gdbsim_target_info; }
diff --git a/gdb/remote.c b/gdb/remote.c
index 90b5dabc8a..d389468919 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -408,8 +408,8 @@ class remote_target : public target_ops
 {
 public:
   remote_target ()
+    : target_ops (process_stratum)
   {
-    to_stratum = process_stratum;
   }
   ~remote_target () override;
 
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index c6a5aca501..212a8fcbca 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -79,7 +79,8 @@ class sol_thread_target final : public target_ops
 {
 public:
   sol_thread_target ()
-  { this->to_stratum = thread_stratum; }
+    : target_ops (thread_stratum)
+  { }
 
   const target_info &info () const override
   { return thread_db_target_info; }
diff --git a/gdb/spu-multiarch.c b/gdb/spu-multiarch.c
index 7e642d663a..30c4586c5b 100644
--- a/gdb/spu-multiarch.c
+++ b/gdb/spu-multiarch.c
@@ -45,7 +45,8 @@ static const target_info spu_multiarch_target_info = {
 struct spu_multiarch_target final : public target_ops
 {
   spu_multiarch_target ()
-  { to_stratum = arch_stratum; };
+    : spu_multiarch_target (arch_stratum)
+  { }
 
   const target_info &info () const override
   { return spu_multiarch_target_info; }
diff --git a/gdb/target.c b/gdb/target.c
index 29ce5eb414..3d82e7ce8b 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3330,13 +3330,13 @@ static const target_info dummy_target_info = {
 };
 
 dummy_target::dummy_target ()
+  : target_ops (dummy_stratum)
 {
-  to_stratum = dummy_stratum;
 }
 
 debug_target::debug_target ()
+  : target_ops (debug_stratum)
 {
-  to_stratum = debug_stratum;
 }
 
 const target_info &
diff --git a/gdb/target.h b/gdb/target.h
index 4731e3bf79..a0a5da25b6 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -431,6 +431,15 @@ struct target_info
 
 struct target_ops
   {
+  protected:
+
+    explicit target_ops (enum strata stratum)
+      : to_stratum (stratum)
+    {
+    }
+
+  public:
+
     /* To the target under this one.  */
     target_ops *beneath () const;
 
@@ -2419,6 +2428,15 @@ extern int memory_insert_breakpoint (struct target_ops *,
 template <typename BaseTarget>
 struct memory_breakpoint_target : public BaseTarget
 {
+protected:
+
+  memory_breakpoint_target ()
+    : BaseTarget (process_stratum)
+  {
+  }
+
+public:
+
   int insert_breakpoint (struct gdbarch *gdbarch,
 			 struct bp_target_info *bp_tgt) override
   { return memory_insert_breakpoint (this, gdbarch, bp_tgt); }
@@ -2584,9 +2602,8 @@ class test_target_ops : public target_ops
 {
 public:
   test_target_ops ()
-    : target_ops {}
+    : target_ops (process_stratum)
   {
-    to_stratum = process_stratum;
   }
 
   const target_info &info () const override;
diff --git a/gdb/tracefile.c b/gdb/tracefile.c
index b367f6e403..5db8426e33 100644
--- a/gdb/tracefile.c
+++ b/gdb/tracefile.c
@@ -471,8 +471,8 @@ tracefile_target::get_trace_status (struct trace_status *ts)
 }
 
 tracefile_target::tracefile_target ()
+  : target_ops (process_stratum)
 {
-  this->to_stratum = process_stratum;
 }
 
 void



More information about the Gdb-patches mailing list