From patchwork Fri Jun 27 14:12:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 1799 Received: (qmail 25318 invoked by alias); 27 Jun 2014 14:53:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 25257 invoked by uid 89); 27 Jun 2014 14:53:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 27 Jun 2014 14:52:58 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5RECiLm032048 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Jun 2014 10:12:45 -0400 Received: from blade.nx (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5REChQ4031785; Fri, 27 Jun 2014 10:12:43 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id E74072640BF; Fri, 27 Jun 2014 15:12:42 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Cc: Mark Kettenis , Pedro Alves Subject: [PATCH 4/7 v2] Pull out common parts of _initialize_{i386, amd64}_linux_nat Date: Fri, 27 Jun 2014 15:12:28 +0100 Message-Id: <1403878351-22974-5-git-send-email-gbenson@redhat.com> In-Reply-To: <1403878351-22974-1-git-send-email-gbenson@redhat.com> References: <1403878351-22974-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes 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 * 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); +}