Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <ac131313@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: [patch, rfc] Tweak trad-frame to reserve .addr == -1
Date: Sun, 29 Jun 2003 20:51:00 -0000	[thread overview]
Message-ID: <3EFF512B.9080706@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

Hello,

The attached tweaks trad-frame so that .addr==-1, instead of .addr==0, 
is used as a reserved value.

A common trick in existing code is to initially set .addr to a cardinal 
offset and then later add that to the inner-most stack address. 
Reserving .addr==0 precluded an edge case.  This adjusts things, at the 
same time adding predicate methods to test for the different possible 
trad-frame saved-reg states.

I'll commit this to the mainline in a few days,
Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 8143 bytes --]

2003-06-29  Andrew Cagney  <cagney@redhat.com>

	* trad-frame.h: Update comments - a -1 .addr is reserved.
	(trad_frame_value_p, trad_frame_addr_p): Declare.
	(trad_frame_reg_p): Declare.
	(trad_frame_set_value): Rename trad_frame_register_value.
	* trad-frame.c (trad_frame_realreg_p): New function.
	(trad_frame_addr_p, trad_frame_value_p): New function.
	(trad_frame_alloc_saved_regs): Initialize .addr to -1, not zero.
	(trad_frame_prev_register): Use trad_frame_realreg_p,
	trad_frame_addr_p and trad_frame_value_p.
	(trad_frame_set_value): Rename trad_frame_register_value.
	* d10v-tdep.c (d10v_frame_unwind_cache): Use trad_frame_addr_p
	and trad_frame_set_value.
	
Index: d10v-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
retrieving revision 1.125
diff -u -r1.125 d10v-tdep.c
--- d10v-tdep.c	13 Jun 2003 20:37:27 -0000	1.125
+++ d10v-tdep.c	29 Jun 2003 20:46:02 -0000
@@ -763,7 +763,7 @@
   /* Adjust all the saved registers so that they contain addresses and
      not offsets.  */
   for (i = 0; i < NUM_REGS - 1; i++)
-    if (info->saved_regs[i].addr)
+    if (trad_frame_addr_p (info->saved_regs, i))
       {
 	info->saved_regs[i].addr = (info->prev_sp + info->saved_regs[i].addr);
       }
@@ -776,8 +776,8 @@
 
   /* The previous frame's SP needed to be computed.  Save the computed
      value.  */
-  trad_frame_register_value (info->saved_regs, D10V_SP_REGNUM,
-			     d10v_make_daddr (prev_sp));
+  trad_frame_set_value (info->saved_regs, D10V_SP_REGNUM,
+			d10v_make_daddr (prev_sp));
 
   return info;
 }
Index: trad-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/trad-frame.c,v
retrieving revision 1.2
diff -u -r1.2 trad-frame.c
--- trad-frame.c	8 Jun 2003 22:10:12 -0000	1.2
+++ trad-frame.c	29 Jun 2003 20:46:04 -0000
@@ -38,17 +38,41 @@
   struct trad_frame_saved_reg *this_saved_regs
     = FRAME_OBSTACK_CALLOC (numregs, struct trad_frame_saved_reg);
   for (regnum = 0; regnum < numregs; regnum++)
-    this_saved_regs[regnum].realnum = regnum;
+    {
+      this_saved_regs[regnum].realreg = regnum;
+      this_saved_regs[regnum].addr = -1;
+    }      
   return this_saved_regs;
 }
 
+int
+trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
+{
+  return (this_saved_regs[regnum].realreg < 0);
+}
+
+int
+trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
+{
+  return (this_saved_regs[regnum].realreg >= 0
+	  && this_saved_regs[regnum].addr != -1);
+}
+
+int
+trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs[],
+		      int regnum)
+{
+  return (this_saved_regs[regnum].realreg >= 0
+	  && this_saved_regs[regnum].addr == -1);
+}
+
 void
-trad_frame_register_value (struct trad_frame_saved_reg this_saved_regs[],
-			   int regnum, LONGEST val)
+trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
+		      int regnum, LONGEST val)
 {
-  /* Make the REALNUM invalid, indicating that the ADDR contains the
+  /* Make the REALREG invalid, indicating that the ADDR contains the
      register's value.  */
-  this_saved_regs[regnum].realnum = -1;
+  this_saved_regs[regnum].realreg = -1;
   this_saved_regs[regnum].addr = val;
 }
 
@@ -57,17 +81,16 @@
 			  struct trad_frame_saved_reg this_saved_regs[],
 			  int regnum, int *optimizedp,
 			  enum lval_type *lvalp, CORE_ADDR *addrp,
-			  int *realnump, void *bufferp)
+			  int *realregp, void *bufferp)
 {
   struct gdbarch *gdbarch = get_frame_arch (next_frame);
-  if (this_saved_regs[regnum].realnum >= 0
-      && this_saved_regs[regnum].addr != 0)
+  if (trad_frame_addr_p (this_saved_regs, regnum))
     {
       /* The register was saved in memory.  */
       *optimizedp = 0;
       *lvalp = lval_memory;
       *addrp = this_saved_regs[regnum].addr;
-      *realnump = -1;
+      *realregp = -1;
       if (bufferp != NULL)
 	{
 	  /* Read the value in from memory.  */
@@ -75,22 +98,25 @@
 			    register_size (gdbarch, regnum));
 	}
     }
-  else if (this_saved_regs[regnum].realnum >= 0
-	   && this_saved_regs[regnum].addr == 0)
+  else if (trad_frame_realreg_p (this_saved_regs, regnum))
     {
       /* As the next frame to return the value of the register.  */
-      frame_register_unwind (next_frame, this_saved_regs[regnum].realnum,
-			     optimizedp, lvalp, addrp, realnump, bufferp);
+      frame_register_unwind (next_frame, this_saved_regs[regnum].realreg,
+			     optimizedp, lvalp, addrp, realregp, bufferp);
     }
-  else
+  else if (trad_frame_value_p (this_saved_regs, regnum))
     {
       /* The register's value is available.  */
       *optimizedp = 0;
       *lvalp = not_lval;
       *addrp = 0;
-      *realnump = -1;
+      *realregp = -1;
       if (bufferp != NULL)
 	store_unsigned_integer (bufferp, register_size (gdbarch, regnum),
 				this_saved_regs[regnum].addr);
+    }
+  else
+    {
+      error ("Register %s not available", REGISTER_NAME (regnum));
     }
 }
Index: trad-frame.h
===================================================================
RCS file: /cvs/src/src/gdb/trad-frame.h,v
retrieving revision 1.3
diff -u -r1.3 trad-frame.h
--- trad-frame.h	17 Jun 2003 19:00:20 -0000	1.3
+++ trad-frame.h	29 Jun 2003 20:46:04 -0000
@@ -28,33 +28,44 @@
    the value of REGNUM for the previous frame can be found in this
    frame.
 
-   The table is initialized with an identity encoding (ADDR == 0,
-   REALNUM == REGNUM) indicating that the value of REGNUM in the
-   previous frame can be found in register REGNUM (== REALNUM) in this
+   The table is initialized with an identity encoding (ADDR == -1,
+   REALREG == REGNUM) indicating that the value of REGNUM in the
+   previous frame can be found in register REGNUM (== REALREG) in this
    frame.
 
    The initial encoding can then be changed:
 
-   Modify ADDR (REALNUM >= 0, ADDR != 0) to indicate that the value of
-   register REGNUM in the previous frame can be found in memory at
-   ADDR in this frame.
-
-   Modify REALNUM (REALNUM >= 0, ADDR == 0) to indicate that the value
-   of register REGNUM in the previous frame is found in register
-   REALNUM in this frame.
-
-   Call trad_frame_register_value (REALNUM < 0) to indicate that the
-   value of register REGNUM in the previous frame is found in ADDR.  */
+   Modify ADDR (REALREG >= 0, ADDR != -1) to indicate that the value
+   of register REGNUM in the previous frame can be found in memory at
+   ADDR in this frame (addr_p, !realreg_p, !value_p).
+
+   Modify REALREG (REALREG >= 0, ADDR == -1) to indicate that the
+   value of register REGNUM in the previous frame is found in register
+   REALREG in this frame (!addr_p, realreg_p, !value_p).
+
+   Call trad_frame_register_value (REALREG < 0) to indicate that the
+   value of register REGNUM in the previous frame is found in ADDR
+   (!addr_p, !realreg_p, value_p).  */
 
 struct trad_frame_saved_reg
 {
   LONGEST addr; /* A CORE_ADDR fits in a longest.  */
-  int realnum;
+  int realreg;
 };
 
 /* Convenience function, encode REGNUM's location in the trad-frame.  */
-void trad_frame_register_value (struct trad_frame_saved_reg this_saved_regs[],
-				int regnum, LONGEST val);
+void trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
+			   int regnum, LONGEST val);
+
+/* Convenience functions, return non-zero if the register has been
+   encoded as specified.  */
+int trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs[],
+			int regnum);
+int trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs[],
+		       int regnum);
+int trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs[],
+			  int regnum);
+
 
 /* Return a freshly allocated (and initialized) trad_frame array.  */
 struct trad_frame_saved_reg *trad_frame_alloc_saved_regs (struct frame_info *next_frame);
@@ -65,6 +76,6 @@
 			       struct trad_frame_saved_reg this_saved_regs[],
 			       int regnum, int *optimizedp,
 			       enum lval_type *lvalp, CORE_ADDR *addrp,
-			       int *realnump, void *bufferp);
+			       int *realregp, void *bufferp);
 
 #endif

             reply	other threads:[~2003-06-29 20:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-29 20:51 Andrew Cagney [this message]
2003-06-29 21:03 ` Andrew Cagney
2003-07-01 21:34   ` 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=3EFF512B.9080706@redhat.com \
    --to=ac131313@redhat.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