Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Richard Henderson <rth@redhat.com>
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	[thread overview]
Message-ID: <1446558190-13482-3-git-send-email-rth@redhat.com> (raw)
In-Reply-To: <1446558190-13482-1-git-send-email-rth@redhat.com>

	* 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;
 }
 \f
 
-- 
2.4.3


  reply	other threads:[~2015-11-03 13:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03 13:43 [PATCH 0/3] Support for x86 segments as address classes Richard Henderson
2015-11-03 13:43 ` Richard Henderson [this message]
2015-11-03 13:44 ` [PATCH 3/3] Segment support for x86_64, part 1 Richard Henderson
2015-11-03 13:44 ` [PATCH 1/3] Add amd64 registers fs_base and gs_base Richard Henderson
2015-11-05 11:21 ` [PATCH 0/3] Support for x86 segments as address classes Pedro Alves
2015-11-05 14:15   ` Richard Henderson
2015-11-18 18:18     ` Ulrich Weigand
2015-11-05 14:18 ` [PATCH 4/3] Segment support for x86_64, part 2 Richard Henderson
2015-11-27 14:34 ` [PATCH 0/3] Support for x86 segments as address classes Gary Benson
2016-04-19 14:23 ` Tedeschi, Walfred
2016-04-19 14:44   ` Richard Henderson
2016-04-19 14:47     ` Walfred Tedeschi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446558190-13482-3-git-send-email-rth@redhat.com \
    --to=rth@redhat.com \
    --cc=gdb-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox