This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] gdb for GNU/kFreeBSD on MIPS


For the record, the copyright assignment paperwork just came through,
and Robert asked me to look at this patch.

> 2011-01-09  Robert Millan  <rmh@gnu.org>
> 
> 	* configure.host: Detect mips-freebsd and mips-kfreebsd-gnu, and set
> 	`gdb_host' appropiately.
> 	* configure.tgt: Detect mips-freebsd and mips-kfreebsd-gnu, and use
> 	the same definitions as with mips-netbsd.
> 
> 	* config/mips/fbsd.mh: New file.
> 	* config/mips/nbsd.mh (MH_CFLAGS): New variable (defines BSD_OSABI
> 	C macro).
> 
> 	* mipsnbsd-tdep.c [BSD_OSABI == GDB_OSABI_FREEBSD_ELF]
> 	(MIPSNBSD_NUM_GREGS): Define as `40'.
> 	(MIPSNBSD_NUM_FPREGS): Define as `34'.
> 	(NBSD_MIPS_JB_PC): Define as `12'.
> 
> 	* mipsnbsd-tdep.c (_initialize_mipsnbsd_tdep): Replace
> 	`GDB_OSABI_NETBSD_ELF' with `BSD_OSABI'.

I think that Mark Kettenis would be a better reviewer for this patch,
as he knows the BSDs better than I do.  However, I can comment on
a few things...

For Mark's benefit, I'll attach a copy of the patch, so that he does
not have to go fish it back.

> +# Host: FreeBSD/mips
> +MH_CFLAGS= -DBSD_OSABI=GDB_OSABI_FREEBSD_ELF

This looked very suspicious, and indeed:


> --- gdb/mipsnbsd-tdep.c	2011-01-01 15:32:52 +0000
> +++ gdb/mipsnbsd-tdep.c	2011-01-09 09:08:54 +0000
> @@ -45,10 +45,18 @@
>  /* Core file support.  */
>  
>  /* Number of registers in `struct reg' from <machine/reg.h>.  */
> +#if BSD_OSABI == GDB_OSABI_NETBSD_ELF
>  #define MIPSNBSD_NUM_GREGS	38
> +#elif BSD_OSABI == GDB_OSABI_FREEBSD_ELF
> +#define MIPSNBSD_NUM_GREGS	40
> +#endif

This is not the way to go. GDB is supposed to be able to support
multiple architectures at the same time (within the same binary).
What you need to do is to make this process dynamic. This can be
achieved via a couple of things: Register the GDB_OSABI_FREEBSD_ELF
osabi, attaching an ABI-init routine, and turning the various macros
into struct gdbarch_tdep field.  I'm having a hard time being more
precise, because the exact work will depend on whether you need to
create your own -tdep file for fbsd or not (I would imagine that
you will - except that it seems that the nbsd and fbsd tdep files
would otherwise share a lot of code).  I hope that Mark will be
able to give you additional guidance.

-- 
Joel
2011-01-09  Robert Millan  <rmh@gnu.org>

	* configure.host: Detect mips-freebsd and mips-kfreebsd-gnu, and set
	`gdb_host' appropiately.
	* configure.tgt: Detect mips-freebsd and mips-kfreebsd-gnu, and use
	the same definitions as with mips-netbsd.

	* config/mips/fbsd.mh: New file.
	* config/mips/nbsd.mh (MH_CFLAGS): New variable (defines BSD_OSABI
	C macro).

	* mipsnbsd-tdep.c [BSD_OSABI == GDB_OSABI_FREEBSD_ELF]
	(MIPSNBSD_NUM_GREGS): Define as `40'.
	(MIPSNBSD_NUM_FPREGS): Define as `34'.
	(NBSD_MIPS_JB_PC): Define as `12'.

	* mipsnbsd-tdep.c (_initialize_mipsnbsd_tdep): Replace
	`GDB_OSABI_NETBSD_ELF' with `BSD_OSABI'.

=== added file 'gdb/config/mips/fbsd.mh'
--- gdb/config/mips/fbsd.mh	1970-01-01 00:00:00 +0000
+++ gdb/config/mips/fbsd.mh	2011-01-09 09:08:54 +0000
@@ -0,0 +1,4 @@
+# Host: FreeBSD/mips
+MH_CFLAGS= -DBSD_OSABI=GDB_OSABI_FREEBSD_ELF
+NATDEPFILES= fork-child.o inf-ptrace.o \
+	fbsd-nat.o mipsnbsd-nat.o

=== modified file 'gdb/config/mips/nbsd.mh'
--- gdb/config/mips/nbsd.mh	2004-10-31 20:47:55 +0000
+++ gdb/config/mips/nbsd.mh	2011-01-09 09:08:54 +0000
@@ -1,2 +1,3 @@
 # Host: NetBSD/mips
+MH_CFLAGS= -DBSD_OSABI=GDB_OSABI_NETBSD_ELF
 NATDEPFILES= fork-child.o inf-ptrace.o mipsnbsd-nat.o

=== modified file 'gdb/configure.host'
--- gdb/configure.host	2010-01-19 10:22:42 +0000
+++ gdb/configure.host	2011-01-08 10:40:17 +0000
@@ -120,6 +120,8 @@ mips-sgi-irix6*)	gdb_host=irix6 ;;
 mips*-*-linux*)		gdb_host=linux ;;
 mips*-*-netbsd* | mips*-*-knetbsd*-gnu)
 			gdb_host=nbsd ;;
+mips*-*-freebsd* | mips*-*-kfreebsd*-gnu)
+			gdb_host=fbsd ;;
 mips64*-*-openbsd*)	gdb_host=obsd64 ;;
 
 powerpc-*-aix* | rs6000-*-*)

=== modified file 'gdb/configure.tgt'
--- gdb/configure.tgt	2010-12-29 16:15:40 +0000
+++ gdb/configure.tgt	2011-01-08 10:40:17 +0000
@@ -356,8 +356,8 @@ mips*-*-linux*)
 	gdb_sim=../sim/mips/libsim.a
 	build_gdbserver=yes
 	;;
-mips*-*-netbsd* | mips*-*-knetbsd*-gnu)
-	# Target: MIPS running NetBSD
+mips*-*-netbsd* | mips*-*-knetbsd*-gnu | mips*-*-freebsd* | mips*-*-kfreebsd*-gnu)
+	# Target: MIPS running *BSD
 	gdb_target_obs="mips-tdep.o mipsnbsd-tdep.o \
 			corelow.o solib.o solib-svr4.o nbsd-tdep.o"
 	gdb_sim=../sim/mips/libsim.a
=== modified file 'gdb/mipsnbsd-tdep.c'
--- gdb/mipsnbsd-tdep.c	2011-01-01 15:32:52 +0000
+++ gdb/mipsnbsd-tdep.c	2011-01-09 09:08:54 +0000
@@ -45,10 +45,18 @@
 /* Core file support.  */
 
 /* Number of registers in `struct reg' from <machine/reg.h>.  */
+#if BSD_OSABI == GDB_OSABI_NETBSD_ELF
 #define MIPSNBSD_NUM_GREGS	38
+#elif BSD_OSABI == GDB_OSABI_FREEBSD_ELF
+#define MIPSNBSD_NUM_GREGS	40
+#endif
 
 /* Number of registers in `struct fpreg' from <machine/reg.h>.  */
+#if BSD_OSABI == GDB_OSABI_NETBSD_ELF
 #define MIPSNBSD_NUM_FPREGS	33
+#elif BSD_OSABI == GDB_OSABI_FREEBSD_ELF
+#define MIPSNBSD_NUM_FPREGS	34
+#endif
 
 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
    in the floating-point register set REGSET to register cache
@@ -251,7 +259,11 @@ static const unsigned char sigtramp_retc
    at.  The PC is copied into *pc.  This routine returns true on
    success.  */
 
+#if BSD_OSABI == GDB_OSABI_NETBSD_ELF
 #define NBSD_MIPS_JB_PC			(2 * 4)
+#elif BSD_OSABI == GDB_OSABI_FREEBSD_ELF
+#define NBSD_MIPS_JB_PC			12
+#endif
 #define NBSD_MIPS_JB_ELEMENT_SIZE(gdbarch)	mips_isa_regsize (gdbarch)
 #define NBSD_MIPS_JB_OFFSET(gdbarch)		(NBSD_MIPS_JB_PC * \
 					 NBSD_MIPS_JB_ELEMENT_SIZE (gdbarch))
@@ -381,6 +393,6 @@ extern initialize_file_ftype _initialize
 void
 _initialize_mipsnbsd_tdep (void)
 {
-  gdbarch_register_osabi (bfd_arch_mips, 0, GDB_OSABI_NETBSD_ELF,
+  gdbarch_register_osabi (bfd_arch_mips, 0, BSD_OSABI,
 			  mipsnbsd_init_abi);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]