From: Luis Machado Date: Thu, 30 Dec 2021 12:47:19 +0000 (-0300) Subject: Code cleanup and refactoring X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c9a3a5c7042c1301e17aa0e6e401af76db9132b1;p=thirdparty%2Fbinutils-gdb.git Code cleanup and refactoring A small refactoring to reduce duplication of code. --- diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index c1ab29094ec..5371cb75e68 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -1984,15 +1984,37 @@ struct aarch64_call_info std::vector 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.