From patchwork Fri Apr 5 16:26:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Franco de Carvalho X-Patchwork-Id: 32171 Received: (qmail 130824 invoked by alias); 5 Apr 2019 16:26:38 -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 130607 invoked by uid 89); 5 Apr 2019 16:26:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-13.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=HTo:U*uweigand, indicator 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; Fri, 05 Apr 2019 16:26:36 +0000 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x35GOoKE001508 for ; Fri, 5 Apr 2019 12:26:34 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rp8pydnwh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 05 Apr 2019 12:26:34 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 5 Apr 2019 17:26:33 +0100 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 5 Apr 2019 17:26:31 +0100 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x35GQUnc21102594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 5 Apr 2019 16:26:30 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D7167805F; Fri, 5 Apr 2019 16:26:30 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C98B978060; Fri, 5 Apr 2019 16:26:29 +0000 (GMT) Received: from pedro.localdomain (unknown [9.85.171.202]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 5 Apr 2019 16:26:29 +0000 (GMT) Received: by pedro.localdomain (Postfix, from userid 1000) id D72643C0373; Fri, 5 Apr 2019 13:26:26 -0300 (-03) From: Pedro Franco de Carvalho To: Ulrich Weigand Cc: Alan Hayward , Simon Marchi , "gdb-patches\@sourceware.org" , nd , anton@linux.ibm.com Subject: Re: [PATCH 2/2] gdbserver: Add linux_get_hwcap In-Reply-To: <20190404134915.95BF1D802CA@oc3748833570.ibm.com> References: <20190404134915.95BF1D802CA@oc3748833570.ibm.com> Date: Fri, 05 Apr 2019 13:26:26 -0300 MIME-Version: 1.0 x-cbid: 19040516-0020-0000-0000-00000ED3F854 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010874; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000284; SDB=6.01184753; UDB=6.00620363; IPR=6.00965495; MB=3.00026307; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-05 16:26:33 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19040516-0021-0000-0000-00006553EFD5 Message-Id: <875zrsctal.fsf@linux.vnet.ibm.com> X-IsSubscribed: yes Hi, I've copied the patch below. Note that there is a difference in the interface between linux_get_auxv and linux_get_hwcap(2), the latter still return both the status and the entry value, but I didn't want to change all their users. Also, contrary to the gdb client version (target_auxv_search gdb/auxv.c), this one doesn't differentiate between an error and the entry not being found. Is that ok? Thanks! From 0af6ec5fdbe9e696e10e22b530c52e3c926c5e9c Mon Sep 17 00:00:00 2001 From: Pedro Franco de Carvalho Date: Thu, 4 Apr 2019 14:49:37 -0300 Subject: [PATCH] Use linux_get_auxv to get AT_PHDR in the PPC stub This patch fixes a build error due to a call to ppc_get_auxv that was left over after linux_get_hwcap and linux_get_hwcap2 were introduced in: 974c89e0882ddb03e294eca76a9e3d3bef90eacf gdbserver: Add linux_get_hwcap Because the missing call fetched AT_PHDR and not AT_HWCAP, linux_get_auxv is now visible. This use also required ppc_get_auxv to return a status variable indicating that the AT_PHDR entry was not found separately from the actual value of of the auxv entry. Therefore, the new linux_get_auxv function is changed to return a status variable and write the entry value to a pointer passed as an argument. Note that linux_get_hwcap and linux_get_hwcap2 still use the return value as both an indicator of that the entry wasn't found and as the actual value of the entry. gdb/gdbserver/ChangeLog: 2019-04-DD Pedro Franco de Carvalho * linux-low.c (linux_get_auxv): Remove static. Return auxv entry value in argument pointer, return 1 if the entry is found and 0 otherwise. Move comment. (linux_get_hwcap, linux_get_hwcap2): Use modified linux_get_auxv. * linux-low.h (linux_get_auxv): Declare. * linux-ppc-low.c (is_elfv2_inferior): Use linux_get_auxv. --- gdb/gdbserver/linux-low.c | 29 +++++++++++++++++++---------- gdb/gdbserver/linux-low.h | 8 ++++++++ gdb/gdbserver/linux-ppc-low.c | 7 +++++-- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 265043f97e..65919c3262 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -7427,11 +7427,10 @@ linux_get_pc_64bit (struct regcache *regcache) return pc; } -/* Fetch the entry MATCH from the auxv vector, where entries are length - WORDSIZE. If no entry was found, return zero. */ +/* See linux-low.h. */ -static CORE_ADDR -linux_get_auxv (int wordsize, CORE_ADDR match) +int +linux_get_auxv (int wordsize, CORE_ADDR match, CORE_ADDR *valp) { gdb_byte *data = (gdb_byte *) alloca (2 * wordsize); int offset = 0; @@ -7442,15 +7441,21 @@ linux_get_auxv (int wordsize, CORE_ADDR match) { if (wordsize == 4) { - uint32_t *data_p = (uint32_t *)data; + uint32_t *data_p = (uint32_t *) data; if (data_p[0] == match) - return data_p[1]; + { + *valp = data_p[1]; + return 1; + } } else { - uint64_t *data_p = (uint64_t *)data; + uint64_t *data_p = (uint64_t *) data; if (data_p[0] == match) - return data_p[1]; + { + *valp = data_p[1]; + return 1; + } } offset += 2 * wordsize; @@ -7464,7 +7469,9 @@ linux_get_auxv (int wordsize, CORE_ADDR match) CORE_ADDR linux_get_hwcap (int wordsize) { - return linux_get_auxv (wordsize, AT_HWCAP); + CORE_ADDR hwcap = 0; + linux_get_auxv (wordsize, AT_HWCAP, &hwcap); + return hwcap; } /* See linux-low.h. */ @@ -7472,7 +7479,9 @@ linux_get_hwcap (int wordsize) CORE_ADDR linux_get_hwcap2 (int wordsize) { - return linux_get_auxv (wordsize, AT_HWCAP2); + CORE_ADDR hwcap2 = 0; + linux_get_auxv (wordsize, AT_HWCAP2, &hwcap2); + return hwcap2; } static struct target_ops linux_target_ops = { diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h index d825184835..d5d074efc5 100644 --- a/gdb/gdbserver/linux-low.h +++ b/gdb/gdbserver/linux-low.h @@ -435,6 +435,14 @@ bool thread_db_thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len); extern int have_ptrace_getregset; +/* Search for the value with type MATCH in the auxv vector with + entries of length WORDSIZE bytes. If found, store the value in + *VALP and return 1. If not found or if there is an error, return + 0. */ + +int linux_get_auxv (int wordsize, CORE_ADDR match, + CORE_ADDR *valp); + /* Fetch the AT_HWCAP entry from the auxv vector, where entries are length WORDSIZE. If no entry was found, return zero. */ diff --git a/gdb/gdbserver/linux-ppc-low.c b/gdb/gdbserver/linux-ppc-low.c index 8deb0ce068..f17f05a0a3 100644 --- a/gdb/gdbserver/linux-ppc-low.c +++ b/gdb/gdbserver/linux-ppc-low.c @@ -1107,10 +1107,13 @@ is_elfv2_inferior (void) #else const int def_res = 0; #endif - unsigned long phdr; + CORE_ADDR phdr; Elf64_Ehdr ehdr; - if (!ppc_get_auxv (AT_PHDR, &phdr)) + const struct target_desc *tdesc = current_process ()->tdesc; + int wordsize = register_size (tdesc, 0); + + if (!linux_get_auxv (wordsize, AT_PHDR, &phdr)) return def_res; /* Assume ELF header is at the beginning of the page where program headers