public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: roland@redhat.com, gdb@sourceware.org
Subject: Fedora utrace changes break PPC GDB
Date: Mon, 29 Oct 2007 21:21:00 -0000	[thread overview]
Message-ID: <200710292121.l9TLLZk7019813@d12av02.megacenter.de.ibm.com> (raw)

Hello,

I've been testing GDB on a PowerPC system running a Fedora 7 kernel,
and there are some regressions that appear to have been introduced
by the ptrace-on-utrace emulation layer that is now included in
Fedora.

Specifically, there are the following two problems (which also seem
to still be present in a current Fedora development kernel):

- PTRACE_SET_DEBUGREG ABI change

  In mainline kernels, PTRACE_SET_DEBUGREG takes an immediate 
  argument (like e.g. PTRACE_POKEUSR).  However, the Fedora code has:

        case PTRACE_GET_DEBUGREG:
        case PTRACE_SET_DEBUGREG:
                return ptrace_onereg_access(child, engine,
                                            utrace_native_view(current), 3,
                                            addr, (unsigned long __user *)data,
                                            *request == PTRACE_SET_DEBUGREG);

  which assumes the "data" argument is a *pointer* to the data,
  instead of the value itself.

  This breaks hardware watchpoint support completely.

- vrsave register access 

  The mainline kernel uses the following function to implement
  the PTRACE_GETVRREGS routine:

        /* copy AltiVec registers VR[0] .. VR[31] */
        regsize = 32 * sizeof(vector128);
        if (copy_to_user(data, task->thread.vr, regsize))
                return -EFAULT;
        data += (regsize / sizeof(unsigned long));

        /* copy VSCR */
        regsize = 1 * sizeof(vector128);
        if (copy_to_user(data, &task->thread.vscr, regsize))
                return -EFAULT;
        data += (regsize / sizeof(unsigned long));

        /* copy VRSAVE */
        if (put_user(task->thread.vrsave, (u32 __user *)data))
                return -EFAULT;

  Note that vscr and vrsave are provided in distinct fields of
  the thread struct:

        /* Complete AltiVec register set */
        vector128       vr[32] __attribute((aligned(16)));
        /* AltiVec status */
        vector128       vscr __attribute((aligned(16)));
        unsigned long   vrsave;
        int             used_vr;        /* set if process has used altivec */


  However, the utrace emulation layer in Fedora does

        case PTRACE_GETVRREGS:
                return ptrace_whole_regset(child, engine, data, 2, 0);
        case PTRACE_SETVRREGS:
                return ptrace_whole_regset(child, engine, data, 2, 1);

  using the following "regset" and access routines

#ifdef CONFIG_ALTIVEC
        {
                .n = 33*4+1, .size = sizeof(u32), .align = sizeof(u32),
                .active = vrregs_active, .get = vrregs_get, .set = vrregs_set
        },
#endif

static int
vrregs_get(struct task_struct *target,
           const struct utrace_regset *regset,
           unsigned int pos, unsigned int count,
           void *kbuf, void __user *ubuf)
{
        BUILD_BUG_ON(offsetof(struct thread_struct, vscr)
                     != offsetof(struct thread_struct, vr[32]));
        BUILD_BUG_ON(offsetof(struct thread_struct, vscr) + sizeof(vector128)
                     != offsetof(struct thread_struct, vrsave));

        flush_altivec_to_thread(target);

        return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
                                     &target->thread.vr, 0, -1);
}

   This has the effect of simply accessing 33*4+1 "u32" values starting
   at &target->thread.vr

   Now, given the declaration above, the vr field is only 32 * 16 bytes
   long, so this is not really legal C in any case.  Even so, access to
   the vscr field happens to actually work correctly, as it immediately
   following vr (and there happens to be no padding).

   However, vrsave is accessed incorrectly on a 64-bit kernel: its value
   resides in the low 32 bits of the "unsigned long", and the copyout
   accesses the high 32 bits ...   (The BUILD_BUG_ON doesn't help.)

   This has the effect of GDB always reading vrsave as 0, even after
   attempting to set it to some other value.  (Every restart of the
   target process will apparently cause the upper 32 bit to be reset.)


Any suggestions how to get this fixed?

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

             reply	other threads:[~2007-10-29 21:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-29 21:21 Ulrich Weigand [this message]
2007-11-02  1:19 ` Roland McGrath
2007-11-05 18:05   ` Ulrich Weigand
2007-11-08  0:07     ` Roland McGrath
2007-11-09 19:21       ` Ulrich Weigand

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=200710292121.l9TLLZk7019813@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb@sourceware.org \
    --cc=roland@redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).