From patchwork Thu May 10 19:58:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pedromfc X-Patchwork-Id: 27212 Received: (qmail 47302 invoked by alias); 10 May 2018 19:59:23 -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 46966 invoked by uid 89); 10 May 2018 19:59:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=common-defs.h, UD:common-defs.h, commondefsh X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 May 2018 19:59:16 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4AJx2aw129305 for ; Thu, 10 May 2018 15:59:14 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0b-001b2d01.pphosted.com with ESMTP id 2hvrbdcjsd-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 10 May 2018 15:59:14 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 May 2018 15:59:13 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 10 May 2018 15:59:11 -0400 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4AJxBk155509080 for ; Thu, 10 May 2018 19:59:11 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ADFA5AC04A for ; Thu, 10 May 2018 16:00:42 -0400 (EDT) Received: from pedro.localdomain (unknown [9.18.235.221]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 66157AC055 for ; Thu, 10 May 2018 16:00:42 -0400 (EDT) Received: by pedro.localdomain (Postfix, from userid 1000) id 6266C3C03DB; Thu, 10 May 2018 16:59:07 -0300 (-03) From: Pedro Franco de Carvalho To: gdb-patches@sourceware.org Subject: [PATCH 2/8] [PowerPC] Consolidate wordsize getter between native and gdbserver Date: Thu, 10 May 2018 16:58:34 -0300 In-Reply-To: <20180510195840.17734-1-pedromfc@linux.vnet.ibm.com> References: <20180510195840.17734-1-pedromfc@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18051019-0040-0000-0000-00000429A125 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009001; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000259; SDB=6.01030392; UDB=6.00526595; IPR=6.00809523; MB=3.00021034; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-10 19:59:12 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051019-0041-0000-0000-0000082FB0A1 Message-Id: <20180510195840.17734-3-pedromfc@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805100185 X-IsSubscribed: yes This patch moves the native target wordsize getter for ppc linux to nat/ so that it can be used to simplify ppc_arch_setup in gdbserver. The ptrace call used to get MSR for this is ultimately the same as before, but it is no longer necessary to create a temporary regcache to call fetch_inferior_registers. gdb/ChangeLog: yyyy-mm-dd Pedro Franco de Carvalho * configure.nat : Add ppc-linux.o to NATDEPFILES. * ppc-linux-nat.c (ppc_linux_target_wordsize): Move to nat/ppc-linux.c. (ppc_linux_nat_target::auxv_parse): Get thread id tid. Call ppc_linux_target wordsize with tid. (ppc_linux_nat_target::read_description): Call ppc_linux_target wordsize with tid. * nat/ppc-linux.c: Include nat/gdb_ptrace.h. (ppc_linux_target_wordsize): Move here from ppc-linux-nat.c. Add tid parameter. Remove static specifier. * nat/ppc-linux.h (ppc_linux_target_wordsize): New declaration. gdb/gdbserver/ChangeLog: yyyy-mm-dd Pedro Franco de Carvalho * linux-ppc-low.c (ppc_arch_setup): Remove code for getting the wordsize of the inferior. Call ppc_linux_target_wordsize. --- gdb/configure.nat | 2 +- gdb/gdbserver/linux-ppc-low.c | 29 ++++++----------------------- gdb/nat/ppc-linux.c | 20 ++++++++++++++++++++ gdb/nat/ppc-linux.h | 3 +++ gdb/ppc-linux-nat.c | 30 ++++++------------------------ 5 files changed, 36 insertions(+), 48 deletions(-) diff --git a/gdb/configure.nat b/gdb/configure.nat index 6b0f44fede..bcaeaf4583 100644 --- a/gdb/configure.nat +++ b/gdb/configure.nat @@ -264,7 +264,7 @@ case ${gdb_host} in ;; powerpc) # Host: PowerPC, running Linux - NATDEPFILES="${NATDEPFILES} ppc-linux-nat.o" + NATDEPFILES="${NATDEPFILES} ppc-linux-nat.o ppc-linux.o" ;; s390) # Host: S390, running Linux diff --git a/gdb/gdbserver/linux-ppc-low.c b/gdb/gdbserver/linux-ppc-low.c index a442a51273..a4182633d7 100644 --- a/gdb/gdbserver/linux-ppc-low.c +++ b/gdb/gdbserver/linux-ppc-low.c @@ -621,33 +621,16 @@ ppc_arch_setup (void) const struct target_desc *tdesc; struct ppc_linux_features features = ppc_linux_no_features; -#ifdef __powerpc64__ - long msr; - struct regcache *regcache; - - /* On a 64-bit host, assume 64-bit inferior process with no - AltiVec registers. Reset ppc_hwcap to ensure that the - collect_register call below does not fail. */ - tdesc = tdesc_powerpc_64l; - current_process ()->tdesc = tdesc; - ppc_hwcap = 0; + int tid = lwpid_of (current_thread); - regcache = new_register_cache (tdesc); - fetch_inferior_registers (regcache, find_regno (tdesc, "msr")); - collect_register_by_name (regcache, "msr", &msr); - free_register_cache (regcache); - if (ppc64_64bit_inferior_p (msr)) - { - features.wordsize = 8; - } -#endif + features.wordsize = ppc_linux_target_wordsize (tid); if (features.wordsize == 4) - { - /* OK, we have a 32-bit inferior. */ tdesc = tdesc_powerpc_32l; - current_process ()->tdesc = tdesc; - } + else + tdesc = tdesc_powerpc_64l; + + current_process ()->tdesc = tdesc; /* The value of current_process ()->tdesc needs to be set for this call. */ diff --git a/gdb/nat/ppc-linux.c b/gdb/nat/ppc-linux.c index 7ab6551316..b87625e3f6 100644 --- a/gdb/nat/ppc-linux.c +++ b/gdb/nat/ppc-linux.c @@ -17,6 +17,7 @@ #include "common-defs.h" #include "ppc-linux.h" +#include "nat/gdb_ptrace.h" #include #ifdef HAVE_GETAUXVAL @@ -73,3 +74,22 @@ ppc64_64bit_inferior_p (long msr) } #endif + +int +ppc_linux_target_wordsize (int tid) +{ + int wordsize = 4; + + /* Check for 64-bit inferior process. This is the case when the host is + 64-bit, and in addition the top bit of the MSR register is set. */ +#ifdef __powerpc64__ + long msr; + + errno = 0; + msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0); + if (errno == 0 && ppc64_64bit_inferior_p (msr)) + wordsize = 8; +#endif + + return wordsize; +} diff --git a/gdb/nat/ppc-linux.h b/gdb/nat/ppc-linux.h index 76a5d181df..d91d3f2a9c 100644 --- a/gdb/nat/ppc-linux.h +++ b/gdb/nat/ppc-linux.h @@ -88,4 +88,7 @@ int ppc64_64bit_inferior_p (long msr); #endif +/* Return the wordsize of the target, either 4 or 8 bytes. */ +int ppc_linux_target_wordsize (int tid); + #endif diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c index af59761cd6..07ec53d1ea 100644 --- a/gdb/ppc-linux-nat.c +++ b/gdb/ppc-linux-nat.c @@ -2368,35 +2368,17 @@ fill_fpregset (const struct regcache *regcache, fpregsetp, sizeof (*fpregsetp)); } -static int -ppc_linux_target_wordsize (void) +int +ppc_linux_nat_target::auxv_parse (gdb_byte **readptr, + gdb_byte *endptr, CORE_ADDR *typep, + CORE_ADDR *valp) { - int wordsize = 4; - - /* Check for 64-bit inferior process. This is the case when the host is - 64-bit, and in addition the top bit of the MSR register is set. */ -#ifdef __powerpc64__ - long msr; - int tid = ptid_get_lwp (inferior_ptid); if (tid == 0) tid = ptid_get_pid (inferior_ptid); - errno = 0; - msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0); - if (errno == 0 && ppc64_64bit_inferior_p (msr)) - wordsize = 8; -#endif - - return wordsize; -} + int sizeof_auxv_field = ppc_linux_target_wordsize (tid); -int -ppc_linux_nat_target::auxv_parse (gdb_byte **readptr, - gdb_byte *endptr, CORE_ADDR *typep, - CORE_ADDR *valp) -{ - int sizeof_auxv_field = ppc_linux_target_wordsize (); enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ()); gdb_byte *ptr = *readptr; @@ -2438,7 +2420,7 @@ ppc_linux_nat_target::read_description () struct ppc_linux_features features = ppc_linux_no_features; unsigned long hwcap = ppc_linux_get_hwcap (); - features.wordsize = ppc_linux_target_wordsize (); + features.wordsize = ppc_linux_target_wordsize (tid); if (have_ptrace_getsetvsxregs && (hwcap & PPC_FEATURE_HAS_VSX))