From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113405 invoked by alias); 3 Nov 2015 13:43:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 113386 invoked by uid 89); 3 Nov 2015 13:43:54 -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,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 03 Nov 2015 13:43:49 +0000 Received: by wmff134 with SMTP id f134so84543839wmf.1 for ; Tue, 03 Nov 2015 05:43:46 -0800 (PST) X-Received: by 10.28.87.67 with SMTP id l64mr18494844wmb.72.1446558226888; Tue, 03 Nov 2015 05:43:46 -0800 (PST) Received: from bigtime.com ([87.111.149.167]) by smtp.gmail.com with ESMTPSA id r13sm23442566wmg.12.2015.11.03.05.43.45 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 03 Nov 2015 05:43:46 -0800 (PST) From: Richard Henderson To: gdb-patches@gcc.gnu.org Subject: [PATCH 2/3] Use register cache for x86_64 ps_get_thread_area Date: Tue, 03 Nov 2015 13:43:00 -0000 Message-Id: <1446558190-13482-3-git-send-email-rth@redhat.com> In-Reply-To: <1446558190-13482-1-git-send-email-rth@redhat.com> References: <1446558190-13482-1-git-send-email-rth@redhat.com> X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg00077.txt.bz2 * amd64-linux-nat.c (ps_get_thread_area): Use regcache to fetch FS_BASE contents. --- gdb/amd64-linux-nat.c | 71 +++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 50 deletions(-) diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c index 0a2cf45..b7211d3e 100644 --- a/gdb/amd64-linux-nat.c +++ b/gdb/amd64-linux-nat.c @@ -283,10 +283,11 @@ ps_err_e ps_get_thread_area (const struct ps_prochandle *ph, lwpid_t lwpid, int idx, void **base) { + ps_err_e result; + if (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word == 32) { unsigned int base_addr; - ps_err_e result; result = x86_linux_get_thread_area (lwpid, (void *) (long) idx, &base_addr); @@ -296,63 +297,33 @@ ps_get_thread_area (const struct ps_prochandle *ph, a "long" and a "void *" are the same. */ (*base) = (void *) (long) base_addr; } - return result; } else { - /* This definition comes from prctl.h, but some kernels may not - have it. */ -#ifndef PTRACE_ARCH_PRCTL -#define PTRACE_ARCH_PRCTL 30 -#endif + struct cleanup *old_chain; + struct regcache *regcache; + enum amd64_regnum gdb_regnum; + /* FIXME: ezannoni-2003-07-09 see comment above about include file order. We could be getting bogus values for these two. */ gdb_assert (FS < ELF_NGREG); gdb_assert (GS < ELF_NGREG); - switch (idx) - { - case FS: -#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE - { - /* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the - fs_base and gs_base fields of user_regs_struct can be - used directly. */ - unsigned long fs; - errno = 0; - fs = ptrace (PTRACE_PEEKUSER, lwpid, - offsetof (struct user_regs_struct, fs_base), 0); - if (errno == 0) - { - *base = (void *) fs; - return PS_OK; - } - } -#endif - if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0) - return PS_OK; - break; - case GS: -#ifdef HAVE_STRUCT_USER_REGS_STRUCT_GS_BASE - { - unsigned long gs; - errno = 0; - gs = ptrace (PTRACE_PEEKUSER, lwpid, - offsetof (struct user_regs_struct, gs_base), 0); - if (errno == 0) - { - *base = (void *) gs; - return PS_OK; - } - } -#endif - if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0) - return PS_OK; - break; - default: /* Should not happen. */ - return PS_BADADDR; - } + if (idx == FS) + gdb_regnum = AMD64_FSBASE_REGNUM; + else if (idx == GS) + gdb_regnum = AMD64_GSBASE_REGNUM; + else + return PS_BADADDR; + + old_chain = save_inferior_ptid (); + inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0); + regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); + result = (regcache_raw_read (regcache, gdb_regnum, (gdb_byte *) base) + == REG_VALID ? PS_OK : PS_ERR); + do_cleanups (old_chain); } - return PS_ERR; /* ptrace failed. */ + + return result; } -- 2.4.3