From patchwork Mon Sep 8 14:38:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edjunior Barbosa Machado X-Patchwork-Id: 2676 Received: (qmail 11022 invoked by alias); 8 Sep 2014 14:40:36 -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 11000 invoked by uid 89); 8 Sep 2014 14:40:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e24smtp01.br.ibm.com Received: from e24smtp01.br.ibm.com (HELO e24smtp01.br.ibm.com) (32.104.18.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 08 Sep 2014 14:40:33 +0000 Received: from /spool/local by e24smtp01.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 8 Sep 2014 11:40:28 -0300 Received: from d24dlp02.br.ibm.com (9.18.248.206) by e24smtp01.br.ibm.com (10.172.0.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 8 Sep 2014 11:40:27 -0300 Received: from d24relay03.br.ibm.com (d24relay03.br.ibm.com [9.13.184.25]) by d24dlp02.br.ibm.com (Postfix) with ESMTP id 2AF4E1DC005C for ; Mon, 8 Sep 2014 10:40:26 -0400 (EDT) Received: from d24av03.br.ibm.com (d24av03.br.ibm.com [9.8.31.95]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id s88EdWNj28246268 for ; Mon, 8 Sep 2014 11:39:33 -0300 Received: from d24av03.br.ibm.com (localhost [127.0.0.1]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s88EeP86023061 for ; Mon, 8 Sep 2014 11:40:26 -0300 Received: from grandaddy.ibm.com ([9.78.142.5]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s88EePW6023049; Mon, 8 Sep 2014 11:40:25 -0300 From: Edjunior Barbosa Machado To: gdb-patches@sourceware.org Cc: Ulrich Weigand , Sergio Durigan Junior Subject: Re: [PATCH] ppc64le/gdbserver: Fix ppc_collect/supply_ptrace_register() routines Date: Mon, 8 Sep 2014 11:38:56 -0300 Message-Id: <1410187136-4222-1-git-send-email-emachado@linux.vnet.ibm.com> In-Reply-To: <201409081151.s88BpOJX015412@d06av02.portsmouth.uk.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14090814-1524-0000-0000-0000006DC953 X-IsSubscribed: yes Thanks Sergio and Ulrich for the review. Here is the patch with the suggested modifications. Thanks and regards, --- Edjunior gdb/gdbserver/ 2014-09-08 Edjunior Barbosa Machado * linux-ppc-low.c (ppc_collect_ptrace_register): Adjust routine to take endianness into account. (ppc_supply_ptrace_register): Likewise. --- gdb/gdbserver/linux-ppc-low.c | 45 ++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/gdb/gdbserver/linux-ppc-low.c b/gdb/gdbserver/linux-ppc-low.c index d743311..8fd4b38 100644 --- a/gdb/gdbserver/linux-ppc-low.c +++ b/gdb/gdbserver/linux-ppc-low.c @@ -202,25 +202,52 @@ ppc_cannot_fetch_register (int regno) static void ppc_collect_ptrace_register (struct regcache *regcache, int regno, char *buf) { - int size = register_size (regcache->tdesc, regno); - memset (buf, 0, sizeof (long)); - if (size < sizeof (long)) - collect_register (regcache, regno, buf + sizeof (long) - size); + if (__BYTE_ORDER == __LITTLE_ENDIAN) + { + /* Little-endian values always sit at the left end of the buffer. */ + collect_register (regcache, regno, buf); + } + else if (__BYTE_ORDER == __BIG_ENDIAN) + { + /* Big-endian values sit at the right end of the buffer. In case of + registers whose sizes are smaller than sizeof (long), we must use a + padding to access them correctly. */ + int size = register_size (regcache->tdesc, regno); + + if (size < sizeof (long)) + collect_register (regcache, regno, buf + sizeof (long) - size); + else + collect_register (regcache, regno, buf); + } else - collect_register (regcache, regno, buf); + perror_with_name ("Unexpected byte order"); } static void ppc_supply_ptrace_register (struct regcache *regcache, int regno, const char *buf) { - int size = register_size (regcache->tdesc, regno); - if (size < sizeof (long)) - supply_register (regcache, regno, buf + sizeof (long) - size); + if (__BYTE_ORDER == __LITTLE_ENDIAN) + { + /* Little-endian values always sit at the left end of the buffer. */ + supply_register (regcache, regno, buf); + } + else if (__BYTE_ORDER == __BIG_ENDIAN) + { + /* Big-endian values sit at the right end of the buffer. In case of + registers whose sizes are smaller than sizeof (long), we must use a + padding to access them correctly. */ + int size = register_size (regcache->tdesc, regno); + + if (size < sizeof (long)) + supply_register (regcache, regno, buf + sizeof (long) - size); + else + supply_register (regcache, regno, buf); + } else - supply_register (regcache, regno, buf); + perror_with_name ("Unexpected byte order"); }