]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Code cleanup and refactoring
authorLuis Machado <luis.machado@linaro.org>
Thu, 30 Dec 2021 12:47:19 +0000 (09:47 -0300)
committerLuis Machado <luis.machado@linaro.org>
Fri, 14 Jan 2022 14:30:18 +0000 (11:30 -0300)
A small refactoring to reduce duplication of code.

gdb/aarch64-tdep.c

index c1ab29094ec576005396f46d8cc7353ba27f742e..5371cb75e687ddf2cb490b1f40e3a129df736ad7 100644 (file)
@@ -1984,15 +1984,37 @@ struct aarch64_call_info
   std::vector<stack_item_t> si;
 };
 
+/* Helper function. Returns true if REGNUM is a tagged register, otherwise
+   returns false.  */
+
+static bool
+morello_is_tagged_register (struct gdbarch *gdbarch, int regnum)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  /* Only Morello's registers have tags.  */
+  if (!tdep->has_capability ())
+    return false;
+
+  /* The last two registers of the C register set don't have tags.  */
+  if (regnum < tdep->cap_reg_base ||
+      regnum > tdep->cap_reg_last - 2)
+    return false;
+
+  return true;
+}
+
 /* Implementation of the gdbarch_register_set_tag hook.  */
 
 static void
 aarch64_register_set_tag (struct gdbarch *gdbarch, struct regcache *regcache,
                          int regnum, bool tag)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  if (!morello_is_tagged_register (gdbarch, regnum))
+    return;
 
   CORE_ADDR tag_map = 0;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   /* Read the tag register, adjust and write back.  */
   regcache->cooked_read (tdep->cap_reg_last - 1, (gdb_byte *) &tag_map);
@@ -5232,15 +5254,7 @@ aarch64_register_has_tag (struct gdbarch *gdbarch,
   if (aarch64_debug)
     debug_printf ("%s: Entering\n", __func__);
 
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  /* Only Morello's registers have tags.  */
-  if (!tdep->has_capability ())
-    return false;
-
-  /* The last two registers of the C register set don't have tags.  */
-  if (regnum < tdep->cap_reg_base ||
-      regnum > tdep->cap_reg_last - 2)
+  if (!morello_is_tagged_register (gdbarch, regnum))
     return false;
 
   if (aarch64_debug)
@@ -5259,16 +5273,10 @@ aarch64_register_tag (struct gdbarch *gdbarch,
   if (aarch64_debug)
     debug_printf ("%s: Entering\n", __func__);
 
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  /* Only Morello's registers have tags.  */
-  if (!tdep->has_capability ())
+  if (!morello_is_tagged_register (gdbarch, regnum))
     return false;
 
-  /* The last two registers of the C register set don't have tags.  */
-  if (regnum < tdep->cap_reg_base ||
-      regnum > tdep->cap_reg_last - 2)
-    return false;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   /* The CSP/PCC tags are swapped in the tag_map because the ordering of CSP/PCC
      in struct user_morello_state is different from GDB's register description.