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] [07/12] Get rid of current_gdbarch in ppc-linux-nat.c


Hi,

this patch gets rid of some of the current_gdbarch's in ppc-linux-nat.c

Is this ok to commit?

ChangeLog:


* ppc-linux-nat.c (fetch_altivec_register, fetch_spe_register) (fetch_register, supply_vrregset, fetch_ppc_registers) (store_altivec_register, store_spe_register, store_register) (fill_vrregset, store_ppc_registers, right_fill_reg, fill_gregset) (fill_fpregset): Use FRAME or REGCACHE to recognize current architecture.


-- 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-06-19 05:22:04.000000000 +0200
+++ dev/gdb/ppc-linux-nat.c	2007-08-02 10:11:39.000000000 +0200
@@ -231,8 +231,9 @@ fetch_altivec_register (struct regcache 
   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)
@@ -250,7 +251,7 @@ fetch_altivec_register (struct regcache 
      vector.  VRSAVE is at the end of the array in a 4 bytes slot, so
      there is no need to define an offset for it.  */
   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_supply (regcache, regno,
 		       regs + (regno - tdep->ppc_vr0_regnum) * vrregsize + offset);
@@ -293,15 +294,16 @@ get_spe_registers (int tid, struct gdb_e
 static void
 fetch_spe_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);
   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));
 
   get_spe_registers (tid, &evrregs);
 
@@ -331,7 +333,8 @@ 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;
@@ -361,7 +364,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;
     }
@@ -370,7 +373,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;
@@ -381,7 +384,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);
 	}
     }
@@ -389,34 +392,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++)
     {
@@ -456,14 +460,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)
@@ -511,8 +516,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)
@@ -528,7 +534,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);
@@ -573,15 +579,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
@@ -627,7 +634,8 @@ 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;
@@ -652,18 +660,18 @@ 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)
+  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
     {
       /* Little-endian values always sit at the left end of the buffer.  */
       regcache_raw_collect (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 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);
     }
 
@@ -685,7 +693,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);
 	}
     }
@@ -695,10 +703,11 @@ static void
 fill_vrregset (const 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++)
     {
@@ -740,14 +749,15 @@ static void
 store_ppc_registers (const 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++)
     store_register (regcache, tid, tdep->ppc_gp0_regnum + i);
   if (tdep->ppc_fp0_regnum >= 0)
     for (i = 0; i < ppc_num_fprs; i++)
       store_register (regcache, tid, tdep->ppc_fp0_regnum + i);
-  store_register (regcache, tid, gdbarch_pc_regnum (current_gdbarch));
+  store_register (regcache, tid, gdbarch_pc_regnum (gdbarch));
   if (tdep->ppc_ps_regnum != -1)
     store_register (regcache, tid, tdep->ppc_ps_regnum);
   if (tdep->ppc_cr_regnum != -1)
@@ -923,7 +933,8 @@ right_fill_reg (const struct regcache *r
   regcache_raw_collect (regcache, regnum,
 			((bfd_byte *) reg
 			 + wordsize
-			 - register_size (current_gdbarch, regnum)));
+			 - register_size (get_regcache_arch (regcache),
+			regnum)));
 }
 
 void
@@ -931,8 +942,9 @@ fill_gregset (const struct regcache *reg
 	      gdb_gregset_t *gregsetp, int regno)
 {
   int regi;
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   elf_greg_t *regp = (elf_greg_t *) gregsetp;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   const int elf_ngreg = 48;
 
 
@@ -946,8 +958,8 @@ fill_gregset (const struct regcache *reg
 			(regp + PT_R0 + regi));
     }
 
-  if ((regno == -1) || regno == gdbarch_pc_regnum (current_gdbarch))
-    right_fill_reg (regcache, gdbarch_pc_regnum (current_gdbarch),
+  if ((regno == -1) || regno == gdbarch_pc_regnum (gdbarch))
+    right_fill_reg (regcache, gdbarch_pc_regnum (gdbarch),
 		    regp + PT_NIP);
   if ((regno == -1) || regno == tdep->ppc_lr_regnum)
     right_fill_reg (regcache, tdep->ppc_lr_regnum, regp + PT_LNK);
@@ -984,10 +996,11 @@ fill_fpregset (const struct regcache *re
 	       gdb_fpregset_t *fpregsetp, int regno)
 {
   int regi;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 
   bfd_byte *fpp = (void *) fpregsetp;
   
-  if (ppc_floating_point_unit_p (current_gdbarch))
+  if (ppc_floating_point_unit_p (gdbarch))
     {
       for (regi = 0; regi < ppc_num_fprs; regi++)
         {





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