prgregset_t vs gdb_gregset_t on Linux: not the same!

Mark Kettenis
Sat Jun 9 11:50:00 GMT 2001

Daniel Jacobowitz <> writes:

> On Fri, Jun 08, 2001 at 01:27:30PM -0700, Daniel Jacobowitz wrote:
> > In proc-service.c, we call fill_gregset and supply_gregset with a
> > prgregset_t cast to a gdb_gregset_t *.  The problem is, they really are
> > different.  We can mostly get away with this, because in almost all cases
> > glibc won't do anything with the gregset except pass it back to gdb again
> > (if the process has terminated, it will memset something the size of a
> > prgregset_t, though...).
> The matching question here is that core-regset.c's fetch_core_registers
> calls supply_gregset with a gregset_t, but supply_gregset is prototyped
> with a gdb_gregset_t.  That doesn't work very well either.

It's a mess.  Linux should have three different regset types:

 * elf_gregset_t: The type used for register sets in ELF core dumps.
   Should be defined by <sys/procfs.h>.

 * prgregset_t: The type used for register sets in the
   <proc_service.h> debugging interface.

 * gregset_t: The type used for register sets in machine contexts.
   Should be defined in <sys/ucontext.h>.

On many Linux ports the elf_gregset_t and gregset_t types differ, and
apparently the MIPS port is one of them.  The type prgregset_t is
equivalent to one of them, but which one?  To make matters worse
<linux/elfcore.h> has a

   typedef elf_gregset_t gregset_t;

which means that there might be two different types bearing the same
name.  Which type you get depends on what headers you include.

The first thing you'll need to do is cleanup up the glibc headers for
MIPS.  The important headers are <sys/procfs.h>, <sys/ucontext.h> and
<sys/user.h>.  Avoid including Linux kernel headers and copy the few
definitions that you really need.  Avoid cross-includes.  I cleaned up
the i386 headers some time ago.  Take a look at those to see what I

Then for GDB you need to make sure that gdb_gregset_t is equivalent to
elf_gregset_t.  The file config/nm-linux.h makes sure it is by
defining GDB_GREGSET_T.  You should include this file from
config/mips/nm-linux (or whatever your native configuration header is

The proc-service.c module assumes that gdb_gregset_t and prgregset_t
are equivalent types.  Preferably, you should fix glibc such that that
is the case.  You might need to change the version of the library if you're worried about backward compatibility.

We could add conversion routines for prgregset_t in GDB, but I'd like
to avoid that.


More information about the Gdb mailing list