public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Fedora utrace changes break PPC GDB
@ 2007-10-29 21:21 Ulrich Weigand
  2007-11-02  1:19 ` Roland McGrath
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Weigand @ 2007-10-29 21:21 UTC (permalink / raw)
  To: roland, gdb

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

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

end of thread, other threads:[~2007-11-09 19:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-29 21:21 Fedora utrace changes break PPC GDB Ulrich Weigand
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

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).