From patchwork Fri Jun 27 09:10:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 1781 Received: (qmail 28821 invoked by alias); 27 Jun 2014 09:10:28 -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 28782 invoked by uid 89); 27 Jun 2014 09:10:27 -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 09:10:25 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5R9AOYX024437 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 27 Jun 2014 05:10:24 -0400 Received: from blade.nx (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5R9AMPB008877 for ; Fri, 27 Jun 2014 05:10:23 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id B770F2640BF for ; Fri, 27 Jun 2014 10:10:21 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 4/7] Pull out common parts of _initialize_{i386, amd64}_linux_nat Date: Fri, 27 Jun 2014 10:10:06 +0100 Message-Id: <1403860209-475-5-git-send-email-gbenson@redhat.com> In-Reply-To: <1403860209-475-1-git-send-email-gbenson@redhat.com> References: <1403860209-475-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. 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 844343c..2aabf37 100644 --- a/gdb/amd64-linux-nat.c +++ b/gdb/amd64-linux-nat.c @@ -1283,42 +1283,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. */ @@ -1328,11 +1314,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 9794a09..e4ae160 100644 --- a/gdb/i386-linux-nat.c +++ b/gdb/i386-linux-nat.c @@ -1231,37 +1231,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. */ @@ -1271,10 +1262,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); +}