From patchwork Thu May 28 14:20:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 6956 Received: (qmail 106534 invoked by alias); 28 May 2015 14:20:41 -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 106295 invoked by uid 89); 28 May 2015 14:20:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f42.google.com Received: from mail-pa0-f42.google.com (HELO mail-pa0-f42.google.com) (209.85.220.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 28 May 2015 14:20:30 +0000 Received: by paza2 with SMTP id a2so24744116paz.3 for ; Thu, 28 May 2015 07:20:28 -0700 (PDT) X-Received: by 10.66.118.166 with SMTP id kn6mr5837942pab.93.1432822828315; Thu, 28 May 2015 07:20:28 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by mx.google.com with ESMTPSA id dd3sm2587101pad.45.2015.05.28.07.20.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 May 2015 07:20:27 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 4/6] Fetch and store GP registers by PTRACE_{G,S}ETREGSET Date: Thu, 28 May 2015 15:20:14 +0100 Message-Id: <1432822816-32327-5-git-send-email-yao.qi@linaro.org> In-Reply-To: <1432822816-32327-1-git-send-email-yao.qi@linaro.org> References: <1432822816-32327-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes If kernel supports PTRACE_GETREGSET, GDB uses PTRACE_{G,S}ETREGSET to fetch and store GP registers. gdb: 2015-05-28 Yao Qi * arm-linux-nat.c (fetch_register): Use PTRACE_GETREGSET. (fetch_regs): Likewise. (store_regs): Use PTRACE_SETREGSET. (store_register): Likewise. --- gdb/arm-linux-nat.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 7 deletions(-) diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c index 877559e..0a86ed6 100644 --- a/gdb/arm-linux-nat.c +++ b/gdb/arm-linux-nat.c @@ -225,7 +225,18 @@ fetch_register (struct regcache *regcache, int regno) /* Get the thread id for the ptrace call. */ tid = GET_THREAD_ID (inferior_ptid); - ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); + if (have_ptrace_getregset == 1) + { + struct iovec iov; + + iov.iov_base = ®s; + iov.iov_len = sizeof (regs); + + ret = ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov); + } + else + ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); + if (ret < 0) { warning (_("Unable to fetch general register.")); @@ -266,8 +277,19 @@ fetch_regs (struct regcache *regcache) /* Get the thread id for the ptrace call. */ tid = GET_THREAD_ID (inferior_ptid); - - ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); + + if (have_ptrace_getregset == 1) + { + struct iovec iov; + + iov.iov_base = ®s; + iov.iov_len = sizeof (regs); + + ret = ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov); + } + else + ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); + if (ret < 0) { warning (_("Unable to fetch general registers.")); @@ -306,7 +328,18 @@ store_register (const struct regcache *regcache, int regno) tid = GET_THREAD_ID (inferior_ptid); /* Get the general registers from the process. */ - ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); + if (have_ptrace_getregset == 1) + { + struct iovec iov; + + iov.iov_base = ®s; + iov.iov_len = sizeof (regs); + + ret = ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov); + } + else + ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); + if (ret < 0) { warning (_("Unable to fetch general registers.")); @@ -322,7 +355,18 @@ store_register (const struct regcache *regcache, int regno) regcache_raw_collect (regcache, ARM_PC_REGNUM, (char *) ®s[ARM_PC_REGNUM]); - ret = ptrace (PTRACE_SETREGS, tid, 0, ®s); + if (have_ptrace_getregset == 1) + { + struct iovec iov; + + iov.iov_base = ®s; + iov.iov_len = sizeof (regs); + + ret = ptrace (PTRACE_SETREGSET, tid, NT_PRSTATUS, &iov); + } + else + ret = ptrace (PTRACE_SETREGS, tid, 0, ®s); + if (ret < 0) { warning (_("Unable to store general register.")); @@ -340,7 +384,18 @@ store_regs (const struct regcache *regcache) tid = GET_THREAD_ID (inferior_ptid); /* Fetch the general registers. */ - ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); + if (have_ptrace_getregset == 1) + { + struct iovec iov; + + iov.iov_base = ®s; + iov.iov_len = sizeof (regs); + + ret = ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov); + } + else + ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); + if (ret < 0) { warning (_("Unable to fetch general registers.")); @@ -357,7 +412,17 @@ store_regs (const struct regcache *regcache) regcache_raw_collect (regcache, ARM_PS_REGNUM, (char *) ®s[ARM_CPSR_GREGNUM]); - ret = ptrace (PTRACE_SETREGS, tid, 0, ®s); + if (have_ptrace_getregset == 1) + { + struct iovec iov; + + iov.iov_base = ®s; + iov.iov_len = sizeof (regs); + + ret = ptrace (PTRACE_SETREGSET, tid, NT_PRSTATUS, &iov); + } + else + ret = ptrace (PTRACE_SETREGS, tid, 0, ®s); if (ret < 0) {