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]

[rfc] [10/15] Add gdbarch to register_name callback in PowerPC


Hi,

this patch adds gdbarch to register_name callback in rs6000-tdep.c. Also this patch replaces some trivial occurences of current_gdbarch. To do this alivec_register_p now has gdbarch as a parameter.

Is this ok to commit?

ChangeLog:


* rs6000-tdep.c (rs6000_register_name): Add gdbarch parameter. Replace current_gdbarch by gdbarch. (ppc_dwarf2_frame_init_reg): Replace current_gdbarch by gdbarch.

	(altivec_register_p): Add gdbarch parameter.
	* ppc-tdep.h (altivec_register_p): Likewise.
	* ppc-linux-nat.c (store_register. fetch_register, supply_vrregset)
	(fetch_ppc_registers, store_altivec_register, store_spe_register): Use
	get_regcache_arch to get at the current architecture by regcache.
	(store_register, fetch_register): Add gdbarch to altivec_register_p
	call.



--
Markus Deuling
GNU Toolchain for Linux on Cell BE
deuling@de.ibm.com





diff -urpN src/gdb/ppc-linux-nat.c dev/gdb/ppc-linux-nat.c
--- src/gdb/ppc-linux-nat.c	2007-10-15 21:49:53.000000000 +0200
+++ dev/gdb/ppc-linux-nat.c	2007-10-31 07:45:06.000000000 +0100
@@ -327,14 +327,15 @@ fetch_spe_register (struct regcache *reg
 static void
 fetch_register (struct regcache *regcache, int tid, int regno)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   /* This isn't really an address.  But ptrace thinks of it as one.  */
   CORE_ADDR regaddr = ppc_register_u_addr (regno);
   int bytes_transferred;
   unsigned int offset;         /* Offset of registers within the u area. */
   char buf[MAX_REGISTER_SIZE];
 
-  if (altivec_register_p (regno))
+  if (altivec_register_p (gdbarch, regno))
     {
       /* If this is the first time through, or if it is not the first
          time through, and we have comfirmed that there is kernel
@@ -357,7 +358,7 @@ fetch_register (struct regcache *regcach
 
   if (regaddr == -1)
     {
-      memset (buf, '\0', register_size (current_gdbarch, regno));   /* Supply zeroes */
+      memset (buf, '\0', register_size (gdbarch, regno));   /* Supply zeroes */
       regcache_raw_supply (regcache, regno, buf);
       return;
     }
@@ -366,7 +367,7 @@ fetch_register (struct regcache *regcach
      32-bit platform, 64-bit floating-point registers will require two
      transfers.  */
   for (bytes_transferred = 0;
-       bytes_transferred < register_size (current_gdbarch, regno);
+       bytes_transferred < register_size (gdbarch, regno);
        bytes_transferred += sizeof (long))
     {
       errno = 0;
@@ -377,7 +378,7 @@ fetch_register (struct regcache *regcach
 	{
           char message[128];
 	  sprintf (message, "reading register %s (#%d)", 
-		   gdbarch_register_name (current_gdbarch, regno), regno);
+		   gdbarch_register_name (gdbarch, regno), regno);
 	  perror_with_name (message);
 	}
     }
@@ -385,34 +386,35 @@ fetch_register (struct regcache *regcach
   /* Now supply the register.  Keep in mind that the regcache's idea
      of the register's size may not be a multiple of sizeof
      (long).  */
-  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_LITTLE)
+  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
     {
       /* Little-endian values are always found at the left end of the
          bytes transferred.  */
       regcache_raw_supply (regcache, regno, buf);
     }
-  else if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+  else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
     {
       /* Big-endian values are found at the right end of the bytes
          transferred.  */
       size_t padding = (bytes_transferred
-                        - register_size (current_gdbarch, regno));
+                        - register_size (gdbarch, regno));
       regcache_raw_supply (regcache, regno, buf + padding);
     }
   else 
     internal_error (__FILE__, __LINE__,
                     _("fetch_register: unexpected byte order: %d"),
-                    gdbarch_byte_order (current_gdbarch));
+                    gdbarch_byte_order (gdbarch));
 }
 
 static void
 supply_vrregset (struct regcache *regcache, gdb_vrregset_t *vrregsetp)
 {
   int i;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   int num_of_vrregs = tdep->ppc_vrsave_regnum - tdep->ppc_vr0_regnum + 1;
-  int vrregsize = register_size (current_gdbarch, tdep->ppc_vr0_regnum);
-  int offset = vrregsize - register_size (current_gdbarch, tdep->ppc_vrsave_regnum);
+  int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum);
+  int offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum);
 
   for (i = 0; i < num_of_vrregs; i++)
     {
@@ -452,14 +454,15 @@ static void 
 fetch_ppc_registers (struct regcache *regcache, int tid)
 {
   int i;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   for (i = 0; i < ppc_num_gprs; i++)
     fetch_register (regcache, tid, tdep->ppc_gp0_regnum + i);
   if (tdep->ppc_fp0_regnum >= 0)
     for (i = 0; i < ppc_num_fprs; i++)
       fetch_register (regcache, tid, tdep->ppc_fp0_regnum + i);
-  fetch_register (regcache, tid, gdbarch_pc_regnum (current_gdbarch));
+  fetch_register (regcache, tid, gdbarch_pc_regnum (gdbarch));
   if (tdep->ppc_ps_regnum != -1)
     fetch_register (regcache, tid, tdep->ppc_ps_regnum);
   if (tdep->ppc_cr_regnum != -1)
@@ -507,8 +510,9 @@ store_altivec_register (const struct reg
   int ret;
   int offset = 0;
   gdb_vrregset_t regs;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
-  int vrregsize = register_size (current_gdbarch, tdep->ppc_vr0_regnum);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum);
 
   ret = ptrace (PTRACE_GETVRREGS, tid, 0, &regs);
   if (ret < 0)
@@ -524,7 +528,7 @@ store_altivec_register (const struct reg
   /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes
      long on the hardware.  */
   if (regno == (tdep->ppc_vrsave_regnum - 1))
-    offset = vrregsize - register_size (current_gdbarch, tdep->ppc_vrsave_regnum);
+    offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum);
 
   regcache_raw_collect (regcache, regno,
 			regs + (regno - tdep->ppc_vr0_regnum) * vrregsize + offset);
@@ -569,15 +573,16 @@ set_spe_registers (int tid, struct gdb_e
 static void
 store_spe_register (const struct regcache *regcache, int tid, int regno)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   struct gdb_evrregset_t evrregs;
 
   gdb_assert (sizeof (evrregs.evr[0])
-              == register_size (current_gdbarch, tdep->ppc_ev0_upper_regnum));
+              == register_size (gdbarch, tdep->ppc_ev0_upper_regnum));
   gdb_assert (sizeof (evrregs.acc)
-              == register_size (current_gdbarch, tdep->ppc_acc_regnum));
+              == register_size (gdbarch, tdep->ppc_acc_regnum));
   gdb_assert (sizeof (evrregs.spefscr)
-              == register_size (current_gdbarch, tdep->ppc_spefscr_regnum));
+              == register_size (gdbarch, tdep->ppc_spefscr_regnum));
 
   if (regno == -1)
     /* Since we're going to write out every register, the code below
@@ -623,14 +628,15 @@ store_spe_register (const struct regcach
 static void
 store_register (const struct regcache *regcache, int tid, int regno)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   /* This isn't really an address.  But ptrace thinks of it as one.  */
   CORE_ADDR regaddr = ppc_register_u_addr (regno);
   int i;
   size_t bytes_to_transfer;
   char buf[MAX_REGISTER_SIZE];
 
-  if (altivec_register_p (regno))
+  if (altivec_register_p (gdbarch, regno))
     {
       store_altivec_register (regcache, tid, regno);
       return;
@@ -648,7 +654,7 @@ store_register (const struct regcache *r
      idea of the register's size may not be a multiple of sizeof
      (long).  */
   memset (buf, 0, sizeof buf);
-  bytes_to_transfer = align_up (register_size (current_gdbarch, regno),
+  bytes_to_transfer = align_up (register_size (gdbarch, regno),
                                 sizeof (long));
   if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_LITTLE)
     {
@@ -659,7 +665,7 @@ store_register (const struct regcache *r
     {
       /* Big-endian values sit at the right end of the buffer.  */
       size_t padding = (bytes_to_transfer
-                        - register_size (current_gdbarch, regno));
+                        - register_size (gdbarch, regno));
       regcache_raw_collect (regcache, regno, buf + padding);
     }
 
@@ -681,7 +687,7 @@ store_register (const struct regcache *r
 	{
           char message[128];
 	  sprintf (message, "writing register %s (#%d)", 
-		   gdbarch_register_name (current_gdbarch, regno), regno);
+		   gdbarch_register_name (gdbarch, regno), regno);
 	  perror_with_name (message);
 	}
     }
diff -urpN src/gdb/ppc-tdep.h dev/gdb/ppc-tdep.h
--- src/gdb/ppc-tdep.h	2007-10-31 05:54:46.000000000 +0100
+++ dev/gdb/ppc-tdep.h	2007-10-31 07:45:06.000000000 +0100
@@ -66,7 +66,7 @@ enum return_value_convention ppc64_sysv_
 							  const gdb_byte *writebuf);
 
 /* From rs6000-tdep.c... */
-int altivec_register_p (int regno);
+int altivec_register_p (struct gdbarch *gdbarch, int regno);
 int spe_register_p (int regno);
 
 /* Return non-zero if the architecture described by GDBARCH has
diff -urpN src/gdb/rs6000-tdep.c dev/gdb/rs6000-tdep.c
--- src/gdb/rs6000-tdep.c	2007-10-31 05:54:46.000000000 +0100
+++ dev/gdb/rs6000-tdep.c	2007-10-31 07:45:06.000000000 +0100
@@ -162,9 +162,9 @@ static CORE_ADDR skip_prologue (CORE_ADD
 
 /* Is REGNO an AltiVec register?  Return 1 if so, 0 otherwise.  */
 int
-altivec_register_p (int regno)
+altivec_register_p (struct gdbarch *gdbarch, int regno)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
     return 0;
   else
@@ -2355,9 +2355,9 @@ regsize (const struct reg *reg, int word
    is an anonymous register.  */
 
 static const char *
-rs6000_register_name (int regno)
+rs6000_register_name (struct gdbarch *gdbarch, int regno)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   /* The upper half "registers" have names in the XML description,
      but we present only the low GPRs and the full 64-bit registers
@@ -3142,9 +3142,9 @@ ppc_dwarf2_frame_init_reg (struct gdbarc
     }
 
   /* Handle PC register and Stack Pointer correctly.  */
-  if (regnum == gdbarch_pc_regnum (current_gdbarch))
+  if (regnum == gdbarch_pc_regnum (gdbarch))
     reg->how = DWARF2_FRAME_REG_RA;
-  else if (regnum == gdbarch_sp_regnum (current_gdbarch))
+  else if (regnum == gdbarch_sp_regnum (gdbarch))
     reg->how = DWARF2_FRAME_REG_CFA;
 }
 
--- src/gdb/rs6000-tdep.c	2007-10-31 05:54:46.000000000 +0100
+++ dev/gdb/rs6000-tdep.c	2007-10-31 08:59:15.000000000 +0100
@@ -2381,7 +2381,7 @@ rs6000_register_name (int regno)
       return spe_regnames[regno - tdep->ppc_ev0_regnum];
     }
 
-  return tdesc_register_name (regno);
+  return tdesc_register_name (gdbarch, regno);
 }
 
 /* Return the GDB type object for the "standard" data type of data in



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