Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Cc: Mark Kettenis <mark.kettenis@xs4all.nl>, Pedro Alves <palves@redhat.com>
Subject: [PATCH 4/7 v2] Pull out common parts of _initialize_{i386,amd64}_linux_nat
Date: Fri, 27 Jun 2014 14:53:00 -0000	[thread overview]
Message-ID: <1403878351-22974-5-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1403878351-22974-1-git-send-email-gbenson@redhat.com>

This commit adds two new helpers, x86_linux_create_target
and x86_linux_register_target, to hold the parts of
_initialize_i386_linux_nat and _initialize_amd64_linux_nat
which are common.

This patch is unchanged from the original version in this series.

gdb/
2014-06-27  Gary Benson  <gbenson@redhat.com>

	* amd64-linux-nat.c (x86_linux_create_target): New function.
	(x86_linux_register_target): Likewise.
	(_initialize_amd64_linux_nat): Delegate to the above new functions.
	* i386-linux-nat.c (x86_linux_create_target): New function.
	(x86_linux_register_target): Likewise.
	(_initialize_i386_linux_nat): Delegate to the above new functions.
---
 gdb/ChangeLog         |    9 ++++++
 gdb/amd64-linux-nat.c |   68 ++++++++++++++++++++++++++++++++----------------
 gdb/i386-linux-nat.c  |   52 +++++++++++++++++++++++++------------
 3 files changed, 89 insertions(+), 40 deletions(-)

diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
index 57e5c51..2a291df 100644
--- a/gdb/amd64-linux-nat.c
+++ b/gdb/amd64-linux-nat.c
@@ -1269,42 +1269,28 @@ x86_linux_read_btrace (struct target_ops *self,
   return linux_read_btrace (data, btinfo, type);
 }
 
-/* Provide a prototype to silence -Wmissing-prototypes.  */
-void _initialize_amd64_linux_nat (void);
+/* Create an x86 GNU/Linux target.  */
 
-void
-_initialize_amd64_linux_nat (void)
+static struct target_ops *
+x86_linux_create_target (void)
 {
-  struct target_ops *t;
-
-  amd64_native_gregset32_reg_offset = amd64_linux_gregset32_reg_offset;
-  amd64_native_gregset32_num_regs = I386_LINUX_NUM_REGS;
-  amd64_native_gregset64_reg_offset = amd64_linux_gregset_reg_offset;
-  amd64_native_gregset64_num_regs = AMD64_LINUX_NUM_REGS;
-
-  gdb_assert (ARRAY_SIZE (amd64_linux_gregset32_reg_offset)
-	      == amd64_native_gregset32_num_regs);
-
   /* Fill in the generic GNU/Linux methods.  */
-  t = linux_target ();
+  struct target_ops *t = linux_target ();
 
+  /* Initialize the debug register function vectors.  */
   i386_use_watchpoints (t);
-
   i386_dr_low.set_control = x86_linux_dr_set_control;
   i386_dr_low.set_addr = x86_linux_dr_set_addr;
   i386_dr_low.get_addr = x86_linux_dr_get_addr;
   i386_dr_low.get_status = x86_linux_dr_get_status;
   i386_dr_low.get_control = x86_linux_dr_get_control;
-  i386_set_debug_register_length (8);
+  i386_set_debug_register_length (sizeof (void *));
 
   /* Override the GNU/Linux inferior startup hook.  */
   super_post_startup_inferior = t->to_post_startup_inferior;
   t->to_post_startup_inferior = x86_linux_child_post_startup_inferior;
 
-  /* Add our register access methods.  */
-  t->to_fetch_registers = amd64_linux_fetch_inferior_registers;
-  t->to_store_registers = amd64_linux_store_inferior_registers;
-
+  /* Add the description reader.  */
   t->to_read_description = x86_linux_read_description;
 
   /* Add btrace methods.  */
@@ -1314,11 +1300,47 @@ _initialize_amd64_linux_nat (void)
   t->to_teardown_btrace = x86_linux_teardown_btrace;
   t->to_read_btrace = x86_linux_read_btrace;
 
-  /* Register the target.  */
+  return t;
+}
+
+/* Register an x86 GNU/Linux target.  */
+
+static void
+x86_linux_register_target (struct target_ops *t)
+{
   linux_nat_add_target (t);
   linux_nat_set_new_thread (t, x86_linux_new_thread);
   linux_nat_set_new_fork (t, x86_linux_new_fork);
   linux_nat_set_forget_process (t, i386_forget_process);
-  linux_nat_set_siginfo_fixup (t, amd64_linux_siginfo_fixup);
   linux_nat_set_prepare_to_resume (t, x86_linux_prepare_to_resume);
 }
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+void _initialize_amd64_linux_nat (void);
+
+void
+_initialize_amd64_linux_nat (void)
+{
+  struct target_ops *t;
+
+  amd64_native_gregset32_reg_offset = amd64_linux_gregset32_reg_offset;
+  amd64_native_gregset32_num_regs = I386_LINUX_NUM_REGS;
+  amd64_native_gregset64_reg_offset = amd64_linux_gregset_reg_offset;
+  amd64_native_gregset64_num_regs = AMD64_LINUX_NUM_REGS;
+
+  gdb_assert (ARRAY_SIZE (amd64_linux_gregset32_reg_offset)
+	      == amd64_native_gregset32_num_regs);
+
+  /* Create a generic x86 GNU/Linux target.  */
+  t = x86_linux_create_target ();
+
+  /* Add our register access methods.  */
+  t->to_fetch_registers = amd64_linux_fetch_inferior_registers;
+  t->to_store_registers = amd64_linux_store_inferior_registers;
+
+  /* Register the target.  */
+  x86_linux_register_target (t);
+
+  /* Add our siginfo layout converter.  */
+  linux_nat_set_siginfo_fixup (t, amd64_linux_siginfo_fixup);
+}
diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
index d647c3d..5ef69ff 100644
--- a/gdb/i386-linux-nat.c
+++ b/gdb/i386-linux-nat.c
@@ -1217,37 +1217,28 @@ x86_linux_read_btrace (struct target_ops *self,
   return linux_read_btrace (data, btinfo, type);
 }
 
-/* -Wmissing-prototypes */
-extern initialize_file_ftype _initialize_i386_linux_nat;
+/* Create an x86 GNU/Linux target.  */
 
-void
-_initialize_i386_linux_nat (void)
+static struct target_ops *
+x86_linux_create_target (void)
 {
-  struct target_ops *t;
-
   /* Fill in the generic GNU/Linux methods.  */
-  t = linux_target ();
+  struct target_ops *t = linux_target ();
 
+  /* Initialize the debug register function vectors.  */
   i386_use_watchpoints (t);
-
   i386_dr_low.set_control = x86_linux_dr_set_control;
   i386_dr_low.set_addr = x86_linux_dr_set_addr;
   i386_dr_low.get_addr = x86_linux_dr_get_addr;
   i386_dr_low.get_status = x86_linux_dr_get_status;
   i386_dr_low.get_control = x86_linux_dr_get_control;
-  i386_set_debug_register_length (4);
-
-  /* Override the default ptrace resume method.  */
-  t->to_resume = i386_linux_resume;
+  i386_set_debug_register_length (sizeof (void *));
 
   /* Override the GNU/Linux inferior startup hook.  */
   super_post_startup_inferior = t->to_post_startup_inferior;
   t->to_post_startup_inferior = x86_linux_child_post_startup_inferior;
 
-  /* Add our register access methods.  */
-  t->to_fetch_registers = i386_linux_fetch_inferior_registers;
-  t->to_store_registers = i386_linux_store_inferior_registers;
-
+  /* Add the description reader.  */
   t->to_read_description = x86_linux_read_description;
 
   /* Add btrace methods.  */
@@ -1257,10 +1248,37 @@ _initialize_i386_linux_nat (void)
   t->to_teardown_btrace = x86_linux_teardown_btrace;
   t->to_read_btrace = x86_linux_read_btrace;
 
-  /* Register the target.  */
+  return t;
+}
+
+/* Register an x86 GNU/Linux target.  */
+
+static void
+x86_linux_register_target (struct target_ops *t)
+{
   linux_nat_add_target (t);
   linux_nat_set_new_thread (t, x86_linux_new_thread);
   linux_nat_set_new_fork (t, x86_linux_new_fork);
   linux_nat_set_forget_process (t, i386_forget_process);
   linux_nat_set_prepare_to_resume (t, x86_linux_prepare_to_resume);
 }
+
+/* -Wmissing-prototypes */
+extern initialize_file_ftype _initialize_i386_linux_nat;
+
+void
+_initialize_i386_linux_nat (void)
+{
+  /* Create a generic x86 GNU/Linux target.  */
+  struct target_ops *t = x86_linux_create_target ();
+
+  /* Override the default ptrace resume method.  */
+  t->to_resume = i386_linux_resume;
+
+  /* Add our register access methods.  */
+  t->to_fetch_registers = i386_linux_fetch_inferior_registers;
+  t->to_store_registers = i386_linux_store_inferior_registers;
+
+  /* Register the target.  */
+  x86_linux_register_target (t);
+}
-- 
1.7.1


  parent reply	other threads:[~2014-06-27 14:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27 14:12 [PATCH 0/7 v2] Refactor shared code in {i386,amd64}-linux-nat.c Gary Benson
2014-06-27 14:12 ` [PATCH 1/7 v2] Rename identical functions Gary Benson
2014-07-09 13:04   ` Pedro Alves
2014-06-27 14:12 ` [PATCH 2/7 v2] Merge {i386,amd64}_linux_read_description Gary Benson
2014-07-09 13:07   ` Pedro Alves
2014-06-27 14:12 ` [PATCH 3/7 v2] Merge ps_get_thread_area Gary Benson
2014-07-09 13:08   ` Pedro Alves
2014-07-09 13:08   ` Pedro Alves
2014-06-27 14:28 ` [PATCH 6/7 v2] Move duplicated code into new files Gary Benson
2014-07-09 13:12   ` Pedro Alves
2014-06-27 14:40 ` [PATCH 5/7 v2] Comment and whitespace changes Gary Benson
2014-07-09 13:11   ` Pedro Alves
2014-06-27 14:52 ` [PATCH 7/7 v2] Tidy #include lists Gary Benson
2014-07-09 13:13   ` Pedro Alves
2014-08-06  9:36   ` Yao Qi
2014-08-06 10:19     ` Gary Benson
2014-08-06 11:16       ` Yao Qi
2014-09-09 15:09   ` [pushed] Fix missing "struct iovec" definition on some x86-linux. (was: "[PATCH 7/7 v2] Tidy #include lists") Joel Brobecker
2014-09-10 10:59     ` Gary Benson
2014-09-10 13:14       ` Joel Brobecker
2014-06-27 14:53 ` Gary Benson [this message]
2014-07-09 13:09   ` [PATCH 4/7 v2] Pull out common parts of _initialize_{i386,amd64}_linux_nat Pedro Alves
2014-07-09 13:17 ` [PATCH 0/7 v2] Refactor shared code in {i386,amd64}-linux-nat.c Pedro Alves
2014-07-11 12:34   ` Gary Benson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403878351-22974-5-git-send-email-gbenson@redhat.com \
    --to=gbenson@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox