MIPS SDE OS ABI support

Message ID 1418629607-20086-1-git-send-email-yao@codesourcery.com
State New, archived
Headers

Commit Message

Yao Qi Dec. 15, 2014, 7:46 a.m. UTC
  This patch is to add SDE OS ABI support in GDB, which has been used in
codesourcery gdb tree for some years.

gdb:

2014-12-15  Maciej W. Rozycki  <macro@codesourcery.com>
	    Nigel Stephens  <nigel@mips.com>
	    Chris Dearman  <chris@mips.com>
	    Luis Machado  <lgustavo@codesourcery.com>

	* sde-mips-tdep.c: New file containg SDE specific code.
	* configure.tgt (mips*-sde*-elf*): Add sde-mips-tdep.o to
	gdb_target_obs.
	* defs.h (gdb_osabi): Add GDB_OSABI_SDE.
	* osabi.c (gdb_osabi_names): Add SDE.
	* NEWS: Mention the change.
---
 gdb/Makefile.in     |   3 +-
 gdb/NEWS            |   4 +
 gdb/configure.tgt   |   5 ++
 gdb/defs.h          |   1 +
 gdb/mips-sde-tdep.c | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/osabi.c         |   1 +
 6 files changed, 265 insertions(+), 1 deletion(-)
 create mode 100644 gdb/mips-sde-tdep.c
  

Comments

Joel Brobecker Dec. 15, 2014, 1:10 p.m. UTC | #1
> 2014-12-15  Maciej W. Rozycki  <macro@codesourcery.com>
> 	    Nigel Stephens  <nigel@mips.com>
> 	    Chris Dearman  <chris@mips.com>
> 	    Luis Machado  <lgustavo@codesourcery.com>
> 
> 	* sde-mips-tdep.c: New file containg SDE specific code.
> 	* configure.tgt (mips*-sde*-elf*): Add sde-mips-tdep.o to
> 	gdb_target_obs.
> 	* defs.h (gdb_osabi): Add GDB_OSABI_SDE.
> 	* osabi.c (gdb_osabi_names): Add SDE.
> 	* NEWS: Mention the change.

I just skimmed through that patch, and noticed a few things, all
of fairly trivial nature. So, as soon as fixed, I think the patch
can go in (modulo NEWS to be approved by Eli).

> +static struct trad_frame_cache *
> +mips_sde_frame_cache (struct frame_info *this_frame, void **this_cache)

All functions should have an introductory comment. Since these
implement callbacks/"methods", the usual one-liner that describe
which callback they implement should be used.

> +static void
> +mips_sde_frame_this_id (struct frame_info *this_frame, void **this_cache,
> +			struct frame_id *this_id)
> +{
> +  struct trad_frame_cache *this_trad_cache
> +    = mips_sde_frame_cache (this_frame, this_cache);
> +  trad_frame_get_id (this_trad_cache, this_id);

Empty line between variable declaration and the rest of the code.

> +static struct value *
> +mips_sde_frame_prev_register (struct frame_info *this_frame,
> +			      void **this_cache,
> +			      int prev_regnum)
> +{
> +  struct trad_frame_cache *trad_cache
> +    = mips_sde_frame_cache (this_frame, this_cache);
> +  return trad_frame_get_register (trad_cache, this_frame, prev_regnum);

Likewise.

> +static CORE_ADDR
> +mips_sde_frame_base_address (struct frame_info *this_frame, void **this_cache)
> +{
> +  struct trad_frame_cache *this_trad_cache
> +    = mips_sde_frame_cache (this_frame, this_cache);
> +  return trad_frame_get_this_base (this_trad_cache);

Same here.
  
Pedro Alves Dec. 18, 2014, 5:36 p.m. UTC | #2
On 12/15/2014 01:10 PM, Joel Brobecker wrote:
>> 	* sde-mips-tdep.c: New file containg SDE specific code.

Nit: I noticed the file was named oddly here,

>> 	* configure.tgt (mips*-sde*-elf*): Add sde-mips-tdep.o to

and here, but then the actual file name looks "regular":

>  gdb/mips-sde-tdep.c | 252


BTW, OOC, I looked around the web for MIPS SDE, and not much
comes out.  What is it exactly?

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 2f69eb2..be69b6f 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -664,7 +664,7 @@  ALL_TARGET_OBS = \
 	m88k-tdep.o \
 	mep-tdep.o \
 	microblaze-tdep.o microblaze-linux-tdep.o \
-	mips-linux-tdep.o \
+	mips-linux-tdep.o mips-sde-tdep.o \
 	mipsnbsd-tdep.o mips-tdep.o \
 	mn10300-linux-tdep.o mn10300-tdep.o \
 	moxie-tdep.o \
@@ -1682,6 +1682,7 @@  ALLDEPFILES = \
 	microblaze-tdep.c microblaze-linux-tdep.c \
 	mingw-hdep.c \
 	mips-linux-nat.c mips-linux-tdep.c \
+	mips-sde-tdep.c \
 	mips-tdep.c \
 	mipsnbsd-nat.c mipsnbsd-tdep.c \
 	mips64obsd-nat.c mips64obsd-tdep.c \
diff --git a/gdb/NEWS b/gdb/NEWS
index a6789bd..ac2b175 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -11,6 +11,10 @@ 
   ** gdb.events.memory_changed: A memory location has been altered.
   ** gdb.events.register_changed: A register has been altered.
 
+* New targets
+
+MIPS SDE			mips*-sde*-elf*
+
 *** Changes since GDB 7.8
 
 * GDB now supports hardware watchpoints on x86 GNU Hurd.
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 1d7f54b..065e797 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -364,6 +364,11 @@  mips64*-*-openbsd*)
 	# Target: OpenBSD/mips64
 	gdb_target_obs="mips-tdep.o mips64obsd-tdep.o obsd-tdep.o solib-svr4.o"
 	;;
+mips*-sde*-elf*)
+	# Target: MIPS SDE
+	gdb_target_obs="mips-tdep.o mips-sde-tdep.o remote-mips.o"
+	gdb_sim=../sim/mips/libsim.a
+	;;
 mips*-*-elf)
 	# Target: MIPS ELF
 	gdb_target_obs="mips-tdep.o remote-mips.o"
diff --git a/gdb/defs.h b/gdb/defs.h
index 7920938..d440afb 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -562,6 +562,7 @@  enum gdb_osabi
   GDB_OSABI_OPENVMS,
   GDB_OSABI_LYNXOS178,
   GDB_OSABI_NEWLIB,
+  GDB_OSABI_SDE,
 
   GDB_OSABI_INVALID		/* keep this last */
 };
diff --git a/gdb/mips-sde-tdep.c b/gdb/mips-sde-tdep.c
new file mode 100644
index 0000000..06d10cc
--- /dev/null
+++ b/gdb/mips-sde-tdep.c
@@ -0,0 +1,252 @@ 
+/* Target-dependent code for SDE on MIPS processors.
+
+   Copyright (C) 2014 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/>.  */
+
+#include "defs.h"
+#include "osabi.h"
+#include "elf-bfd.h"
+#include "block.h"
+#include "symtab.h"
+
+#include "frame.h"
+#include "frame-unwind.h"
+#include "frame-base.h"
+#include "trad-frame.h"
+
+#include "mips-tdep.h"
+
+static struct trad_frame_cache *
+mips_sde_frame_cache (struct frame_info *this_frame, void **this_cache)
+{
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  const struct mips_regnum *regs = mips_regnum (gdbarch);
+  const int sizeof_reg_t = mips_abi_regsize (gdbarch);
+						/* FIXME: Is this correct?  */
+  enum mips_abi abi = mips_abi (gdbarch);
+  struct trad_frame_cache *cache;
+  CORE_ADDR xcpt_frame;
+  CORE_ADDR start_addr;
+  CORE_ADDR stack_addr;
+  CORE_ADDR pc;
+  int i;
+
+  if (*this_cache != NULL)
+    return *this_cache;
+  cache = trad_frame_cache_zalloc (this_frame);
+  *this_cache = cache;
+
+  /* The previous registers are held in struct xcptcontext
+     which is at $sp+offs
+
+     struct xcptcontext {
+       reg_t	sr;		CP0 Status
+       reg_t	cr;		CP0 Cause
+       reg_t	epc;		CP0 EPC
+       reg_t	vaddr;		CP0 BadVAddr
+       reg_t	regs[32];	General registers
+       reg_t	mdlo;		LO
+       reg_t	mdhi;		HI
+       reg_t	mdex;		ACX
+       ...
+     };
+  */
+
+  stack_addr = get_frame_register_signed (this_frame,
+					  gdbarch_sp_regnum (gdbarch));
+  switch (abi)
+    {
+    case MIPS_ABI_O32:
+      /* 40: XCPTCONTEXT
+	 24: xcpt_gen() argspace		(16 bytes)
+	 16: _xcptcall() saved ra, rounded up	( 8 bytes)
+	 00: _xcptcall() argspace 		(16 bytes)  */
+      xcpt_frame = stack_addr + 40;
+      break;
+    case MIPS_ABI_N32:
+    case MIPS_ABI_N64:
+    default:			/* Wild guess.  */
+      /* 16: XCPTCONTEXT
+	 16: xcpt_gen() argspace 		( 0 bytes)
+	 00: _xcptcall() saved ra, rounded up	(16 bytes)  */
+      xcpt_frame = stack_addr + 16;
+      break;
+    }
+
+  trad_frame_set_reg_addr (cache,
+			   MIPS_PS_REGNUM + gdbarch_num_regs (gdbarch),
+			   xcpt_frame + 0 * sizeof_reg_t);
+  trad_frame_set_reg_addr (cache,
+			   regs->cause + gdbarch_num_regs (gdbarch),
+			   xcpt_frame + 1 * sizeof_reg_t);
+  trad_frame_set_reg_addr (cache,
+			   regs->pc + gdbarch_num_regs (gdbarch),
+			   xcpt_frame + 2 * sizeof_reg_t);
+  trad_frame_set_reg_addr (cache,
+			   regs->badvaddr + gdbarch_num_regs (gdbarch),
+			   xcpt_frame + 3 * sizeof_reg_t);
+  for (i = 0; i < MIPS_NUMREGS; i++)
+    trad_frame_set_reg_addr (cache,
+			     i + MIPS_ZERO_REGNUM + gdbarch_num_regs (gdbarch),
+			     xcpt_frame + (4 + i) * sizeof_reg_t);
+  trad_frame_set_reg_addr (cache,
+			   regs->lo + gdbarch_num_regs (gdbarch),
+			   xcpt_frame + 36 * sizeof_reg_t);
+  trad_frame_set_reg_addr (cache,
+			   regs->hi + gdbarch_num_regs (gdbarch),
+			   xcpt_frame + 37 * sizeof_reg_t);
+
+  pc = get_frame_pc (this_frame);
+  find_pc_partial_function (pc, NULL, &start_addr, NULL);
+  trad_frame_set_id (cache, frame_id_build (start_addr, stack_addr));
+
+  return cache;
+}
+
+static void
+mips_sde_frame_this_id (struct frame_info *this_frame, void **this_cache,
+			struct frame_id *this_id)
+{
+  struct trad_frame_cache *this_trad_cache
+    = mips_sde_frame_cache (this_frame, this_cache);
+  trad_frame_get_id (this_trad_cache, this_id);
+}
+
+static struct value *
+mips_sde_frame_prev_register (struct frame_info *this_frame,
+			      void **this_cache,
+			      int prev_regnum)
+{
+  struct trad_frame_cache *trad_cache
+    = mips_sde_frame_cache (this_frame, this_cache);
+  return trad_frame_get_register (trad_cache, this_frame, prev_regnum);
+}
+
+static int
+mips_sde_frame_sniffer (const struct frame_unwind *self,
+			struct frame_info *this_frame,
+			void **this_cache)
+{
+  CORE_ADDR pc = get_frame_pc (this_frame);
+  const char *name;
+
+  find_pc_partial_function (pc, &name, NULL, NULL);
+  return (name
+	  && (strcmp (name, "_xcptcall") == 0
+	      || strcmp (name, "_sigtramp") == 0));
+}
+
+static const struct frame_unwind mips_sde_frame_unwind =
+{
+  SIGTRAMP_FRAME,
+  default_frame_unwind_stop_reason,
+  mips_sde_frame_this_id,
+  mips_sde_frame_prev_register,
+  NULL,
+  mips_sde_frame_sniffer
+};
+
+static CORE_ADDR
+mips_sde_frame_base_address (struct frame_info *this_frame, void **this_cache)
+{
+  struct trad_frame_cache *this_trad_cache
+    = mips_sde_frame_cache (this_frame, this_cache);
+  return trad_frame_get_this_base (this_trad_cache);
+}
+
+static const struct frame_base mips_sde_frame_base =
+{
+  &mips_sde_frame_unwind,
+  mips_sde_frame_base_address,
+  mips_sde_frame_base_address,
+  mips_sde_frame_base_address
+};
+
+static const struct frame_base *
+mips_sde_frame_base_sniffer (struct frame_info *this_frame)
+{
+  if (mips_sde_frame_sniffer (&mips_sde_frame_unwind, this_frame, NULL))
+    return &mips_sde_frame_base;
+  else
+    return NULL;
+}
+
+static void
+mips_sde_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
+					   void *obj)
+{
+  enum gdb_osabi *os_ident_ptr = obj;
+  const char *name;
+
+  name = bfd_get_section_name (abfd, sect);
+
+  /* The presence of a section with a ".sde" prefix is indicative
+     of an SDE binary.  */
+  if (strncmp (name, ".sde", 4) == 0)
+    *os_ident_ptr = GDB_OSABI_SDE;
+}
+
+static enum gdb_osabi
+mips_sde_elf_osabi_sniffer (bfd *abfd)
+{
+  enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
+  unsigned int elfosabi;
+
+  /* If the generic sniffer gets a hit, return and let other sniffers
+     get a crack at it.  */
+  bfd_map_over_sections (abfd,
+			 generic_elf_osabi_sniff_abi_tag_sections,
+			 &osabi);
+  if (osabi != GDB_OSABI_UNKNOWN)
+    return GDB_OSABI_UNKNOWN;
+
+  elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
+
+  if (elfosabi == ELFOSABI_NONE)
+    {
+      /* When elfosabi is ELFOSABI_NONE (0), then the ELF structures in the
+         file are conforming to the base specification for that machine
+         (there are no OS-specific extensions).  In order to determine the
+         real OS in use we must look for OS notes that have been added.
+
+         For SDE, we simply look for sections named with .sde as prefixes.  */
+      bfd_map_over_sections (abfd,
+			     mips_sde_elf_osabi_sniff_abi_tag_sections,
+			     &osabi);
+    }
+  return osabi;
+}
+
+static void
+mips_sde_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  frame_unwind_append_unwinder (gdbarch, &mips_sde_frame_unwind);
+  frame_base_append_sniffer (gdbarch, mips_sde_frame_base_sniffer);
+}
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_mips_sde_tdep;
+
+void
+_initialize_mips_sde_tdep (void)
+{
+  gdbarch_register_osabi_sniffer (bfd_arch_mips,
+				  bfd_target_elf_flavour,
+				  mips_sde_elf_osabi_sniffer);
+
+  gdbarch_register_osabi (bfd_arch_mips, 0, GDB_OSABI_SDE, mips_sde_init_abi);
+}
diff --git a/gdb/osabi.c b/gdb/osabi.c
index 50d391a..895b476 100644
--- a/gdb/osabi.c
+++ b/gdb/osabi.c
@@ -83,6 +83,7 @@  static const struct osabi_names gdb_osabi_names[] =
   { "OpenVMS", NULL },
   { "LynxOS178", NULL },
   { "Newlib", NULL },
+  { "SDE", NULL },
 
   { "<invalid>", NULL }
 };