* [PATCH 0/3] Add FreeBSD/mips targets to GDB @ 2016-11-23 20:59 John Baldwin 2016-11-23 20:59 ` [PATCH 3/3] Add native target for FreeBSD/mips John Baldwin ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: John Baldwin @ 2016-11-23 20:59 UTC (permalink / raw) To: gdb-patches, binutils The first patch works around an issue where FreeBSD/mips core dumps from the kernel include an empty ei_flags value in the ELF header. This causes bfd to select the default MIPS architecture (bfd_mach_3000) even though it is a 64-bit core file. As a result, parsing the core dump notes doesn't work correctly since bits_per_word is 32. It's not clear to me if bfd shouldn't default to a 64-bit MIPS machine if the ELF header indicates a 64-bit class instead of this change? John Baldwin (3): Use the ELF class to determine the word size for FreeBSD core notes. Add FreeBSD/mips architecture. Add native target for FreeBSD/mips. bfd/ChangeLog | 6 + bfd/elf.c | 23 +- gdb/ChangeLog | 15 ++ gdb/Makefile.in | 3 + gdb/config/mips/fbsd.mh | 3 + gdb/configure.host | 1 + gdb/configure.tgt | 5 + gdb/mips-fbsd-nat.c | 141 +++++++++++++ gdb/mips-fbsd-tdep.c | 541 ++++++++++++++++++++++++++++++++++++++++++++++++ gdb/mips-fbsd-tdep.h | 28 +++ 10 files changed, 756 insertions(+), 10 deletions(-) create mode 100644 gdb/config/mips/fbsd.mh create mode 100644 gdb/mips-fbsd-nat.c create mode 100644 gdb/mips-fbsd-tdep.c create mode 100644 gdb/mips-fbsd-tdep.h -- 2.9.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] Add native target for FreeBSD/mips. 2016-11-23 20:59 [PATCH 0/3] Add FreeBSD/mips targets to GDB John Baldwin @ 2016-11-23 20:59 ` John Baldwin 2016-11-26 4:26 ` Luis Machado 2016-11-23 20:59 ` [PATCH 2/3] Add FreeBSD/mips architecture John Baldwin 2016-11-23 20:59 ` [PATCH 1/3] Use the ELF class to determine the word size for FreeBSD core notes John Baldwin 2 siblings, 1 reply; 8+ messages in thread From: John Baldwin @ 2016-11-23 20:59 UTC (permalink / raw) To: gdb-patches, binutils This supports the o32 and n64 ABIs. gdb/ChangeLog: * Makefile.in (ALLDEPFILES): Add mips-fbsd-nat.c. * config/mips/fbsd.mh: New file. * configure.host: Add mips*-*-freebsd*. * mips-fbsd-nat.c: New file. --- gdb/ChangeLog | 7 +++ gdb/Makefile.in | 1 + gdb/config/mips/fbsd.mh | 3 ++ gdb/configure.host | 1 + gdb/mips-fbsd-nat.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 gdb/config/mips/fbsd.mh create mode 100644 gdb/mips-fbsd-nat.c diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 092ca9e..83fc91b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2016-11-23 John Baldwin <jhb@FreeBSD.org> + * Makefile.in (ALLDEPFILES): Add mips-fbsd-nat.c. + * config/mips/fbsd.mh: New file. + * configure.host: Add mips*-*-freebsd*. + * mips-fbsd-nat.c: New file. + +2016-11-23 John Baldwin <jhb@FreeBSD.org> + * Makefile.in (ALL_TARGET_OBS): Add mips-fbsd-tdep.o. (ALLDEPFILES): Add mips-fbsd-tdep.c. * configure.tgt: Add mips*-*-freebsd*. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index d89a17f..e0ca5e7 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2542,6 +2542,7 @@ ALLDEPFILES = \ microblaze-linux-tdep.c \ microblaze-tdep.c \ mingw-hdep.c \ + mips-fbsd-nat.c \ mips-fbsd-tdep.c \ mips-linux-nat.c \ mips-linux-tdep.c \ diff --git a/gdb/config/mips/fbsd.mh b/gdb/config/mips/fbsd.mh new file mode 100644 index 0000000..f433347 --- /dev/null +++ b/gdb/config/mips/fbsd.mh @@ -0,0 +1,3 @@ +# Host: FreeBSD/mips +NATDEPFILES= fork-child.o inf-ptrace.o fbsd-nat.o mips-fbsd-nat.o +HAVE_NATIVE_GCORE_HOST = 1 diff --git a/gdb/configure.host b/gdb/configure.host index ef265eb..c45f61d 100644 --- a/gdb/configure.host +++ b/gdb/configure.host @@ -129,6 +129,7 @@ m88*-*-openbsd*) gdb_host=obsd ;; mips*-*-linux*) gdb_host=linux ;; mips*-*-netbsd* | mips*-*-knetbsd*-gnu) gdb_host=nbsd ;; +mips*-*-freebsd*) gdb_host=fbsd ;; mips64*-*-openbsd*) gdb_host=obsd64 ;; powerpc-*-aix* | rs6000-*-* | powerpc64-*-aix*) diff --git a/gdb/mips-fbsd-nat.c b/gdb/mips-fbsd-nat.c new file mode 100644 index 0000000..67ce683 --- /dev/null +++ b/gdb/mips-fbsd-nat.c @@ -0,0 +1,141 @@ +/* Target-dependent code for FreeBSD/mips. + + Copyright (C) 2016 Free Software Foundation, Inc. + + This software was developed by SRI International and the University + of Cambridge Computer Laboratory under DARPA/AFRL contract + FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research + programme. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "defs.h" +#include "inferior.h" +#include "regcache.h" +#include "target.h" + +#include <sys/types.h> +#include <sys/ptrace.h> +#include <machine/reg.h> + +#include "fbsd-nat.h" +#include "mips-tdep.h" +#include "mips-fbsd-tdep.h" +#include "inf-ptrace.h" + +/* Determine if PT_GETREGS fetches this register. */ + +static int +getregs_supplies (struct gdbarch *gdbarch, int regnum) +{ + return ((regnum) >= MIPS_ZERO_REGNUM + && (regnum) <= gdbarch_pc_regnum (gdbarch)); +} + +/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this + for all registers. */ + +static void +mipsfbsd_fetch_inferior_registers (struct target_ops *ops, + struct regcache *regcache, int regnum) +{ + struct gdbarch *gdbarch = get_regcache_arch (regcache); + if (regnum == -1 || getregs_supplies (gdbarch, regnum)) + { + struct reg regs; + + if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid), + (PTRACE_TYPE_ARG3) ®s, 0) == -1) + perror_with_name (_("Couldn't get registers")); + + mipsfbsd_supply_gregs (regcache, regnum, ®s, sizeof (register_t)); + if (regnum != -1) + return; + } + + if (regnum == -1 + || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache))) + { + struct fpreg fpregs; + + if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid), + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) + perror_with_name (_("Couldn't get floating point status")); + + mipsfbsd_supply_fpregs (regcache, regnum, &fpregs, + sizeof (f_register_t)); + } +} + +/* Store register REGNUM back into the inferior. If REGNUM is -1, do + this for all registers. */ + +static void +mipsfbsd_store_inferior_registers (struct target_ops *ops, + struct regcache *regcache, int regnum) +{ + struct gdbarch *gdbarch = get_regcache_arch (regcache); + if (regnum == -1 || getregs_supplies (gdbarch, regnum)) + { + struct reg regs; + + if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid), + (PTRACE_TYPE_ARG3) ®s, 0) == -1) + perror_with_name (_("Couldn't get registers")); + + mipsfbsd_collect_gregs (regcache, regnum, (char *) ®s, + sizeof (register_t)); + + if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid), + (PTRACE_TYPE_ARG3) ®s, 0) == -1) + perror_with_name (_("Couldn't write registers")); + + if (regnum != -1) + return; + } + + if (regnum == -1 + || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache))) + { + struct fpreg fpregs; + + if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid), + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) + perror_with_name (_("Couldn't get floating point status")); + + mipsfbsd_collect_fpregs (regcache, regnum, (char *) &fpregs, + sizeof (f_register_t)); + + if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid), + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) + perror_with_name (_("Couldn't write floating point status")); + } +} +\f + +/* Provide a prototype to silence -Wmissing-prototypes. */ +void _initialize_mipsfbsd_nat (void); + +void +_initialize_mipsfbsd_nat (void) +{ + struct target_ops *t; + + t = inf_ptrace_target (); + t->to_fetch_registers = mipsfbsd_fetch_inferior_registers; + t->to_store_registers = mipsfbsd_store_inferior_registers; + fbsd_nat_add_target (t); +} -- 2.9.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] Add native target for FreeBSD/mips. 2016-11-23 20:59 ` [PATCH 3/3] Add native target for FreeBSD/mips John Baldwin @ 2016-11-26 4:26 ` Luis Machado 2016-11-28 22:54 ` John Baldwin 0 siblings, 1 reply; 8+ messages in thread From: Luis Machado @ 2016-11-26 4:26 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils A few comments, mostly cosmetic in nature. On 11/23/2016 02:59 PM, John Baldwin wrote: > This supports the o32 and n64 ABIs. > > gdb/ChangeLog: > > * Makefile.in (ALLDEPFILES): Add mips-fbsd-nat.c. > * config/mips/fbsd.mh: New file. > * configure.host: Add mips*-*-freebsd*. > * mips-fbsd-nat.c: New file. > --- > gdb/ChangeLog | 7 +++ > gdb/Makefile.in | 1 + > gdb/config/mips/fbsd.mh | 3 ++ > gdb/configure.host | 1 + > gdb/mips-fbsd-nat.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 153 insertions(+) > create mode 100644 gdb/config/mips/fbsd.mh > create mode 100644 gdb/mips-fbsd-nat.c > > diff --git a/gdb/mips-fbsd-nat.c b/gdb/mips-fbsd-nat.c > new file mode 100644 > index 0000000..67ce683 > --- /dev/null > +++ b/gdb/mips-fbsd-nat.c > @@ -0,0 +1,141 @@ > +/* Target-dependent code for FreeBSD/mips. FreeBSD/MIPS native support? > + > + Copyright (C) 2016 Free Software Foundation, Inc. > + > + This software was developed by SRI International and the University > + of Cambridge Computer Laboratory under DARPA/AFRL contract > + FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research > + programme. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see <http://www.gnu.org/licenses/>. */ > + > +#include "defs.h" > +#include "inferior.h" > +#include "regcache.h" > +#include "target.h" > + > +#include <sys/types.h> > +#include <sys/ptrace.h> > +#include <machine/reg.h> > + > +#include "fbsd-nat.h" > +#include "mips-tdep.h" > +#include "mips-fbsd-tdep.h" > +#include "inf-ptrace.h" > + > +/* Determine if PT_GETREGS fetches this register. */ > + > +static int With GDB having switched to C++, using bool here sounds more appropriate. > +getregs_supplies (struct gdbarch *gdbarch, int regnum) get_regs_supplies? > +{ > + return ((regnum) >= MIPS_ZERO_REGNUM > + && (regnum) <= gdbarch_pc_regnum (gdbarch)); > +} > + > +/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this > + for all registers. */ > + > +static void > +mipsfbsd_fetch_inferior_registers (struct target_ops *ops, > + struct regcache *regcache, int regnum) Same as patch 2/3, mips_fbsd_* sounds more appropriate for the name? > +{ > + struct gdbarch *gdbarch = get_regcache_arch (regcache); > + if (regnum == -1 || getregs_supplies (gdbarch, regnum)) > + { > + struct reg regs; > + > + if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid), > + (PTRACE_TYPE_ARG3) ®s, 0) == -1) > + perror_with_name (_("Couldn't get registers")); > + > + mipsfbsd_supply_gregs (regcache, regnum, ®s, sizeof (register_t)); > + if (regnum != -1) > + return; > + } > + > + if (regnum == -1 > + || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache))) > + { > + struct fpreg fpregs; > + > + if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid), > + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) > + perror_with_name (_("Couldn't get floating point status")); "Couldn't get floating point registers"? > + > + mipsfbsd_supply_fpregs (regcache, regnum, &fpregs, > + sizeof (f_register_t)); > + } > +} > + > +/* Store register REGNUM back into the inferior. If REGNUM is -1, do > + this for all registers. */ > + > +static void > +mipsfbsd_store_inferior_registers (struct target_ops *ops, > + struct regcache *regcache, int regnum) > +{ > + struct gdbarch *gdbarch = get_regcache_arch (regcache); > + if (regnum == -1 || getregs_supplies (gdbarch, regnum)) > + { > + struct reg regs; > + > + if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid), > + (PTRACE_TYPE_ARG3) ®s, 0) == -1) > + perror_with_name (_("Couldn't get registers")); > + > + mipsfbsd_collect_gregs (regcache, regnum, (char *) ®s, > + sizeof (register_t)); > + > + if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid), > + (PTRACE_TYPE_ARG3) ®s, 0) == -1) > + perror_with_name (_("Couldn't write registers")); > + > + if (regnum != -1) > + return; > + } > + > + if (regnum == -1 > + || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache))) > + { > + struct fpreg fpregs; > + > + if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid), > + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) > + perror_with_name (_("Couldn't get floating point status")); "Couldn't get floating point registers"? > + > + mipsfbsd_collect_fpregs (regcache, regnum, (char *) &fpregs, > + sizeof (f_register_t)); > + > + if (ptrace (PT_SETFPREGS, get_ptrace_pid (inferior_ptid), > + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) > + perror_with_name (_("Couldn't write floating point status")); "Couldn't get floating point registers"? > + } > +} > +\f > + Spurious newline above. > +/* Provide a prototype to silence -Wmissing-prototypes. */ > +void _initialize_mipsfbsd_nat (void); > + > +void > +_initialize_mipsfbsd_nat (void) > +{ > + struct target_ops *t; > + > + t = inf_ptrace_target (); > + t->to_fetch_registers = mipsfbsd_fetch_inferior_registers; > + t->to_store_registers = mipsfbsd_store_inferior_registers; > + fbsd_nat_add_target (t); > +} > -- 2.9.2 > Otherwise looks good to me. Thanks, Luis ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] Add native target for FreeBSD/mips. 2016-11-26 4:26 ` Luis Machado @ 2016-11-28 22:54 ` John Baldwin 0 siblings, 0 replies; 8+ messages in thread From: John Baldwin @ 2016-11-28 22:54 UTC (permalink / raw) To: Luis Machado; +Cc: gdb-patches, binutils On Friday, November 25, 2016 10:25:53 PM Luis Machado wrote: > On 11/23/2016 02:59 PM, John Baldwin wrote: > > @@ -0,0 +1,141 @@ > > +/* Target-dependent code for FreeBSD/mips. > > FreeBSD/MIPS native support? Whoops, 'Native-dependent' seems to be what many other native targets use, so I'll go with that. > > +/* Determine if PT_GETREGS fetches this register. */ > > + > > +static int > > With GDB having switched to C++, using bool here sounds more appropriate. Ok. This was actually borrowed from mips-nbsd-tdep.c, but I can use bool here. > > +getregs_supplies (struct gdbarch *gdbarch, int regnum) > > get_regs_supplies? (Also copied as above). The ptrace operation to which this refers is PT_GETREGS rather than PT_GET_REGS, so I think 'getregs' here is better. > > + if (regnum == -1 > > + || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache))) > > + { > > + struct fpreg fpregs; > > + > > + if (ptrace (PT_GETFPREGS, get_ptrace_pid (inferior_ptid), > > + (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) > > + perror_with_name (_("Couldn't get floating point status")); > > "Couldn't get floating point registers"? Most targets use "status" rather than "registers" (including Linux/i386 and Linux/x86-64). (Curiously, sparc-nat.c uses both "status" and "registers".) > > + } > > +} > > +\f > > + > > Spurious newline above. There's actually a form feed (^L) in there as in many other targets before the _initialize_foo() routine. mips-linux-*.c don't include one, but many other targets do. This may be a no-longer-followed rule though (it is still in the GNU coding standards at the end of 5.1)? -- John Baldwin ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] Add FreeBSD/mips architecture. 2016-11-23 20:59 [PATCH 0/3] Add FreeBSD/mips targets to GDB John Baldwin 2016-11-23 20:59 ` [PATCH 3/3] Add native target for FreeBSD/mips John Baldwin @ 2016-11-23 20:59 ` John Baldwin 2016-11-25 22:52 ` Luis Machado 2016-11-23 20:59 ` [PATCH 1/3] Use the ELF class to determine the word size for FreeBSD core notes John Baldwin 2 siblings, 1 reply; 8+ messages in thread From: John Baldwin @ 2016-11-23 20:59 UTC (permalink / raw) To: gdb-patches, binutils This has been tested for the n64 and o32 ABIs. Signal frame unwinders for both ABIs are provided. FreeBSD/mips requires custom linkmap offsets since it contains an additional l_off member in 'struct link_map' that other FreeBSD platforms do not have. Support for collecting and supplying general purpose and floating point register sets are provided. Common routines for working with native format register sets are exported for use by the native target. gdb/ChangeLog: * Makefile.in (ALL_TARGET_OBS): Add mips-fbsd-tdep.o. (ALLDEPFILES): Add mips-fbsd-tdep.c. * configure.tgt: Add mips*-*-freebsd*. * mips-fbsd-tdep.c: New file. * mips-fbsd-tdep.h: New file. --- gdb/ChangeLog | 8 + gdb/Makefile.in | 2 + gdb/configure.tgt | 5 + gdb/mips-fbsd-tdep.c | 541 +++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/mips-fbsd-tdep.h | 28 +++ 5 files changed, 584 insertions(+) create mode 100644 gdb/mips-fbsd-tdep.c create mode 100644 gdb/mips-fbsd-tdep.h diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a2a11e2..092ca9e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2016-11-23 John Baldwin <jhb@FreeBSD.org> + + * Makefile.in (ALL_TARGET_OBS): Add mips-fbsd-tdep.o. + (ALLDEPFILES): Add mips-fbsd-tdep.c. + * configure.tgt: Add mips*-*-freebsd*. + * mips-fbsd-tdep.c: New file. + * mips-fbsd-tdep.h: New file. + 2016-11-23 Pedro Alves <palves@redhat.com> * Makefile.in (SFILES): Add common/run-time-clock.c. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 44a743e..d89a17f 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -817,6 +817,7 @@ ALL_TARGET_OBS = \ mep-tdep.o \ microblaze-linux-tdep.o \ microblaze-tdep.o \ + mips-fbsd-tdep.o \ mips-linux-tdep.o \ mips-nbsd-tdep.o \ mips-sde-tdep.o \ @@ -2541,6 +2542,7 @@ ALLDEPFILES = \ microblaze-linux-tdep.c \ microblaze-tdep.c \ mingw-hdep.c \ + mips-fbsd-tdep.c \ mips-linux-nat.c \ mips-linux-tdep.c \ mips-nbsd-nat.c \ diff --git a/gdb/configure.tgt b/gdb/configure.tgt index 3a1ea6f..1a43604 100644 --- a/gdb/configure.tgt +++ b/gdb/configure.tgt @@ -369,6 +369,11 @@ mips*-*-netbsd* | mips*-*-knetbsd*-gnu) gdb_target_obs="mips-tdep.o mips-nbsd-tdep.o solib-svr4.o nbsd-tdep.o" gdb_sim=../sim/mips/libsim.a ;; +mips*-*-freebsd*) + # Target: MIPS running FreeBSD + gdb_target_obs="mips-tdep.o mips-fbsd-tdep.o solib-svr4.o fbsd-tdep.o" + gdb_sim=../sim/mips/libsim.a + ;; mips64*-*-openbsd*) # Target: OpenBSD/mips64 gdb_target_obs="mips-tdep.o mips64-obsd-tdep.o obsd-tdep.o solib-svr4.o" diff --git a/gdb/mips-fbsd-tdep.c b/gdb/mips-fbsd-tdep.c new file mode 100644 index 0000000..424eb95 --- /dev/null +++ b/gdb/mips-fbsd-tdep.c @@ -0,0 +1,541 @@ +/* Target-dependent code for FreeBSD/mips. + + Copyright (C) 2016 Free Software Foundation, Inc. + + This software was developed by SRI International and the University + of Cambridge Computer Laboratory under DARPA/AFRL contract + FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research + programme. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "defs.h" +#include "osabi.h" +#include "regset.h" +#include "trad-frame.h" +#include "tramp-frame.h" + +#include "fbsd-tdep.h" +#include "mips-tdep.h" +#include "mips-fbsd-tdep.h" + +#include "solib-svr4.h" + +/* Shorthand for some register numbers used below. */ +#define MIPS_PC_REGNUM MIPS_EMBED_PC_REGNUM +#define MIPS_FP0_REGNUM MIPS_EMBED_FP0_REGNUM +#define MIPS_FSR_REGNUM MIPS_EMBED_FP0_REGNUM + 32 + +/* Core file support. */ + +/* Number of registers in `struct reg' from <machine/reg.h>. The + first 38 follow the standard MIPS layout. The 39th holds + IC_INT_REG on RM7K and RM9K processors. The 40th is a dummy for + padding. */ +#define MIPSFBSD_NUM_GREGS 40 + +/* Number of registers in `struct fpreg' from <machine/reg.h>. The + first 32 hold floating point registers. 33 holds the FSR. The + 34th is a dummy for padding. */ +#define MIPSFBSD_NUM_FPREGS 34 + +/* Supply a single register. If the source register size matches the + size the regcache expects, this can use regcache_raw_supply(). If + they are different, this copies the source register into a buffer + that can be passed to regcache_raw_supply(). */ + +static void +mipsfbsd_supply_reg (struct regcache *regcache, int regnum, const void *addr, + size_t len) +{ + struct gdbarch *gdbarch = get_regcache_arch (regcache); + + if (register_size (gdbarch, regnum) == len) + { + regcache_raw_supply (regcache, regnum, addr); + } + else + { + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + gdb_byte buf[MAX_REGISTER_SIZE]; + LONGEST val; + + val = extract_signed_integer ((const gdb_byte *) addr, len, byte_order); + store_signed_integer (buf, register_size (gdbarch, regnum), byte_order, + val); + regcache_raw_supply (regcache, regnum, buf); + } +} + +/* Collect a single register. If the destination register size + matches the size the regcache expects, this can use + regcache_raw_supply(). If they are different, this fetches the + register via regcache_raw_supply() into a buffer and then copies it + into the final destination. */ + +static void +mipsfbsd_collect_reg (const struct regcache *regcache, int regnum, void *addr, + size_t len) +{ + struct gdbarch *gdbarch = get_regcache_arch (regcache); + + if (register_size (gdbarch, regnum) == len) + { + regcache_raw_collect (regcache, regnum, addr); + } + else + { + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + gdb_byte buf[MAX_REGISTER_SIZE]; + LONGEST val; + + regcache_raw_collect (regcache, regnum, buf); + val = extract_signed_integer (buf, register_size (gdbarch, regnum), + byte_order); + store_signed_integer ((gdb_byte *) addr, len, byte_order, val); + } +} + +/* Supply the floating-point registers stored in FPREGS to REGCACHE. + Each floating-point register in FPREGS is REGSIZE bytes in + length. */ + +void +mipsfbsd_supply_fpregs (struct regcache *regcache, int regnum, + const void *fpregs, size_t regsize) +{ + const char *regs = (const char *) fpregs; + int i; + + for (i = MIPS_FP0_REGNUM; i <= MIPS_FSR_REGNUM; i++) + { + if (regnum == i || regnum == -1) + mipsfbsd_supply_reg (regcache, i, + regs + (i - MIPS_FP0_REGNUM) * regsize, regsize); + } +} + +/* Supply the general-purpose registers stored in GREGS to REGCACHE. + Each general-purpose register in GREGS is REGSIZE bytes in + length. */ + +void +mipsfbsd_supply_gregs (struct regcache *regcache, int regnum, + const void *gregs, size_t regsize) +{ + const char *regs = (const char *) gregs; + int i; + + for (i = 0; i <= MIPS_PC_REGNUM; i++) + { + if (regnum == i || regnum == -1) + mipsfbsd_supply_reg (regcache, i, regs + i * regsize, regsize); + } +} + +/* Collect the floating-point registers from REGCACHE and store them + in FPREGS. Each floating-point register in FPREGS is REGSIZE bytes + in length. */ + +void +mipsfbsd_collect_fpregs (const struct regcache *regcache, int regnum, + void *fpregs, size_t regsize) +{ + char *regs = (char *) fpregs; + int i; + + for (i = MIPS_FP0_REGNUM; i <= MIPS_FSR_REGNUM; i++) + { + if (regnum == i || regnum == -1) + mipsfbsd_collect_reg (regcache, i, + regs + (i - MIPS_FP0_REGNUM) * regsize, regsize); + } +} + +/* Collect the general-purpose registers from REGCACHE and store them + in GREGS. Each general-purpose register in GREGS is REGSIZE bytes + in length. */ + +void +mipsfbsd_collect_gregs (const struct regcache *regcache, int regnum, + void *gregs, size_t regsize) +{ + char *regs = (char *) gregs; + int i; + + for (i = 0; i <= MIPS_PC_REGNUM; i++) + { + if (regnum == i || regnum == -1) + mipsfbsd_collect_reg (regcache, i, regs + i * regsize, regsize); + } +} + +/* Supply register REGNUM from the buffer specified by FPREGS and LEN + in the floating-point register set REGSET to register cache + REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ + +static void +mipsfbsd_supply_fpregset (const struct regset *regset, + struct regcache *regcache, + int regnum, const void *fpregs, size_t len) +{ + size_t regsize = mips_abi_regsize (get_regcache_arch (regcache)); + + gdb_assert (len >= MIPSFBSD_NUM_FPREGS * regsize); + + mipsfbsd_supply_fpregs (regcache, regnum, fpregs, regsize); +} + +/* Collect register REGNUM from the register cache REGCACHE and store + it in the buffer specified by FPREGS and LEN in the floating-point + register set REGSET. If REGNUM is -1, do this for all registers in + REGSET. */ + +static void +mipsfbsd_collect_fpregset (const struct regset *regset, + const struct regcache *regcache, + int regnum, void *fpregs, size_t len) +{ + size_t regsize = mips_abi_regsize (get_regcache_arch (regcache)); + + gdb_assert (len >= MIPSFBSD_NUM_FPREGS * regsize); + + mipsfbsd_collect_fpregs (regcache, regnum, fpregs, regsize); +} + +/* Supply register REGNUM from the buffer specified by GREGS and LEN + in the general-purpose register set REGSET to register cache + REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ + +static void +mipsfbsd_supply_gregset (const struct regset *regset, + struct regcache *regcache, int regnum, + const void *gregs, size_t len) +{ + size_t regsize = mips_abi_regsize (get_regcache_arch (regcache)); + + gdb_assert (len >= MIPSFBSD_NUM_GREGS * regsize); + + mipsfbsd_supply_gregs (regcache, regnum, gregs, regsize); +} + +/* Collect register REGNUM from the register cache REGCACHE and store + it in the buffer specified by GREGS and LEN in the general-purpose + register set REGSET. If REGNUM is -1, do this for all registers in + REGSET. */ + +static void +mipsfbsd_collect_gregset (const struct regset *regset, + const struct regcache *regcache, + int regnum, void *gregs, size_t len) +{ + size_t regsize = mips_abi_regsize (get_regcache_arch (regcache)); + + gdb_assert (len >= MIPSFBSD_NUM_GREGS * regsize); + + mipsfbsd_collect_gregs (regcache, regnum, gregs, regsize); +} + +/* FreeBSD/mips register sets. */ + +static const struct regset mipsfbsd_gregset = +{ + NULL, + mipsfbsd_supply_gregset, + mipsfbsd_collect_gregset, +}; + +static const struct regset mipsfbsd_fpregset = +{ + NULL, + mipsfbsd_supply_fpregset, + mipsfbsd_collect_fpregset, +}; + +/* Iterate over core file register note sections. */ + +static void +mipsfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, + iterate_over_regset_sections_cb *cb, + void *cb_data, + const struct regcache *regcache) +{ + size_t regsize = mips_abi_regsize (gdbarch); + + cb (".reg", MIPSFBSD_NUM_GREGS * regsize, &mipsfbsd_gregset, + NULL, cb_data); + cb (".reg2", MIPSFBSD_NUM_FPREGS * regsize, &mipsfbsd_fpregset, + NULL, cb_data); +} + +/* Signal trampoline support. */ + +static void +mipsfbsd_sigframe_init (const struct tramp_frame *self, + struct frame_info *this_frame, + struct trad_frame_cache *cache, + CORE_ADDR func) +{ + struct gdbarch *gdbarch = get_frame_arch (this_frame); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + CORE_ADDR sp, ucontext_addr, addr; + int regnum; + gdb_byte buf[4]; + + /* We find the appropriate instance of `ucontext_t' at a + fixed offset in the signal frame. */ + sp = get_frame_register_signed (this_frame, + MIPS_SP_REGNUM + gdbarch_num_regs (gdbarch)); + ucontext_addr = sp + 16; + + /* PC. */ + regnum = mips_regnum (gdbarch)->pc; + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + ucontext_addr + 20); + + /* GPRs. */ + for (regnum = MIPS_AT_REGNUM, addr = ucontext_addr + 28; + regnum <= MIPS_RA_REGNUM; regnum++, addr += 4) + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + addr); + + regnum = MIPS_PS_REGNUM; + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + ucontext_addr + 152); + + /* HI and LO. */ + regnum = mips_regnum (gdbarch)->lo; + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + ucontext_addr + 156); + regnum = mips_regnum (gdbarch)->hi; + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + ucontext_addr + 160); + + if (target_read_memory (ucontext_addr + 164, buf, 4) == 0 && + extract_unsigned_integer (buf, 4, byte_order) != 0) + { + for (regnum = 0, addr = ucontext_addr + 168; + regnum < 32; regnum++, addr += 8) + trad_frame_set_reg_addr (cache, + regnum + gdbarch_fp0_regnum (gdbarch), + addr); + trad_frame_set_reg_addr (cache, mips_regnum (gdbarch)->fp_control_status, + addr); + } + + trad_frame_set_id (cache, frame_id_build (sp, func)); +} + +static const struct tramp_frame mipsfbsd_sigframe = +{ + SIGTRAMP_FRAME, + MIPS_INSN32_SIZE, + { + { 0x27a40010, -1 }, /* addiu a0, sp, SIGF_UC */ + { 0x240201a1, -1 }, /* li v0, SYS_sigreturn */ + { 0x0000000c, -1 }, /* syscall */ + { 0x0000000d, -1 }, /* break */ + { TRAMP_SENTINEL_INSN, -1 } + }, + mipsfbsd_sigframe_init +}; + +static void +mips64fbsd_sigframe_init (const struct tramp_frame *self, + struct frame_info *this_frame, + struct trad_frame_cache *cache, + CORE_ADDR func) +{ + struct gdbarch *gdbarch = get_frame_arch (this_frame); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + CORE_ADDR sp, ucontext_addr, addr; + int regnum; + gdb_byte buf[4]; + + /* We find the appropriate instance of `ucontext_t' at a + fixed offset in the signal frame. */ + sp = get_frame_register_signed (this_frame, + MIPS_SP_REGNUM + gdbarch_num_regs (gdbarch)); + ucontext_addr = sp + 32; + + /* PC. */ + regnum = mips_regnum (gdbarch)->pc; + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + ucontext_addr + 24); + + /* GPRs. */ + for (regnum = MIPS_AT_REGNUM, addr = ucontext_addr + 40; + regnum <= MIPS_RA_REGNUM; regnum++, addr += 8) + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + addr); + + regnum = MIPS_PS_REGNUM; + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + ucontext_addr + 288); + + /* HI and LO. */ + regnum = mips_regnum (gdbarch)->lo; + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + ucontext_addr + 296); + regnum = mips_regnum (gdbarch)->hi; + trad_frame_set_reg_addr (cache, + regnum + gdbarch_num_regs (gdbarch), + ucontext_addr + 304); + + if (target_read_memory (ucontext_addr + 312, buf, 4) == 0 && + extract_unsigned_integer (buf, 4, byte_order) != 0) + { + for (regnum = 0, addr = ucontext_addr + 320; + regnum < 32; regnum++, addr += 8) + trad_frame_set_reg_addr (cache, + regnum + gdbarch_fp0_regnum (gdbarch), + addr); + trad_frame_set_reg_addr (cache, mips_regnum (gdbarch)->fp_control_status, + addr); + } + + trad_frame_set_id (cache, frame_id_build (sp, func)); +} + +static const struct tramp_frame mips64fbsd_sigframe = +{ + SIGTRAMP_FRAME, + MIPS_INSN32_SIZE, + { + { 0x67a40020, -1 }, /* daddiu a0, sp, SIGF_UC */ + { 0x240201a1, -1 }, /* li v0, SYS_sigreturn */ + { 0x0000000c, -1 }, /* syscall */ + { 0x0000000d, -1 }, /* break */ + { TRAMP_SENTINEL_INSN, -1 } + }, + mips64fbsd_sigframe_init +}; + +/* Shared library support. */ + +/* FreeBSD/mips uses a slightly different `struct link_map' than the + other FreeBSD platforms as it includes an additional `l_off' + member. */ + +static struct link_map_offsets * +mipsfbsd_ilp32_fetch_link_map_offsets (void) +{ + static struct link_map_offsets lmo; + static struct link_map_offsets *lmp = NULL; + + if (lmp == NULL) + { + lmp = &lmo; + + lmo.r_version_offset = 0; + lmo.r_version_size = 4; + lmo.r_map_offset = 4; + lmo.r_brk_offset = 8; + lmo.r_ldsomap_offset = -1; + + lmo.link_map_size = 24; + lmo.l_addr_offset = 0; + lmo.l_name_offset = 8; + lmo.l_ld_offset = 12; + lmo.l_next_offset = 16; + lmo.l_prev_offset = 20; + } + + return lmp; +} + +static struct link_map_offsets * +mipsfbsd_lp64_fetch_link_map_offsets (void) +{ + static struct link_map_offsets lmo; + static struct link_map_offsets *lmp = NULL; + + if (lmp == NULL) + { + lmp = &lmo; + + lmo.r_version_offset = 0; + lmo.r_version_size = 4; + lmo.r_map_offset = 8; + lmo.r_brk_offset = 16; + lmo.r_ldsomap_offset = -1; + + lmo.link_map_size = 48; + lmo.l_addr_offset = 0; + lmo.l_name_offset = 16; + lmo.l_ld_offset = 24; + lmo.l_next_offset = 32; + lmo.l_prev_offset = 40; + } + + return lmp; +} + +static void +mipsfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + enum mips_abi abi = mips_abi (gdbarch); + + /* Generic FreeBSD support. */ + fbsd_init_abi (info, gdbarch); + + set_gdbarch_software_single_step (gdbarch, mips_software_single_step); + + switch (abi) + { + case MIPS_ABI_O32: + tramp_frame_prepend_unwinder (gdbarch, &mipsfbsd_sigframe); + break; + case MIPS_ABI_N32: + /* Float formats similar to Linux? */ + break; + case MIPS_ABI_N64: + /* Float formats similar to Linux? */ + tramp_frame_prepend_unwinder (gdbarch, &mips64fbsd_sigframe); + break; + } + + /* TODO: set_gdbarch_longjmp_target */ + + set_gdbarch_iterate_over_regset_sections + (gdbarch, mipsfbsd_iterate_over_regset_sections); + + /* FreeBSD/mips has SVR4-style shared libraries. */ + set_solib_svr4_fetch_link_map_offsets + (gdbarch, (gdbarch_ptr_bit (gdbarch) == 32 ? + mipsfbsd_ilp32_fetch_link_map_offsets : + mipsfbsd_lp64_fetch_link_map_offsets)); +} +\f + +/* Provide a prototype to silence -Wmissing-prototypes. */ +void _initialize_mipsfbsd_tdep (void); + +void +_initialize_mipsfbsd_tdep (void) +{ + gdbarch_register_osabi (bfd_arch_mips, 0, GDB_OSABI_FREEBSD_ELF, + mipsfbsd_init_abi); +} diff --git a/gdb/mips-fbsd-tdep.h b/gdb/mips-fbsd-tdep.h new file mode 100644 index 0000000..dd344f3 --- /dev/null +++ b/gdb/mips-fbsd-tdep.h @@ -0,0 +1,28 @@ +/* Common target dependent code for GDB on MIPS systems running FreeBSD. + + Copyright (C) 2016 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef MIPS_FBSD_TDEP_H +#define MIPS_FBSD_TDEP_H + +void mipsfbsd_supply_fpregs (struct regcache *, int, const void *, size_t); +void mipsfbsd_supply_gregs (struct regcache *, int, const void *, size_t); +void mipsfbsd_collect_fpregs (const struct regcache *, int, void *, size_t); +void mipsfbsd_collect_gregs (const struct regcache *, int, void *, size_t); + +#endif /* MIPS_FBSD_TDEP_H */ -- 2.9.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] Add FreeBSD/mips architecture. 2016-11-23 20:59 ` [PATCH 2/3] Add FreeBSD/mips architecture John Baldwin @ 2016-11-25 22:52 ` Luis Machado 2016-11-28 22:54 ` John Baldwin 0 siblings, 1 reply; 8+ messages in thread From: Luis Machado @ 2016-11-25 22:52 UTC (permalink / raw) To: John Baldwin, gdb-patches, binutils Code looks good. I have a few comments on other things. On 11/23/2016 02:59 PM, John Baldwin wrote: > @@ -0,0 +1,541 @@ > +/* Target-dependent code for FreeBSD/mips. > + > + Copyright (C) 2016 Free Software Foundation, Inc. > + > + This software was developed by SRI International and the University > + of Cambridge Computer Laboratory under DARPA/AFRL contract > + FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research > + programme. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see <http://www.gnu.org/licenses/>. */ > + > +#include "defs.h" > +#include "osabi.h" > +#include "regset.h" > +#include "trad-frame.h" > +#include "tramp-frame.h" > + > +#include "fbsd-tdep.h" > +#include "mips-tdep.h" > +#include "mips-fbsd-tdep.h" > + > +#include "solib-svr4.h" > + > +/* Shorthand for some register numbers used below. */ > +#define MIPS_PC_REGNUM MIPS_EMBED_PC_REGNUM > +#define MIPS_FP0_REGNUM MIPS_EMBED_FP0_REGNUM > +#define MIPS_FSR_REGNUM MIPS_EMBED_FP0_REGNUM + 32 > + > +/* Core file support. */ > + > +/* Number of registers in `struct reg' from <machine/reg.h>. The > + first 38 follow the standard MIPS layout. The 39th holds > + IC_INT_REG on RM7K and RM9K processors. The 40th is a dummy for > + padding. */ > +#define MIPSFBSD_NUM_GREGS 40 > + > +/* Number of registers in `struct fpreg' from <machine/reg.h>. The > + first 32 hold floating point registers. 33 holds the FSR. The > + 34th is a dummy for padding. */ > +#define MIPSFBSD_NUM_FPREGS 34 Should all the above defines be moved to the header file mips-fbsd-tdep.h? > + > +/* Supply a single register. If the source register size matches the > + size the regcache expects, this can use regcache_raw_supply(). If > + they are different, this copies the source register into a buffer > + that can be passed to regcache_raw_supply(). */ > + > +static void > +mipsfbsd_supply_reg (struct regcache *regcache, int regnum, const void *addr, > + size_t len) How about mips_fbsd_* for the function names? Multiple occurrences of this. > +{ > + struct gdbarch *gdbarch = get_regcache_arch (regcache); > + > + if (register_size (gdbarch, regnum) == len) > + { > + regcache_raw_supply (regcache, regnum, addr); > + } No need for curly braces for single-statement blocks. Multiple occurrences of this. > +/* Supply the floating-point registers stored in FPREGS to REGCACHE. > + Each floating-point register in FPREGS is REGSIZE bytes in > + length. */ > + > +void > +mipsfbsd_supply_fpregs (struct regcache *regcache, int regnum, > + const void *fpregs, size_t regsize) > +{ > + const char *regs = (const char *) fpregs; Should these const char * types be const gdb_byte * types instead? Multiple occurrences. > +/* FreeBSD/mips register sets. */ > + > +static const struct regset mipsfbsd_gregset = > +{ > + NULL, > + mipsfbsd_supply_gregset, > + mipsfbsd_collect_gregset, > +}; > + > +static const struct regset mipsfbsd_fpregset = > +{ > + NULL, > + mipsfbsd_supply_fpregset, > + mipsfbsd_collect_fpregset, > +}; > + > +/* Iterate over core file register note sections. */ > + > +static void > +mipsfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, > + iterate_over_regset_sections_cb *cb, > + void *cb_data, > + const struct regcache *regcache) > +{ > + size_t regsize = mips_abi_regsize (gdbarch); > + > + cb (".reg", MIPSFBSD_NUM_GREGS * regsize, &mipsfbsd_gregset, > + NULL, cb_data); > + cb (".reg2", MIPSFBSD_NUM_FPREGS * regsize, &mipsfbsd_fpregset, > + NULL, cb_data); > +} > + > +/* Signal trampoline support. */ > + > +static void > +mipsfbsd_sigframe_init (const struct tramp_frame *self, > + struct frame_info *this_frame, > + struct trad_frame_cache *cache, > + CORE_ADDR func) > +{ > + struct gdbarch *gdbarch = get_frame_arch (this_frame); > + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); > + CORE_ADDR sp, ucontext_addr, addr; > + int regnum; > + gdb_byte buf[4]; > + > + /* We find the appropriate instance of `ucontext_t' at a > + fixed offset in the signal frame. */ > + sp = get_frame_register_signed (this_frame, > + MIPS_SP_REGNUM + gdbarch_num_regs (gdbarch)); > + ucontext_addr = sp + 16; We should make the fixed offset a constant with a #define. Maybe move those to the header file as well. > + > + /* PC. */ > + regnum = mips_regnum (gdbarch)->pc; > + trad_frame_set_reg_addr (cache, > + regnum + gdbarch_num_regs (gdbarch), > + ucontext_addr + 20); Same here for the PC offset. > + > + /* GPRs. */ > + for (regnum = MIPS_AT_REGNUM, addr = ucontext_addr + 28; Same here for all the other GPR's, and so on for the other fixed offsets. > + regnum <= MIPS_RA_REGNUM; regnum++, addr += 4) > + trad_frame_set_reg_addr (cache, > + regnum + gdbarch_num_regs (gdbarch), > + addr); > + > + regnum = MIPS_PS_REGNUM; > + trad_frame_set_reg_addr (cache, > + regnum + gdbarch_num_regs (gdbarch), > + ucontext_addr + 152); Here. > + > + /* HI and LO. */ > + regnum = mips_regnum (gdbarch)->lo; > + trad_frame_set_reg_addr (cache, > + regnum + gdbarch_num_regs (gdbarch), > + ucontext_addr + 156); Here. > + regnum = mips_regnum (gdbarch)->hi; > + trad_frame_set_reg_addr (cache, > + regnum + gdbarch_num_regs (gdbarch), > + ucontext_addr + 160); > + Here. > + if (target_read_memory (ucontext_addr + 164, buf, 4) == 0 && And here. More occurrences throughout the patch. > + extract_unsigned_integer (buf, 4, byte_order) != 0) > + { > + for (regnum = 0, addr = ucontext_addr + 168; > + regnum < 32; regnum++, addr += 8) > + trad_frame_set_reg_addr (cache, > + regnum + gdbarch_fp0_regnum (gdbarch), > + addr); > + trad_frame_set_reg_addr (cache, mips_regnum (gdbarch)->fp_control_status, > + addr); > + } > + > + trad_frame_set_id (cache, frame_id_build (sp, func)); > +} > + > +static const struct tramp_frame mipsfbsd_sigframe = > +{ > + SIGTRAMP_FRAME, > + MIPS_INSN32_SIZE, > + { > + { 0x27a40010, -1 }, /* addiu a0, sp, SIGF_UC */ > + { 0x240201a1, -1 }, /* li v0, SYS_sigreturn */ > + { 0x0000000c, -1 }, /* syscall */ > + { 0x0000000d, -1 }, /* break */ > + { TRAMP_SENTINEL_INSN, -1 } > + }, > + mipsfbsd_sigframe_init These hex constants should be set with a #define. See mips-linux-tdep.c. More occurrences throughout the patch. > +static void > +mipsfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) > +{ > + enum mips_abi abi = mips_abi (gdbarch); > + > + /* Generic FreeBSD support. */ > + fbsd_init_abi (info, gdbarch); > + > + set_gdbarch_software_single_step (gdbarch, mips_software_single_step); > + > + switch (abi) > + { > + case MIPS_ABI_O32: > + tramp_frame_prepend_unwinder (gdbarch, &mipsfbsd_sigframe); > + break; > + case MIPS_ABI_N32: > + /* Float formats similar to Linux? */ Is it similar? If so, then it should make it explicit. > + break; > + case MIPS_ABI_N64: > + /* Float formats similar to Linux? */ Same here. > + tramp_frame_prepend_unwinder (gdbarch, &mips64fbsd_sigframe); > + break; > + } > + > + /* TODO: set_gdbarch_longjmp_target */ > + I think we're fine without the TODO here. It can be addressed later. Thanks, Luis ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] Add FreeBSD/mips architecture. 2016-11-25 22:52 ` Luis Machado @ 2016-11-28 22:54 ` John Baldwin 0 siblings, 0 replies; 8+ messages in thread From: John Baldwin @ 2016-11-28 22:54 UTC (permalink / raw) To: gdb-patches, Luis Machado; +Cc: binutils On Friday, November 25, 2016 04:52:31 PM Luis Machado wrote: > On 11/23/2016 02:59 PM, John Baldwin wrote: > > +/* Shorthand for some register numbers used below. */ > > +#define MIPS_PC_REGNUM MIPS_EMBED_PC_REGNUM > > +#define MIPS_FP0_REGNUM MIPS_EMBED_FP0_REGNUM > > +#define MIPS_FSR_REGNUM MIPS_EMBED_FP0_REGNUM + 32 > > + > > +/* Core file support. */ > > + > > +/* Number of registers in `struct reg' from <machine/reg.h>. The > > + first 38 follow the standard MIPS layout. The 39th holds > > + IC_INT_REG on RM7K and RM9K processors. The 40th is a dummy for > > + padding. */ > > +#define MIPSFBSD_NUM_GREGS 40 > > + > > +/* Number of registers in `struct fpreg' from <machine/reg.h>. The > > + first 32 hold floating point registers. 33 holds the FSR. The > > + 34th is a dummy for padding. */ > > +#define MIPSFBSD_NUM_FPREGS 34 > > Should all the above defines be moved to the header file mips-fbsd-tdep.h? They are only used in this file by virtue of the callbacks being exported for use by the native target. I wasn't inclined to export more to the header than is necessary. (This matches the approach used in mips-nbsd-tdep.* FWIW.) > > + > > +/* Supply a single register. If the source register size matches the > > + size the regcache expects, this can use regcache_raw_supply(). If > > + they are different, this copies the source register into a buffer > > + that can be passed to regcache_raw_supply(). */ > > + > > +static void > > +mipsfbsd_supply_reg (struct regcache *regcache, int regnum, const void *addr, > > + size_t len) > > How about mips_fbsd_* for the function names? Multiple occurrences of this. The reason it uses the current scheme is to match other *BSD targets (both mipsnbsd_* and mips64obsd_*, but also other platforms such as x86bsd_* and amd64bsd_*, etc.) On the other hand, Simon just renamed all the BSD target files to add a - between the architecture and OS, so that pattern might be an old one. I'm fine using mips_* for new code if that is generally desired. > > +{ > > + struct gdbarch *gdbarch = get_regcache_arch (regcache); > > + > > + if (register_size (gdbarch, regnum) == len) > > + { > > + regcache_raw_supply (regcache, regnum, addr); > > + } > > No need for curly braces for single-statement blocks. Multiple > occurrences of this. Ok. (Too many different style guides to juggle in one's head) > > +/* Supply the floating-point registers stored in FPREGS to REGCACHE. > > + Each floating-point register in FPREGS is REGSIZE bytes in > > + length. */ > > + > > +void > > +mipsfbsd_supply_fpregs (struct regcache *regcache, int regnum, > > + const void *fpregs, size_t regsize) > > +{ > > + const char *regs = (const char *) fpregs; > > Should these const char * types be const gdb_byte * types instead? > Multiple occurrences. Hmm, perhaps? The NetBSD/mips target I used as a template uses 'char', but other places use gdb_byte (e.g. amd64_collect_*). I'll go ahead and switch it. > > +/* Signal trampoline support. */ > > + > > +static void > > +mipsfbsd_sigframe_init (const struct tramp_frame *self, > > + struct frame_info *this_frame, > > + struct trad_frame_cache *cache, > > + CORE_ADDR func) > > +{ > > + struct gdbarch *gdbarch = get_frame_arch (this_frame); > > + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); > > + CORE_ADDR sp, ucontext_addr, addr; > > + int regnum; > > + gdb_byte buf[4]; > > + > > + /* We find the appropriate instance of `ucontext_t' at a > > + fixed offset in the signal frame. */ > > + sp = get_frame_register_signed (this_frame, > > + MIPS_SP_REGNUM + gdbarch_num_regs (gdbarch)); > > + ucontext_addr = sp + 16; > > We should make the fixed offset a constant with a #define. Maybe move > those to the header file as well. FWIW, mips64-obsd just used magic numbers (which is what I used as my template for the signal frame bits), but I can add constants for the layout of ucontext_t, etc. I'm inclined to keep them in the C file as they won't be used outside of it. > > +static const struct tramp_frame mipsfbsd_sigframe = > > +{ > > + SIGTRAMP_FRAME, > > + MIPS_INSN32_SIZE, > > + { > > + { 0x27a40010, -1 }, /* addiu a0, sp, SIGF_UC */ > > + { 0x240201a1, -1 }, /* li v0, SYS_sigreturn */ > > + { 0x0000000c, -1 }, /* syscall */ > > + { 0x0000000d, -1 }, /* break */ > > + { TRAMP_SENTINEL_INSN, -1 } > > + }, > > + mipsfbsd_sigframe_init > > These hex constants should be set with a #define. See mips-linux-tdep.c. > More occurrences throughout the patch. Will fix. As above, this was copied from the mips64-obsd target. > > +static void > > +mipsfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) > > +{ > > + enum mips_abi abi = mips_abi (gdbarch); > > + > > + /* Generic FreeBSD support. */ > > + fbsd_init_abi (info, gdbarch); > > + > > + set_gdbarch_software_single_step (gdbarch, mips_software_single_step); > > + > > + switch (abi) > > + { > > + case MIPS_ABI_O32: > > + tramp_frame_prepend_unwinder (gdbarch, &mipsfbsd_sigframe); > > + break; > > + case MIPS_ABI_N32: > > + /* Float formats similar to Linux? */ > > Is it similar? If so, then it should make it explicit. I don't know yet. I have another pending patch to do so, but I think FreeBSD/mips is currently using long double == double on n32 and n64 rather than 128-bit long doubles (as Linux, NetBSD, and OpenBSD all seem to do). > > + tramp_frame_prepend_unwinder (gdbarch, &mips64fbsd_sigframe); > > + break; > > + } > > + > > + /* TODO: set_gdbarch_longjmp_target */ > > + > > I think we're fine without the TODO here. It can be addressed later. I left it as a reminder for myself, but I can axe it. -- John Baldwin ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] Use the ELF class to determine the word size for FreeBSD core notes. 2016-11-23 20:59 [PATCH 0/3] Add FreeBSD/mips targets to GDB John Baldwin 2016-11-23 20:59 ` [PATCH 3/3] Add native target for FreeBSD/mips John Baldwin 2016-11-23 20:59 ` [PATCH 2/3] Add FreeBSD/mips architecture John Baldwin @ 2016-11-23 20:59 ` John Baldwin 2 siblings, 0 replies; 8+ messages in thread From: John Baldwin @ 2016-11-23 20:59 UTC (permalink / raw) To: gdb-patches, binutils FreeBSD MIPS64 core dumps contain an empty e_flags value so are assigned to the default bfd_arch_mips which is 32-bits. bfd/ChangeLog: * elf.c (elfcore_grok_freebsd_psinfo): Use ELF header class to determine structure sizes. (elfcore_grok_freebsd_prstatus): Likewise. --- bfd/ChangeLog | 6 ++++++ bfd/elf.c | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 346ff29..05dd4f5 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2016-11-23 John Baldwin <jhb@FreeBSD.org> + + * elf.c (elfcore_grok_freebsd_psinfo): Use ELF header class to + determine structure sizes. + (elfcore_grok_freebsd_prstatus): Likewise. + 2016-11-23 Nick Clifton <nickc@redhat.com> PR ld/20815 diff --git a/bfd/elf.c b/bfd/elf.c index 936255e..01e02f6 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -9749,14 +9749,14 @@ elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note) { size_t offset; - switch (abfd->arch_info->bits_per_word) + switch (elf_elfheader (abfd)->e_ident[EI_CLASS]) { - case 32: + case ELFCLASS32: if (note->descsz < 108) return FALSE; break; - case 64: + case ELFCLASS64: if (note->descsz < 120) return FALSE; break; @@ -9771,7 +9771,7 @@ elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note) offset = 4; /* Skip over pr_psinfosz. */ - if (abfd->arch_info->bits_per_word == 32) + if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS32) offset += 4; else { @@ -9814,13 +9814,13 @@ elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note) offset = 4; /* Skip over pr_statussz. */ - switch (abfd->arch_info->bits_per_word) + switch (elf_elfheader (abfd)->e_ident[EI_CLASS]) { - case 32: + case ELFCLASS32: offset += 4; break; - case 64: + case ELFCLASS64: offset += 4; /* Padding before pr_statussz. */ offset += 8; break; @@ -9830,13 +9830,16 @@ elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note) } /* Extract size of pr_reg from pr_gregsetsz. */ - if (abfd->arch_info->bits_per_word == 32) + if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS32) size = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset); else size = bfd_h_get_64 (abfd, (bfd_byte *) note->descdata + offset); /* Skip over pr_gregsetsz and pr_fpregsetsz. */ - offset += (abfd->arch_info->bits_per_word / 8) * 2; + if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS32) + offset += 4 * 2; + else + offset += 8 * 2; /* Skip over pr_osreldate. */ offset += 4; @@ -9853,7 +9856,7 @@ elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note) offset += 4; /* Padding before pr_reg. */ - if (abfd->arch_info->bits_per_word == 64) + if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) offset += 4; /* Make a ".reg/999" section and a ".reg" section. */ -- 2.9.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-11-28 22:54 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-11-23 20:59 [PATCH 0/3] Add FreeBSD/mips targets to GDB John Baldwin 2016-11-23 20:59 ` [PATCH 3/3] Add native target for FreeBSD/mips John Baldwin 2016-11-26 4:26 ` Luis Machado 2016-11-28 22:54 ` John Baldwin 2016-11-23 20:59 ` [PATCH 2/3] Add FreeBSD/mips architecture John Baldwin 2016-11-25 22:52 ` Luis Machado 2016-11-28 22:54 ` John Baldwin 2016-11-23 20:59 ` [PATCH 1/3] Use the ELF class to determine the word size for FreeBSD core notes John Baldwin
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).