]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
AArch64: Tidy up aarch64_gdbarch_init
authorAlan Hayward <alan.hayward@arm.com>
Mon, 15 Apr 2019 11:27:31 +0000 (12:27 +0100)
committerAlan Hayward <alan.hayward@arm.com>
Mon, 15 Apr 2019 14:12:43 +0000 (15:12 +0100)
Move the lookup_by_info to the top of the function to avoid unnecessarily
creating a new feature when the gdbarch already exists.

Add some additional cleanups that have no functional effect.

gdb/ChangeLog:

* aarch64-tdep.c (aarch64_gdbarch_init): Move gdbarch lookup.

gdb/ChangeLog
gdb/aarch64-tdep.c

index adafc198d8a87cfe47be452894c0ac4812f67efd..02e8feaca73df32359f9da969206f1c08ff59624 100644 (file)
@@ -1,3 +1,7 @@
+2019-04-15  Alan Hayward  <alan.hayward@arm.com>
+
+       * aarch64-tdep.c (aarch64_gdbarch_init): Move gdbarch lookup.
+
 2019-04-13  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * dwarf2read.c (dwarf2_init_complex_target_type): Handle complex
index 1b3977bfaf2095ec380ca711806cb82d301e193b..ea3f5ec5427233a6861b8c95f0672598c6844a90 100644 (file)
@@ -3192,36 +3192,37 @@ aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
 static struct gdbarch *
 aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 {
-  struct gdbarch_tdep *tdep;
-  struct gdbarch *gdbarch;
-  struct gdbarch_list *best_arch;
-  struct tdesc_arch_data *tdesc_data = NULL;
-  const struct target_desc *tdesc = info.target_desc;
-  int i;
-  int valid_p = 1;
-  const struct tdesc_feature *feature_core;
-  const struct tdesc_feature *feature_fpu;
-  const struct tdesc_feature *feature_sve;
+  const struct tdesc_feature *feature_core, *feature_fpu, *feature_sve;
   const struct tdesc_feature *feature_pauth;
-  int num_regs = 0;
-  int num_pseudo_regs = 0;
-  int first_pauth_regnum = -1;
-  int pauth_ra_state_offset = -1;
+  bool valid_p = true;
+  int i, num_regs = 0, num_pseudo_regs = 0;
+  int first_pauth_regnum = -1, pauth_ra_state_offset = -1;
+
+  /* If there is already a candidate, use it.  */
+  for (gdbarch_list *best_arch = gdbarch_list_lookup_by_info (arches, &info);
+       best_arch != nullptr;
+       best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
+    {
+      struct gdbarch_tdep *tdep = gdbarch_tdep (best_arch->gdbarch);
+      if (tdep)
+       return best_arch->gdbarch;
+    }
 
   /* Ensure we always have a target description.  */
+  const struct target_desc *tdesc = info.target_desc;
   if (!tdesc_has_registers (tdesc))
     tdesc = aarch64_read_description (0, false);
   gdb_assert (tdesc);
 
-  feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.core");
+  feature_core = tdesc_find_feature (tdesc,"org.gnu.gdb.aarch64.core");
   feature_fpu = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.fpu");
   feature_sve = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.sve");
   feature_pauth = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.pauth");
 
-  if (feature_core == NULL)
-    return NULL;
+  if (feature_core == nullptr)
+    return nullptr;
 
-  tdesc_data = tdesc_data_alloc ();
+  struct tdesc_arch_data *tdesc_data = tdesc_data_alloc ();
 
   /* Validate the description provides the mandatory core R registers
      and allocate their numbers.  */
@@ -3233,9 +3234,9 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   num_regs = AARCH64_X0_REGNUM + i;
 
   /* Add the V registers.  */
-  if (feature_fpu != NULL)
+  if (feature_fpu != nullptr)
     {
-      if (feature_sve != NULL)
+      if (feature_sve != nullptr)
        error (_("Program contains both fpu and SVE features."));
 
       /* Validate the description provides the mandatory V registers
@@ -3249,7 +3250,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     }
 
   /* Add the SVE registers.  */
-  if (feature_sve != NULL)
+  if (feature_sve != nullptr)
     {
       /* Validate the description provides the mandatory SVE registers
         and allocate their numbers.  */
@@ -3262,7 +3263,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       num_pseudo_regs += 32;   /* add the Vn register pseudos.  */
     }
 
-  if (feature_fpu != NULL || feature_sve != NULL)
+  if (feature_fpu != nullptr || feature_sve != nullptr)
     {
       num_pseudo_regs += 32;   /* add the Qn scalar register pseudos */
       num_pseudo_regs += 32;   /* add the Dn scalar register pseudos */
@@ -3290,30 +3291,14 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (!valid_p)
     {
       tdesc_data_cleanup (tdesc_data);
-      return NULL;
+      return nullptr;
     }
 
   /* AArch64 code is always little-endian.  */
   info.byte_order_for_code = BFD_ENDIAN_LITTLE;
 
-  /* If there is already a candidate, use it.  */
-  for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
-       best_arch != NULL;
-       best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
-    {
-      /* Found a match.  */
-      break;
-    }
-
-  if (best_arch != NULL)
-    {
-      if (tdesc_data != NULL)
-       tdesc_data_cleanup (tdesc_data);
-      return best_arch->gdbarch;
-    }
-
-  tdep = XCNEW (struct gdbarch_tdep);
-  gdbarch = gdbarch_alloc (&info, tdep);
+  struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep);
+  struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep);
 
   /* This should be low enough for everything.  */
   tdep->lowest_pc = 0x20;
@@ -3324,7 +3309,6 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   tdep->pauth_ra_state_regnum = (feature_pauth == NULL) ? -1
                                : pauth_ra_state_offset + num_regs;
 
-
   set_gdbarch_push_dummy_call (gdbarch, aarch64_push_dummy_call);
   set_gdbarch_frame_align (gdbarch, aarch64_frame_align);