Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Kettenis <kettenis@chello.nl>
To: cagney@gnu.org
Cc: drow@mvista.com, gdb-patches@sources.redhat.com
Subject: Re: [PATCH/RFC] Per-architecture DWARF CFI register state initialization hooks
Date: Sun, 15 Feb 2004 21:31:00 -0000	[thread overview]
Message-ID: <200402152130.i1FLUvdB005788@elgar.kettenis.dyndns.org> (raw)
In-Reply-To: <402F988A.1080508@gnu.org> (message from Andrew Cagney on Sun, 15 Feb 2004 11:04:26 -0500)

Thanks for the info.  Based on what you wrote, I committed the
attached patch.  It should now be possible to integrate the IBM S/390
and zSeries stuff.

Mark


Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* dwarf2-frame.h (dwarf2_frame_set_init_reg): New prototype.
	* dwarf2-frame.c (dwarf2_frame_data): New variable.
	(struct dwarf2_frame_ops): New.
	(dwarf2_frame_default_init_reg): New function, based on
	dwarf2_frame_init_reg.
	(dwarf2_frame_init, dwarf2_frame_set_init_reg): New function.
	(dwarf2_frame_init_reg): Call architecture-specific function.
	(dwarf2_frame_objfile_data): Renamed from dwarf2_frame_data.
	(dwarf2_frame_find_fde, add_fde): Use dwarf2_frame_objfile_data
	instead of dwarf2_frame_data.
	(_initialize_dwarf2_frame): Initailize new dwarf2_frame_data.
	Initialize dwarf2_frame_objfile instead of old dwarf2_frame_data.

Index: dwarf2-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v
retrieving revision 1.29
diff -u -p -r1.29 dwarf2-frame.c
--- dwarf2-frame.c 7 Feb 2004 18:29:53 -0000 1.29
+++ dwarf2-frame.c 15 Feb 2004 21:27:19 -0000
@@ -454,53 +454,107 @@ execute_cfa_program (unsigned char *insn
   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.
-
-   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.
-
-   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).  For those targets we should override
-   the defaults given here.  */
+/* Default architecture-specific register state initialization
+   function.  */
 
 static void
-dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
-		       struct dwarf2_frame_state_reg *reg)
+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;
+}
+
+/* Set the architecture-specific register state initialization
+   function for GDBARCH to INIT_REG.  */
+
+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;
+
+  ops = gdbarch_data (gdbarch, dwarf2_frame_data);
+  ops->init_reg = init_reg;
+}
+
+/* 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)
+{
+  struct dwarf2_frame_ops *ops;
+
+  ops = gdbarch_data (gdbarch, dwarf2_frame_data);
+  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 +905,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 +1165,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 +1191,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 +1515,6 @@ decode_frame_entry (struct comp_unit *un
 
   return ret;
 }
-
 \f
 
 /* FIXME: kettenis/20030504: This still needs to be integrated with
@@ -1541,5 +1594,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 ();
 }
Index: dwarf2-frame.h
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2-frame.h,v
retrieving revision 1.4
diff -u -p -r1.4 dwarf2-frame.h
--- dwarf2-frame.h 7 Feb 2004 14:44:50 -0000 1.4
+++ dwarf2-frame.h 15 Feb 2004 21:27:19 -0000
@@ -71,6 +71,13 @@ struct dwarf2_frame_state_reg
   enum dwarf2_frame_reg_rule how;
 };
 
+/* Set the architecture-specific register state initialization
+   function for GDBARCH to INIT_REG.  */
+
+extern void dwarf2_frame_set_init_reg (struct gdbarch *gdbarch,
+				       void (*init_reg) (struct gdbarch *, int,
+					     struct dwarf2_frame_state_reg *));
+
 /* Return the frame unwind methods for the function that contains PC,
    or NULL if it can't be handled by DWARF CFI frame unwinder.  */
 


  parent reply	other threads:[~2004-02-15 21:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-07 22:38 Mark Kettenis
2004-02-07 23:03 ` Daniel Jacobowitz
2004-02-07 23:48 ` Andrew Cagney
2004-02-15 15:31   ` Mark Kettenis
2004-02-15 16:04     ` Andrew Cagney
2004-02-15 18:09       ` Daniel Jacobowitz
2004-02-15 19:49         ` Andrew Cagney
2004-02-15 20:37           ` Daniel Jacobowitz
2004-02-15 21:37             ` Andrew Cagney
2004-02-15 22:54               ` Daniel Jacobowitz
2004-02-15 21:31       ` Mark Kettenis [this message]
2004-02-08  1:01 ` Ulrich Weigand
2004-02-16  1:28 Ulrich Weigand
2004-02-16  1:56 ` Daniel Jacobowitz
2004-02-16 13:01   ` Ulrich Weigand
2004-02-16 19:47     ` Daniel Jacobowitz
2004-02-16 20:50       ` Andrew Cagney
2004-02-16 20:55         ` Andrew Cagney
2004-02-18 16:59           ` Mark Kettenis
2004-02-18 18:40             ` Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200402152130.i1FLUvdB005788@elgar.kettenis.dyndns.org \
    --to=kettenis@chello.nl \
    --cc=cagney@gnu.org \
    --cc=drow@mvista.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox