]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/ppc-linux-nat.c
2.41 Release sources
[thirdparty/binutils-gdb.git] / gdb / ppc-linux-nat.c
index f1ba165d54054eea06e31b6f4ef6c0868f305491..d14aba694e539d182438207f1141ea799d8dc9b4 100644 (file)
@@ -1,6 +1,6 @@
 /* PPC GNU/Linux native support.
 
-   Copyright (C) 1988-2021 Free Software Foundation, Inc.
+   Copyright (C) 1988-2023 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -178,7 +178,6 @@ struct ppc_hw_breakpoint
 
    The layout is like this (where x is the actual value of the vscr reg): */
 
-/* *INDENT-OFF* */
 /*
 Big-Endian:
    |.|.|.|.|.....|.|.|.|.||.|.|.|x||.|
@@ -189,7 +188,6 @@ Little-Endian:
    <------->     <-------><-------><->
      VR0           VR31     VSCR    VRSAVE
 */
-/* *INDENT-ON* */
 
 typedef char gdb_vrregset_t[PPC_LINUX_SIZEOF_VRREGSET];
 
@@ -335,7 +333,7 @@ public:
 
   /* One and only one of these three functions returns true, indicating
      whether the corresponding interface is the one we detected.  The
-     interface must already have been detected as a precontidion.  */
+     interface must already have been detected as a precondition.  */
 
   bool hwdebug_p ()
   {
@@ -456,7 +454,7 @@ private:
 
      UNAVAILABLE can indicate that the kernel doesn't support any of the
      two sets of requests or that there was an error when we tried to
-     detect wich interface is available.  */
+     detect which interface is available.  */
 
   enum debug_reg_interface
     {
@@ -530,8 +528,8 @@ struct ppc_linux_nat_target final : public linux_nat_target
 
   const struct target_desc *read_description ()  override;
 
-  int auxv_parse (gdb_byte **readptr,
-                 gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+  int auxv_parse (const gdb_byte **readptr,
+                 const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
     override;
 
   /* Override linux_nat_target low methods.  */
@@ -628,7 +626,6 @@ private:
 
 static ppc_linux_nat_target the_ppc_linux_nat_target;
 
-/* *INDENT-OFF* */
 /* registers layout, as presented by the ptrace interface:
 PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
 PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15,
@@ -643,13 +640,12 @@ PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46,
 PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54,
 PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62,
 PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */
-/* *INDENT_ON * */
 
 static int
 ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
 {
   int u_addr = -1;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace
      interface, and not the wordsize of the program's ABI.  */
   int wordsize = sizeof (long);
@@ -802,7 +798,7 @@ static void
 fetch_spe_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct gdb_evrregset_t evrregs;
 
   gdb_assert (sizeof (evrregs.evr[0])
@@ -911,7 +907,7 @@ static void
 fetch_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   /* This isn't really an address.  But ptrace thinks of it as one.  */
   CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno);
   int bytes_transferred;
@@ -1113,8 +1109,7 @@ fetch_register (struct regcache *regcache, int tid, int regno)
       regcache->raw_supply (regno, buf + padding);
     }
   else 
-    internal_error (__FILE__, __LINE__,
-                   _("fetch_register: unexpected byte order: %d"),
+    internal_error (_("fetch_register: unexpected byte order: %d"),
                    gdbarch_byte_order (gdbarch));
 }
 
@@ -1138,7 +1133,7 @@ fetch_all_gp_regs (struct regcache *regcache, int tid)
          have_ptrace_getsetregs = 0;
          return 0;
        }
-      perror_with_name (_("Couldn't get general-purpose registers."));
+      perror_with_name (_("Couldn't get general-purpose registers"));
     }
 
   supply_gregset (regcache, (const gdb_gregset_t *) &gregset);
@@ -1156,7 +1151,7 @@ static void
 fetch_gp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1190,7 +1185,7 @@ fetch_all_fp_regs (struct regcache *regcache, int tid)
          have_ptrace_getsetfpregs = 0;
          return 0;
        }
-      perror_with_name (_("Couldn't get floating-point registers."));
+      perror_with_name (_("Couldn't get floating-point registers"));
     }
 
   supply_fpregset (regcache, (const gdb_fpregset_t *) &fpregs);
@@ -1208,7 +1203,7 @@ static void
 fetch_fp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1226,7 +1221,7 @@ static void
 fetch_ppc_registers (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   fetch_gp_regs (regcache, tid);
   if (tdep->ppc_fp0_regnum >= 0)
@@ -1425,7 +1420,7 @@ static void
 store_spe_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct gdb_evrregset_t evrregs;
 
   gdb_assert (sizeof (evrregs.evr[0])
@@ -1477,7 +1472,7 @@ static void
 store_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   /* This isn't really an address.  But ptrace thinks of it as one.  */
   CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno);
   int i;
@@ -1690,7 +1685,7 @@ store_all_gp_regs (const struct regcache *regcache, int tid, int regno)
          have_ptrace_getsetregs = 0;
          return 0;
        }
-      perror_with_name (_("Couldn't get general-purpose registers."));
+      perror_with_name (_("Couldn't get general-purpose registers"));
     }
 
   fill_gregset (regcache, &gregset, regno);
@@ -1702,7 +1697,7 @@ store_all_gp_regs (const struct regcache *regcache, int tid, int regno)
          have_ptrace_getsetregs = 0;
          return 0;
        }
-      perror_with_name (_("Couldn't set general-purpose registers."));
+      perror_with_name (_("Couldn't set general-purpose registers"));
     }
 
   return 1;
@@ -1718,7 +1713,7 @@ static void
 store_gp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1752,7 +1747,7 @@ store_all_fp_regs (const struct regcache *regcache, int tid, int regno)
          have_ptrace_getsetfpregs = 0;
          return 0;
        }
-      perror_with_name (_("Couldn't get floating-point registers."));
+      perror_with_name (_("Couldn't get floating-point registers"));
     }
 
   fill_fpregset (regcache, &fpregs, regno);
@@ -1764,7 +1759,7 @@ store_all_fp_regs (const struct regcache *regcache, int tid, int regno)
          have_ptrace_getsetfpregs = 0;
          return 0;
        }
-      perror_with_name (_("Couldn't set floating-point registers."));
+      perror_with_name (_("Couldn't set floating-point registers"));
     }
 
   return 1;
@@ -1780,7 +1775,7 @@ static void
 store_fp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1798,7 +1793,7 @@ static void
 store_ppc_registers (const struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
  
   store_gp_regs (regcache, tid, -1);
   if (tdep->ppc_fp0_regnum >= 0)
@@ -1915,8 +1910,8 @@ fill_fpregset (const struct regcache *regcache,
 }
 
 int
-ppc_linux_nat_target::auxv_parse (gdb_byte **readptr,
-                                 gdb_byte *endptr, CORE_ADDR *typep,
+ppc_linux_nat_target::auxv_parse (const gdb_byte **readptr,
+                                 const gdb_byte *endptr, CORE_ADDR *typep,
                                  CORE_ADDR *valp)
 {
   int tid = inferior_ptid.lwp ();
@@ -1926,7 +1921,7 @@ ppc_linux_nat_target::auxv_parse (gdb_byte **readptr,
   int sizeof_auxv_field = ppc_linux_target_wordsize (tid);
 
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
-  gdb_byte *ptr = *readptr;
+  const gdb_byte *ptr = *readptr;
 
   if (endptr == ptr)
     return 0;
@@ -1946,9 +1941,10 @@ ppc_linux_nat_target::auxv_parse (gdb_byte **readptr,
 const struct target_desc *
 ppc_linux_nat_target::read_description ()
 {
-  int tid = inferior_ptid.lwp ();
-  if (tid == 0)
-    tid = inferior_ptid.pid ();
+  if (inferior_ptid == null_ptid)
+    return this->beneath ()->read_description ();
+
+  int tid = inferior_ptid.pid ();
 
   if (have_ptrace_getsetevrregs)
     {
@@ -1967,8 +1963,8 @@ ppc_linux_nat_target::read_description ()
 
   features.wordsize = ppc_linux_target_wordsize (tid);
 
-  CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
-  CORE_ADDR hwcap2 = linux_get_hwcap2 (current_top_target ());
+  CORE_ADDR hwcap = linux_get_hwcap ();
+  CORE_ADDR hwcap2 = linux_get_hwcap2 ();
 
   if (have_ptrace_getsetvsxregs
       && (hwcap & PPC_FEATURE_HAS_VSX))
@@ -2125,7 +2121,7 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
         takes two hardware watchpoints though.  */
       if (len > 1
          && hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_RANGE
-         && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+         && (linux_get_hwcap () & PPC_FEATURE_BOOKE))
        return 2;
       /* Check if the processor provides DAWR interface.  */
       if (hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_DAWR)
@@ -2133,7 +2129,7 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
          /* DAWR interface allows to watch up to 512 byte wide ranges.  */
          region_size = 512;
          /* DAWR interface allows to watch up to 512 byte wide ranges which
-            can't cross a 512 byte bondary on machines that doesn't have a
+            can't cross a 512 byte boundary on machines that don't have a
             second DAWR (P9 or less).  */
          if (!(hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_ARCH_31))
            region_align = 512;
@@ -2153,7 +2149,7 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
     {
       gdb_assert (m_dreg_interface.debugreg_p ());
 
-      if (((linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+      if (((linux_get_hwcap () & PPC_FEATURE_BOOKE)
           && (addr + len) > (addr & ~3) + 4)
          || (addr + len) > (addr & ~7) + 8)
        return 0;
@@ -2458,14 +2454,14 @@ ppc_linux_nat_target::num_memory_accesses (const std::vector<value_ref_ptr>
       struct value *v = iter.get ();
 
       /* Constants and values from the history are fine.  */
-      if (VALUE_LVAL (v) == not_lval || deprecated_value_modifiable (v) == 0)
+      if (v->lval () == not_lval || !v->deprecated_modifiable ())
        continue;
-      else if (VALUE_LVAL (v) == lval_memory)
+      else if (v->lval () == lval_memory)
        {
          /* A lazy memory lvalue is one that GDB never needed to fetch;
             we either just used its address (e.g., `a' in `a.b') or
             we never needed it at all (e.g., `a' in `a,b').  */
-         if (!value_lazy (v))
+         if (!v->lazy ())
            found_memory_cnt++;
        }
       /* Other kinds of values are not fine.  */
@@ -2512,24 +2508,24 @@ ppc_linux_nat_target::check_condition (CORE_ADDR watch_addr,
     return 0;
 
   if (num_accesses_left == 1 && num_accesses_right == 0
-      && VALUE_LVAL (left_val) == lval_memory
-      && value_address (left_val) == watch_addr)
+      && left_val->lval () == lval_memory
+      && left_val->address () == watch_addr)
     {
       *data_value = value_as_long (right_val);
 
       /* DATA_VALUE is the constant in RIGHT_VAL, but actually has
         the same type as the memory region referenced by LEFT_VAL.  */
-      *len = TYPE_LENGTH (check_typedef (value_type (left_val)));
+      *len = check_typedef (left_val->type ())->length ();
     }
   else if (num_accesses_left == 0 && num_accesses_right == 1
-          && VALUE_LVAL (right_val) == lval_memory
-          && value_address (right_val) == watch_addr)
+          && right_val->lval () == lval_memory
+          && right_val->address () == watch_addr)
     {
       *data_value = value_as_long (left_val);
 
       /* DATA_VALUE is the constant in LEFT_VAL, but actually has
         the same type as the memory region referenced by RIGHT_VAL.  */
-      *len = TYPE_LENGTH (check_typedef (value_type (right_val)));
+      *len = check_typedef (right_val->type ())->length ();
     }
   else
     return 0;
@@ -2640,7 +2636,7 @@ ppc_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
       long wp_value;
       long read_mode, write_mode;
 
-      if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+      if (linux_get_hwcap () & PPC_FEATURE_BOOKE)
        {
          /* PowerPC 440 requires only the read/write flags to be passed
             to the kernel.  */
@@ -2740,7 +2736,7 @@ ppc_linux_nat_target::low_forget_process (pid_t pid)
 }
 
 /* Copy the per-process state associated with the pid of PARENT to the
-   sate of CHILD_PID.  GDB expects that a forked process will have the
+   state of CHILD_PID.  GDB expects that a forked process will have the
    same hardware breakpoints and watchpoints as the parent.
 
    If we're using the HWDEBUG interface, also copy the thread debug
@@ -2887,7 +2883,7 @@ ppc_linux_nat_target::low_prepare_to_resume (struct lwp_info *lp)
                  perror_with_name (_("Error deleting hardware "
                                      "breakpoint or watchpoint"));
 
-             /* We erase the entries one at a time after successfuly
+             /* We erase the entries one at a time after successfully
                 removing the corresponding slot form the thread so that
                 if we throw an exception above in a future iteration the
                 map remains consistent.  */
@@ -3013,9 +3009,9 @@ ppc_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
   int mask;
 
   if (m_dreg_interface.hwdebug_p ()
-      && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+      && (linux_get_hwcap () & PPC_FEATURE_BOOKE))
     return start <= addr && start + length >= addr;
-  else if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+  else if (linux_get_hwcap () & PPC_FEATURE_BOOKE)
     mask = 3;
   else
     mask = 7;