Reviewed and approved by Alan Modra <amodra@bigpond.net.au>
[deliverable/binutils-gdb.git] / gdb / dwarf2-frame.c
index 5a559762fb32e951d55f2e264b1ba13d8d075681..8c6241984532335a7948993a2384e51c5893ccd2 100644 (file)
@@ -454,52 +454,120 @@ execute_cfa_program (unsigned char *insn_ptr, unsigned char *insn_end,
   dwarf2_frame_state_free_regs (fs->regs.prev);
   fs->regs.prev = NULL;
 }
+\f
 
-struct dwarf2_frame_cache
-{
-  /* DWARF Call Frame Address.  */
-  CORE_ADDR cfa;
+/* Architecture-specific operations.  */
 
-  /* Saved registers, indexed by GDB register number, not by DWARF
-     register number.  */
-  struct dwarf2_frame_state_reg *reg;
+/* Per-architecture data key.  */
+static struct gdbarch_data *dwarf2_frame_data;
+
+struct dwarf2_frame_ops
+{
+  /* Pre-initialize the register state REG for register REGNUM.  */
+  void (*init_reg) (struct gdbarch *, int, struct dwarf2_frame_state_reg *);
 };
 
-/* Initialize the register state REG.  If we have a register that acts
-   as a program counter, mark it as a destination for the return
-   address.  If we have a register that serves as the stack pointer,
-   arrange for it to be filled with the call frame address (CFA).  The
-   other registers are marked as unspecified.
+/* Default architecture-specific register state initialization
+   function.  */
+
+static void
+dwarf2_frame_default_init_reg (struct gdbarch *gdbarch, int regnum,
+                              struct dwarf2_frame_state_reg *reg)
+{
+  /* If we have a register that acts as a program counter, mark it as
+     a destination for the return address.  If we have a register that
+     serves as the stack pointer, arrange for it to be filled with the
+     call frame address (CFA).  The other registers are marked as
+     unspecified.
+
+     We copy the return address to the program counter, since many
+     parts in GDB assume that it is possible to get the return address
+     by unwinding the program counter register.  However, on ISA's
+     with a dedicated return address register, the CFI usually only
+     contains information to unwind that return address register.
+
+     The reason we're treating the stack pointer special here is
+     because in many cases GCC doesn't emit CFI for the stack pointer
+     and implicitly assumes that it is equal to the CFA.  This makes
+     some sense since the DWARF specification (version 3, draft 8,
+     p. 102) says that:
+
+     "Typically, the CFA is defined to be the value of the stack
+     pointer at the call site in the previous frame (which may be
+     different from its value on entry to the current frame)."
+
+     However, this isn't true for all platforms supported by GCC
+     (e.g. IBM S/390 and zSeries).  Those architectures should provide
+     their own architecture-specific initialization function.  */
+
+  if (regnum == PC_REGNUM)
+    reg->how = DWARF2_FRAME_REG_RA;
+  else if (regnum == SP_REGNUM)
+    reg->how = DWARF2_FRAME_REG_CFA;
+}
+
+/* Return a default for the architecture-specific operations.  */
+
+static void *
+dwarf2_frame_init (struct gdbarch *gdbarch)
+{
+  struct dwarf2_frame_ops *ops;
+  
+  ops = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dwarf2_frame_ops);
+  ops->init_reg = dwarf2_frame_default_init_reg;
+  return ops;
+}
+
+static struct dwarf2_frame_ops *
+dwarf2_frame_ops (struct gdbarch *gdbarch)
+{
+  struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
+  if (ops == NULL)
+    {
+      /* ULGH, called during architecture initialization.  Patch
+         things up.  */
+      ops = dwarf2_frame_init (gdbarch);
+      set_gdbarch_data (gdbarch, dwarf2_frame_data, ops);
+    }
+  return ops;
+}
 
-   We copy the return address to the program counter, since many parts
-   in GDB assume that it is possible to get the return address by
-   unwind the program counter register.  However, on ISA's with a
-   dedicated return address register, the CFI usually only contains
-   information to unwind that return address register.
+/* Set the architecture-specific register state initialization
+   function for GDBARCH to INIT_REG.  */
 
-   The reason we're treating the stack pointer special here is because
-   in many cases GCC doesn't emit CFI for the stack pointer and
-   implicitly assumes that it is equal to the CFA.  This makes some
-   sense since the DWARF specification (version 3, draft 8, p. 102)
-   says that:
+void
+dwarf2_frame_set_init_reg (struct gdbarch *gdbarch,
+                          void (*init_reg) (struct gdbarch *, int,
+                                            struct dwarf2_frame_state_reg *))
+{
+  struct dwarf2_frame_ops *ops;
 
-   "Typically, the CFA is defined to be the value of the stack pointer
-   at the call site in the previous frame (which may be different from
-   its value on entry to the current frame)."
+  ops = dwarf2_frame_ops (gdbarch);
+  ops->init_reg = init_reg;
+}
 
-   However, this isn't true for all platforms supported by GCC
-   (e.g. IBM S/390 and zSeries).  For those targets we should override
-   the defaults given here.  */
+/* Pre-initialize the register state REG for register REGNUM.  */
 
 static void
 dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
                       struct dwarf2_frame_state_reg *reg)
 {
-  if (regnum == PC_REGNUM)
-    reg->how = DWARF2_FRAME_REG_RA;
-  else if (regnum == SP_REGNUM)
-    reg->how = DWARF2_FRAME_REG_CFA;
+  struct dwarf2_frame_ops *ops;
+
+  ops = dwarf2_frame_ops (gdbarch);
+  ops->init_reg (gdbarch, regnum, reg);
 }
+\f
+
+struct dwarf2_frame_cache
+{
+  /* DWARF Call Frame Address.  */
+  CORE_ADDR cfa;
+
+  /* Saved registers, indexed by GDB register number, not by DWARF
+     register number.  */
+  struct dwarf2_frame_state_reg *reg;
+};
 
 static struct dwarf2_frame_cache *
 dwarf2_frame_cache (struct frame_info *next_frame, void **this_cache)
@@ -851,7 +919,7 @@ struct comp_unit
   bfd_vma tbase;
 };
 
-const struct objfile_data *dwarf2_frame_data;
+const struct objfile_data *dwarf2_frame_objfile_data;
 
 static unsigned int
 read_1_byte (bfd *bfd, char *buf)
@@ -1111,7 +1179,7 @@ dwarf2_frame_find_fde (CORE_ADDR *pc)
       struct dwarf2_fde *fde;
       CORE_ADDR offset;
 
-      fde = objfile_data (objfile, dwarf2_frame_data);
+      fde = objfile_data (objfile, dwarf2_frame_objfile_data);
       if (fde == NULL)
        continue;
 
@@ -1137,8 +1205,8 @@ dwarf2_frame_find_fde (CORE_ADDR *pc)
 static void
 add_fde (struct comp_unit *unit, struct dwarf2_fde *fde)
 {
-  fde->next = objfile_data (unit->objfile, dwarf2_frame_data);
-  set_objfile_data (unit->objfile, dwarf2_frame_data, fde);
+  fde->next = objfile_data (unit->objfile, dwarf2_frame_objfile_data);
+  set_objfile_data (unit->objfile, dwarf2_frame_objfile_data, fde);
 }
 
 #ifdef CC_HAS_LONG_LONG
@@ -1461,7 +1529,6 @@ decode_frame_entry (struct comp_unit *unit, char *start, int eh_frame_p)
 
   return ret;
 }
-
 \f
 
 /* FIXME: kettenis/20030504: This still needs to be integrated with
@@ -1541,5 +1608,6 @@ void _initialize_dwarf2_frame (void);
 void
 _initialize_dwarf2_frame (void)
 {
-  dwarf2_frame_data = register_objfile_data ();
+  dwarf2_frame_data = register_gdbarch_data (dwarf2_frame_init);
+  dwarf2_frame_objfile_data = register_objfile_data ();
 }
This page took 0.026003 seconds and 4 git commands to generate.