From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28009 invoked by alias); 28 Feb 2010 20:12:40 -0000 Received: (qmail 27982 invoked by uid 22791); 28 Feb 2010 20:12:38 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from sibelius.xs4all.nl (HELO glazunov.sibelius.xs4all.nl) (83.163.83.176) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 28 Feb 2010 20:12:33 +0000 Received: from glazunov.sibelius.xs4all.nl (kettenis@localhost [127.0.0.1]) by glazunov.sibelius.xs4all.nl (8.14.3/8.14.3) with ESMTP id o1SK9M95010647; Sun, 28 Feb 2010 21:09:22 +0100 (CET) Received: (from kettenis@localhost) by glazunov.sibelius.xs4all.nl (8.14.3/8.14.3/Submit) id o1SK9JqK006858; Sun, 28 Feb 2010 21:09:19 +0100 (CET) Date: Sun, 28 Feb 2010 20:12:00 -0000 Message-Id: <201002282009.o1SK9JqK006858@glazunov.sibelius.xs4all.nl> From: Mark Kettenis To: hjl.tools@gmail.com CC: dan@codesourcery.com, gdb-patches@sourceware.org, suresh.b.siddha@intel.com, hpa@zytor.com In-reply-to: <6dc9ffc81002221341j735bdedeo7285951f4fc39c27@mail.gmail.com> (hjl.tools@gmail.com) Subject: Re: PATCH: Enable x86 XML target descriptions References: <20100218054312.GA9022@lucon.org> <6dc9ffc81002220734i15bd1279mb54cb0b64a37f3dc@mail.gmail.com> <20100222155243.GC30100@caradoc.them.org> <6dc9ffc81002220757v5e9b48bdnba56a260f0f3c0a8@mail.gmail.com> <20100222161040.GD30100@caradoc.them.org> <201002221656.o1MGuw5q009795@glazunov.sibelius.xs4all.nl> <20100222170303.GG9493@caradoc.them.org> <201002221950.o1MJoomn007989@glazunov.sibelius.xs4all.nl> <6dc9ffc81002221306y6287491dv5aaac541ba303199@mail.gmail.com> <201002222130.o1MLU3ub013661@glazunov.sibelius.xs4all.nl> <6dc9ffc81002221341j735bdedeo7285951f4fc39c27@mail.gmail.com> 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 X-SW-Source: 2010-02/txt/msg00702.txt.bz2 > Date: Mon, 22 Feb 2010 13:41:07 -0800 > From: "H.J. Lu" > > On Mon, Feb 22, 2010 at 1:30 PM, Mark Kettenis wrote: > >> Date: Mon, 22 Feb 2010 13:06:31 -0800 > >> From: "H.J. Lu" > >> > >> On Mon, Feb 22, 2010 at 11:50 AM, Mark Kettenis wrote: > >> >> Date: Mon, 22 Feb 2010 12:03:03 -0500 > >> >> From: Daniel Jacobowitz > >> >> > >> >> On Mon, Feb 22, 2010 at 05:56:58PM +0100, Mark Kettenis wrote: > >> >> > I've looked at the Linux kernel sources for the kernel on my > >> >> > workstation (2.6.27 in its OpenSUSE incarnation), and the only way to > >> >> > distinguish between a 32-bit and a 64-bit process seems to be to > >> >> > attempt to write one of the debug address registers with a value > >> >> > that's larger than 0xffffffff.  If that fails, you have a 32-bit > >> >> > process, otherwise it's a 64-bit process. > >> >> > >> >> Yuck :-(  But I didn't see anything else either. > >> > > >> > Indeed. > >> > > >> >> Is there an eflags bit for this?  Even if so, IIRC, we may not want to > >> >> use it; it's possible to run 32-bit code in a 64-bit process and some > >> >> overly clever programs may do so. > >> > > >> > Nope, there is no %eflags/%rflags bit for this.  Not quite sure what > >> > running 32-bit code in a 64-bit process actually means.  But I'd guess > >> > you want the 64-bit view on the registers in that case. > >> > > >> > Anyway, I think it's probably best if HJ leaves this bit out of this > >> > diff for now.  We can revisit the issue when AVX support is > >> > introduced. > >> > > >> > >> Please see if my latest patch is OK: > >> > >> --- > >>  /* Get CS register.  */ > >>   errno = 0; > >>   cs = ptrace (PTRACE_PEEKUSER, tid, > >>                offsetof (struct user_regs_struct, cs), 0); > >>   if (errno != 0) > >>     perror_with_name (_("Couldn't get CS register")); > >> > >>   /* Value of CS register: > >>      1. 64bit: 0x33. > >>      2. 32bit: 0x23. > >>    */ > >>   if (cs == 0x33) > >>     return tdesc_amd64_linux; > >>   else > >>     return tdesc_i386_linux; > >> --- > >> > >> In kernel, there is > >> > >>       regs->cs = test_thread_flag(TIF_64BIT_ILP32) ? __USER_CS : __USER32_CS; > > > > I fear that's rather fragile.  I mean, the actual value of > > __USER_CS/__USER32_CS is just an implementation detail isn't it? > > > > That is how strace checks 32bit process on Linux/x86-64 I have > discussed it with Peter and Suresh. It is very unlikely Linux kernel will > break strace. In any case, we will add a new ptrace option to Linux > 2.6.35 to get TIF_64BIT_ILP32 among other things. I will update gdb > to try the new ptrace option first and then fail back to CS register. OK, that makes it less fragile than I thought. But please use #defines with meaningful names instead of magic constants.