[PATCH v2] Add support for the x86 XSAVE extended state on FreeBSD/x86.

H.J. Lu hjl.tools@gmail.com
Mon Apr 13 17:47:00 GMT 2015


On Thu, Mar 26, 2015 at 4:53 PM, John Baldwin <jhb@freebsd.org> wrote:
> Recognize NT_X86_XSTATE notes in FreeBSD process cores.  Recent
> FreeBSD versions include a note containing the XSAVE state for each
> thread in the process when XSAVE is in use.  The note stores a copy of
> the current XSAVE mask in a reserved section of the machine-defined
> XSAVE state at the same offset as Linux's NT_X86_XSTATE note.
>
> For native processes, use the PT_GETXSTATE_INFO ptrace request to
> determine if XSAVE is enabled, and if so the active XSAVE state mask
> (that is, the value of %xcr0 for the target process) as well as the
> size of XSAVE state area.  Use the PT_GETXSTATE and PT_SETXSTATE requests
> to fetch and store the XSAVE state, respectively, in the BSD x86
> native targets.
>
> In addition, the FreeBSD amd64 and i386 native targets now include
> "read_description" target methods to determine the correct x86 target
> description for the current XSAVE mask.  On FreeBSD amd64 this also
> properly returns an i386 target description for 32-bit binaries which
> allows the 64-bit GDB to run 32-bit binaries.
>
> Note that the ptrace changes are in the BSD native targets, not the
> FreeBSD-specific native targets since that is where the other ptrace
> register accesses occur.  Of the other BSDs, NetBSD and DragonFly use
> XSAVE in the kernel but do not currently export the extended state via
> ptrace(2).  OpenBSD does not currently support XSAVE.
>
> bfd/ChangeLog:
>
>         * elf.c (elfcore_grok_note): Recognize NT_X86_XSTATE on
>         FreeBSD.
>         (elfcore_write_xstatereg): Use correct note name on FreeBSD.
>
...
> ---
> diff --git a/bfd/elf.c b/bfd/elf.c
> index 13d4272..7cd3533 100644
> --- a/bfd/elf.c
> +++ b/bfd/elf.c
> @@ -8670,6 +8670,9 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
>        if (note->namesz == 6
>           && strcmp (note->namedata, "LINUX") == 0)
>         return elfcore_grok_xstatereg (abfd, note);
> +      else if (note->namesz == 8
> +         && strcmp (note->namedata, "FreeBSD") == 0)
> +       return elfcore_grok_xstatereg (abfd, note);
>        else
>         return TRUE;

OK.

> @@ -9490,6 +9493,8 @@ elfcore_write_xstatereg (bfd *abfd, char *buf, int *bufsiz,
>                          const void *xfpregs, int size)
>  {
>    char *note_name = "LINUX";
> +  if (get_elf_backend_data (abfd)->elf_osabi == ELFOSABI_FREEBSD)
> +    note_name = "FreeBSD";

Please use

      else
          note_name = "LINUX";

bfd change is OK with this change.   Thanks.

>    return elfcore_write_note (abfd, buf, bufsiz,
>                              note_name, NT_X86_XSTATE, xfpregs, size);
>  }
>

H.J.



More information about the Gdb-patches mailing list