Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* PATCH: Check DS segment register for x32 process
@ 2012-05-11 19:31 H.J. Lu
  2012-05-11 20:25 ` Mark Kettenis
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2012-05-11 19:31 UTC (permalink / raw)
  To: GDB

Hi,

This patch checks DS segment register for x32 process.  Tested on
Linux/x86-64.  OK to install?

Thanks.

H.J.
---
	* amd64-linux-nat.c (AMD64_LINUX_X32_DS): New.
	(amd64_linux_read_description): Check DS segment register for
	x32 process.

diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
index 3be8404..97c9a49 100644
--- a/gdb/amd64-linux-nat.c
+++ b/gdb/amd64-linux-nat.c
@@ -756,16 +945,23 @@ amd64_linux_siginfo_fixup (siginfo_t *native, gdb_byte *inf, int direction)
    Value of CS segment register:
      1. 64bit process: 0x33.
      2. 32bit process: 0x23.
+
+   Value of DS segment register:
+     1. LP64 process: 0x0.
+     2. X32 process: 0x2b.
  */
 
 #define AMD64_LINUX_USER64_CS	0x33
+#define AMD64_LINUX_X32_DS	0x2b
 
 static const struct target_desc *
 amd64_linux_read_description (struct target_ops *ops)
 {
   unsigned long cs;
+  unsigned long ds;
   int tid;
   int is_64bit;
+  int is_x32;
   static uint64_t xcr0;
 
   /* GNU/Linux LWP ID's are process ID's.  */
@@ -782,6 +978,18 @@ amd64_linux_read_description (struct target_ops *ops)
 
   is_64bit = cs == AMD64_LINUX_USER64_CS;
 
+  /* Get DS register.  */
+  errno = 0;
+  ds = ptrace (PTRACE_PEEKUSER, tid,
+	       offsetof (struct user_regs_struct, ds), 0);
+  if (errno != 0)
+    perror_with_name (_("Couldn't get DS register"));
+
+  is_x32 = ds == AMD64_LINUX_X32_DS;
+
+  if (sizeof (void *) == 4 && is_64bit && !is_x32)
+    error (_("Can't debug 64-bit process with 32-bit GDB"));
+
   if (have_ptrace_getregset == -1)
     {
       uint64_t xstateregs[(I386_XSTATE_SSE_SIZE / sizeof (uint64_t))];
@@ -809,14 +1017,24 @@ amd64_linux_read_description (struct target_ops *ops)
       && (xcr0 & I386_XSTATE_AVX_MASK) == I386_XSTATE_AVX_MASK)
     {
       if (is_64bit)
-	return tdesc_amd64_avx_linux;
+	{
+	  if (is_x32)
+	    return tdesc_x32_avx_linux;
+	  else
+	    return tdesc_amd64_avx_linux;
+	}
       else
 	return tdesc_i386_avx_linux;
     }
   else
     {
       if (is_64bit)
-	return tdesc_amd64_linux;
+	{
+	  if (is_x32)
+	    return tdesc_x32_linux;
+	  else
+	    return tdesc_amd64_linux;
+	}
       else
 	return tdesc_i386_linux;
     }


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Check DS segment register for x32 process
  2012-05-11 19:31 PATCH: Check DS segment register for x32 process H.J. Lu
@ 2012-05-11 20:25 ` Mark Kettenis
  2012-05-11 20:29   ` H.J. Lu
  2012-05-12  3:13   ` Mike Frysinger
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Kettenis @ 2012-05-11 20:25 UTC (permalink / raw)
  To: hjl.tools; +Cc: gdb-patches

> Date: Fri, 11 May 2012 12:31:14 -0700
> From: "H.J. Lu" <hongjiu.lu@intel.com>
> 
> Hi,
> 
> This patch checks DS segment register for x32 process.  Tested on
> Linux/x86-64.  OK to install?
> 
> Thanks.
> 
> H.J.
> ---
> 	* amd64-linux-nat.c (AMD64_LINUX_X32_DS): New.
> 	(amd64_linux_read_description): Check DS segment register for
> 	x32 process.
> 
> diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
> index 3be8404..97c9a49 100644
> --- a/gdb/amd64-linux-nat.c
> +++ b/gdb/amd64-linux-nat.c

> +  if (sizeof (void *) == 4 && is_64bit && !is_x32)
> +    error (_("Can't debug 64-bit process with 32-bit GDB"));

I really think we should refuse to even build a GDB as an X32 binary.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Check DS segment register for x32 process
  2012-05-11 20:25 ` Mark Kettenis
@ 2012-05-11 20:29   ` H.J. Lu
  2012-05-12  3:13   ` Mike Frysinger
  1 sibling, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2012-05-11 20:29 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb-patches

On Fri, May 11, 2012 at 1:25 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> Date: Fri, 11 May 2012 12:31:14 -0700
>> From: "H.J. Lu" <hongjiu.lu@intel.com>
>>
>> Hi,
>>
>> This patch checks DS segment register for x32 process.  Tested on
>> Linux/x86-64.  OK to install?
>>
>> Thanks.
>>
>> H.J.
>> ---
>>       * amd64-linux-nat.c (AMD64_LINUX_X32_DS): New.
>>       (amd64_linux_read_description): Check DS segment register for
>>       x32 process.
>>
>> diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
>> index 3be8404..97c9a49 100644
>> --- a/gdb/amd64-linux-nat.c
>> +++ b/gdb/amd64-linux-nat.c
>
>> +  if (sizeof (void *) == 4 && is_64bit && !is_x32)
>> +    error (_("Can't debug 64-bit process with 32-bit GDB"));
>
> I really think we should refuse to even build a GDB as an X32 binary.

Some x32 OSes don't have any 64bit binaries nor 64bit libraries.
32-bit x32 GDB work without any problems.

-- 
H.J.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Check DS segment register for x32 process
  2012-05-11 20:25 ` Mark Kettenis
  2012-05-11 20:29   ` H.J. Lu
@ 2012-05-12  3:13   ` Mike Frysinger
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2012-05-12  3:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mark Kettenis, hjl.tools

[-- Attachment #1: Type: Text/Plain, Size: 572 bytes --]

On Friday 11 May 2012 16:25:00 Mark Kettenis wrote:
> From: "H.J. Lu" <hongjiu.lu@intel.com>
> > This patch checks DS segment register for x32 process.  Tested on
> > Linux/x86-64.  OK to install?
> > 
> > --- a/gdb/amd64-linux-nat.c
> > +++ b/gdb/amd64-linux-nat.c
> > 
> > +  if (sizeof (void *) == 4 && is_64bit && !is_x32)
> > +    error (_("Can't debug 64-bit process with 32-bit GDB"));
> 
> I really think we should refuse to even build a GDB as an X32 binary.

huh ?  why would we restrict the host ABI ?  i plan on doing pure x32 
installs.
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-05-12  3:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-11 19:31 PATCH: Check DS segment register for x32 process H.J. Lu
2012-05-11 20:25 ` Mark Kettenis
2012-05-11 20:29   ` H.J. Lu
2012-05-12  3:13   ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox